safe-array-concat (1.1.3)

Published 2026-02-24 14:04:39 +00:00 by atheaadmin

Installation

registry=
npm install safe-array-concat@1.1.3
"safe-array-concat": "1.1.3"

About this package

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

Dependencies

Dependencies

ID Version
call-bind ^1.0.8
call-bound ^1.0.2
get-intrinsic ^1.2.6
has-symbols ^1.1.0
isarray ^2.0.5

Development Dependencies

ID Version
@arethetypeswrong/cli ^0.17.1
@ljharb/eslint-config ^21.1.1
@ljharb/tsconfig ^0.2.2
@types/call-bind ^1.0.5
@types/get-intrinsic ^1.2.3
@types/has-symbols ^1.0.2
@types/isarray ^2.0.2
@types/tape ^5.6.5
auto-changelog ^2.5.0
encoding ^0.1.13
eslint =8.8.0
evalmd ^0.0.19
in-publish ^2.0.1
mock-property ^1.1.0
npmignore ^0.3.1
nyc ^10.3.2
safe-publish-latest ^2.0.0
set-function-length ^1.2.2
tape ^5.9.0
typescript next

Keywords

safe Array concat push isConcatSpreadable
Details
npm
2026-02-24 14:04:39 +00:00
1
Jordan Harband
MIT
latest
6.4 KiB
Assets (1)
Versions (1) View all
1.1.3 2026-02-24