Skip to content

Commit 0b3b4ee

Browse files
author
Peter Svetlichny
committed
chore(misc): minor updates
1 parent b363af8 commit 0b3b4ee

File tree

442 files changed

+97573
-31
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

442 files changed

+97573
-31
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
build/
21
node_modules/
32
logs/
43
**/*.log

.npmignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
dockerfiles
2-
test
3-
src
42
.gitignore
5-
.jshintrc
3+
.jshintrc
4+
coverage

.yarn-cache/npm-circular-json-0.3.3-815c99ea84f6809529d2f45791bdf82711352d66/build/circular-json.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/*!
2+
Copyright (C) 2013 by WebReflection
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.
21+
22+
*/
23+
var CircularJSON = (function(JSON, RegExp){
24+
var
25+
// should be a not so common char
26+
// possibly one JSON does not encode
27+
// possibly one encodeURIComponent does not encode
28+
// right now this char is '~' but this might change in the future
29+
specialChar = '~',
30+
safeSpecialChar = '\\x' + (
31+
'0' + specialChar.charCodeAt(0).toString(16)
32+
).slice(-2),
33+
escapedSafeSpecialChar = '\\' + safeSpecialChar,
34+
specialCharRG = new RegExp(safeSpecialChar, 'g'),
35+
safeSpecialCharRG = new RegExp(escapedSafeSpecialChar, 'g'),
36+
37+
safeStartWithSpecialCharRG = new RegExp('(?:^|([^\\\\]))' + escapedSafeSpecialChar),
38+
39+
indexOf = [].indexOf || function(v){
40+
for(var i=this.length;i--&&this[i]!==v;);
41+
return i;
42+
},
43+
$String = String // there's no way to drop warnings in JSHint
44+
// about new String ... well, I need that here!
45+
// faked, and happy linter!
46+
;
47+
48+
function generateReplacer(value, replacer, resolve) {
49+
var
50+
path = [],
51+
all = [value],
52+
seen = [value],
53+
mapp = [resolve ? specialChar : '[Circular]'],
54+
last = value,
55+
lvl = 1,
56+
i
57+
;
58+
return function(key, value) {
59+
// the replacer has rights to decide
60+
// if a new object should be returned
61+
// or if there's some key to drop
62+
// let's call it here rather than "too late"
63+
if (replacer) value = replacer.call(this, key, value);
64+
65+
// did you know ? Safari passes keys as integers for arrays
66+
// which means if (key) when key === 0 won't pass the check
67+
if (key !== '') {
68+
if (last !== this) {
69+
i = lvl - indexOf.call(all, this) - 1;
70+
lvl -= i;
71+
all.splice(lvl, all.length);
72+
path.splice(lvl - 1, path.length);
73+
last = this;
74+
}
75+
// console.log(lvl, key, path);
76+
if (typeof value === 'object' && value) {
77+
// if object isn't referring to parent object, add to the
78+
// object path stack. Otherwise it is already there.
79+
if (indexOf.call(all, value) < 0) {
80+
all.push(last = value);
81+
}
82+
lvl = all.length;
83+
i = indexOf.call(seen, value);
84+
if (i < 0) {
85+
i = seen.push(value) - 1;
86+
if (resolve) {
87+
// key cannot contain specialChar but could be not a string
88+
path.push(('' + key).replace(specialCharRG, safeSpecialChar));
89+
mapp[i] = specialChar + path.join(specialChar);
90+
} else {
91+
mapp[i] = mapp[0];
92+
}
93+
} else {
94+
value = mapp[i];
95+
}
96+
} else {
97+
if (typeof value === 'string' && resolve) {
98+
// ensure no special char involved on deserialization
99+
// in this case only first char is important
100+
// no need to replace all value (better performance)
101+
value = value .replace(safeSpecialChar, escapedSafeSpecialChar)
102+
.replace(specialChar, safeSpecialChar);
103+
}
104+
}
105+
}
106+
return value;
107+
};
108+
}
109+
110+
function retrieveFromPath(current, keys) {
111+
for(var i = 0, length = keys.length; i < length; current = current[
112+
// keys should be normalized back here
113+
keys[i++].replace(safeSpecialCharRG, specialChar)
114+
]);
115+
return current;
116+
}
117+
118+
function generateReviver(reviver) {
119+
return function(key, value) {
120+
var isString = typeof value === 'string';
121+
if (isString && value.charAt(0) === specialChar) {
122+
return new $String(value.slice(1));
123+
}
124+
if (key === '') value = regenerate(value, value, {});
125+
// again, only one needed, do not use the RegExp for this replacement
126+
// only keys need the RegExp
127+
if (isString) value = value .replace(safeStartWithSpecialCharRG, '$1' + specialChar)
128+
.replace(escapedSafeSpecialChar, safeSpecialChar);
129+
return reviver ? reviver.call(this, key, value) : value;
130+
};
131+
}
132+
133+
function regenerateArray(root, current, retrieve) {
134+
for (var i = 0, length = current.length; i < length; i++) {
135+
current[i] = regenerate(root, current[i], retrieve);
136+
}
137+
return current;
138+
}
139+
140+
function regenerateObject(root, current, retrieve) {
141+
for (var key in current) {
142+
if (current.hasOwnProperty(key)) {
143+
current[key] = regenerate(root, current[key], retrieve);
144+
}
145+
}
146+
return current;
147+
}
148+
149+
function regenerate(root, current, retrieve) {
150+
return current instanceof Array ?
151+
// fast Array reconstruction
152+
regenerateArray(root, current, retrieve) :
153+
(
154+
current instanceof $String ?
155+
(
156+
// root is an empty string
157+
current.length ?
158+
(
159+
retrieve.hasOwnProperty(current) ?
160+
retrieve[current] :
161+
retrieve[current] = retrieveFromPath(
162+
root, current.split(specialChar)
163+
)
164+
) :
165+
root
166+
) :
167+
(
168+
current instanceof Object ?
169+
// dedicated Object parser
170+
regenerateObject(root, current, retrieve) :
171+
// value as it is
172+
current
173+
)
174+
)
175+
;
176+
}
177+
178+
function stringifyRecursion(value, replacer, space, doNotResolve) {
179+
return JSON.stringify(value, generateReplacer(value, replacer, !doNotResolve), space);
180+
}
181+
182+
function parseRecursion(text, reviver) {
183+
return JSON.parse(text, generateReviver(reviver));
184+
}
185+
return {
186+
stringify: stringifyRecursion,
187+
parse: parseRecursion
188+
};
189+
}(JSON, RegExp));
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
/*!
2+
Copyright (C) 2013 by WebReflection
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.
21+
22+
*/
23+
var
24+
// should be a not so common char
25+
// possibly one JSON does not encode
26+
// possibly one encodeURIComponent does not encode
27+
// right now this char is '~' but this might change in the future
28+
specialChar = '~',
29+
safeSpecialChar = '\\x' + (
30+
'0' + specialChar.charCodeAt(0).toString(16)
31+
).slice(-2),
32+
escapedSafeSpecialChar = '\\' + safeSpecialChar,
33+
specialCharRG = new RegExp(safeSpecialChar, 'g'),
34+
safeSpecialCharRG = new RegExp(escapedSafeSpecialChar, 'g'),
35+
36+
safeStartWithSpecialCharRG = new RegExp('(?:^|([^\\\\]))' + escapedSafeSpecialChar),
37+
38+
indexOf = [].indexOf || function(v){
39+
for(var i=this.length;i--&&this[i]!==v;);
40+
return i;
41+
},
42+
$String = String // there's no way to drop warnings in JSHint
43+
// about new String ... well, I need that here!
44+
// faked, and happy linter!
45+
;
46+
47+
function generateReplacer(value, replacer, resolve) {
48+
var
49+
path = [],
50+
all = [value],
51+
seen = [value],
52+
mapp = [resolve ? specialChar : '[Circular]'],
53+
last = value,
54+
lvl = 1,
55+
i
56+
;
57+
return function(key, value) {
58+
// the replacer has rights to decide
59+
// if a new object should be returned
60+
// or if there's some key to drop
61+
// let's call it here rather than "too late"
62+
if (replacer) value = replacer.call(this, key, value);
63+
64+
// did you know ? Safari passes keys as integers for arrays
65+
// which means if (key) when key === 0 won't pass the check
66+
if (key !== '') {
67+
if (last !== this) {
68+
i = lvl - indexOf.call(all, this) - 1;
69+
lvl -= i;
70+
all.splice(lvl, all.length);
71+
path.splice(lvl - 1, path.length);
72+
last = this;
73+
}
74+
// console.log(lvl, key, path);
75+
if (typeof value === 'object' && value) {
76+
// if object isn't referring to parent object, add to the
77+
// object path stack. Otherwise it is already there.
78+
if (indexOf.call(all, value) < 0) {
79+
all.push(last = value);
80+
}
81+
lvl = all.length;
82+
i = indexOf.call(seen, value);
83+
if (i < 0) {
84+
i = seen.push(value) - 1;
85+
if (resolve) {
86+
// key cannot contain specialChar but could be not a string
87+
path.push(('' + key).replace(specialCharRG, safeSpecialChar));
88+
mapp[i] = specialChar + path.join(specialChar);
89+
} else {
90+
mapp[i] = mapp[0];
91+
}
92+
} else {
93+
value = mapp[i];
94+
}
95+
} else {
96+
if (typeof value === 'string' && resolve) {
97+
// ensure no special char involved on deserialization
98+
// in this case only first char is important
99+
// no need to replace all value (better performance)
100+
value = value .replace(safeSpecialChar, escapedSafeSpecialChar)
101+
.replace(specialChar, safeSpecialChar);
102+
}
103+
}
104+
}
105+
return value;
106+
};
107+
}
108+
109+
function retrieveFromPath(current, keys) {
110+
for(var i = 0, length = keys.length; i < length; current = current[
111+
// keys should be normalized back here
112+
keys[i++].replace(safeSpecialCharRG, specialChar)
113+
]);
114+
return current;
115+
}
116+
117+
function generateReviver(reviver) {
118+
return function(key, value) {
119+
var isString = typeof value === 'string';
120+
if (isString && value.charAt(0) === specialChar) {
121+
return new $String(value.slice(1));
122+
}
123+
if (key === '') value = regenerate(value, value, {});
124+
// again, only one needed, do not use the RegExp for this replacement
125+
// only keys need the RegExp
126+
if (isString) value = value .replace(safeStartWithSpecialCharRG, '$1' + specialChar)
127+
.replace(escapedSafeSpecialChar, safeSpecialChar);
128+
return reviver ? reviver.call(this, key, value) : value;
129+
};
130+
}
131+
132+
function regenerateArray(root, current, retrieve) {
133+
for (var i = 0, length = current.length; i < length; i++) {
134+
current[i] = regenerate(root, current[i], retrieve);
135+
}
136+
return current;
137+
}
138+
139+
function regenerateObject(root, current, retrieve) {
140+
for (var key in current) {
141+
if (current.hasOwnProperty(key)) {
142+
current[key] = regenerate(root, current[key], retrieve);
143+
}
144+
}
145+
return current;
146+
}
147+
148+
function regenerate(root, current, retrieve) {
149+
return current instanceof Array ?
150+
// fast Array reconstruction
151+
regenerateArray(root, current, retrieve) :
152+
(
153+
current instanceof $String ?
154+
(
155+
// root is an empty string
156+
current.length ?
157+
(
158+
retrieve.hasOwnProperty(current) ?
159+
retrieve[current] :
160+
retrieve[current] = retrieveFromPath(
161+
root, current.split(specialChar)
162+
)
163+
) :
164+
root
165+
) :
166+
(
167+
current instanceof Object ?
168+
// dedicated Object parser
169+
regenerateObject(root, current, retrieve) :
170+
// value as it is
171+
current
172+
)
173+
)
174+
;
175+
}
176+
177+
function stringifyRecursion(value, replacer, space, doNotResolve) {
178+
return JSON.stringify(value, generateReplacer(value, replacer, !doNotResolve), space);
179+
}
180+
181+
function parseRecursion(text, reviver) {
182+
return JSON.parse(text, generateReviver(reviver));
183+
}
184+
this.stringify = stringifyRecursion;
185+
this.parse = parseRecursion;

0 commit comments

Comments
 (0)