mirror of
https://github.com/swc-project/swc.git
synced 2024-12-21 12:41:54 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
78 lines
2.0 KiB
TypeScript
78 lines
2.0 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/keys.js
|
|
|
|
|
|
import _curry1 from './internal/_curry1.js';
|
|
import _has from './internal/_has.js';
|
|
import _isArguments from './internal/_isArguments.js';
|
|
|
|
// cover IE < 9 keys issues
|
|
var hasEnumBug = !({toString: null}).propertyIsEnumerable('toString');
|
|
var nonEnumerableProps = [
|
|
'constructor', 'valueOf', 'isPrototypeOf', 'toString',
|
|
'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'
|
|
];
|
|
// Safari bug
|
|
var hasArgsEnumBug = (function() {
|
|
'use strict';
|
|
return arguments.propertyIsEnumerable('length');
|
|
}());
|
|
|
|
var contains = function contains(list, item) {
|
|
var idx = 0;
|
|
while (idx < list.length) {
|
|
if (list[idx] === item) {
|
|
return true;
|
|
}
|
|
idx += 1;
|
|
}
|
|
return false;
|
|
};
|
|
|
|
/**
|
|
* Returns a list containing the names of all the enumerable own properties of
|
|
* the supplied object.
|
|
* Note that the order of the output array is not guaranteed to be consistent
|
|
* across different JS platforms.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.1.0
|
|
* @category Object
|
|
* @sig {k: v} -> [k]
|
|
* @param {Object} obj The object to extract properties from
|
|
* @return {Array} An array of the object's own properties.
|
|
* @see R.keysIn, R.values
|
|
* @example
|
|
*
|
|
* R.keys({a: 1, b: 2, c: 3}); //=> ['a', 'b', 'c']
|
|
*/
|
|
var keys = typeof Object.keys === 'function' && !hasArgsEnumBug ?
|
|
_curry1(function keys(obj) {
|
|
return Object(obj) !== obj ? [] : Object.keys(obj);
|
|
}) :
|
|
_curry1(function keys(obj) {
|
|
if (Object(obj) !== obj) {
|
|
return [];
|
|
}
|
|
var prop, nIdx;
|
|
var ks = [];
|
|
var checkArgsLength = hasArgsEnumBug && _isArguments(obj);
|
|
for (prop in obj) {
|
|
if (_has(prop, obj) && (!checkArgsLength || prop !== 'length')) {
|
|
ks[ks.length] = prop;
|
|
}
|
|
}
|
|
if (hasEnumBug) {
|
|
nIdx = nonEnumerableProps.length - 1;
|
|
while (nIdx >= 0) {
|
|
prop = nonEnumerableProps[nIdx];
|
|
if (_has(prop, obj) && !contains(ks, prop)) {
|
|
ks[ks.length] = prop;
|
|
}
|
|
nIdx -= 1;
|
|
}
|
|
}
|
|
return ks;
|
|
});
|
|
export default keys;
|