source: imaps-frontend/node_modules/safe-array-concat/README.md@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[d565449]1# safe-array-concat <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2
3[![github actions][actions-image]][actions-url]
4[![coverage][codecov-image]][codecov-url]
5[![License][license-image]][license-url]
6[![Downloads][downloads-image]][downloads-url]
7
8[![npm badge][npm-badge-png]][package-url]
9
10`Array.prototype.concat`, but made safe by ignoring Symbol.isConcatSpreadable
11
12## Getting started
13
14```sh
15npm install --save safe-array-concat
16```
17
18## Usage/Examples
19
20```js
21var safeConcat = require('safe-array-concat');
22var assert = require('assert');
23
24assert.deepEqual([].concat([1, 2], 3, [[4]]), [1, 2, 3, [4]], 'arrays spread as expected with normal concat');
25assert.deepEqual(safeConcat([1, 2], 3, [[4]]), [1, 2, 3, [4]], 'arrays spread as expected with safe concat');
26
27String.prototype[Symbol.isConcatSpreadable] = true;
28assert.deepEqual([].concat('foo', Object('bar')), ['foo', 'b', 'a', 'r'], 'spreadable String objects are spread with normal concat!!!');
29assert.deepEqual(safeConcat('foo', Object('bar')), ['foo', Object('bar')], 'spreadable String objects are not spread with safe concat');
30
31Array.prototype[Symbol.isConcatSpreadable] = false;
32assert.deepEqual([].concat([1, 2], 3, [[4]]), [[], [1, 2], 3, [[4]]], 'non-concat-spreadable arrays do not spread with normal concat!!!');
33assert.deepEqual(safeConcat([1, 2], 3, [[4]]), [1, 2, 3, [4]], 'non-concat-spreadable arrays still spread with safe concat');
34```
35
36## Tests
37Simply clone the repo, `npm install`, and run `npm test`
38
39[package-url]: https://npmjs.org/package/safe-array-concat
40[npm-version-svg]: https://versionbadg.es/ljharb/safe-array-concat.svg
41[deps-svg]: https://david-dm.org/ljharb/safe-array-concat.svg
42[deps-url]: https://david-dm.org/ljharb/safe-array-concat
43[dev-deps-svg]: https://david-dm.org/ljharb/safe-array-concat/dev-status.svg
44[dev-deps-url]: https://david-dm.org/ljharb/safe-array-concat#info=devDependencies
45[npm-badge-png]: https://nodei.co/npm/safe-array-concat.png?downloads=true&stars=true
46[license-image]: https://img.shields.io/npm/l/safe-array-concat.svg
47[license-url]: LICENSE
48[downloads-image]: https://img.shields.io/npm/dm/safe-array-concat.svg
49[downloads-url]: https://npm-stat.com/charts.html?package=safe-array-concat
50[codecov-image]: https://codecov.io/gh/ljharb/safe-array-concat/branch/main/graphs/badge.svg
51[codecov-url]: https://app.codecov.io/gh/ljharb/safe-array-concat/
52[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/safe-array-concat
53[actions-url]: https://github.com/ljharb/safe-array-concat/actions
Note: See TracBrowser for help on using the repository browser.