1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00
budibase/packages/string-templates/src/utilities.js

24 lines
615 B
JavaScript
Raw Normal View History

const ALPHA_NUMERIC_REGEX = /^[A-Za-z0-9]+$/g
module.exports.FIND_HBS_REGEX = /{{([^{}])+}}/g
2021-01-22 00:32:26 +13:00
module.exports.isAlphaNumeric = char => {
return char.match(ALPHA_NUMERIC_REGEX)
}
module.exports.swapStrings = (string, start, length, swap) => {
return string.slice(0, start) + swap + string.slice(start + length)
}
// removes null and undefined
module.exports.removeNull = obj => {
return Object.fromEntries(
Object.entries(obj)
2021-01-22 07:08:04 +13:00
.filter(entry => entry[1] != null)
.map(([key, value]) => [
key,
value === Object(value) ? module.exports.removeNull(value) : value,
])
)
}