main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 2 weeks ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[79a0317] | 1 | 'use strict';
|
---|
| 2 | var uncurryThis = require('../internals/function-uncurry-this');
|
---|
| 3 | var isArray = require('../internals/is-array');
|
---|
| 4 | var isCallable = require('../internals/is-callable');
|
---|
| 5 | var classof = require('../internals/classof-raw');
|
---|
| 6 | var toString = require('../internals/to-string');
|
---|
| 7 |
|
---|
| 8 | var push = uncurryThis([].push);
|
---|
| 9 |
|
---|
| 10 | module.exports = function (replacer) {
|
---|
| 11 | if (isCallable(replacer)) return replacer;
|
---|
| 12 | if (!isArray(replacer)) return;
|
---|
| 13 | var rawLength = replacer.length;
|
---|
| 14 | var keys = [];
|
---|
| 15 | for (var i = 0; i < rawLength; i++) {
|
---|
| 16 | var element = replacer[i];
|
---|
| 17 | if (typeof element == 'string') push(keys, element);
|
---|
| 18 | else if (typeof element == 'number' || classof(element) === 'Number' || classof(element) === 'String') push(keys, toString(element));
|
---|
| 19 | }
|
---|
| 20 | var keysLength = keys.length;
|
---|
| 21 | var root = true;
|
---|
| 22 | return function (key, value) {
|
---|
| 23 | if (root) {
|
---|
| 24 | root = false;
|
---|
| 25 | return value;
|
---|
| 26 | }
|
---|
| 27 | if (isArray(this)) return value;
|
---|
| 28 | for (var j = 0; j < keysLength; j++) if (keys[j] === key) return value;
|
---|
| 29 | };
|
---|
| 30 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.