You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
huazhiyu/node_modules/core-js/internals/get-json-replacer-function.js

30 lines
1.0 KiB

'use strict';
var uncurryThis = require('../internals/function-uncurry-this');
var isArray = require('../internals/is-array');
var isCallable = require('../internals/is-callable');
var classof = require('../internals/classof-raw');
var toString = require('../internals/to-string');
var push = uncurryThis([].push);
module.exports = function (replacer) {
if (isCallable(replacer)) return replacer;
if (!isArray(replacer)) return;
var rawLength = replacer.length;
var keys = [];
for (var i = 0; i < rawLength; i++) {
var element = replacer[i];
if (typeof element == 'string') push(keys, element);
else if (typeof element == 'number' || classof(element) === 'Number' || classof(element) === 'String') push(keys, toString(element));
}
var keysLength = keys.length;
var root = true;
return function (key, value) {
if (root) {
root = false;
return value;
}
if (isArray(this)) return value;
for (var j = 0; j < keysLength; j++) if (keys[j] === key) return value;
};
};