mirror of
https://github.com/donl/JSON-js.git
synced 2026-06-30 06:11:58 -06:00
ternary
This commit is contained in:
parent
c07c287e39
commit
5b81c7b381
2 changed files with 18 additions and 16 deletions
17
json.js
17
json.js
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
json.js
|
||||
2014-02-25
|
||||
2015-05-01
|
||||
|
||||
Public Domain
|
||||
|
||||
|
|
@ -343,8 +343,8 @@ if (typeof JSON !== 'object') {
|
|||
v = partial.length === 0
|
||||
? '[]'
|
||||
: gap
|
||||
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
|
||||
: '[' + partial.join(',') + ']';
|
||||
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
|
||||
: '[' + partial.join(',') + ']';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
|
@ -386,8 +386,8 @@ if (typeof JSON !== 'object') {
|
|||
v = partial.length === 0
|
||||
? '{}'
|
||||
: gap
|
||||
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
|
||||
: '{' + partial.join(',') + '}';
|
||||
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
|
||||
: '{' + partial.join(',') + '}';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
|
@ -510,9 +510,10 @@ if (typeof JSON !== 'object') {
|
|||
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
||||
|
||||
if (/^[\],:{}\s]*$/.test(
|
||||
text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||
.replace(/(?:^|:|,)(?:\s*\[)+/g, '')
|
||||
text
|
||||
.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||
.replace(/(?:^|:|,)(?:\s*\[)+/g, '')
|
||||
)) {
|
||||
|
||||
// In the third stage we use the eval function to compile the text into a
|
||||
|
|
|
|||
17
json2.js
17
json2.js
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
json2.js
|
||||
2015-02-25
|
||||
2015-05-01
|
||||
|
||||
Public Domain.
|
||||
|
||||
|
|
@ -311,8 +311,8 @@ if (typeof JSON !== 'object') {
|
|||
v = partial.length === 0
|
||||
? '[]'
|
||||
: gap
|
||||
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
|
||||
: '[' + partial.join(',') + ']';
|
||||
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
|
||||
: '[' + partial.join(',') + ']';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
|
@ -358,8 +358,8 @@ if (typeof JSON !== 'object') {
|
|||
v = partial.length === 0
|
||||
? '{}'
|
||||
: gap
|
||||
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
|
||||
: '{' + partial.join(',') + '}';
|
||||
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
|
||||
: '{' + partial.join(',') + '}';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
|
@ -483,9 +483,10 @@ if (typeof JSON !== 'object') {
|
|||
|
||||
if (
|
||||
/^[\],:{}\s]*$/.test(
|
||||
text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||
.replace(/(?:^|:|,)(?:\s*\[)+/g, '')
|
||||
text
|
||||
.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
|
||||
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
|
||||
.replace(/(?:^|:|,)(?:\s*\[)+/g, '')
|
||||
)
|
||||
) {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue