{"id":15643300,"url":"https://github.com/azu/immutable-array-prototype","last_synced_at":"2025-04-14T06:43:42.523Z","repository":{"id":57118400,"uuid":"95221892","full_name":"azu/immutable-array-prototype","owner":"azu","description":"A collection of Immutable Array prototype methods(Per method packages).","archived":false,"fork":false,"pushed_at":"2023-01-09T11:45:54.000Z","size":378,"stargazers_count":59,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T05:37:32.872Z","etag":null,"topics":["array","data-structure","immutable","javascript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azu.png","metadata":{"funding":{"github":"azu"},"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-23T13:18:25.000Z","updated_at":"2024-05-11T04:24:19.000Z","dependencies_parsed_at":"2023-02-08T10:31:49.059Z","dependency_job_id":null,"html_url":"https://github.com/azu/immutable-array-prototype","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fimmutable-array-prototype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fimmutable-array-prototype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fimmutable-array-prototype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azu%2Fimmutable-array-prototype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azu","download_url":"https://codeload.github.com/azu/immutable-array-prototype/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248837264,"owners_count":21169373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","data-structure","immutable","javascript"],"created_at":"2024-10-03T11:59:59.471Z","updated_at":"2025-04-14T06:43:42.494Z","avatar_url":"https://github.com/azu.png","language":"TypeScript","readme":"# immutable-array-prototype [![Actions Status: test](https://github.com/azu/immutable-array-prototype/workflows/test/badge.svg)](https://github.com/azu/immutable-array-prototype/actions?query=workflow%3A\"test\")\n\nImmutable Array prototype methods.\n\n- TypeScript\n- Small and Thin\n    - `@immutable-array/prototype` that includes all methods: ~500bytes(gzip+minify)\n- Per method packages\n    - `@immutable-array/push`, `@immutable-array/pop` etc...\n- Same usage with native `Array.prototype` methods\n\n## Why?\n\nECMAScript `Array` has some mutable methods.\n\nThis library provide immutable version of each methods.\n\n### Mutable method on `Array.prototype`\n\n| Native method: Return type               | `@immutable-array/*`                       |\n| ---------------------------------------- | ---------------------------------------- |\n| [`Array.prototype.pop()`](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/pop): `any`| [`pop()`](packages/pop): new  `Array` |\n| [`Array.prototype.push()`](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/push): `Number`| [`push()`](packages/push): new  `Array` |\n| [`Array.prototype.shift()`](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/shift): `any`| [`shift()`](packages/shift): new  `Array` |\n| [`Array.prototype.unshift()`](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift): `Number`| [`unshift()`](packages/unshift): new  `Array` |\n| [`Array.prototype.splice()`](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/splice): `Array`| [`splice()`](packages/splice): new  `Array` |\n| [`Array.prototype.reverse()`](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse): `Array`| [`reverse()`](packages/sort): new `Array` |\n| [`Array.prototype.sort()`](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/sort): `Array`| [`sort()`](packages/sort): new  `Array` |\n| [`Array.prototype.fill()`](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/fill): `Array`| [`fill()`](packages/fill): new `Array` |\n| [`Array.prototype.copyWithin()`](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin): `Array`| [`copyWithin()`](packages/copy-within): new `Array` |\n\n\n## Install\n\n`@immutable-array/prototype` includes all methods.\n\nInstall with [npm](https://www.npmjs.com/):\n\n    npm install @immutable-array/prototype\n\nIf you want to a single method, you can use a method as a package.\n\nPer method packages:\n\n    npm install @immutable-array/pop\n    npm install @immutable-array/push\n    npm install @immutable-array/shift\n    npm install @immutable-array/unshift\n    npm install @immutable-array/sort\n    npm install @immutable-array/reverse\n    npm install @immutable-array/fill\n    npm install @immutable-array/splice\n    npm install @immutable-array/copy-within\n\nSee each [package's README](./packages/) for more details.\n\n## Usage\n\n`@immutable-array/prototype` is a collection of immutable `Array.prototype` methods.\n\nBasically, the usage of these method is same with mutable version.\n\n```js\nimport {\n  sort,\n  unshift,\n  push,\n  fill,\n  splice,\n  pop,\n  reverse,\n  copyWithin,\n  shift\n} from '@immutable-array/prototype';\ndescribe('prototype', () =\u003e {\n  it('shift', () =\u003e {\n    assert.deepStrictEqual(shift(['a', 'b', 'c', 'd', 'e']), [\n      'b',\n      'c',\n      'd',\n      'e'\n    ]);\n  });\n  it('unshift', () =\u003e {\n    assert.deepStrictEqual(unshift(['a', 'b', 'c', 'd', 'e'], 'x'), [\n      'x',\n      'a',\n      'b',\n      'c',\n      'd',\n      'e'\n    ]);\n  });\n  it('pop', () =\u003e {\n    assert.deepStrictEqual(pop(['a', 'b', 'c', 'd', 'e']), [\n      'a',\n      'b',\n      'c',\n      'd'\n    ]);\n  });\n  it('push', () =\u003e {\n    assert.deepStrictEqual(push(['a', 'b', 'c', 'd', 'e'], 'x'), [\n      'a',\n      'b',\n      'c',\n      'd',\n      'e',\n      'x'\n    ]);\n  });\n  it('splice', () =\u003e {\n    assert.deepStrictEqual(splice(['a', 'b', 'c', 'd', 'e'], 0, 1, 'x'), [\n      'x',\n      'b',\n      'c',\n      'd',\n      'e'\n    ]);\n  });\n  it('sort', () =\u003e {\n    assert.deepStrictEqual(sort(['e', 'a', 'c', 'b', 'd']), [\n      'a',\n      'b',\n      'c',\n      'd',\n      'e'\n    ]);\n  });\n  it('reverse', () =\u003e {\n    assert.deepStrictEqual(reverse(['a', 'b', 'c', 'd', 'e']), [\n      'e',\n      'd',\n      'c',\n      'b',\n      'a'\n    ]);\n  });\n  it('fill', () =\u003e {\n    assert.deepStrictEqual(fill(new Array(5), 'x'), ['x', 'x', 'x', 'x', 'x']);\n  });\n  it('copyWithin', () =\u003e {\n    assert.deepStrictEqual(copyWithin(['a', 'b', 'c', 'd', 'e'], 0, 3, 4), [\n      'd',\n      'b',\n      'c',\n      'd',\n      'e'\n    ]);\n  });\n});\n```\n\n## Benchmarks\n\nBenchmark that is native `Array.prototype` methods vs. `@immutable-array`\n\nSee [benchmark](packages/benchmark).\n    \n    Native `Array.prototype`          |    @immutable-array\n    \u003e node src/array.js |                  \u003e immutable-array.js\n                                      |\n    # pop 200000 times               \u003e\u003e\u003e   # pop 200000 times\n    ok ~330 ms (0 s + 330397151 ns)  \u003e\u003e\u003e   ok ~267 ms (0 s + 267348617 ns)\n                                  |\n    # push 200000 times              \u003e\u003e\u003e   # push 200000 times\n    ok ~169 ms (0 s + 168738061 ns)  \u003e\u003e\u003e   ok ~141 ms (0 s + 140502324 ns)\n                                  |\n    # shift 200000 times             \u003c\u003c\u003c   # shift 200000 times\n    ok ~296 ms (0 s + 295892983 ns)  \u003c\u003c\u003c   ok ~419 ms (0 s + 418852725 ns)\n                                  |\n    # unshift 200000 times           \u003c\u003c\u003c   # unshift 200000 times\n    ok ~51 ms (0 s + 50817590 ns)    \u003c\u003c\u003c   ok ~191 ms (0 s + 191329502 ns)\n                                  |\n    # sort 2000 times                \u003e\u003e\u003e   # sort 2000 times\n    ok ~933 ms (0 s + 932551400 ns)  \u003e\u003e\u003e   ok ~611 ms (0 s + 610748601 ns)\n                                  |\n    # reverse 200000 times           \u003e\u003e\u003e   # reverse 200000 times\n    ok ~555 ms (0 s + 554921645 ns)  \u003e\u003e\u003e   ok ~455 ms (0 s + 455068191 ns)\n                                  |\n    # fill 200000 times              \u003e\u003e\u003e   # fill 200000 times\n    ok ~782 ms (0 s + 782159758 ns)  \u003e\u003e\u003e   ok ~699 ms (0 s + 698677543 ns)\n                                  |\n    # splice 200000 times            \u003c\u003c\u003c   # splice 200000 times\n    ok ~287 ms (0 s + 286547242 ns)  \u003c\u003c\u003c   ok ~391 ms (0 s + 391294720 ns)\n                                  |\n    # copyWithin 200000 times        \u003c\u003c\u003c   # copyWithin 200000 times\n    ok ~237 ms (0 s + 236837575 ns)  \u003c\u003c\u003c   ok ~275 ms (0 s + 275267401 ns)\n                                  |\n    all benchmarks completed         \u003e\u003e\u003e   all benchmarks completed\n    ok ~3.64 s (3 s + 638863405 ns)  \u003e\u003e\u003e   ok ~3.45 s (3 s + 449089624 ns)\n\n## Support Policy\n\n### Do\n\n- Provide immutable version of `Array.prototype` method\n- Provide each method as an module\n    - e.g.) `import push from \"@immutable-array/push\"`\n    - All prototype method: `import { push } from \"@immutable-array/prototype\"`\n- ECMAScript compatible API\n\nFor example, `@immutable-array/*` method should return same result with native API.\n\n```js\nimport { splice } from '@immutable-array/splice';\nvar array = [1, 2, 3];\n// immutable\nvar resultArray = splice(array, -1, 1, 'x');\n// native\narray.splice(-1, 1, 'x');\nassert.deepStrictEqual(array, resultArray);\n```\n\n### Do not\n\n- Add non-standard method in ECMAScript\n    - e.g.) `update`, `delete`, `merge`...\n- Each method depended on other method\n\n## Related\n\n- [Pure javascript immutable arrays](https://vincent.billey.me/pure-javascript-immutable-array/ \"Pure javascript immutable arrays\")\n- [georapbox/immutable-arrays: Immutable versions of normally mutable array methods](https://github.com/georapbox/immutable-arrays \"georapbox/immutable-arrays: Immutable versions of normally mutable array methods\")\n- [micnews/immutable-array-methods](https://github.com/micnews/immutable-array-methods \"micnews/immutable-array-methods\")\n- [kolodny/immutability-helper: mutate a copy of data without changing the original source](https://github.com/kolodny/immutability-helper \"kolodny/immutability-helper: mutate a copy of data without changing the original source\")\n\n## Changelog\n\nSee [Releases page](https://github.com/azu/immutable-array-prototype/releases).\n\n## Running tests\n\nRun following commands:\n\n    yarn install\n    yarn test\n\n## Contributing\n\nPull requests and stars are always welcome.\n\nFor bugs and feature requests, [please create an issue](https://github.com/azu/immutable-array-prototype/issues).\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n## Author\n\n- [github/azu](https://github.com/azu)\n- [twitter/azu_re](https://twitter.com/azu_re)\n\n## License\n\nMIT © azu\n","funding_links":["https://github.com/sponsors/azu"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazu%2Fimmutable-array-prototype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazu%2Fimmutable-array-prototype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazu%2Fimmutable-array-prototype/lists"}