包详细信息

safe-array-concat

ljharb141.1mMIT1.1.3

Array.prototype.concat, but made safe by ignoring Symbol.isConcatSpreadable

safe, Array, concat, push

自述文件

safe-array-concat Version Badge

github actions coverage License Downloads

npm badge

Array.prototype.concat, but made safe by ignoring Symbol.isConcatSpreadable

Getting started

npm install --save safe-array-concat

Usage/Examples

var safeConcat = require('safe-array-concat');
var assert = require('assert');

assert.deepEqual([].concat([1, 2], 3, [[4]]), [1, 2, 3, [4]], 'arrays spread as expected with normal concat');
assert.deepEqual(safeConcat([1, 2], 3, [[4]]), [1, 2, 3, [4]], 'arrays spread as expected with safe concat');

String.prototype[Symbol.isConcatSpreadable] = true;
assert.deepEqual([].concat('foo', Object('bar')), ['foo', 'b', 'a', 'r'], 'spreadable String objects are spread with normal concat!!!');
assert.deepEqual(safeConcat('foo', Object('bar')), ['foo', Object('bar')], 'spreadable String objects are not spread with safe concat');

Array.prototype[Symbol.isConcatSpreadable] = false;
assert.deepEqual([].concat([1, 2], 3, [[4]]), [[], [1, 2], 3, [[4]]], 'non-concat-spreadable arrays do not spread with normal concat!!!');
assert.deepEqual(safeConcat([1, 2], 3, [[4]]), [1, 2, 3, [4]], 'non-concat-spreadable arrays still spread with safe concat');

Tests

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

更新日志

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.1.3 - 2024-12-11

Commits

  • [Dev Deps] update @arethetypeswrong/cli, @ljharb/eslint-config, @ljharb/tsconfig, @types/get-intrinsic, @types/tape, auto-changelog, mock-property, tape 9452ca7
  • [actions] split out node 10-20, and 20+ 8166059
  • [Deps] update call-bind, get-intrinsic, has-symbols d35014a
  • [Refactor] use call-bound directly 0bdddbd
  • [Tests] replace aud with npm audit c62dae0
  • [Dev Deps] add missing peer dep 4860aae

v1.1.2 - 2024-03-09

Commits

  • [types] use a generic a1d744d
  • [Dev Deps] update @ljharb/tsconfig, set-function-length 3d3da0a

v1.1.1 - 2024-03-09

Commits

v1.1.0 - 2024-01-15

Commits

  • [New] add types bd92413
  • [Dev Deps] update aud, mock-property, npmignore, set-function-length, tape 497ffcb
  • [Deps] update call-bind, get-intrinsic 770f870
  • [Dev Deps] update mock-property, tape be76bd9
  • [Tests] use set-function-length/env 89b1167
  • [meta] add missing npmrc values 3185cc7
  • [meta] add sideEffects flag df6c7eb

v1.0.1 - 2023-09-05

Fixed

  • [Perf] set Symbol.isConcatSpreadable only when required #2

Commits

  • [Dev Deps] update @ljharb/eslint-config, aud, tape c0791b0
  • [Deps] update get-intrinsic 7d07ae6

v1.0.0 - 2023-04-20

Commits