/node_modules/cordova-plugin-disable-bitcode/node_modules/lodash-node/compat/internals/createIterator.js

https://gitlab.com/blocknotary/IonicInterviews · JavaScript · 127 lines · 79 code · 14 blank · 34 comment · 6 complexity · bcb442a30b2ce31a1d000e45894ea426 MD5 · raw file

  1. /**
  2. * Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/>
  3. * Build: `lodash modularize exports="node" -o ./compat/`
  4. * Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>
  5. * Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE>
  6. * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  7. * Available under MIT license <http://lodash.com/license>
  8. */
  9. var baseCreateCallback = require('./baseCreateCallback'),
  10. indicatorObject = require('./indicatorObject'),
  11. isArguments = require('../objects/isArguments'),
  12. isArray = require('../objects/isArray'),
  13. isString = require('../objects/isString'),
  14. iteratorTemplate = require('./iteratorTemplate'),
  15. objectTypes = require('./objectTypes');
  16. /** Used to fix the JScript [[DontEnum]] bug */
  17. var shadowedProps = [
  18. 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
  19. 'toLocaleString', 'toString', 'valueOf'
  20. ];
  21. /** `Object#toString` result shortcuts */
  22. var arrayClass = '[object Array]',
  23. boolClass = '[object Boolean]',
  24. dateClass = '[object Date]',
  25. errorClass = '[object Error]',
  26. funcClass = '[object Function]',
  27. numberClass = '[object Number]',
  28. objectClass = '[object Object]',
  29. regexpClass = '[object RegExp]',
  30. stringClass = '[object String]';
  31. /** Used as the data object for `iteratorTemplate` */
  32. var iteratorData = {
  33. 'args': '',
  34. 'array': null,
  35. 'bottom': '',
  36. 'firstArg': '',
  37. 'init': '',
  38. 'keys': null,
  39. 'loop': '',
  40. 'shadowedProps': null,
  41. 'support': null,
  42. 'top': '',
  43. 'useHas': false
  44. };
  45. /** Used for native method references */
  46. var errorProto = Error.prototype,
  47. objectProto = Object.prototype,
  48. stringProto = String.prototype;
  49. /** Used to resolve the internal [[Class]] of values */
  50. var toString = objectProto.toString;
  51. /** Native method shortcuts */
  52. var hasOwnProperty = objectProto.hasOwnProperty;
  53. /** Used to avoid iterating non-enumerable properties in IE < 9 */
  54. var nonEnumProps = {};
  55. nonEnumProps[arrayClass] = nonEnumProps[dateClass] = nonEnumProps[numberClass] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
  56. nonEnumProps[boolClass] = nonEnumProps[stringClass] = { 'constructor': true, 'toString': true, 'valueOf': true };
  57. nonEnumProps[errorClass] = nonEnumProps[funcClass] = nonEnumProps[regexpClass] = { 'constructor': true, 'toString': true };
  58. nonEnumProps[objectClass] = { 'constructor': true };
  59. (function() {
  60. var length = shadowedProps.length;
  61. while (length--) {
  62. var key = shadowedProps[length];
  63. for (var className in nonEnumProps) {
  64. if (hasOwnProperty.call(nonEnumProps, className) && !hasOwnProperty.call(nonEnumProps[className], key)) {
  65. nonEnumProps[className][key] = false;
  66. }
  67. }
  68. }
  69. }());
  70. /**
  71. * Creates compiled iteration functions.
  72. *
  73. * @private
  74. * @param {...Object} [options] The compile options object(s).
  75. * @param {string} [options.array] Code to determine if the iterable is an array or array-like.
  76. * @param {boolean} [options.useHas] Specify using `hasOwnProperty` checks in the object loop.
  77. * @param {Function} [options.keys] A reference to `_.keys` for use in own property iteration.
  78. * @param {string} [options.args] A comma separated string of iteration function arguments.
  79. * @param {string} [options.top] Code to execute before the iteration branches.
  80. * @param {string} [options.loop] Code to execute in the object loop.
  81. * @param {string} [options.bottom] Code to execute after the iteration branches.
  82. * @returns {Function} Returns the compiled function.
  83. */
  84. function createIterator() {
  85. // data properties
  86. iteratorData.shadowedProps = shadowedProps;
  87. // iterator options
  88. iteratorData.array = iteratorData.bottom = iteratorData.loop = iteratorData.top = '';
  89. iteratorData.init = 'iterable';
  90. iteratorData.useHas = true;
  91. // merge options into a template data object
  92. for (var object, index = 0; object = arguments[index]; index++) {
  93. for (var key in object) {
  94. iteratorData[key] = object[key];
  95. }
  96. }
  97. var args = iteratorData.args;
  98. iteratorData.firstArg = /^[^,]+/.exec(args)[0];
  99. // create the function factory
  100. var factory = Function(
  101. 'baseCreateCallback, errorClass, errorProto, hasOwnProperty, ' +
  102. 'indicatorObject, isArguments, isArray, isString, keys, objectProto, ' +
  103. 'objectTypes, nonEnumProps, stringClass, stringProto, toString',
  104. 'return function(' + args + ') {\n' + iteratorTemplate(iteratorData) + '\n}'
  105. );
  106. // return the compiled function
  107. return factory(
  108. baseCreateCallback, errorClass, errorProto, hasOwnProperty,
  109. indicatorObject, isArguments, isArray, isString, iteratorData.keys, objectProto,
  110. objectTypes, nonEnumProps, stringClass, stringProto, toString
  111. );
  112. }
  113. module.exports = createIterator;