-
Notifications
You must be signed in to change notification settings - Fork 0
/
t.js
47 lines (44 loc) · 1.32 KB
/
t.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//const tempalte = require("json-templater")
var jsonpatch =require("jsonpatch");
var render = require('json-templater/string');
console.log(render('<div class="font-size:{{size}}">{{xfoo}} {{say.what}}</div>', { xfoo: 'yep', say: { what: 'yep' },size:"100px" }));
var object = require('json-templater/object');
var template={
"magic_key_{{magic}}": {
"key": "interpolation is nice {{value}}"
},
"appname_{{name}}":{
"value":"{{name}}"
},
"appinfo":"{{appinfo}}",
"appversion":"{{appversion}}",
"biscuits":"{{biscuits}}"
}
var deprecateditems={
"appinfo":true,
"appurl":false
}
var oldob= {
name:"dalong",
age:333,
appinfo:"demoapp",
magic: 'key',
value: 'value'
}
console.log(object(
template,
jsonpatch.apply_patch(oldob,
[
{ "op": "replace", "path": "/name", "value": "boo" },
{ "op": "move", "from": "/appinfo", "path": "/appversion"},
{ "op": "add", "path": "/biscuits",value:[] },
{ "op": "add", "path": "/biscuits/0", "value": { "name": "dalong" } },
{ "op": "add", "path": "/biscuits/1", "value": { "name": "appdemo" } },
{ "op": "copy", "from": "/biscuits", "path": "/newbiscuits" }
]),
function(value, data, key){
if(deprecateditems[key]) {
return "my default value"
}
return render(value, data);
}));