Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: test/js-perf-test/Lodash/lodash.custom.js

Issue 1746383003: [js-perf-test] add microbenchmarks for Object.values(), Object.entries() (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /**
2 * @license
caitp (gmail) 2016/03/04 16:50:16 The infra isn't happy about the lodash file not co
Camillo Bruni 2016/03/04 17:18:37 For our purpose I guess it would suffice to just h
3 * lodash 4.5.1 (Custom Build) <https://lodash.com/>
4 * Build: `lodash include="values,toPairs"`
5 * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
6 * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7 * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporter s & Editors
8 * Available under MIT license <https://lodash.com/license>
9 */
10 ;(function() {
11
12 /** Used as a safe reference for `undefined` in pre-ES5 environments. */
13 var undefined;
14
15 /** Used as the semantic version number. */
16 var VERSION = '4.5.1';
17
18 /** Used as references for various `Number` constants. */
19 var MAX_SAFE_INTEGER = 9007199254740991;
20
21 /** `Object#toString` result references. */
22 var argsTag = '[object Arguments]',
23 funcTag = '[object Function]',
24 genTag = '[object GeneratorFunction]',
25 stringTag = '[object String]';
26
27 /** Used to detect unsigned integer values. */
28 var reIsUint = /^(?:0|[1-9]\d*)$/;
29
30 /** Used to determine if values are of the language type `Object`. */
31 var objectTypes = {
32 'function': true,
33 'object': true
34 };
35
36 /** Detect free variable `exports`. */
37 var freeExports = (objectTypes[typeof exports] && exports && !exports.nodeType )
38 ? exports
39 : undefined;
40
41 /** Detect free variable `module`. */
42 var freeModule = (objectTypes[typeof module] && module && !module.nodeType)
43 ? module
44 : undefined;
45
46 /** Detect the popular CommonJS extension `module.exports`. */
47 var moduleExports = (freeModule && freeModule.exports === freeExports)
48 ? freeExports
49 : undefined;
50
51 /** Detect free variable `global` from Node.js. */
52 var freeGlobal = checkGlobal(freeExports && freeModule && typeof global == 'ob ject' && global);
53
54 /** Detect free variable `self`. */
55 var freeSelf = checkGlobal(objectTypes[typeof self] && self);
56
57 /** Detect free variable `window`. */
58 var freeWindow = checkGlobal(objectTypes[typeof window] && window);
59
60 /** Detect `this` as the global object. */
61 var thisGlobal = checkGlobal(objectTypes[typeof this] && this);
62
63 /**
64 * Used as a reference to the global object.
65 *
66 * The `this` value is used if it's the global object to avoid Greasemonkey's
67 * restricted `window` object, otherwise the `window` object is used.
68 */
69 var root = freeGlobal ||
70 ((freeWindow !== (thisGlobal && thisGlobal.window)) && freeWindow) ||
71 freeSelf || thisGlobal || Function('return this')();
72
73 /*--------------------------------------------------------------------------*/
74
75 /**
76 * A specialized version of `_.map` for arrays without support for iteratee
77 * shorthands.
78 *
79 * @private
80 * @param {Array} array The array to iterate over.
81 * @param {Function} iteratee The function invoked per iteration.
82 * @returns {Array} Returns the new mapped array.
83 */
84 function arrayMap(array, iteratee) {
85 var index = -1,
86 length = array.length,
87 result = Array(length);
88
89 while (++index < length) {
90 result[index] = iteratee(array[index], index, array);
91 }
92 return result;
93 }
94
95 /**
96 * The base implementation of `_.times` without support for iteratee shorthand s
97 * or max array length checks.
98 *
99 * @private
100 * @param {number} n The number of times to invoke `iteratee`.
101 * @param {Function} iteratee The function invoked per iteration.
102 * @returns {Array} Returns the array of results.
103 */
104 function baseTimes(n, iteratee) {
105 var index = -1,
106 result = Array(n);
107
108 while (++index < n) {
109 result[index] = iteratee(index);
110 }
111 return result;
112 }
113
114 /**
115 * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an a rray
116 * of key-value pairs for `object` corresponding to the property names of `pro ps`.
117 *
118 * @private
119 * @param {Object} object The object to query.
120 * @param {Array} props The property names to get values for.
121 * @returns {Object} Returns the new array of key-value pairs.
122 */
123 function baseToPairs(object, props) {
124 return arrayMap(props, function(key) {
125 return [key, object[key]];
126 });
127 }
128
129 /**
130 * The base implementation of `_.values` and `_.valuesIn` which creates an
131 * array of `object` property values corresponding to the property names
132 * of `props`.
133 *
134 * @private
135 * @param {Object} object The object to query.
136 * @param {Array} props The property names to get values for.
137 * @returns {Object} Returns the array of property values.
138 */
139 function baseValues(object, props) {
140 return arrayMap(props, function(key) {
141 return object[key];
142 });
143 }
144
145 /**
146 * Checks if `value` is a global object.
147 *
148 * @private
149 * @param {*} value The value to check.
150 * @returns {null|Object} Returns `value` if it's a global object, else `null` .
151 */
152 function checkGlobal(value) {
153 return (value && value.Object === Object) ? value : null;
154 }
155
156 /**
157 * Checks if `value` is a valid array-like index.
158 *
159 * @private
160 * @param {*} value The value to check.
161 * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index .
162 * @returns {boolean} Returns `true` if `value` is a valid index, else `false` .
163 */
164 function isIndex(value, length) {
165 value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
166 length = length == null ? MAX_SAFE_INTEGER : length;
167 return value > -1 && value % 1 == 0 && value < length;
168 }
169
170 /*--------------------------------------------------------------------------*/
171
172 /** Used for built-in method references. */
173 var objectProto = Object.prototype;
174
175 /** Used to check objects for own properties. */
176 var hasOwnProperty = objectProto.hasOwnProperty;
177
178 /**
179 * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/ 6.0/#sec-object.prototype.tostring)
180 * of values.
181 */
182 var objectToString = objectProto.toString;
183
184 /** Built-in value references. */
185 var Symbol = root.Symbol,
186 getPrototypeOf = Object.getPrototypeOf,
187 propertyIsEnumerable = objectProto.propertyIsEnumerable;
188
189 /* Built-in method references for those with the same name as other `lodash` m ethods. */
190 var nativeKeys = Object.keys;
191
192 /** Used to lookup unminified function names. */
193 var realNames = {};
194
195 /*------------------------------------------------------------------------*/
196
197 /**
198 * Creates a `lodash` object which wraps `value` to enable implicit method
199 * chaining. Methods that operate on and return arrays, collections, and
200 * functions can be chained together. Methods that retrieve a single value or
201 * may return a primitive value will automatically end the chain sequence and
202 * return the unwrapped value. Otherwise, the value must be unwrapped with
203 * `_#value`.
204 *
205 * Explicit chaining, which must be unwrapped with `_#value` in all cases,
206 * may be enabled using `_.chain`.
207 *
208 * The execution of chained methods is lazy, that is, it's deferred until
209 * `_#value` is implicitly or explicitly called.
210 *
211 * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
212 * fusion is an optimization to merge iteratee calls; this avoids the creation
213 * of intermediate arrays and can greatly reduce the number of iteratee execut ions.
214 * Sections of a chain sequence qualify for shortcut fusion if the section is
215 * applied to an array of at least two hundred elements and any iteratees
216 * accept only one argument. The heuristic for whether a section qualifies
217 * for shortcut fusion is subject to change.
218 *
219 * Chaining is supported in custom builds as long as the `_#value` method is
220 * directly or indirectly included in the build.
221 *
222 * In addition to lodash methods, wrappers have `Array` and `String` methods.
223 *
224 * The wrapper `Array` methods are:
225 * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
226 *
227 * The wrapper `String` methods are:
228 * `replace` and `split`
229 *
230 * The wrapper methods that support shortcut fusion are:
231 * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
232 * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
233 * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
234 *
235 * The chainable wrapper methods are:
236 * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
237 * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
238 * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
239 * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, `differe nce`,
240 * `differenceBy`, `differenceWith`, `drop`, `dropRight`, `dropRightWhile`,
241 * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flattenDepth`,
242 * `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, `functionsIn`,
243 * `groupBy`, `initial`, `intersection`, `intersectionBy`, `intersectionWith`,
244 * `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, `keys`, `keysIn`,
245 * `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, `memoize`,
246 * `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, `nthArg`,
247 * `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, `overEvery`,
248 * `overSome`, `partial`, `partialRight`, `partition`, `pick`, `pickBy`, `plan t`,
249 * `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`, `pullAt`, `push`,
250 * `range`, `rangeRight`, `rearg`, `reject`, `remove`, `rest`, `reverse`,
251 * `sampleSize`, `set`, `setWith`, `shuffle`, `slice`, `sort`, `sortBy`,
252 * `splice`, `spread`, `tail`, `take`, `takeRight`, `takeRightWhile`,
253 * `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, `toPairs`, `toPairsIn`,
254 * `toPath`, `toPlainObject`, `transform`, `unary`, `union`, `unionBy`,
255 * `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, `unshift`, `unzip`,
256 * `unzipWith`, `values`, `valuesIn`, `without`, `wrap`, `xor`, `xorBy`,
257 * `xorWith`, `zip`, `zipObject`, `zipObjectDeep`, and `zipWith`
258 *
259 * The wrapper methods that are **not** chainable by default are:
260 * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
261 * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `deburr`, `endsWith`, `eq`,
262 * `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLas t`,
263 * `findLastIndex`, `findLastKey`, `floor`, `forEach`, `forEachRight`, `forIn` ,
264 * `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`, `hasIn`,
265 * `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`, `isArgument s`,
266 * `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, `isBoolean` ,
267 * `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isEqualWith`,
268 * `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, `isMap`,
269 * `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, `isNumber `,
270 * `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, `isSafeInteger`,
271 * `isSet`, `isString`, `isUndefined`, `isTypedArray`, `isWeakMap`, `isWeakSet `,
272 * `join`, `kebabCase`, `last`, `lastIndexOf`, `lowerCase`, `lowerFirst`,
273 * `lt`, `lte`, `max`, `maxBy`, `mean`, `min`, `minBy`, `noConflict`, `noop`,
274 * `now`, `pad`, `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`,
275 * `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `sample`,
276 * `shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`,
277 * `sortedLastIndex`, `sortedLastIndexBy`, `startCase`, `startsWith`, `subtrac t`,
278 * `sum`, `sumBy`, `template`, `times`, `toLower`, `toInteger`, `toLength`,
279 * `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`, `trimEnd`,
280 * `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`, `upperFirst`,
281 * `value`, and `words`
282 *
283 * @name _
284 * @constructor
285 * @category Seq
286 * @param {*} value The value to wrap in a `lodash` instance.
287 * @returns {Object} Returns the new `lodash` wrapper instance.
288 * @example
289 *
290 * function square(n) {
291 * return n * n;
292 * }
293 *
294 * var wrapped = _([1, 2, 3]);
295 *
296 * // Returns an unwrapped value.
297 * wrapped.reduce(_.add);
298 * // => 6
299 *
300 * // Returns a wrapped value.
301 * var squares = wrapped.map(square);
302 *
303 * _.isArray(squares);
304 * // => false
305 *
306 * _.isArray(squares.value());
307 * // => true
308 */
309 function lodash() {
310 // No operation performed.
311 }
312
313 /*------------------------------------------------------------------------*/
314
315 /**
316 * The base implementation of `_.has` without support for deep paths.
317 *
318 * @private
319 * @param {Object} object The object to query.
320 * @param {Array|string} key The key to check.
321 * @returns {boolean} Returns `true` if `key` exists, else `false`.
322 */
323 function baseHas(object, key) {
324 // Avoid a bug in IE 10-11 where objects with a [[Prototype]] of `null`,
325 // that are composed entirely of index properties, return `false` for
326 // `hasOwnProperty` checks of them.
327 return hasOwnProperty.call(object, key) ||
328 (typeof object == 'object' && key in object && getPrototypeOf(object) === null);
329 }
330
331 /**
332 * The base implementation of `_.keys` which doesn't skip the constructor
333 * property of prototypes or treat sparse arrays as dense.
334 *
335 * @private
336 * @param {Object} object The object to query.
337 * @returns {Array} Returns the array of property names.
338 */
339 function baseKeys(object) {
340 return nativeKeys(Object(object));
341 }
342
343 /**
344 * The base implementation of `_.property` without support for deep paths.
345 *
346 * @private
347 * @param {string} key The key of the property to get.
348 * @returns {Function} Returns the new function.
349 */
350 function baseProperty(key) {
351 return function(object) {
352 return object == null ? undefined : object[key];
353 };
354 }
355
356 /**
357 * Gets the "length" property value of `object`.
358 *
359 * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.or g/show_bug.cgi?id=142792)
360 * that affects Safari on at least iOS 8.1-8.3 ARM64.
361 *
362 * @private
363 * @param {Object} object The object to query.
364 * @returns {*} Returns the "length" value.
365 */
366 var getLength = baseProperty('length');
367
368 /**
369 * Creates an array of index keys for `object` values of arrays,
370 * `arguments` objects, and strings, otherwise `null` is returned.
371 *
372 * @private
373 * @param {Object} object The object to query.
374 * @returns {Array|null} Returns index keys, else `null`.
375 */
376 function indexKeys(object) {
377 var length = object ? object.length : undefined;
378 if (isLength(length) &&
379 (isArray(object) || isString(object) || isArguments(object))) {
380 return baseTimes(length, String);
381 }
382 return null;
383 }
384
385 /**
386 * Checks if `value` is likely a prototype object.
387 *
388 * @private
389 * @param {*} value The value to check.
390 * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
391 */
392 function isPrototype(value) {
393 var Ctor = value && value.constructor,
394 proto = (isFunction(Ctor) && Ctor.prototype) || objectProto;
395
396 return value === proto;
397 }
398
399 /*------------------------------------------------------------------------*/
400
401 /**
402 * Checks if `value` is likely an `arguments` object.
403 *
404 * @static
405 * @memberOf _
406 * @category Lang
407 * @param {*} value The value to check.
408 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
409 * @example
410 *
411 * _.isArguments(function() { return arguments; }());
412 * // => true
413 *
414 * _.isArguments([1, 2, 3]);
415 * // => false
416 */
417 function isArguments(value) {
418 // Safari 8.1 incorrectly makes `arguments.callee` enumerable in strict mode .
419 return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
420 (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
421 }
422
423 /**
424 * Checks if `value` is classified as an `Array` object.
425 *
426 * @static
427 * @memberOf _
428 * @type {Function}
429 * @category Lang
430 * @param {*} value The value to check.
431 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
432 * @example
433 *
434 * _.isArray([1, 2, 3]);
435 * // => true
436 *
437 * _.isArray(document.body.children);
438 * // => false
439 *
440 * _.isArray('abc');
441 * // => false
442 *
443 * _.isArray(_.noop);
444 * // => false
445 */
446 var isArray = Array.isArray;
447
448 /**
449 * Checks if `value` is array-like. A value is considered array-like if it's
450 * not a function and has a `value.length` that's an integer greater than or
451 * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
452 *
453 * @static
454 * @memberOf _
455 * @category Lang
456 * @param {*} value The value to check.
457 * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
458 * @example
459 *
460 * _.isArrayLike([1, 2, 3]);
461 * // => true
462 *
463 * _.isArrayLike(document.body.children);
464 * // => true
465 *
466 * _.isArrayLike('abc');
467 * // => true
468 *
469 * _.isArrayLike(_.noop);
470 * // => false
471 */
472 function isArrayLike(value) {
473 return value != null &&
474 !(typeof value == 'function' && isFunction(value)) && isLength(getLength(v alue));
475 }
476
477 /**
478 * This method is like `_.isArrayLike` except that it also checks if `value`
479 * is an object.
480 *
481 * @static
482 * @memberOf _
483 * @category Lang
484 * @param {*} value The value to check.
485 * @returns {boolean} Returns `true` if `value` is an array-like object, else `false`.
486 * @example
487 *
488 * _.isArrayLikeObject([1, 2, 3]);
489 * // => true
490 *
491 * _.isArrayLikeObject(document.body.children);
492 * // => true
493 *
494 * _.isArrayLikeObject('abc');
495 * // => false
496 *
497 * _.isArrayLikeObject(_.noop);
498 * // => false
499 */
500 function isArrayLikeObject(value) {
501 return isObjectLike(value) && isArrayLike(value);
502 }
503
504 /**
505 * Checks if `value` is classified as a `Function` object.
506 *
507 * @static
508 * @memberOf _
509 * @category Lang
510 * @param {*} value The value to check.
511 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
512 * @example
513 *
514 * _.isFunction(_);
515 * // => true
516 *
517 * _.isFunction(/abc/);
518 * // => false
519 */
520 function isFunction(value) {
521 // The use of `Object#toString` avoids issues with the `typeof` operator
522 // in Safari 8 which returns 'object' for typed array constructors, and
523 // PhantomJS 1.9 which returns 'function' for `NodeList` instances.
524 var tag = isObject(value) ? objectToString.call(value) : '';
525 return tag == funcTag || tag == genTag;
526 }
527
528 /**
529 * Checks if `value` is a valid array-like length.
530 *
531 * **Note:** This function is loosely based on [`ToLength`](http://ecma-intern ational.org/ecma-262/6.0/#sec-tolength).
532 *
533 * @static
534 * @memberOf _
535 * @category Lang
536 * @param {*} value The value to check.
537 * @returns {boolean} Returns `true` if `value` is a valid length, else `false `.
538 * @example
539 *
540 * _.isLength(3);
541 * // => true
542 *
543 * _.isLength(Number.MIN_VALUE);
544 * // => false
545 *
546 * _.isLength(Infinity);
547 * // => false
548 *
549 * _.isLength('3');
550 * // => false
551 */
552 function isLength(value) {
553 return typeof value == 'number' &&
554 value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
555 }
556
557 /**
558 * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Obj ect`.
559 * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String ('')`)
560 *
561 * @static
562 * @memberOf _
563 * @category Lang
564 * @param {*} value The value to check.
565 * @returns {boolean} Returns `true` if `value` is an object, else `false`.
566 * @example
567 *
568 * _.isObject({});
569 * // => true
570 *
571 * _.isObject([1, 2, 3]);
572 * // => true
573 *
574 * _.isObject(_.noop);
575 * // => true
576 *
577 * _.isObject(null);
578 * // => false
579 */
580 function isObject(value) {
581 var type = typeof value;
582 return !!value && (type == 'object' || type == 'function');
583 }
584
585 /**
586 * Checks if `value` is object-like. A value is object-like if it's not `null`
587 * and has a `typeof` result of "object".
588 *
589 * @static
590 * @memberOf _
591 * @category Lang
592 * @param {*} value The value to check.
593 * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
594 * @example
595 *
596 * _.isObjectLike({});
597 * // => true
598 *
599 * _.isObjectLike([1, 2, 3]);
600 * // => true
601 *
602 * _.isObjectLike(_.noop);
603 * // => false
604 *
605 * _.isObjectLike(null);
606 * // => false
607 */
608 function isObjectLike(value) {
609 return !!value && typeof value == 'object';
610 }
611
612 /**
613 * Checks if `value` is classified as a `String` primitive or object.
614 *
615 * @static
616 * @memberOf _
617 * @category Lang
618 * @param {*} value The value to check.
619 * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
620 * @example
621 *
622 * _.isString('abc');
623 * // => true
624 *
625 * _.isString(1);
626 * // => false
627 */
628 function isString(value) {
629 return typeof value == 'string' ||
630 (!isArray(value) && isObjectLike(value) && objectToString.call(value) == s tringTag);
631 }
632
633 /*------------------------------------------------------------------------*/
634
635 /**
636 * Creates an array of the own enumerable property names of `object`.
637 *
638 * **Note:** Non-object values are coerced to objects. See the
639 * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
640 * for more details.
641 *
642 * @static
643 * @memberOf _
644 * @category Object
645 * @param {Object} object The object to query.
646 * @returns {Array} Returns the array of property names.
647 * @example
648 *
649 * function Foo() {
650 * this.a = 1;
651 * this.b = 2;
652 * }
653 *
654 * Foo.prototype.c = 3;
655 *
656 * _.keys(new Foo);
657 * // => ['a', 'b'] (iteration order is not guaranteed)
658 *
659 * _.keys('hi');
660 * // => ['0', '1']
661 */
662 function keys(object) {
663 var isProto = isPrototype(object);
664 if (!(isProto || isArrayLike(object))) {
665 return baseKeys(object);
666 }
667 var indexes = indexKeys(object),
668 skipIndexes = !!indexes,
669 result = indexes || [],
670 length = result.length;
671
672 for (var key in object) {
673 if (baseHas(object, key) &&
674 !(skipIndexes && (key == 'length' || isIndex(key, length))) &&
675 !(isProto && key == 'constructor')) {
676 result.push(key);
677 }
678 }
679 return result;
680 }
681
682 /**
683 * Creates an array of own enumerable key-value pairs for `object` which
684 * can be consumed by `_.fromPairs`.
685 *
686 * @static
687 * @memberOf _
688 * @category Object
689 * @param {Object} object The object to query.
690 * @returns {Array} Returns the new array of key-value pairs.
691 * @example
692 *
693 * function Foo() {
694 * this.a = 1;
695 * this.b = 2;
696 * }
697 *
698 * Foo.prototype.c = 3;
699 *
700 * _.toPairs(new Foo);
701 * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
702 */
703 function toPairs(object) {
704 return baseToPairs(object, keys(object));
705 }
706
707 /**
708 * Creates an array of the own enumerable property values of `object`.
709 *
710 * **Note:** Non-object values are coerced to objects.
711 *
712 * @static
713 * @memberOf _
714 * @category Object
715 * @param {Object} object The object to query.
716 * @returns {Array} Returns the array of property values.
717 * @example
718 *
719 * function Foo() {
720 * this.a = 1;
721 * this.b = 2;
722 * }
723 *
724 * Foo.prototype.c = 3;
725 *
726 * _.values(new Foo);
727 * // => [1, 2] (iteration order is not guaranteed)
728 *
729 * _.values('hi');
730 * // => ['h', 'i']
731 */
732 function values(object) {
733 return object ? baseValues(object, keys(object)) : [];
734 }
735
736 /*------------------------------------------------------------------------*/
737
738 // Add functions that return wrapped values when chaining.
739 lodash.keys = keys;
740 lodash.toPairs = toPairs;
741 lodash.values = values;
742
743 /*------------------------------------------------------------------------*/
744
745 // Add functions that return unwrapped values when chaining.
746 lodash.isArguments = isArguments;
747 lodash.isArray = isArray;
748 lodash.isArrayLike = isArrayLike;
749 lodash.isArrayLikeObject = isArrayLikeObject;
750 lodash.isFunction = isFunction;
751 lodash.isLength = isLength;
752 lodash.isObject = isObject;
753 lodash.isObjectLike = isObjectLike;
754 lodash.isString = isString;
755
756 /*------------------------------------------------------------------------*/
757
758 /**
759 * The semantic version number.
760 *
761 * @static
762 * @memberOf _
763 * @type {string}
764 */
765 lodash.VERSION = VERSION;
766
767 /*--------------------------------------------------------------------------*/
768
769 // Expose lodash on the free variable `window` or `self` when available. This
770 // prevents errors in cases where lodash is loaded by a script tag in the pres ence
771 // of an AMD loader. See http://requirejs.org/docs/errors.html#mismatch for mo re details.
772 (freeWindow || freeSelf || {})._ = lodash;
773
774 // Some AMD build optimizers like r.js check for condition patterns like the f ollowing:
775 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd ) {
776 // Define as an anonymous module so, through path mapping, it can be
777 // referenced as the "underscore" module.
778 define(function() {
779 return lodash;
780 });
781 }
782 // Check for `exports` after `define` in case a build optimizer adds an `expor ts` object.
783 else if (freeExports && freeModule) {
784 // Export for Node.js.
785 if (moduleExports) {
786 (freeModule.exports = lodash)._ = lodash;
787 }
788 // Export for CommonJS support.
789 freeExports._ = lodash;
790 }
791 else {
792 // Export to the global object.
793 root._ = lodash;
794 }
795 }.call(this));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698