Node-Red configuration
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.

get-json-replacer-function.js 1.0KB

123456789101112131415161718192021222324252627282930
  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. var push = uncurryThis([].push);
  8. module.exports = function (replacer) {
  9. if (isCallable(replacer)) return replacer;
  10. if (!isArray(replacer)) return;
  11. var rawLength = replacer.length;
  12. var keys = [];
  13. for (var i = 0; i < rawLength; i++) {
  14. var element = replacer[i];
  15. if (typeof element == 'string') push(keys, element);
  16. else if (typeof element == 'number' || classof(element) === 'Number' || classof(element) === 'String') push(keys, toString(element));
  17. }
  18. var keysLength = keys.length;
  19. var root = true;
  20. return function (key, value) {
  21. if (root) {
  22. root = false;
  23. return value;
  24. }
  25. if (isArray(this)) return value;
  26. for (var j = 0; j < keysLength; j++) if (keys[j] === key) return value;
  27. };
  28. };