We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Given a template and either an array or object output a string interpolated with values:
template
array
object
For example in Javascript one might implement it as follows:
registerFunction( 'format', ([template, templateStringsMap]) => { let newTemplate = template; for (const attr in templateStringsMap) { const rgx = new RegExp(`\\$\\{${attr}\\}`, 'g'); newTemplate = newTemplate.replace(rgx, templateStringsMap[attr] ?? ''); } return newTemplate; }, [{ types: [TYPE_STRING] }, { types: [TYPE_OBJECT, TYPE_ARRAY] }], );
Examples:
// With ARRAY input: jmespath.search( [1,"2", null, ["a", 2, "foo"], {b: "z"}, true, false], "format4('${0} | ${1} | ${2} | ${3} | ${4} | ${5} | ${6} | ${7}', @)" ) // OUTPUTS: '1 | 2 | null | a,2,foo | [object Object] | true | false | ${7}'
// With **OBJECT** input: jmespath.search( {foo: 'FOO', bar: null}, "format4('${foo} | ${bar} | ${baz}', @)" ); // OUTPUTS: 'FOO | null | 12 | ${baz}'
The text was updated successfully, but these errors were encountered:
format()
No branches or pull requests
Given a
template
and either anarray
orobject
output a string interpolated with values:For example in Javascript one might implement it as follows:
Examples:
The text was updated successfully, but these errors were encountered: