Coder Social home page Coder Social logo

es-shims / array.prototype.flat Goto Github PK

View Code? Open in Web Editor NEW
32.0 5.0 8.0 133 KB

An ESnext spec-compliant `Array.prototype.flat` shim/polyfill/replacement that works as far down as ES3.

License: MIT License

JavaScript 100.00%
ecmascript javascript polyfill shim array flat flatten

array.prototype.flat's Introduction

array.prototype.flat Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

An ES2019 spec-compliant Array.prototype.flat shim/polyfill/replacement that works as far down as ES3.

This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the proposed spec.

Because Array.prototype.flat depends on a receiver (the this value), the main export takes the array to operate on as the first argument.

Getting started

npm install --save array.prototype.flat

Usage/Examples

var flat = require('array.prototype.flat');
var assert = require('assert');

var arr = [1, [2], [], 3, [[4]]];

assert.deepEqual(flat(arr, 1), [1, 2, 3, [4]]);
var flat = require('array.prototype.flat');
var assert = require('assert');
/* when Array#flat is not present */
delete Array.prototype.flat;
var shimmedFlat = flat.shim();

assert.equal(shimmedFlat, flat.getPolyfill());
assert.deepEqual(arr.flat(), flat(arr));
var flat = require('array.prototype.flat');
var assert = require('assert');
/* when Array#flat is present */
var shimmedIncludes = flat.shim();

var mapper = function (x) { return [x, 1]; };

assert.equal(shimmedIncludes, Array.prototype.flat);
assert.deepEqual(arr.flat(mapper), flat(arr, mapper));

Tests

Simply clone the repo, npm install, and run npm test

array.prototype.flat's People

Contributors

aminland avatar bakkot avatar ljharb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

array.prototype.flat's Issues

An in-range update of es-abstract is breaking the build 🚨


☝️ Important announcement: Greenkeeper will be saying goodbye πŸ‘‹ and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io


The dependency es-abstract was updated from 1.17.4 to 1.17.5.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

es-abstract is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details

Commits

The new version differs by 5 commits.

  • 3641bbb v1.17.5
  • bdd77b5 [Fix] CreateDataProperty: update an existing property
  • 920a682 [Dev Deps] update make-arrow-function, tape
  • b9069ac [Fix] run missing spackle from cd7504701879ddea0f5981e99cbcf93bfea9171d
  • 9f1690f [Dev Deps] update @ljharb/eslint-config

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of es-abstract is breaking the build 🚨

The dependency es-abstract was updated from 1.17.0-next.1 to 1.17.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

es-abstract is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details

Commits

The new version differs by 12 commits.

  • 91c2c22 v1.17.0
  • 96719b9 [Dev Deps] update @ljharb/eslint-config
  • c52fa59 [Fix] GetIntrinsic: IE 8 has a broken Object.getOwnPropertyDescriptor
  • fb308ec [Deps] update is-callable, string.prototype.trimleft, string.prototype.trimright
  • b84552d [Dev Deps] update tape
  • 9be0385 [Refactor] GetIntrinsic: further simplification
  • 0c7f99a [Tests] add .eslintignore
  • e2df4de [Dev Deps] update object-is
  • 158ed34 [Deps] update is-regex
  • 3567ae9 [Refactor] GetIntrinsic: remove the internal property salts, since % already handles that
  • 84c50fb [Dev Deps] update object.fromentries
  • f0b1083 [meta] remove unused Makefile and associated utils

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Backwards compatibility: v1.2.3 seems to use [email protected]

It seems the latest version is referencing [email protected] which I think may have some backwards compatibility issues.
Seeing things like:

Test suite failed to run

    Cannot find module 'es-abstract/2019/ArraySpeciesCreate' from 'implementation.js'

      at Resolver.resolveModule (../home/devusr/node_modules/jest-resolve/build/index.js:221:17)
      at Object.<anonymous> (../home/devusr/node_modules/array.prototype.flat/implementation.js:3:26)

It's possible it could be something in our dependency try that I'm confusing. I guess I'm looking to make sure the use of [email protected] in the current release is intentional.

Incorrectly eats React nodes in jest tests

console.log([<span>Hello</span>].flat(Infinity)) outputs [] when using this shim in tests, but it should output [{ $type...etc }].

It seems to eat the react (jsx) element.

npm error installing on windows

When I run npm i array.prototype.flat -D
I got the error

npm ERR! code ENOENT
npm ERR! syscall rename
npm ERR! path C:\ProjectCode\pwc-frontend-framework\node_modules\array.prototype.flat
npm ERR! dest C:\ProjectCode\pwc-frontend-framework\node_modules.array.prototype.flat.DELETE
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, rename 'C:\ProjectCode\pwc-frontend-framework\node_modules\array.prototype.flat' -> 'C:\ProjectCode\pwc-frontend-framework\node_modules.array.prototype.flat.DELETE'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\meng mb zhang\AppData\Roaming\npm-cache_logs\2019-12-19T02_08_04_234Z-debug.log

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm aud Unavailable

Pending Approval

These branches will be created by Renovate only once you click their checkbox below.

  • [Deps] Update Update eslint to v8.57.0
  • [Deps] Update Update aud to v3
  • [Deps] Update Update eslint to v9
  • [Deps] Update Update nyc to v17
  • πŸ” Create all pending approval PRs at once πŸ”

Detected dependencies

github-actions
.github/workflows/node-aught.yml
.github/workflows/node-pretest.yml
.github/workflows/node-tens.yml
.github/workflows/rebase.yml
.github/workflows/require-allow-edits.yml
npm
package.json
  • call-bind ^1.0.2
  • define-properties ^1.2.0
  • es-abstract ^1.22.1
  • es-shim-unscopables ^1.0.0
  • @es-shims/api ^2.4.2
  • @ljharb/eslint-config ^21.1.0
  • aud ^2.0.3
  • auto-changelog ^2.4.0
  • covert ^1.1.1
  • eslint =8.8.0
  • evalmd ^0.0.19
  • function-bind ^1.1.1
  • has-strict-mode ^1.0.1
  • in-publish ^2.0.1
  • npmignore ^0.3.0
  • nyc ^10.3.2
  • object-inspect ^1.12.3
  • safe-publish-latest ^2.0.0
  • tape ^5.6.6
  • node >= 0.4

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.