2021-01-21 12:30:53 +01:00
|
|
|
const ALPHA_NUMERIC_REGEX = /^[A-Za-z0-9]+$/g
|
|
|
|
|
2021-01-25 19:14:45 +01:00
|
|
|
module.exports.FIND_HBS_REGEX = /{{([^{].*?)}}/g
|
2022-02-03 19:26:26 +01:00
|
|
|
module.exports.FIND_DOUBLE_HBS_REGEX = /(?<!{){{[^{}]+}}(?!})/g
|
2021-01-21 12:30:53 +01:00
|
|
|
|
2021-05-04 12:32:22 +02:00
|
|
|
module.exports.isAlphaNumeric = char => {
|
2021-01-21 12:30:53 +01:00
|
|
|
return char.match(ALPHA_NUMERIC_REGEX)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.swapStrings = (string, start, length, swap) => {
|
|
|
|
return string.slice(0, start) + swap + string.slice(start + length)
|
|
|
|
}
|
|
|
|
|
2021-12-06 18:58:43 +01:00
|
|
|
module.exports.removeHandlebarsStatements = (
|
|
|
|
string,
|
|
|
|
replacement = "Invalid binding"
|
|
|
|
) => {
|
2021-02-03 14:04:19 +01:00
|
|
|
let regexp = new RegExp(exports.FIND_HBS_REGEX)
|
|
|
|
let matches = string.match(regexp)
|
|
|
|
if (matches == null) {
|
|
|
|
return string
|
|
|
|
}
|
|
|
|
for (let match of matches) {
|
|
|
|
const idx = string.indexOf(match)
|
2021-12-06 18:58:43 +01:00
|
|
|
string = exports.swapStrings(string, idx, match.length, replacement)
|
2021-02-03 14:04:19 +01:00
|
|
|
}
|
|
|
|
return string
|
|
|
|
}
|
2021-10-14 12:51:05 +02:00
|
|
|
|
|
|
|
module.exports.btoa = plainText => {
|
|
|
|
return Buffer.from(plainText, "utf-8").toString("base64")
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.atob = base64 => {
|
|
|
|
return Buffer.from(base64, "base64").toString("utf-8")
|
|
|
|
}
|