1 | import _curry1 from "./internal/_curry1.js";
|
---|
2 | import _has from "./internal/_has.js";
|
---|
3 | import _isArguments from "./internal/_isArguments.js"; // cover IE < 9 keys issues
|
---|
4 |
|
---|
5 | var hasEnumBug = !
|
---|
6 | /*#__PURE__*/
|
---|
7 | {
|
---|
8 | toString: null
|
---|
9 | }.propertyIsEnumerable('toString');
|
---|
10 | var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString', 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString']; // Safari bug
|
---|
11 |
|
---|
12 | var hasArgsEnumBug =
|
---|
13 | /*#__PURE__*/
|
---|
14 | function () {
|
---|
15 | 'use strict';
|
---|
16 |
|
---|
17 | return arguments.propertyIsEnumerable('length');
|
---|
18 | }();
|
---|
19 |
|
---|
20 | var contains = function contains(list, item) {
|
---|
21 | var idx = 0;
|
---|
22 |
|
---|
23 | while (idx < list.length) {
|
---|
24 | if (list[idx] === item) {
|
---|
25 | return true;
|
---|
26 | }
|
---|
27 |
|
---|
28 | idx += 1;
|
---|
29 | }
|
---|
30 |
|
---|
31 | return false;
|
---|
32 | };
|
---|
33 | /**
|
---|
34 | * Returns a list containing the names of all the enumerable own properties of
|
---|
35 | * the supplied object.
|
---|
36 | * Note that the order of the output array is not guaranteed to be consistent
|
---|
37 | * across different JS platforms.
|
---|
38 | *
|
---|
39 | * @func
|
---|
40 | * @memberOf R
|
---|
41 | * @since v0.1.0
|
---|
42 | * @category Object
|
---|
43 | * @sig {k: v} -> [k]
|
---|
44 | * @param {Object} obj The object to extract properties from
|
---|
45 | * @return {Array} An array of the object's own properties.
|
---|
46 | * @see R.keysIn, R.values, R.toPairs
|
---|
47 | * @example
|
---|
48 | *
|
---|
49 | * R.keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c']
|
---|
50 | */
|
---|
51 |
|
---|
52 |
|
---|
53 | var keys = typeof Object.keys === 'function' && !hasArgsEnumBug ?
|
---|
54 | /*#__PURE__*/
|
---|
55 | _curry1(function keys(obj) {
|
---|
56 | return Object(obj) !== obj ? [] : Object.keys(obj);
|
---|
57 | }) :
|
---|
58 | /*#__PURE__*/
|
---|
59 | _curry1(function keys(obj) {
|
---|
60 | if (Object(obj) !== obj) {
|
---|
61 | return [];
|
---|
62 | }
|
---|
63 |
|
---|
64 | var prop, nIdx;
|
---|
65 | var ks = [];
|
---|
66 |
|
---|
67 | var checkArgsLength = hasArgsEnumBug && _isArguments(obj);
|
---|
68 |
|
---|
69 | for (prop in obj) {
|
---|
70 | if (_has(prop, obj) && (!checkArgsLength || prop !== 'length')) {
|
---|
71 | ks[ks.length] = prop;
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | if (hasEnumBug) {
|
---|
76 | nIdx = nonEnumerableProps.length - 1;
|
---|
77 |
|
---|
78 | while (nIdx >= 0) {
|
---|
79 | prop = nonEnumerableProps[nIdx];
|
---|
80 |
|
---|
81 | if (_has(prop, obj) && !contains(ks, prop)) {
|
---|
82 | ks[ks.length] = prop;
|
---|
83 | }
|
---|
84 |
|
---|
85 | nIdx -= 1;
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | return ks;
|
---|
90 | });
|
---|
91 | export default keys; |
---|