Skip to content

Commit 8cb217a

Browse files
committed
feat: add "json" mode;
- for JSON values only! - 240B // 330-340k op/s
1 parent 1762c15 commit 8cb217a

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ node_modules
55
*.log
66

77
/dist
8+
/json
89
/lite

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"dist"
1919
],
2020
"modes": {
21+
"json": "src/json.js",
2122
"default": "src/index.js",
2223
"lite": "src/lite.js"
2324
},

Diff for: src/json.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export function klona(val) {
2+
var k, out, tmp;
3+
4+
if (Array.isArray(val)) {
5+
out = Array(k=val.length);
6+
while (k--) out[k] = (tmp=val[k]) && typeof tmp === 'object' ? klona(tmp) : tmp;
7+
return out;
8+
}
9+
10+
if (Object.prototype.toString.call(val) === '[object Object]') {
11+
out = {}; // null
12+
for (k in val) {
13+
if (k === '__proto__') {
14+
Object.defineProperty(out, k, {
15+
value: klona(val[k]),
16+
configurable: true,
17+
enumerable: true,
18+
writable: true,
19+
});
20+
} else {
21+
out[k] = (tmp=val[k]) && typeof tmp === 'object' ? klona(tmp) : tmp;
22+
}
23+
}
24+
return out;
25+
}
26+
27+
return val;
28+
}

0 commit comments

Comments
 (0)