https://github.com/mathiasbynens/array.from
A robust & optimized ES3-compatible polyfill for the `Array.from` method in ECMAScript 6.
https://github.com/mathiasbynens/array.from
Last synced: 9 months ago
JSON representation
A robust & optimized ES3-compatible polyfill for the `Array.from` method in ECMAScript 6.
- Host: GitHub
- URL: https://github.com/mathiasbynens/array.from
- Owner: mathiasbynens
- License: mit
- Created: 2013-12-20T16:09:57.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2024-03-23T05:45:10.000Z (almost 2 years ago)
- Last Synced: 2025-03-31T18:19:29.963Z (9 months ago)
- Language: JavaScript
- Homepage: https://mths.be/array-from
- Size: 164 KB
- Stars: 67
- Watchers: 4
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# Array.from [![Version Badge][npm-version-svg]][package-url]
[![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]
A spec-compliant `Array.from` shim/polyfill/replacement that works as far down as ES3.
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](http://www.ecma-international.org/ecma-262/6.0/#sec-array.from).
The `Array.from()` method creates a new Array instance from an array-like or iterable object.
## Installation
```bash
npm install array.from
```
## Example
```js
var from = require('array.from');
var assert = require('assert');
assert.deepEqual(from('abc'), ['a', 'b', 'c']);
```
```js
var from = require('array.from');
var assert = require('assert');
/* when Array#from is not present */
delete Array.from;
var shimmedFrom = from.shim();
assert.equal(shimmedFrom, from.getPolyfill());
assert.deepEqual(Array.from('foo'), from('foo'));
```
```js
var from = require('array.from');
var assert = require('assert');
/* when Array#from is present */
var shimmedFrom = from.shim();
assert.equal(shimmedFrom, Array.from);
assert.deepEqual(Array.from('abc'), from('abc'));
```
## Tests
Simply clone the repo, `npm install`, and run `npm test`
## Author
| [](https://twitter.com/mathias "Follow @mathias on Twitter") |
|---|
| [Mathias Bynens](https://mathiasbynens.be/) |
## License
This polyfill is available under the [MIT](https://mths.be/mit) license.
[package-url]: https://npmjs.org/package/array.from
[npm-version-svg]: http://versionbadg.es/mathiasbynens/Array.from.svg
[travis-svg]: https://travis-ci.org/mathiasbynens/Array.from.svg
[travis-url]: https://travis-ci.org/mathiasbynens/Array.from
[deps-svg]: https://david-dm.org/mathiasbynens/Array.from.svg
[deps-url]: https://david-dm.org/mathiasbynens/Array.from
[dev-deps-svg]: https://david-dm.org/mathiasbynens/Array.from/dev-status.svg
[dev-deps-url]: https://david-dm.org/mathiasbynens/Array.from#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/array.from.png?downloads=true&stars=true
[license-image]: http://img.shields.io/npm/l/array.from.svg
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/array.from.svg
[downloads-url]: http://npm-stat.com/charts.html?package=array.from