updated npm modules
This commit is contained in:
26
node_modules/serialize-javascript/index.js
generated
vendored
26
node_modules/serialize-javascript/index.js
generated
vendored
@@ -8,7 +8,7 @@ See the accompanying LICENSE file for terms.
|
||||
|
||||
// Generate an internal UID to make the regexp pattern harder to guess.
|
||||
var UID = Math.floor(Math.random() * 0x10000000000).toString(16);
|
||||
var PLACE_HOLDER_REGEXP = new RegExp('"@__(F|R|D)-' + UID + '-(\\d+)__@"', 'g');
|
||||
var PLACE_HOLDER_REGEXP = new RegExp('"@__(F|R|D|M|S)-' + UID + '-(\\d+)__@"', 'g');
|
||||
|
||||
var IS_NATIVE_CODE_REGEXP = /\{\s*\[native code\]\s*\}/g;
|
||||
var IS_PURE_FUNCTION = /function.*?\(/;
|
||||
@@ -41,6 +41,8 @@ module.exports = function serialize(obj, options) {
|
||||
var functions = [];
|
||||
var regexps = [];
|
||||
var dates = [];
|
||||
var maps = [];
|
||||
var sets = [];
|
||||
|
||||
// Returns placeholders for functions and regexps (identified by index)
|
||||
// which are later replaced by their string representation.
|
||||
@@ -62,6 +64,14 @@ module.exports = function serialize(obj, options) {
|
||||
if(origValue instanceof Date) {
|
||||
return '@__D-' + UID + '-' + (dates.push(origValue) - 1) + '__@';
|
||||
}
|
||||
|
||||
if(origValue instanceof Map) {
|
||||
return '@__M-' + UID + '-' + (maps.push(origValue) - 1) + '__@';
|
||||
}
|
||||
|
||||
if(origValue instanceof Set) {
|
||||
return '@__S-' + UID + '-' + (sets.push(origValue) - 1) + '__@';
|
||||
}
|
||||
}
|
||||
|
||||
if (type === 'function') {
|
||||
@@ -126,11 +136,11 @@ module.exports = function serialize(obj, options) {
|
||||
str = str.replace(UNSAFE_CHARS_REGEXP, escapeUnsafeChars);
|
||||
}
|
||||
|
||||
if (functions.length === 0 && regexps.length === 0 && dates.length === 0) {
|
||||
if (functions.length === 0 && regexps.length === 0 && dates.length === 0 && maps.length === 0 && sets.length === 0) {
|
||||
return str;
|
||||
}
|
||||
|
||||
// Replaces all occurrences of function, regexp and date placeholders in the
|
||||
// Replaces all occurrences of function, regexp, date, map and set placeholders in the
|
||||
// JSON string with their string representations. If the original value can
|
||||
// not be found, then `undefined` is used.
|
||||
return str.replace(PLACE_HOLDER_REGEXP, function (match, type, valueIndex) {
|
||||
@@ -142,7 +152,15 @@ module.exports = function serialize(obj, options) {
|
||||
return regexps[valueIndex].toString();
|
||||
}
|
||||
|
||||
var fn = functions[valueIndex];
|
||||
if (type === 'M') {
|
||||
return "new Map(" + serialize(Array.from(maps[valueIndex].entries()), options) + ")";
|
||||
}
|
||||
|
||||
if (type === 'S') {
|
||||
return "new Set(" + serialize(Array.from(sets[valueIndex].values()), options) + ")";
|
||||
}
|
||||
|
||||
var fn = functions[valueIndex];
|
||||
|
||||
return serializeFunc(fn);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user