replaceallstr and replaceallregexp JEXL transformations not working
We have the following functions JEXL transformations in lib/jexlTranformsMap.js
replaceallstr: (str, from, to) => str.replaceAll(from, to),
replaceallregexp: (str, reg, to) => str.replaceAll(new RegExp(reg, 'g'), to),
Both are using str.replaceAll()
However, according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#browser_compatibility str.replaceAll() is not supported in Nodejs until v15. Currently we have >=12 in packages.json (and v14 in Dockerfile).
We should check if they replaceallstr and replaceallregexp JEXL transformation are actually working. In negative case, I'd suggest to disable them commenting out in that file with a FIXME mark about it, to be re-enabled once we update node to v16.
replaceAll is still working ini nodejs v16:
node Welcome to Node.js v16.16.0. Type ".help" for more information.
var a = "33" undefined a.replaceAll('3','c') 'cc'
const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?'; undefined
console.log(p.replaceAll('dog', 'monkey')); The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy? undefined // expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?" undefined
// global flag required when calling replaceAll with regex undefined const regex = /Dog/ig; undefined console.log(p.replaceAll(regex, 'ferret')); The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy? undefined // expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?" undefined
replaceAll is still working ini nodejs v16:
Note we have >=12 in packages.json. Thus, if we upgrade to >=16 I think we could close this issue without any further action.
Currently we are using nodejs 16 or upper: https://github.com/telefonicaid/iotagent-node-lib/blob/7b7c9506bec8db6a29ac8ef3a193e969f09334e6/package.json#L25-L27
so, can we close this issue @fgalan ?