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