-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
71 lines (59 loc) · 952 Bytes
/
example.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"use strict";
var rename = require("./");
var a = [
{
"name": "Foo",
"amount": 55
},
{
"name": {
"name": 23
},
"amount": 33
},
{
"name": ["id", "name"]
},
{
"name": ["mystring", 1, {"name": "Bar"}]
}
];
var b = {
"home": {
"name": "Foo",
"amount": 55
},
"jlanza": {
"name": {
"name": 23
},
"amount": 33
},
"name": {
"name": {
"name": 23
},
"amount": 33
}};
var c = [ "name"];
var d = [{
"name": ["id", {"name": "Bar"}]
}];
function jlanza(key) {
return (key === "name") ? "ref" : key;
}
console.log("a-----------");
console.log(rename(a, jlanza));
console.log("\n");
console.log("b---------");
console.log(rename(b, jlanza));
console.log("\n");
console.log("c---------");
console.log(rename(c, jlanza));
console.log("\n");
console.log("d-----------");
console.log(d[0].name[1]["name"]);
console.log("-----------");
var d2 = rename(d, jlanza);
console.log(d2);
console.log(d2[0].ref[1]["ref"]);