mirror of
https://github.com/musix-org/musix-oss
synced 2025-06-16 22:06:01 +00:00
Modules
This commit is contained in:
16
node_modules/json-bigint/.npmignore
generated
vendored
Normal file
16
node_modules/json-bigint/.npmignore
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
lib-cov
|
||||
*.seed
|
||||
*.log
|
||||
*.csv
|
||||
*.dat
|
||||
*.out
|
||||
*.pid
|
||||
*.gz
|
||||
.*.swp
|
||||
node_modules
|
||||
|
||||
pids
|
||||
logs
|
||||
results
|
||||
|
||||
npm-debug.log
|
4
node_modules/json-bigint/.travis.yml
generated
vendored
Normal file
4
node_modules/json-bigint/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
- "0.11"
|
20
node_modules/json-bigint/LICENSE
generated
vendored
Normal file
20
node_modules/json-bigint/LICENSE
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Andrey Sidorov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
117
node_modules/json-bigint/README.md
generated
vendored
Normal file
117
node_modules/json-bigint/README.md
generated
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
json-bigint
|
||||
===========
|
||||
|
||||
[](http://travis-ci.org/sidorares/json-bigint)
|
||||
[](https://nodei.co/npm/json-bigint/)
|
||||
|
||||
JSON.parse/stringify with bigints support. Based on Douglas Crockford [JSON.js](https://github.com/douglascrockford/JSON-js) package and [bignumber.js](https://github.com/MikeMcl/bignumber.js) library.
|
||||
|
||||
While most JSON parsers assume numeric values have same precision restrictions as IEEE 754 double, JSON specification _does not_ say anything about number precision. Any floating point number in decimal (optionally scientific) notation is valid JSON value. It's a good idea to serialize values which might fall out of IEEE 754 integer precision as strings in your JSON api, but `{ "value" : 9223372036854775807}`, for example, is still a valid RFC4627 JSON string, and in most JS runtimes the result of `JSON.parse` is this object: `{ value: 9223372036854776000 }`
|
||||
|
||||
==========
|
||||
|
||||
example:
|
||||
|
||||
```js
|
||||
var JSONbig = require('json-bigint');
|
||||
|
||||
var json = '{ "value" : 9223372036854775807, "v2": 123 }';
|
||||
console.log('Input:', json);
|
||||
console.log('');
|
||||
|
||||
console.log('node.js bult-in JSON:')
|
||||
var r = JSON.parse(json);
|
||||
console.log('JSON.parse(input).value : ', r.value.toString());
|
||||
console.log('JSON.stringify(JSON.parse(input)):', JSON.stringify(r));
|
||||
|
||||
console.log('\n\nbig number JSON:');
|
||||
var r1 = JSONbig.parse(json);
|
||||
console.log('JSON.parse(input).value : ', r1.value.toString());
|
||||
console.log('JSON.stringify(JSON.parse(input)):', JSONbig.stringify(r1));
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```
|
||||
Input: { "value" : 9223372036854775807, "v2": 123 }
|
||||
|
||||
node.js bult-in JSON:
|
||||
JSON.parse(input).value : 9223372036854776000
|
||||
JSON.stringify(JSON.parse(input)): {"value":9223372036854776000,"v2":123}
|
||||
|
||||
|
||||
big number JSON:
|
||||
JSON.parse(input).value : 9223372036854775807
|
||||
JSON.stringify(JSON.parse(input)): {"value":9223372036854775807,"v2":123}
|
||||
```
|
||||
### Options
|
||||
The behaviour of the parser is somewhat configurable through 'options'
|
||||
|
||||
#### options.strict, boolean, default false
|
||||
Specifies the parsing should be "strict" towards reporting duplicate-keys in the parsed string.
|
||||
The default follows what is allowed in standard json and resembles the behavior of JSON.parse, but overwrites any previous values with the last one assigned to the duplicate-key.
|
||||
|
||||
Setting options.strict = true will fail-fast on such duplicate-key occurances and thus warn you upfront of possible lost information.
|
||||
|
||||
example:
|
||||
```js
|
||||
var JSONbig = require('json-bigint');
|
||||
var JSONstrict = require('json-bigint')({"strict": true});
|
||||
|
||||
var dupkeys = '{ "dupkey": "value 1", "dupkey": "value 2"}';
|
||||
console.log('\n\nDuplicate Key test with both lenient and strict JSON parsing');
|
||||
console.log('Input:', dupkeys);
|
||||
var works = JSONbig.parse(dupkeys);
|
||||
console.log('JSON.parse(dupkeys).dupkey: %s', works.dupkey);
|
||||
var fails = "will stay like this";
|
||||
try {
|
||||
fails = JSONstrict.parse(dupkeys);
|
||||
console.log('ERROR!! Should never get here');
|
||||
} catch (e) {
|
||||
console.log('Succesfully catched expected exception on duplicate keys: %j', e);
|
||||
}
|
||||
```
|
||||
|
||||
Output
|
||||
```
|
||||
Duplicate Key test with big number JSON
|
||||
Input: { "dupkey": "value 1", "dupkey": "value 2"}
|
||||
JSON.parse(dupkeys).dupkey: value 2
|
||||
Succesfully catched expected exception on duplicate keys: {"name":"SyntaxError","message":"Duplicate key \"dupkey\"","at":33,"text":"{ \"dupkey\": \"value 1\", \"dupkey\": \"value 2\"}"}
|
||||
|
||||
```
|
||||
|
||||
#### options.storeAsString, boolean, default false
|
||||
Specifies if BigInts should be stored in the object as a string, rather than the default BigNumber.
|
||||
|
||||
Note that this is a dangerous behavior as it breaks the default functionality of being able to convert back-and-forth without data type changes (as this will convert all BigInts to be-and-stay strings).
|
||||
|
||||
example:
|
||||
```js
|
||||
var JSONbig = require('json-bigint');
|
||||
var JSONbigString = require('json-bigint')({"storeAsString": true});
|
||||
var key = '{ "key": 1234567890123456789 }';
|
||||
console.log('\n\nStoring the BigInt as a string, instead of a BigNumber');
|
||||
console.log('Input:', key);
|
||||
var withInt = JSONbig.parse(key);
|
||||
var withString = JSONbigString.parse(key);
|
||||
console.log('Default type: %s, With option type: %s', typeof withInt.key, typeof withString.key);
|
||||
|
||||
```
|
||||
|
||||
Output
|
||||
```
|
||||
Storing the BigInt as a string, instead of a BigNumber
|
||||
Input: { "key": 1234567890123456789 }
|
||||
Default type: object, With option type: string
|
||||
|
||||
```
|
||||
|
||||
|
||||
### Links:
|
||||
- [RFC4627: The application/json Media Type for JavaScript Object Notation (JSON)](http://www.ietf.org/rfc/rfc4627.txt)
|
||||
- [Re: \[Json\] Limitations on number size?](http://www.ietf.org/mail-archive/web/json/current/msg00297.html)
|
||||
- [Is there any proper way to parse JSON with large numbers? (long, bigint, int64)](http://stackoverflow.com/questions/18755125/node-js-is-there-any-proper-way-to-parse-json-with-large-numbers-long-bigint)
|
||||
- [What is JavaScript's Max Int? What's the highest Integer value a Number can go to without losing precision?](http://stackoverflow.com/questions/307179/what-is-javascripts-max-int-whats-the-highest-integer-value-a-number-can-go-t)
|
||||
- [Large numbers erroneously rounded in Javascript](http://stackoverflow.com/questions/1379934/large-numbers-erroneously-rounded-in-javascript)
|
||||
|
12
node_modules/json-bigint/index.js
generated
vendored
Normal file
12
node_modules/json-bigint/index.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
var json_stringify = require('./lib/stringify.js').stringify;
|
||||
var json_parse = require('./lib/parse.js');
|
||||
|
||||
module.exports = function(options) {
|
||||
return {
|
||||
parse: json_parse(options),
|
||||
stringify: json_stringify
|
||||
}
|
||||
};
|
||||
//create the default method members with no options applied for backwards compatibility
|
||||
module.exports.parse = json_parse();
|
||||
module.exports.stringify = json_stringify;
|
384
node_modules/json-bigint/lib/parse.js
generated
vendored
Normal file
384
node_modules/json-bigint/lib/parse.js
generated
vendored
Normal file
@ -0,0 +1,384 @@
|
||||
var BigNumber = null;
|
||||
/*
|
||||
json_parse.js
|
||||
2012-06-20
|
||||
|
||||
Public Domain.
|
||||
|
||||
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||
|
||||
This file creates a json_parse function.
|
||||
During create you can (optionally) specify some behavioural switches
|
||||
|
||||
require('json-bigint')(options)
|
||||
|
||||
The optional options parameter holds switches that drive certain
|
||||
aspects of the parsing process:
|
||||
* options.strict = true will warn about duplicate-key usage in the json.
|
||||
The default (strict = false) will silently ignore those and overwrite
|
||||
values for keys that are in duplicate use.
|
||||
|
||||
The resulting function follows this signature:
|
||||
json_parse(text, reviver)
|
||||
This method parses a JSON text to produce an object or array.
|
||||
It can throw a SyntaxError exception.
|
||||
|
||||
The optional reviver parameter is a function that can filter and
|
||||
transform the results. It receives each of the keys and values,
|
||||
and its return value is used instead of the original value.
|
||||
If it returns what it received, then the structure is not modified.
|
||||
If it returns undefined then the member is deleted.
|
||||
|
||||
Example:
|
||||
|
||||
// Parse the text. Values that look like ISO date strings will
|
||||
// be converted to Date objects.
|
||||
|
||||
myData = json_parse(text, function (key, value) {
|
||||
var a;
|
||||
if (typeof value === 'string') {
|
||||
a =
|
||||
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
||||
if (a) {
|
||||
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
||||
+a[5], +a[6]));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
This is a reference implementation. You are free to copy, modify, or
|
||||
redistribute.
|
||||
|
||||
This code should be minified before deployment.
|
||||
See http://javascript.crockford.com/jsmin.html
|
||||
|
||||
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
||||
NOT CONTROL.
|
||||
*/
|
||||
|
||||
/*members "", "\"", "\/", "\\", at, b, call, charAt, f, fromCharCode,
|
||||
hasOwnProperty, message, n, name, prototype, push, r, t, text
|
||||
*/
|
||||
|
||||
var json_parse = function (options) {
|
||||
"use strict";
|
||||
|
||||
// This is a function that can parse a JSON text, producing a JavaScript
|
||||
// data structure. It is a simple, recursive descent parser. It does not use
|
||||
// eval or regular expressions, so it can be used as a model for implementing
|
||||
// a JSON parser in other languages.
|
||||
|
||||
// We are defining the function inside of another function to avoid creating
|
||||
// global variables.
|
||||
|
||||
|
||||
// Default options one can override by passing options to the parse()
|
||||
var _options = {
|
||||
"strict": false, // not being strict means do not generate syntax errors for "duplicate key"
|
||||
"storeAsString": false // toggles whether the values should be stored as BigNumber (default) or a string
|
||||
};
|
||||
|
||||
|
||||
// If there are options, then use them to override the default _options
|
||||
if (options !== undefined && options !== null) {
|
||||
if (options.strict === true) {
|
||||
_options.strict = true;
|
||||
}
|
||||
if (options.storeAsString === true) {
|
||||
_options.storeAsString = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var at, // The index of the current character
|
||||
ch, // The current character
|
||||
escapee = {
|
||||
'"': '"',
|
||||
'\\': '\\',
|
||||
'/': '/',
|
||||
b: '\b',
|
||||
f: '\f',
|
||||
n: '\n',
|
||||
r: '\r',
|
||||
t: '\t'
|
||||
},
|
||||
text,
|
||||
|
||||
error = function (m) {
|
||||
|
||||
// Call error when something is wrong.
|
||||
|
||||
throw {
|
||||
name: 'SyntaxError',
|
||||
message: m,
|
||||
at: at,
|
||||
text: text
|
||||
};
|
||||
},
|
||||
|
||||
next = function (c) {
|
||||
|
||||
// If a c parameter is provided, verify that it matches the current character.
|
||||
|
||||
if (c && c !== ch) {
|
||||
error("Expected '" + c + "' instead of '" + ch + "'");
|
||||
}
|
||||
|
||||
// Get the next character. When there are no more characters,
|
||||
// return the empty string.
|
||||
|
||||
ch = text.charAt(at);
|
||||
at += 1;
|
||||
return ch;
|
||||
},
|
||||
|
||||
number = function () {
|
||||
// Parse a number value.
|
||||
|
||||
var number,
|
||||
string = '';
|
||||
|
||||
if (ch === '-') {
|
||||
string = '-';
|
||||
next('-');
|
||||
}
|
||||
while (ch >= '0' && ch <= '9') {
|
||||
string += ch;
|
||||
next();
|
||||
}
|
||||
if (ch === '.') {
|
||||
string += '.';
|
||||
while (next() && ch >= '0' && ch <= '9') {
|
||||
string += ch;
|
||||
}
|
||||
}
|
||||
if (ch === 'e' || ch === 'E') {
|
||||
string += ch;
|
||||
next();
|
||||
if (ch === '-' || ch === '+') {
|
||||
string += ch;
|
||||
next();
|
||||
}
|
||||
while (ch >= '0' && ch <= '9') {
|
||||
string += ch;
|
||||
next();
|
||||
}
|
||||
}
|
||||
number = +string;
|
||||
if (!isFinite(number)) {
|
||||
error("Bad number");
|
||||
} else {
|
||||
if (BigNumber == null)
|
||||
BigNumber = require('bignumber.js');
|
||||
//if (number > 9007199254740992 || number < -9007199254740992)
|
||||
// Bignumber has stricter check: everything with length > 15 digits disallowed
|
||||
if (string.length > 15)
|
||||
return (_options.storeAsString === true) ? string : new BigNumber(string);
|
||||
return number;
|
||||
}
|
||||
},
|
||||
|
||||
string = function () {
|
||||
|
||||
// Parse a string value.
|
||||
|
||||
var hex,
|
||||
i,
|
||||
string = '',
|
||||
uffff;
|
||||
|
||||
// When parsing for string values, we must look for " and \ characters.
|
||||
|
||||
if (ch === '"') {
|
||||
while (next()) {
|
||||
if (ch === '"') {
|
||||
next();
|
||||
return string;
|
||||
}
|
||||
if (ch === '\\') {
|
||||
next();
|
||||
if (ch === 'u') {
|
||||
uffff = 0;
|
||||
for (i = 0; i < 4; i += 1) {
|
||||
hex = parseInt(next(), 16);
|
||||
if (!isFinite(hex)) {
|
||||
break;
|
||||
}
|
||||
uffff = uffff * 16 + hex;
|
||||
}
|
||||
string += String.fromCharCode(uffff);
|
||||
} else if (typeof escapee[ch] === 'string') {
|
||||
string += escapee[ch];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
string += ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
error("Bad string");
|
||||
},
|
||||
|
||||
white = function () {
|
||||
|
||||
// Skip whitespace.
|
||||
|
||||
while (ch && ch <= ' ') {
|
||||
next();
|
||||
}
|
||||
},
|
||||
|
||||
word = function () {
|
||||
|
||||
// true, false, or null.
|
||||
|
||||
switch (ch) {
|
||||
case 't':
|
||||
next('t');
|
||||
next('r');
|
||||
next('u');
|
||||
next('e');
|
||||
return true;
|
||||
case 'f':
|
||||
next('f');
|
||||
next('a');
|
||||
next('l');
|
||||
next('s');
|
||||
next('e');
|
||||
return false;
|
||||
case 'n':
|
||||
next('n');
|
||||
next('u');
|
||||
next('l');
|
||||
next('l');
|
||||
return null;
|
||||
}
|
||||
error("Unexpected '" + ch + "'");
|
||||
},
|
||||
|
||||
value, // Place holder for the value function.
|
||||
|
||||
array = function () {
|
||||
|
||||
// Parse an array value.
|
||||
|
||||
var array = [];
|
||||
|
||||
if (ch === '[') {
|
||||
next('[');
|
||||
white();
|
||||
if (ch === ']') {
|
||||
next(']');
|
||||
return array; // empty array
|
||||
}
|
||||
while (ch) {
|
||||
array.push(value());
|
||||
white();
|
||||
if (ch === ']') {
|
||||
next(']');
|
||||
return array;
|
||||
}
|
||||
next(',');
|
||||
white();
|
||||
}
|
||||
}
|
||||
error("Bad array");
|
||||
},
|
||||
|
||||
object = function () {
|
||||
|
||||
// Parse an object value.
|
||||
|
||||
var key,
|
||||
object = {};
|
||||
|
||||
if (ch === '{') {
|
||||
next('{');
|
||||
white();
|
||||
if (ch === '}') {
|
||||
next('}');
|
||||
return object; // empty object
|
||||
}
|
||||
while (ch) {
|
||||
key = string();
|
||||
white();
|
||||
next(':');
|
||||
if (_options.strict === true && Object.hasOwnProperty.call(object, key)) {
|
||||
error('Duplicate key "' + key + '"');
|
||||
}
|
||||
object[key] = value();
|
||||
white();
|
||||
if (ch === '}') {
|
||||
next('}');
|
||||
return object;
|
||||
}
|
||||
next(',');
|
||||
white();
|
||||
}
|
||||
}
|
||||
error("Bad object");
|
||||
};
|
||||
|
||||
value = function () {
|
||||
|
||||
// Parse a JSON value. It could be an object, an array, a string, a number,
|
||||
// or a word.
|
||||
|
||||
white();
|
||||
switch (ch) {
|
||||
case '{':
|
||||
return object();
|
||||
case '[':
|
||||
return array();
|
||||
case '"':
|
||||
return string();
|
||||
case '-':
|
||||
return number();
|
||||
default:
|
||||
return ch >= '0' && ch <= '9' ? number() : word();
|
||||
}
|
||||
};
|
||||
|
||||
// Return the json_parse function. It will have access to all of the above
|
||||
// functions and variables.
|
||||
|
||||
return function (source, reviver) {
|
||||
var result;
|
||||
|
||||
text = source + '';
|
||||
at = 0;
|
||||
ch = ' ';
|
||||
result = value();
|
||||
white();
|
||||
if (ch) {
|
||||
error("Syntax error");
|
||||
}
|
||||
|
||||
// If there is a reviver function, we recursively walk the new structure,
|
||||
// passing each name/value pair to the reviver function for possible
|
||||
// transformation, starting with a temporary root object that holds the result
|
||||
// in an empty key. If there is not a reviver function, we simply return the
|
||||
// result.
|
||||
|
||||
return typeof reviver === 'function'
|
||||
? (function walk(holder, key) {
|
||||
var k, v, value = holder[key];
|
||||
if (value && typeof value === 'object') {
|
||||
Object.keys(value).forEach(function(k) {
|
||||
v = walk(value, k);
|
||||
if (v !== undefined) {
|
||||
value[k] = v;
|
||||
} else {
|
||||
delete value[k];
|
||||
}
|
||||
});
|
||||
}
|
||||
return reviver.call(holder, key, value);
|
||||
}({'': result}, ''))
|
||||
: result;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = json_parse;
|
383
node_modules/json-bigint/lib/stringify.js
generated
vendored
Normal file
383
node_modules/json-bigint/lib/stringify.js
generated
vendored
Normal file
@ -0,0 +1,383 @@
|
||||
var BigNumber = require('bignumber.js');
|
||||
|
||||
/*
|
||||
json2.js
|
||||
2013-05-26
|
||||
|
||||
Public Domain.
|
||||
|
||||
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||
|
||||
See http://www.JSON.org/js.html
|
||||
|
||||
|
||||
This code should be minified before deployment.
|
||||
See http://javascript.crockford.com/jsmin.html
|
||||
|
||||
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
||||
NOT CONTROL.
|
||||
|
||||
|
||||
This file creates a global JSON object containing two methods: stringify
|
||||
and parse.
|
||||
|
||||
JSON.stringify(value, replacer, space)
|
||||
value any JavaScript value, usually an object or array.
|
||||
|
||||
replacer an optional parameter that determines how object
|
||||
values are stringified for objects. It can be a
|
||||
function or an array of strings.
|
||||
|
||||
space an optional parameter that specifies the indentation
|
||||
of nested structures. If it is omitted, the text will
|
||||
be packed without extra whitespace. If it is a number,
|
||||
it will specify the number of spaces to indent at each
|
||||
level. If it is a string (such as '\t' or ' '),
|
||||
it contains the characters used to indent at each level.
|
||||
|
||||
This method produces a JSON text from a JavaScript value.
|
||||
|
||||
When an object value is found, if the object contains a toJSON
|
||||
method, its toJSON method will be called and the result will be
|
||||
stringified. A toJSON method does not serialize: it returns the
|
||||
value represented by the name/value pair that should be serialized,
|
||||
or undefined if nothing should be serialized. The toJSON method
|
||||
will be passed the key associated with the value, and this will be
|
||||
bound to the value
|
||||
|
||||
For example, this would serialize Dates as ISO strings.
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
return this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z';
|
||||
};
|
||||
|
||||
You can provide an optional replacer method. It will be passed the
|
||||
key and value of each member, with this bound to the containing
|
||||
object. The value that is returned from your method will be
|
||||
serialized. If your method returns undefined, then the member will
|
||||
be excluded from the serialization.
|
||||
|
||||
If the replacer parameter is an array of strings, then it will be
|
||||
used to select the members to be serialized. It filters the results
|
||||
such that only members with keys listed in the replacer array are
|
||||
stringified.
|
||||
|
||||
Values that do not have JSON representations, such as undefined or
|
||||
functions, will not be serialized. Such values in objects will be
|
||||
dropped; in arrays they will be replaced with null. You can use
|
||||
a replacer function to replace those with JSON values.
|
||||
JSON.stringify(undefined) returns undefined.
|
||||
|
||||
The optional space parameter produces a stringification of the
|
||||
value that is filled with line breaks and indentation to make it
|
||||
easier to read.
|
||||
|
||||
If the space parameter is a non-empty string, then that string will
|
||||
be used for indentation. If the space parameter is a number, then
|
||||
the indentation will be that many spaces.
|
||||
|
||||
Example:
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
||||
// text is '["e",{"pluribus":"unum"}]'
|
||||
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
||||
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
||||
|
||||
text = JSON.stringify([new Date()], function (key, value) {
|
||||
return this[key] instanceof Date ?
|
||||
'Date(' + this[key] + ')' : value;
|
||||
});
|
||||
// text is '["Date(---current time---)"]'
|
||||
|
||||
|
||||
JSON.parse(text, reviver)
|
||||
This method parses a JSON text to produce an object or array.
|
||||
It can throw a SyntaxError exception.
|
||||
|
||||
The optional reviver parameter is a function that can filter and
|
||||
transform the results. It receives each of the keys and values,
|
||||
and its return value is used instead of the original value.
|
||||
If it returns what it received, then the structure is not modified.
|
||||
If it returns undefined then the member is deleted.
|
||||
|
||||
Example:
|
||||
|
||||
// Parse the text. Values that look like ISO date strings will
|
||||
// be converted to Date objects.
|
||||
|
||||
myData = JSON.parse(text, function (key, value) {
|
||||
var a;
|
||||
if (typeof value === 'string') {
|
||||
a =
|
||||
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
||||
if (a) {
|
||||
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
||||
+a[5], +a[6]));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
||||
var d;
|
||||
if (typeof value === 'string' &&
|
||||
value.slice(0, 5) === 'Date(' &&
|
||||
value.slice(-1) === ')') {
|
||||
d = new Date(value.slice(5, -1));
|
||||
if (d) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
|
||||
This is a reference implementation. You are free to copy, modify, or
|
||||
redistribute.
|
||||
*/
|
||||
|
||||
/*jslint evil: true, regexp: true */
|
||||
|
||||
/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
|
||||
call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
||||
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
||||
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
||||
test, toJSON, toString, valueOf
|
||||
*/
|
||||
|
||||
|
||||
// Create a JSON object only if one does not already exist. We create the
|
||||
// methods in a closure to avoid creating global variables.
|
||||
|
||||
var JSON = module.exports;
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
|
||||
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
gap,
|
||||
indent,
|
||||
meta = { // table of character substitutions
|
||||
'\b': '\\b',
|
||||
'\t': '\\t',
|
||||
'\n': '\\n',
|
||||
'\f': '\\f',
|
||||
'\r': '\\r',
|
||||
'"' : '\\"',
|
||||
'\\': '\\\\'
|
||||
},
|
||||
rep;
|
||||
|
||||
|
||||
function quote(string) {
|
||||
|
||||
// If the string contains no control characters, no quote characters, and no
|
||||
// backslash characters, then we can safely slap some quotes around it.
|
||||
// Otherwise we must also replace the offending characters with safe escape
|
||||
// sequences.
|
||||
|
||||
escapable.lastIndex = 0;
|
||||
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
|
||||
var c = meta[a];
|
||||
return typeof c === 'string'
|
||||
? c
|
||||
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
}) + '"' : '"' + string + '"';
|
||||
}
|
||||
|
||||
|
||||
function str(key, holder) {
|
||||
|
||||
// Produce a string from holder[key].
|
||||
|
||||
var i, // The loop counter.
|
||||
k, // The member key.
|
||||
v, // The member value.
|
||||
length,
|
||||
mind = gap,
|
||||
partial,
|
||||
value = holder[key],
|
||||
isBigNumber = value != null && (value instanceof BigNumber || BigNumber.isBigNumber(value));
|
||||
|
||||
// If the value has a toJSON method, call it to obtain a replacement value.
|
||||
|
||||
if (value && typeof value === 'object' &&
|
||||
typeof value.toJSON === 'function') {
|
||||
value = value.toJSON(key);
|
||||
}
|
||||
|
||||
// If we were called with a replacer function, then call the replacer to
|
||||
// obtain a replacement value.
|
||||
|
||||
if (typeof rep === 'function') {
|
||||
value = rep.call(holder, key, value);
|
||||
}
|
||||
|
||||
// What happens next depends on the value's type.
|
||||
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
if (isBigNumber) {
|
||||
return value;
|
||||
} else {
|
||||
return quote(value);
|
||||
}
|
||||
|
||||
case 'number':
|
||||
|
||||
// JSON numbers must be finite. Encode non-finite numbers as null.
|
||||
|
||||
return isFinite(value) ? String(value) : 'null';
|
||||
|
||||
case 'boolean':
|
||||
case 'null':
|
||||
|
||||
// If the value is a boolean or null, convert it to a string. Note:
|
||||
// typeof null does not produce 'null'. The case is included here in
|
||||
// the remote chance that this gets fixed someday.
|
||||
|
||||
return String(value);
|
||||
|
||||
// If the type is 'object', we might be dealing with an object or an array or
|
||||
// null.
|
||||
|
||||
case 'object':
|
||||
|
||||
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
||||
// so watch out for that case.
|
||||
|
||||
if (!value) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
// Make an array to hold the partial results of stringifying this object value.
|
||||
|
||||
gap += indent;
|
||||
partial = [];
|
||||
|
||||
// Is the value an array?
|
||||
|
||||
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
||||
|
||||
// The value is an array. Stringify every element. Use null as a placeholder
|
||||
// for non-JSON values.
|
||||
|
||||
length = value.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
partial[i] = str(i, value) || 'null';
|
||||
}
|
||||
|
||||
// Join all of the elements together, separated with commas, and wrap them in
|
||||
// brackets.
|
||||
|
||||
v = partial.length === 0
|
||||
? '[]'
|
||||
: gap
|
||||
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
|
||||
: '[' + partial.join(',') + ']';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
||||
// If the replacer is an array, use it to select the members to be stringified.
|
||||
|
||||
if (rep && typeof rep === 'object') {
|
||||
length = rep.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
if (typeof rep[i] === 'string') {
|
||||
k = rep[i];
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// Otherwise, iterate through all of the keys in the object.
|
||||
|
||||
Object.keys(value).forEach(function(k) {
|
||||
var v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Join all of the member texts together, separated with commas,
|
||||
// and wrap them in braces.
|
||||
|
||||
v = partial.length === 0
|
||||
? '{}'
|
||||
: gap
|
||||
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
|
||||
: '{' + partial.join(',') + '}';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
// If the JSON object does not yet have a stringify method, give it one.
|
||||
|
||||
if (typeof JSON.stringify !== 'function') {
|
||||
JSON.stringify = function (value, replacer, space) {
|
||||
|
||||
// The stringify method takes a value and an optional replacer, and an optional
|
||||
// space parameter, and returns a JSON text. The replacer can be a function
|
||||
// that can replace values, or an array of strings that will select the keys.
|
||||
// A default replacer method can be provided. Use of the space parameter can
|
||||
// produce text that is more easily readable.
|
||||
|
||||
var i;
|
||||
gap = '';
|
||||
indent = '';
|
||||
|
||||
// If the space parameter is a number, make an indent string containing that
|
||||
// many spaces.
|
||||
|
||||
if (typeof space === 'number') {
|
||||
for (i = 0; i < space; i += 1) {
|
||||
indent += ' ';
|
||||
}
|
||||
|
||||
// If the space parameter is a string, it will be used as the indent string.
|
||||
|
||||
} else if (typeof space === 'string') {
|
||||
indent = space;
|
||||
}
|
||||
|
||||
// If there is a replacer, it must be a function or an array.
|
||||
// Otherwise, throw an error.
|
||||
|
||||
rep = replacer;
|
||||
if (replacer && typeof replacer !== 'function' &&
|
||||
(typeof replacer !== 'object' ||
|
||||
typeof replacer.length !== 'number')) {
|
||||
throw new Error('JSON.stringify');
|
||||
}
|
||||
|
||||
// Make a fake root object containing our value under the key of ''.
|
||||
// Return the result of stringifying the value.
|
||||
|
||||
return str('', {'': value});
|
||||
};
|
||||
}
|
||||
}());
|
65
node_modules/json-bigint/package.json
generated
vendored
Normal file
65
node_modules/json-bigint/package.json
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"json-bigint@0.3.0",
|
||||
"C:\\Users\\matia\\Musix"
|
||||
]
|
||||
],
|
||||
"_from": "json-bigint@0.3.0",
|
||||
"_id": "json-bigint@0.3.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-DM2RLEuCcNBfBW+9E4FLU9OCWx4=",
|
||||
"_location": "/json-bigint",
|
||||
"_optional": true,
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "json-bigint@0.3.0",
|
||||
"name": "json-bigint",
|
||||
"escapedName": "json-bigint",
|
||||
"rawSpec": "0.3.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "0.3.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/gcp-metadata"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-0.3.0.tgz",
|
||||
"_spec": "0.3.0",
|
||||
"_where": "C:\\Users\\matia\\Musix",
|
||||
"author": {
|
||||
"name": "Andrey Sidorov",
|
||||
"email": "sidorares@yandex.ru"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sidorares/json-bigint/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"bignumber.js": "^7.0.0"
|
||||
},
|
||||
"description": "JSON.parse with bigints support",
|
||||
"devDependencies": {
|
||||
"chai": "~1.9.1",
|
||||
"mocha": "~1.20.1"
|
||||
},
|
||||
"homepage": "https://github.com/sidorares/json-bigint#readme",
|
||||
"keywords": [
|
||||
"JSON",
|
||||
"bigint",
|
||||
"bignumber",
|
||||
"parse",
|
||||
"json"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "json-bigint",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/sidorares/json-bigint.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "./node_modules/mocha/bin/mocha -R spec --check-leaks test/*-test.js"
|
||||
},
|
||||
"version": "0.3.0"
|
||||
}
|
31
node_modules/json-bigint/test/bigint-test.js
generated
vendored
Normal file
31
node_modules/json-bigint/test/bigint-test.js
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
var mocha = require('mocha')
|
||||
, assert = require('chai').assert
|
||||
, expect = require('chai').expect
|
||||
, BigNumber = require('bignumber.js')
|
||||
;
|
||||
|
||||
describe("Testing bigint support", function(){
|
||||
var input = '{"big":9223372036854775807,"small":123}';
|
||||
|
||||
it("Should show classic JSON.parse lacks bigint support", function(done){
|
||||
var obj = JSON.parse(input);
|
||||
expect(obj.small.toString(), "string from small int").to.equal("123");
|
||||
expect(obj.big.toString(), "string from big int").to.not.equal("9223372036854775807");
|
||||
|
||||
var output = JSON.stringify(obj);
|
||||
expect(output).to.not.equal(input);
|
||||
done();
|
||||
});
|
||||
|
||||
it("Should show JSNbig does support bigint parse/stringify roundtrip", function(done){
|
||||
var JSONbig = require('../index');
|
||||
var obj = JSONbig.parse(input);
|
||||
expect(obj.small.toString(), "string from small int").to.equal("123");
|
||||
expect(obj.big.toString(), "string from big int").to.equal("9223372036854775807");
|
||||
expect(obj.big, "instanceof big int").to.be.instanceof(BigNumber);
|
||||
|
||||
var output = JSONbig.stringify(obj);
|
||||
expect(output).to.equal(input);
|
||||
done();
|
||||
});
|
||||
});
|
34
node_modules/json-bigint/test/strict-option-test.js
generated
vendored
Normal file
34
node_modules/json-bigint/test/strict-option-test.js
generated
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
var mocha = require('mocha')
|
||||
, assert = require('chai').assert
|
||||
, expect = require('chai').expect
|
||||
;
|
||||
|
||||
describe("Testing 'strict' option", function(){
|
||||
var dupkeys = '{ "dupkey": "value 1", "dupkey": "value 2"}';
|
||||
it("Should show that duplicate keys just get overwritten by default", function(done){
|
||||
var JSONbig = require('../index');
|
||||
var result = "before";
|
||||
function tryParse() {
|
||||
result = JSONbig.parse(dupkeys);
|
||||
}
|
||||
expect(tryParse).to.not.throw("anything");
|
||||
expect(result.dupkey).to.equal("value 2");
|
||||
done();
|
||||
});
|
||||
|
||||
it("Should show that the 'strict' option will fail-fast on duplicate keys", function(done){
|
||||
var JSONstrict = require('../index')({"strict": true});
|
||||
var result = "before";
|
||||
function tryParse() {
|
||||
result = JSONstrict.parse(dupkeys);
|
||||
}
|
||||
expect(tryParse).to.throw({
|
||||
name: 'SyntaxError',
|
||||
message: 'Duplicate key "dupkey"',
|
||||
at: 33,
|
||||
text: '{ "dupkey": "value 1", "dupkey": "value 2"}'
|
||||
});
|
||||
expect(result).to.equal("before");
|
||||
done();
|
||||
});
|
||||
});
|
21
node_modules/json-bigint/test/string-option-test.js
generated
vendored
Normal file
21
node_modules/json-bigint/test/string-option-test.js
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
var mocha = require('mocha')
|
||||
, assert = require('chai').assert
|
||||
, expect = require('chai').expect
|
||||
;
|
||||
|
||||
describe("Testing 'storeAsString' option", function(){
|
||||
var key = '{ "key": 12345678901234567 }';
|
||||
it("Should show that the key is of type object", function(done){
|
||||
var JSONbig = require('../index');
|
||||
var result = JSONbig.parse(key);
|
||||
expect(typeof result.key).to.equal("object");
|
||||
done();
|
||||
});
|
||||
|
||||
it("Should show that key is of type string, when storeAsString option is true", function(done){
|
||||
var JSONstring = require('../index')({"storeAsString": true});
|
||||
var result = JSONstring.parse(key);
|
||||
expect(typeof result.key).to.equal("string");
|
||||
done();
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user