object.getownpropertydescriptors
Advanced tools
Comparing version 2.0.3 to 2.1.0
@@ -0,1 +1,17 @@ | ||
2.1.0 / 2019-12-12 | ||
================= | ||
* [New] add auto entry point | ||
* [Refactor] use split-up `es-abstract` (78% bundle size decrease) | ||
* [readme] fix repo URLs, remove testling | ||
* [Docs] Fix formatting in the README (#30) | ||
* [Deps] update `define-properties`, `es-abstract` | ||
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `functions-have-names`, `covert`, `replace`, `semver`, `tape`, `@es-shims/api`; add `safe-publish-latest` | ||
* [meta] add `funding` field | ||
* [meta] Only apps should have lockfiles. | ||
* [Tests] use shared travis-ci configs | ||
* [Tests] use `functions-have-names` | ||
* [Tests] use `npx aud` instead of `nsp` or `npm audit` with hoops | ||
* [Tests] remove `jscs` | ||
* [actions] add automatic rebasing / merge commit blocking | ||
2.0.3 / 2016-07-26 | ||
@@ -2,0 +18,0 @@ ================= |
'use strict'; | ||
var ES = require('es-abstract/es7'); | ||
var CreateDataProperty = require('es-abstract/2019/CreateDataProperty'); | ||
var IsCallable = require('es-abstract/2019/IsCallable'); | ||
var RequireObjectCoercible = require('es-abstract/2019/RequireObjectCoercible'); | ||
var ToObject = require('es-abstract/2019/ToObject'); | ||
var callBound = require('es-abstract/helpers/callBound'); | ||
var defineProperty = Object.defineProperty; | ||
var getDescriptor = Object.getOwnPropertyDescriptor; | ||
var getOwnNames = Object.getOwnPropertyNames; | ||
var getSymbols = Object.getOwnPropertySymbols; | ||
var concat = Function.call.bind(Array.prototype.concat); | ||
var reduce = Function.call.bind(Array.prototype.reduce); | ||
var getAll = getSymbols ? function (obj) { | ||
return concat(getOwnNames(obj), getSymbols(obj)); | ||
} : getOwnNames; | ||
var $gOPD = Object.getOwnPropertyDescriptor; | ||
var $getOwnNames = Object.getOwnPropertyNames; | ||
var $getSymbols = Object.getOwnPropertySymbols; | ||
var $concat = callBound('Array.prototype.concat'); | ||
var $reduce = callBound('Array.prototype.reduce'); | ||
var getAll = $getSymbols ? function (obj) { | ||
return $concat($getOwnNames(obj), $getSymbols(obj)); | ||
} : $getOwnNames; | ||
var isES5 = ES.IsCallable(getDescriptor) && ES.IsCallable(getOwnNames); | ||
var isES5 = IsCallable($gOPD) && IsCallable($getOwnNames); | ||
var safePut = function put(obj, prop, val) { // eslint-disable-line max-params | ||
if (defineProperty && prop in obj) { | ||
defineProperty(obj, prop, { | ||
configurable: true, | ||
enumerable: true, | ||
value: val, | ||
writable: true | ||
}); | ||
} else { | ||
obj[prop] = val; | ||
} | ||
}; | ||
module.exports = function getOwnPropertyDescriptors(value) { | ||
ES.RequireObjectCoercible(value); | ||
RequireObjectCoercible(value); | ||
if (!isES5) { | ||
@@ -36,10 +26,14 @@ throw new TypeError('getOwnPropertyDescriptors requires Object.getOwnPropertyDescriptor'); | ||
var O = ES.ToObject(value); | ||
return reduce(getAll(O), function (acc, key) { | ||
var descriptor = getDescriptor(O, key); | ||
if (typeof descriptor !== 'undefined') { | ||
safePut(acc, key, descriptor); | ||
} | ||
return acc; | ||
}, {}); | ||
var O = ToObject(value); | ||
return $reduce( | ||
getAll(O), | ||
function (acc, key) { | ||
var descriptor = $gOPD(O, key); | ||
if (typeof descriptor !== 'undefined') { | ||
CreateDataProperty(acc, key, descriptor); | ||
} | ||
return acc; | ||
}, | ||
{} | ||
); | ||
}; |
{ | ||
"name": "object.getownpropertydescriptors", | ||
"version": "2.0.3", | ||
"author": "Jordan Harband", | ||
"version": "2.1.0", | ||
"author": "Jordan Harband <ljharb@gmail.com>", | ||
"funding": { | ||
"url": "https://github.com/sponsors/ljharb" | ||
}, | ||
"description": "ES2017 spec-compliant shim for `Object.getOwnPropertyDescriptors` that works in ES5.", | ||
@@ -9,18 +12,16 @@ "license": "MIT", | ||
"scripts": { | ||
"pretest": "npm run --silent lint && es-shim-api", | ||
"prepublish": "safe-publish-latest", | ||
"pretest": "npm run --silent lint && es-shim-api --bound", | ||
"test": "npm run --silent tests-only", | ||
"posttest": "npm run --silent security", | ||
"posttest": "npx aud", | ||
"tests-only": "npm run --silent test:shimmed && npm run --silent test:module", | ||
"test:shimmed": "node test/shimmed.js", | ||
"test:module": "node test/index.js", | ||
"test:shimmed": "node test/shimmed", | ||
"test:module": "node test", | ||
"coverage": "covert test/*.js", | ||
"coverage:quiet": "covert test/*.js --quiet", | ||
"lint": "npm run --silent jscs && npm run --silent eslint", | ||
"jscs": "jscs test/*.js *.js", | ||
"eslint": "eslint test/*.js *.js", | ||
"security": "nsp check" | ||
"lint": "eslint ." | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/ljharb/object.getownpropertydescriptors.git" | ||
"url": "git://github.com/es-shims/object.getownpropertydescriptors.git" | ||
}, | ||
@@ -39,15 +40,15 @@ "keywords": [ | ||
"dependencies": { | ||
"define-properties": "^1.1.2", | ||
"es-abstract": "^1.5.1" | ||
"define-properties": "^1.1.3", | ||
"es-abstract": "^1.17.0-next.1" | ||
}, | ||
"devDependencies": { | ||
"tape": "^4.6.0", | ||
"covert": "^1.1.0", | ||
"jscs": "^3.0.7", | ||
"nsp": "^2.6.1", | ||
"eslint": "^3.1.1", | ||
"@ljharb/eslint-config": "^6.0.0", | ||
"semver": "^5.3.0", | ||
"replace": "^0.3.0", | ||
"@es-shims/api": "^1.2.0" | ||
"@es-shims/api": "^2.1.2", | ||
"@ljharb/eslint-config": "^15.0.2", | ||
"covert": "^1.1.1", | ||
"eslint": "^6.7.2", | ||
"functions-have-names": "^1.2.0", | ||
"replace": "^1.1.1", | ||
"safe-publish-latest": "^1.1.4", | ||
"semver": "^6.3.0", | ||
"tape": "^4.11.0" | ||
}, | ||
@@ -79,2 +80,1 @@ "testling": { | ||
} | ||
@@ -1,2 +0,2 @@ | ||
#object.getownpropertydescriptors <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
# Object.getOwnPropertyDescriptors <sup>[![Version Badge][npm-version-svg]][package-url]</sup> | ||
@@ -11,4 +11,2 @@ [![Build Status][travis-svg]][travis-url] | ||
[![browser support][testling-svg]][testling-url] | ||
An ES2017 spec-compliant shim for `Object.getOwnPropertyDescriptors` that works in ES5. | ||
@@ -87,11 +85,9 @@ Invoke its "shim" method to shim `Object.getOwnPropertyDescriptors` if it is unavailable, and if `Object.getOwnPropertyDescriptor` is available. | ||
[package-url]: https://npmjs.org/package/object.getownpropertydescriptors | ||
[npm-version-svg]: http://versionbadg.es/ljharb/object.getownpropertydescriptors.svg | ||
[travis-svg]: https://travis-ci.org/ljharb/object.getownpropertydescriptors.svg | ||
[travis-url]: https://travis-ci.org/ljharb/object.getownpropertydescriptors | ||
[deps-svg]: https://david-dm.org/ljharb/object.getownpropertydescriptors.svg | ||
[deps-url]: https://david-dm.org/ljharb/object.getownpropertydescriptors | ||
[dev-deps-svg]: https://david-dm.org/ljharb/object.getownpropertydescriptors/dev-status.svg | ||
[dev-deps-url]: https://david-dm.org/ljharb/object.getownpropertydescriptors#info=devDependencies | ||
[testling-svg]: https://ci.testling.com/ljharb/object.getownpropertydescriptors.png | ||
[testling-url]: https://ci.testling.com/ljharb/object.getownpropertydescriptors | ||
[npm-version-svg]: http://versionbadg.es/es-shims/object.getownpropertydescriptors.svg | ||
[travis-svg]: https://travis-ci.org/es-shims/Object.getOwnPropertyDescriptors.svg | ||
[travis-url]: https://travis-ci.org/es-shims/Object.getOwnPropertyDescriptors | ||
[deps-svg]: https://david-dm.org/es-shims/object.getownpropertydescriptors.svg | ||
[deps-url]: https://david-dm.org/es-shims/object.getownpropertydescriptors | ||
[dev-deps-svg]: https://david-dm.org/es-shims/object.getownpropertydescriptors/dev-status.svg | ||
[dev-deps-url]: https://david-dm.org/es-shims/object.getownpropertydescriptors#info=devDependencies | ||
[npm-badge-png]: https://nodei.co/npm/object.getownpropertydescriptors.png?downloads=true&stars=true | ||
@@ -98,0 +94,0 @@ [license-image]: http://img.shields.io/npm/l/object.getownpropertydescriptors.svg |
@@ -9,4 +9,4 @@ 'use strict'; | ||
t.test('bad object/this value', function (st) { | ||
st.throws(function () { return getDescriptors(undefined); }, TypeError, 'undefined is not an object'); | ||
st.throws(function () { return getDescriptors(null); }, TypeError, 'null is not an object'); | ||
st['throws'](function () { return getDescriptors(undefined); }, TypeError, 'undefined is not an object'); | ||
st['throws'](function () { return getDescriptors(null); }, TypeError, 'null is not an object'); | ||
st.end(); | ||
@@ -13,0 +13,0 @@ }); |
@@ -10,3 +10,3 @@ 'use strict'; | ||
var isEnumerable = Object.prototype.propertyIsEnumerable; | ||
var functionsHaveNames = function f() {}.name === 'f'; | ||
var functionsHaveNames = require('functions-have-names')(); | ||
@@ -28,4 +28,4 @@ test('shimmed', function (t) { | ||
t.test('bad object/this value', { skip: !supportsStrictMode }, function (st) { | ||
st.throws(function () { return getDescriptors(undefined, 'a'); }, TypeError, 'undefined is not an object'); | ||
st.throws(function () { return getDescriptors(null, 'a'); }, TypeError, 'null is not an object'); | ||
st['throws'](function () { return getDescriptors(undefined, 'a'); }, TypeError, 'undefined is not an object'); | ||
st['throws'](function () { return getDescriptors(null, 'a'); }, TypeError, 'null is not an object'); | ||
st.end(); | ||
@@ -32,0 +32,0 @@ }); |
@@ -51,5 +51,3 @@ 'use strict'; | ||
/* eslint-disable no-extend-native */ | ||
delete Object.prototype[key]; | ||
/* eslint-enable no-extend-native */ | ||
st.end(); | ||
@@ -78,5 +76,5 @@ }); | ||
var supportsSymbols = typeof Symbol === 'function' && typeof Symbol() === 'symbol'; | ||
var supportsSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol'; | ||
t.test('gets Symbol descriptors too', { skip: !supportsSymbols }, function (st) { | ||
var symbol = Symbol(); | ||
var symbol = Symbol('sym'); | ||
var symDescriptor = { | ||
@@ -120,6 +118,3 @@ configurable: false, | ||
ownKeys: function () { | ||
return [ | ||
'foo', | ||
'bar' | ||
]; | ||
return ['foo', 'bar']; | ||
} | ||
@@ -126,0 +121,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21141
17
209
96
Updateddefine-properties@^1.1.3
Updatedes-abstract@^1.17.0-next.1