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.

37 lines
884 B

4 years ago
  1. var arrayLikeKeys = require('./_arrayLikeKeys'),
  2. baseKeys = require('./_baseKeys'),
  3. isArrayLike = require('./isArrayLike');
  4. /**
  5. * Creates an array of the own enumerable property names of `object`.
  6. *
  7. * **Note:** Non-object values are coerced to objects. See the
  8. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  9. * for more details.
  10. *
  11. * @static
  12. * @since 0.1.0
  13. * @memberOf _
  14. * @category Object
  15. * @param {Object} object The object to query.
  16. * @returns {Array} Returns the array of property names.
  17. * @example
  18. *
  19. * function Foo() {
  20. * this.a = 1;
  21. * this.b = 2;
  22. * }
  23. *
  24. * Foo.prototype.c = 3;
  25. *
  26. * _.keys(new Foo);
  27. * // => ['a', 'b'] (iteration order is not guaranteed)
  28. *
  29. * _.keys('hi');
  30. * // => ['0', '1']
  31. */
  32. function keys(object) {
  33. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  34. }
  35. module.exports = keys;