terran-source / interpolate-json Goto Github PK
View Code? Open in Web Editor NEWInterpolate a Javascript Object or string with json - Advanced
Home Page: https://www.npmjs.com/package/interpolate-json
License: MIT License
Interpolate a Javascript Object or string with json - Advanced
Home Page: https://www.npmjs.com/package/interpolate-json
License: MIT License
I'm probably doing something wrong but here is my code below
`inputData[itemIndex] = {
json: {
timestamp: '2023-03-17T17:20:42.093+00:00',
'Readable date': 'March 17th 2023, 5:20:42 pm',
'Readable time': '5:20:42 pm',
'Day of week': 'Friday',
Year: '2023',
Month: 'March',
'Day of month': '17',
Hour: '17',
Minute: '20',
Second: '42',
Timezone: 'GMT +00:00'
}
}
const paramterValue = [ { value1: '{{json.Minute}}', operation: 'equal', value2: '20' } ]
const paramterNew = interpolation.expand(parameterValue, inputData[itemIndex], {prefix: "{{",suffix: "}}",});
`
This does not replace the {{json.Minute}} template with the value 20
Any help greatly apreciated
Describe the bug
reading a json string values substitution with only one entry seems to fail, returning the ${variable} within the original string.
Using two or more works as expected, even if the second variable does not exist within the values json
To Reproduce
Steps to reproduce the behavior:
Code snippet:
`'const {interpolation} = require('interpolate-json');
// interpolation.debug();
var json1 = {variable: "test ${one}, ${two}, ${three}"};
//this works as expected
console.log("result 1");
console.log(interpolation.expand(json1, {one : "test1", two: "test2", three: "test3"}));
//this one fails
console.log("result 2");
console.log(interpolation.expand("this is ${language}" , {language: "english"}));
//same as above, just adding a second value, it works
console.log("result 3");
console.log(interpolation.expand("this is ${language} ${nowitworks}" , {language: "english", nowitworks:"ofcourse"}));
//correctly supresses the ${a} value and correctly replaces ${thing}
console.log("result 4");
console.log(interpolation.expand("${thing} it works without value ${a}" , {thing: "there is only one"}));
'2. Run command:
$ ....3. Error:
Exception:...`
Expected behavior
console.log(interpolation.expand("this is ${language}" , {language: "english"}));
should output
"this is english"
Environment (please complete the following information):
Additional context
nothing else, this library is exactly what i need but its not working for that specific case.
workaround: just add a ${x} at the end as a white space:
interpolation.expand( localeStrings.settinglanguage+"${a}", {language: lang_name} )
Describe the bug
The interpolation is not working when using dashes.
To Reproduce
Steps to reproduce the behavior:
interpolation.expand('http://${my-domain}/whatever/', {'my-domain': 'example.com'})
The output is still "http://${my-domain}/whatever/"
Expected behavior
I would expect to have "${my-domain}" replaced by "example.com".
Environment (please complete the following information):
The expand method is not able to replace templates located within strings nested in arrays. Support seems to be only for JSON objects that don't have any data nested in arrays.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.