source: node_modules/ramda/es/keys.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1import _curry1 from "./internal/_curry1.js";
2import _has from "./internal/_has.js";
3import _isArguments from "./internal/_isArguments.js"; // cover IE < 9 keys issues
4
5var hasEnumBug = !
6/*#__PURE__*/
7{
8 toString: null
9}.propertyIsEnumerable('toString');
10var nonEnumerableProps = ['constructor', 'valueOf', 'isPrototypeOf', 'toString', 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString']; // Safari bug
11
12var hasArgsEnumBug =
13/*#__PURE__*/
14function () {
15 'use strict';
16
17 return arguments.propertyIsEnumerable('length');
18}();
19
20var 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
53var 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});
91export default keys;
Note: See TracBrowser for help on using the repository browser.