init source
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
max_line_length = 150
|
||||
|
||||
[CHANGELOG.md]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.json]
|
||||
max_line_length = off
|
||||
|
||||
[Makefile]
|
||||
max_line_length = off
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"root": true,
|
||||
|
||||
"extends": "@ljharb",
|
||||
|
||||
"rules": {
|
||||
"max-statements-per-line": [2, { "max": 2 }],
|
||||
"max-statements": [2, 22],
|
||||
"multiline-comment-style": 1,
|
||||
"new-cap": [2, {
|
||||
"capIsNewExceptions": [
|
||||
"AddEntriesFromIterable",
|
||||
"CreateDataPropertyOrThrow",
|
||||
"Get",
|
||||
"GetIterator",
|
||||
"IsArray",
|
||||
"IteratorStep",
|
||||
"IteratorClose",
|
||||
"IteratorValue",
|
||||
"ThrowCompletion",
|
||||
"ToPropertyKey",
|
||||
"Type",
|
||||
"RequireObjectCoercible",
|
||||
],
|
||||
}],
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"files": "test/**",
|
||||
"rules": {
|
||||
"no-invalid-this": 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
+319
@@ -0,0 +1,319 @@
|
||||
language: node_js
|
||||
os:
|
||||
- linux
|
||||
node_js:
|
||||
- "12.11"
|
||||
- "11.15"
|
||||
- "10.16"
|
||||
- "9.11"
|
||||
- "8.16"
|
||||
- "7.10"
|
||||
- "6.17"
|
||||
- "5.12"
|
||||
- "4.9"
|
||||
- "iojs-v3.3"
|
||||
- "iojs-v2.5"
|
||||
- "iojs-v1.8"
|
||||
- "0.12"
|
||||
- "0.10"
|
||||
- "0.8"
|
||||
before_install:
|
||||
- 'case "${TRAVIS_NODE_VERSION}" in 0.*) export NPM_CONFIG_STRICT_SSL=false ;; esac'
|
||||
- 'nvm install-latest-npm'
|
||||
install:
|
||||
- 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;'
|
||||
script:
|
||||
- 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi'
|
||||
- 'if [ -n "${POSTTEST-}" ]; then npm run posttest ; fi'
|
||||
- 'if [ -n "${COVERAGE-}" ]; then npm run coverage ; fi'
|
||||
- 'if [ -n "${TEST-}" ]; then npm run tests-only ; fi'
|
||||
sudo: false
|
||||
env:
|
||||
- TEST=true
|
||||
matrix:
|
||||
fast_finish: true
|
||||
include:
|
||||
- node_js: "lts/*"
|
||||
env: PRETEST=true
|
||||
- node_js: "lts/*"
|
||||
env: POSTTEST=true
|
||||
- node_js: "4"
|
||||
env: COVERAGE=true
|
||||
- node_js: "12.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "12.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.14"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.13"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.12"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.11"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "11.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.15"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.14"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.13"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.12"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.11"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "10.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "9.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.15"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.14"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.13"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.12"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.11"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "8.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "7.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.16"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.15"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.14"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.13"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.12"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.11"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "6.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.11"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.10"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "5.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.8"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "4.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v3.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v3.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v3.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v2.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v2.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v2.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v2.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v2.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.7"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.5"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.3"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.2"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.1"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "iojs-v1.0"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "0.11"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "0.9"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "0.6"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
- node_js: "0.4"
|
||||
env: TEST=true ALLOW_FAILURE=true
|
||||
allow_failures:
|
||||
- os: osx
|
||||
- env: TEST=true ALLOW_FAILURE=true
|
||||
- env: COVERAGE=true
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
2.0.1 / 2019-10-03
|
||||
=================
|
||||
* [Fix] do not mutate `Object.fromEntries` when already present
|
||||
* [Deps] update `define-properties`, `es-abstract`, `has`
|
||||
* [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `covert`, `tape`
|
||||
* [Tests] up to `node` `v12.9`, `v11.15`, `v10.16`, `v9.11`, `v8.16`, `v6.17`, `v4.9`
|
||||
* [Tests] use `npx aud` instead of `nsp` or `npm audit` with hoops
|
||||
|
||||
2.0.0 / 2018-08-09
|
||||
=================
|
||||
* [Breaking] throw when `iterable` is nullish
|
||||
* [Docs] Fix link to proposed spec
|
||||
|
||||
1.0.0 / 2018-03-21
|
||||
=================
|
||||
* v1.0.0
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 Jordan Harband
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
# object.fromentries <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
||||
|
||||
[![Build Status][travis-svg]][travis-url]
|
||||
[![dependency status][deps-svg]][deps-url]
|
||||
[![dev dependency status][dev-deps-svg]][dev-deps-url]
|
||||
[![License][license-image]][license-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
|
||||
[![npm badge][npm-badge-png]][package-url]
|
||||
|
||||
[![browser support][testling-svg]][testling-url]
|
||||
|
||||
An ES spec-proposal-compliant `Object.fromEntries` shim. Invoke its "shim" method to shim `Object.fromEntries` if it is unavailable or noncompliant.
|
||||
|
||||
This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the [proposed spec](https://tc39.github.io/proposal-object-from-entries/).
|
||||
|
||||
Most common usage:
|
||||
```js
|
||||
var assert = require('assert');
|
||||
var fromEntries = require('object.fromentries');
|
||||
|
||||
var obj = { a: 1, b: 2, c: 3 };
|
||||
var actual = fromEntries(Object.entries(obj));
|
||||
|
||||
assert.deepEqual(obj, actual);
|
||||
|
||||
if (!Object.fromEntries) {
|
||||
fromEntries.shim();
|
||||
}
|
||||
|
||||
assert.deepEqual(Object.fromEntries(Object.entries(obj)), obj);
|
||||
```
|
||||
|
||||
## Tests
|
||||
Simply clone the repo, `npm install`, and run `npm test`
|
||||
|
||||
[package-url]: https://npmjs.com/package/object.fromentries
|
||||
[npm-version-svg]: http://versionbadg.es/es-shims/Object.fromEntries.svg
|
||||
[travis-svg]: https://travis-ci.org/es-shims/Object.fromEntries.svg
|
||||
[travis-url]: https://travis-ci.org/es-shims/Object.fromEntries
|
||||
[deps-svg]: https://david-dm.org/es-shims/Object.fromEntries.svg
|
||||
[deps-url]: https://david-dm.org/es-shims/Object.fromEntries
|
||||
[dev-deps-svg]: https://david-dm.org/es-shims/Object.fromEntries/dev-status.svg
|
||||
[dev-deps-url]: https://david-dm.org/es-shims/Object.fromEntries#info=devDependencies
|
||||
[testling-svg]: https://ci.testling.com/es-shims/Object.fromEntries.png
|
||||
[testling-url]: https://ci.testling.com/es-shims/Object.fromEntries
|
||||
[npm-badge-png]: https://nodei.co/npm/object.fromentries.png?downloads=true&stars=true
|
||||
[license-image]: http://img.shields.io/npm/l/object.fromentries.svg
|
||||
[license-url]: LICENSE
|
||||
[downloads-image]: http://img.shields.io/npm/dm/object.fromentries.svg
|
||||
[downloads-url]: http://npm-stat.com/charts.html?package=object.fromentries
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
require('./shim')();
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
var ES = require('es-abstract/es2019');
|
||||
|
||||
var adder = function addDataProperty(key, value) {
|
||||
var O = this; // eslint-disable-line no-invalid-this
|
||||
var propertyKey = ES.ToPropertyKey(key);
|
||||
ES.CreateDataPropertyOrThrow(O, propertyKey, value);
|
||||
};
|
||||
|
||||
var legacyAssign = function assign(obj, entries) {
|
||||
for (var i = 0; i < entries.length; ++i) {
|
||||
var entry = entries[i];
|
||||
if (ES.Type(entry) !== 'Object') {
|
||||
throw new TypeError('iterator returned a non-object; entry expected');
|
||||
}
|
||||
|
||||
var key = ES.Get(entry, '0');
|
||||
var value = ES.Get(entry, '1');
|
||||
var propertyKey = ES.ToPropertyKey(key);
|
||||
ES.CreateDataPropertyOrThrow(obj, propertyKey, value);
|
||||
}
|
||||
};
|
||||
|
||||
var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
|
||||
|
||||
module.exports = function fromEntries(iterable) {
|
||||
ES.RequireObjectCoercible(iterable);
|
||||
|
||||
var obj = {};
|
||||
|
||||
// this part isn't in the spec, it's for a reasonable fallback for pre-ES6 environments
|
||||
if (!hasSymbols) {
|
||||
if (!ES.IsArray(iterable)) {
|
||||
throw new TypeError('this environment lacks native Symbols, and can not support non-Array iterables');
|
||||
}
|
||||
legacyAssign(obj, iterable);
|
||||
return obj;
|
||||
}
|
||||
|
||||
return ES.AddEntriesFromIterable(obj, iterable, adder);
|
||||
};
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
var define = require('define-properties');
|
||||
var bind = require('function-bind');
|
||||
|
||||
var implementation = require('./implementation');
|
||||
var getPolyfill = require('./polyfill');
|
||||
var shim = require('./shim');
|
||||
|
||||
var polyfill = bind.call(getPolyfill());
|
||||
|
||||
define(polyfill, {
|
||||
getPolyfill: getPolyfill,
|
||||
implementation: implementation,
|
||||
shim: shim
|
||||
});
|
||||
|
||||
module.exports = polyfill;
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"object.fromentries@2.0.1",
|
||||
"/home/app"
|
||||
]
|
||||
],
|
||||
"_development": true,
|
||||
"_from": "object.fromentries@2.0.1",
|
||||
"_id": "object.fromentries@2.0.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-PUQv8Hbg3j2QX0IQYv3iAGCbGcu4yY4KQ92/dhA4sFSixBmSmp13UpDLs6jGK8rBtbmhNNIK99LD2k293jpiGA==",
|
||||
"_location": "/object.fromentries",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "object.fromentries@2.0.1",
|
||||
"name": "object.fromentries",
|
||||
"escapedName": "object.fromentries",
|
||||
"rawSpec": "2.0.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.0.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/eslint-plugin-react"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/object.fromentries/-/object.fromentries-2.0.1.tgz",
|
||||
"_spec": "2.0.1",
|
||||
"_where": "/home/app",
|
||||
"author": {
|
||||
"name": "Jordan Harband"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/es-shims/Object.fromEntries/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"define-properties": "^1.1.3",
|
||||
"es-abstract": "^1.15.0",
|
||||
"function-bind": "^1.1.1",
|
||||
"has": "^1.0.3"
|
||||
},
|
||||
"description": "ES proposal-spec-compliant Object.fromEntries shim.",
|
||||
"devDependencies": {
|
||||
"@es-shims/api": "^2.1.2",
|
||||
"@ljharb/eslint-config": "^14.1.0",
|
||||
"array-map": "^0.0.0",
|
||||
"covert": "^1.1.1",
|
||||
"eslint": "^6.5.1",
|
||||
"tape": "^4.11.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"homepage": "https://github.com/es-shims/Object.fromEntries#readme",
|
||||
"keywords": [
|
||||
"Object.fromEntries",
|
||||
"Object.entries",
|
||||
"Object.values",
|
||||
"Object.keys",
|
||||
"entries",
|
||||
"values",
|
||||
"ES7",
|
||||
"ES8",
|
||||
"ES2017",
|
||||
"shim",
|
||||
"object",
|
||||
"keys",
|
||||
"polyfill",
|
||||
"es-shim API"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "object.fromentries",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/es-shims/Object.fromEntries.git"
|
||||
},
|
||||
"scripts": {
|
||||
"coverage": "covert test/*.js",
|
||||
"coverage-quiet": "covert test/*.js --quiet",
|
||||
"lint": "eslint test/*.js *.js",
|
||||
"posttest": "npx aud",
|
||||
"pretest": "npm run --silent lint",
|
||||
"test": "npm run --silent tests-only",
|
||||
"test:module": "node test/index.js",
|
||||
"test:shimmed": "node test/shimmed.js",
|
||||
"tests-only": "es-shim-api --bound && npm run --silent test:shimmed && npm run --silent test:module"
|
||||
},
|
||||
"testling": {
|
||||
"files": "test/index.js",
|
||||
"browsers": [
|
||||
"iexplore/9.0..latest",
|
||||
"firefox/4.0..6.0",
|
||||
"firefox/15.0..latest",
|
||||
"firefox/nightly",
|
||||
"chrome/4.0..10.0",
|
||||
"chrome/20.0..latest",
|
||||
"chrome/canary",
|
||||
"opera/11.6..latest",
|
||||
"opera/next",
|
||||
"safari/5.0..latest",
|
||||
"ipad/6.0..latest",
|
||||
"iphone/6.0..latest",
|
||||
"android-browser/4.2"
|
||||
]
|
||||
},
|
||||
"version": "2.0.1"
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var implementation = require('./implementation');
|
||||
|
||||
module.exports = function getPolyfill() {
|
||||
return typeof Object.fromEntries === 'function' ? Object.fromEntries : implementation;
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
var getPolyfill = require('./polyfill');
|
||||
var define = require('define-properties');
|
||||
|
||||
module.exports = function shimEntries() {
|
||||
var polyfill = getPolyfill();
|
||||
define(Object, { fromEntries: polyfill }, {
|
||||
fromEntries: function testEntries() {
|
||||
return Object.fromEntries !== polyfill;
|
||||
}
|
||||
});
|
||||
return polyfill;
|
||||
};
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
var fromEntries = require('../');
|
||||
var test = require('tape');
|
||||
var runTests = require('./tests');
|
||||
|
||||
test('as a function', function (t) {
|
||||
t.test('bad array/this value', function (st) {
|
||||
st['throws'](function () { fromEntries(undefined); }, TypeError, 'undefined is not an object');
|
||||
st['throws'](function () { fromEntries(null); }, TypeError, 'null is not an object');
|
||||
st.end();
|
||||
});
|
||||
|
||||
runTests(fromEntries, t);
|
||||
|
||||
t.end();
|
||||
});
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
var fromEntries = require('../');
|
||||
fromEntries.shim();
|
||||
|
||||
var test = require('tape');
|
||||
var keys = require('object-keys');
|
||||
var defineProperties = require('define-properties');
|
||||
var isEnumerable = Object.prototype.propertyIsEnumerable;
|
||||
var functionsHaveNames = function f() {}.name === 'f';
|
||||
|
||||
var runTests = require('./tests');
|
||||
|
||||
test('shimmed', function (t) {
|
||||
t.equal(Object.fromEntries.length, 1, 'Object.fromEntries has a length of 1');
|
||||
t.test('Function name', { skip: !functionsHaveNames }, function (st) {
|
||||
st.equal(Object.fromEntries.name, 'fromEntries', 'Object.fromEntries has name "fromEntries"');
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('enumerability', { skip: !defineProperties.supportsDescriptors }, function (et) {
|
||||
et.equal(false, isEnumerable.call(Object, 'fromEntries'), 'Object.fromEntries is not enumerable');
|
||||
et.end();
|
||||
});
|
||||
|
||||
var supportsStrictMode = (function () { return typeof this === 'undefined'; }());
|
||||
|
||||
t.test('bad object value', { skip: !supportsStrictMode }, function (st) {
|
||||
st['throws'](function () { return Object.fromEntries(undefined); }, TypeError, 'undefined is not an object');
|
||||
st['throws'](function () { return Object.fromEntries(null); }, TypeError, 'null is not an object');
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.test('does not mutate global method', function (st) {
|
||||
st.deepEqual(keys(Object.fromEntries), [], 'no enumerable keys');
|
||||
st.equal('shim' in Object.fromEntries, false, '"shim" is not present');
|
||||
st.equal('getPolyfill' in Object.fromEntries, false, '"getPolyfill" is not present');
|
||||
st.equal('implementation' in Object.fromEntries, false, '"implementation" is not present');
|
||||
st.end();
|
||||
});
|
||||
|
||||
runTests(Object.fromEntries, t);
|
||||
|
||||
t.end();
|
||||
});
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (fromEntries, t) {
|
||||
var a = {};
|
||||
var b = {};
|
||||
var c = {};
|
||||
var entries = [['a', a], ['b', b], ['c', c]];
|
||||
var obj = { a: a, b: b, c: c };
|
||||
|
||||
t.deepEqual(fromEntries(entries), obj, 'entries -> obj');
|
||||
|
||||
t['throws'](function () { fromEntries(); }, 'entries throws on absent iterable');
|
||||
t['throws'](function () { fromEntries(undefined); }, 'entries throws on undefined');
|
||||
t['throws'](function () { fromEntries(null); }, 'entries throws on null');
|
||||
};
|
||||
Reference in New Issue
Block a user