{"id":15388212,"url":"https://github.com/georapbox/immutable-arrays","last_synced_at":"2025-04-15T17:33:14.411Z","repository":{"id":19872400,"uuid":"88062732","full_name":"georapbox/immutable-arrays","owner":"georapbox","description":"Immutable versions of normally mutable array methods","archived":false,"fork":false,"pushed_at":"2023-01-06T01:32:39.000Z","size":2202,"stargazers_count":20,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T20:06:19.100Z","etag":null,"topics":["array","delete","immutable","methods","pop","push","reverse","shift","splice","unshift"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/georapbox.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-04-12T14:42:47.000Z","updated_at":"2023-12-21T17:48:14.000Z","dependencies_parsed_at":"2023-01-13T20:38:41.968Z","dependency_job_id":null,"html_url":"https://github.com/georapbox/immutable-arrays","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georapbox%2Fimmutable-arrays","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georapbox%2Fimmutable-arrays/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georapbox%2Fimmutable-arrays/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/georapbox%2Fimmutable-arrays/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/georapbox","download_url":"https://codeload.github.com/georapbox/immutable-arrays/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219911903,"owners_count":16567838,"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","delete","immutable","methods","pop","push","reverse","shift","splice","unshift"],"created_at":"2024-10-01T14:55:58.042Z","updated_at":"2024-10-16T23:21:37.870Z","avatar_url":"https://github.com/georapbox.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# immutable-arrays\n\nImmutable versions of normally mutable array methods\n\n[![npm version](https://img.shields.io/npm/v/immutable-arrays.svg)](http://badge.fury.io/js/immutable-arrays)\n[![Build Status](https://travis-ci.com/georapbox/immutable-arrays.svg?branch=master)](https://travis-ci.com/georapbox/immutable-arrays)\n[![Maintainability](https://api.codeclimate.com/v1/badges/a9558f63e22c3e89d06c/maintainability)](https://codeclimate.com/github/georapbox/immutable-arrays/maintainability)\n[![Issue Count](https://codeclimate.com/github/georapbox/immutable-arrays/badges/issue_count.svg)](https://codeclimate.com/github/georapbox/immutable-arrays)\n[![Coverage Status](https://coveralls.io/repos/github/georapbox/immutable-arrays/badge.svg?branch=master)](https://coveralls.io/github/georapbox/immutable-arrays?branch=master)\n[![npm license](https://img.shields.io/npm/l/immutable-arrays.svg)](http://badge.fury.io/js/immutable-arrays)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)\n[![npm downloads](https://img.shields.io/npm/dt/immutable-arrays.svg)](http://badge.fury.io/js/immutable-arrays)\n\n## Install\n\n```sh\n$ npm install --save immutable-arrays\n```\n\n## Usage\n\nThe library is exported in the following formats:\n- `UMD (Universal Module Definition)` for usage in browsers\n- `CJS (CommonJS)` for usage in Node.js\n- `ESM (Ecmascript Modules)` for usage in browsers or environments that support ESM\n\n### Old school browser global\n\n```html\n\u003cscript src=\"https://unpkg.com/immutable-arrays@\u003cVERSION_GOES_HERE\u003e/dist/immutable-arrays.umd.min.js\"\u003e\u003c/script\u003e\n```\n\nAfter importing the library it can be accessed via the global variable `immutableArrays`.\n\n### Node.js\n\n```js\nconst push = require('immutable-arrays').push;\n```\n\n### ES2015 imports\n\n```js\nimport { push } from 'immutable-arrays';\n```\n\n## API\n\n### push(array, ...elementN) ⇒ \u003ccode\u003eArray\u003c/code\u003e\nAdds one or more elements to the end of an array by returning\na new array instead of mutating the original one.\n\n**Returns**: \u003ccode\u003eArray\u003c/code\u003e - A new array with the new entries added to the end.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e | The original array. |\n| ...elementN | \u003ccode\u003e\\*\u003c/code\u003e | The elements to add to the end of the array. |\n\n**Example**  \n```js\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = push(originalArray, 'f', 'g');\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray ['a', 'b', 'c', 'd', 'e', 'f', 'g']\n```\n\n### pop(array) ⇒ \u003ccode\u003eArray\u003c/code\u003e\nRemoves the last element from an array by returning\na new array instead of mutating the original one.\n\n**Returns**: \u003ccode\u003eArray\u003c/code\u003e - A new array with the last element removed.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e | The original array. |\n\n**Example**  \n```js\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = pop(originalArray);\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray ['a', 'b', 'c', 'd']\n```\n\n### shift(array) ⇒ \u003ccode\u003eArray\u003c/code\u003e\nRemoves the first element from an array.\n\n**Returns**: \u003ccode\u003eArray\u003c/code\u003e - A new array with the first element removed.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e | The original array. |\n\n**Example**  \n```js\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = shift(originalArray);\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray ['b', 'c', 'd', 'e']\n```\n\n### unshift(array, ...elementN) ⇒ \u003ccode\u003eArray\u003c/code\u003e\nAdds one or more elements to the beginning of an array.\n\n**Returns**: \u003ccode\u003eArray\u003c/code\u003e - A new array with the new elements added to the front.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e | The original array. |\n| ...elementN | \u003ccode\u003e\\*\u003c/code\u003e | [description] The elements to add to the front of the array. |\n\n**Example**  \n```js\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = unshift(originalArray, 'f', 'g');\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray ['f', 'g', 'a', 'b', 'c', 'd', 'e']\n```\n\n### reverse(array) ⇒ \u003ccode\u003eArray\u003c/code\u003e\nReverses an array (not in place).\nThe first array element becomes the last, and the last array element becomes the first.\n\n**Returns**: \u003ccode\u003eArray\u003c/code\u003e - A new array reversed.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e | The original array. |\n\n**Example**  \n```js\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = reverse(originalArray);\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray ['e', 'd', 'c', 'b', 'a']\n```\n\n### sort(array, [compareFunction]) ⇒ \u003ccode\u003eArray\u003c/code\u003e\nSorts the elements of an array (not in place) and returns a sorted array.\n\n**Returns**: \u003ccode\u003eArray\u003c/code\u003e - A new sorted array.\n\n| Param | Type | Description |\n| --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e | The original array. |\n| [compareFunction] | \u003ccode\u003eFunction\u003c/code\u003e | Specifies a function that defines the sort order. If omitted, the array is sorted according to each character's Unicode code point value, according to the string conversion of each element. |\n\n**Example**  \n```js\nconst numberArray = [20, 3, 4, 10, -3, 1, 0, 5];\nconst stringArray = ['Blue', 'Humpback', 'Beluga'];\n\nconst resultArray = sort(numberArray, (a, b) =\u003e a - b);\n// -\u003e numberArray [20, 3, 4, 10, -3, 1, 0, 5]\n// -\u003e resultArray [-3, 0, 1, 3, 4, 5, 10, 20]\n\nconst resultArray = sort(numberArray, (a, b) =\u003e b - a);\n// -\u003e numberArray [20, 3, 4, 10, -3, 1, 0, 5]\n// -\u003e resultArray [20, 10, 5, 4, 3, 1, 0, -3]\n\nconst resultArray = sort(stringArray);\n// -\u003e stringArray ['Blue', 'Humpback', 'Beluga']\n// -\u003e resultArray ['Beluga', 'Blue', 'Humpback']\n\nconst resultArray = sort(stringArray, (a, b) =\u003e a.toLowerCase() \u003c b.toLowerCase());\n// -\u003e stringArray ['Blue', 'Humpback', 'Beluga']\n// -\u003e resultArray ['Humpback', 'Blue', 'Beluga']\n```\n\n### splice(array, [start], [deleteCount], [...elementN]) ⇒ \u003ccode\u003eArray\u003c/code\u003e\nRemoves existing elements and/or adds new elements to an array.\n\n**Returns**: \u003ccode\u003eArray\u003c/code\u003e - The result array.  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e |  | The original array. |\n| [start] | \u003ccode\u003eNumber\u003c/code\u003e | \u003ccode\u003earray.length\u003c/code\u003e | Zero based index at which to start changing the array.        If greater than the length of the array, actual starting index will be set to the length of the array. |\n| [deleteCount] | \u003ccode\u003eNumber\u003c/code\u003e | \u003ccode\u003earray.length - start\u003c/code\u003e | An integer indicating the number of old array elements to remove.        If `deleteCount` is 0, no elements are removed.        If `deleteCount` is lower than 0, `deleteCount` will be equal to 0.        If `deleteCount` is greater than the number of elements left in the array starting at        `start`, then all of the elements through the end of the array will be deleted.        If `deleteCount` is omitted, `deleteCount` will be equal to (`array.length - start`),        i.e., all of the elements beginning with `start` index on through the end of the array will be deleted. |\n| [...elementN] | \u003ccode\u003e\\*\u003c/code\u003e |  | The elements to add to the array, beginning at the start index.        If you don't specify any elements, will only remove elements from the array. |\n\n**Example**  \n```js\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = splice(originalArray, 0);\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray []\n\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = splice(originalArray, 0, 1);\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray ['b', 'c', 'd', 'e']\n\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = splice(originalArray, 0, 3);\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray ['d', 'e']\n\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = splice(originalArray, 0, originalArray.length);\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray []\n\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = splice(originalArray, 0, -3);\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray ['a', 'b', 'c', 'd', 'e']\n\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = splice(originalArray, 0, 0, 'lorem', 'ipsum');\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray ['lorem', 'ipsum', 'a', 'b', 'c', 'd', 'e']\n\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = splice(originalArray, originalArray.length, 0, 'lorem', 'ipsum');\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray ['a', 'b', 'c', 'd', 'e', 'lorem', 'ipsum']\n\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = splice(originalArray, 0, 2, 'lorem', 'ipsum');\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray ['lorem', 'ipsum', 'c', 'd', 'e']\n\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = splice(originalArray, originalArray.length - 2, 2, 'lorem', 'ipsum');\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray ['a', 'b', 'c', 'lorem', 'ipsum']\n```\n\n### del(array, index) ⇒ \u003ccode\u003eArray\u003c/code\u003e\nDeletes an element from an array by its index in the array.\n\n**Returns**: \u003ccode\u003eArray\u003c/code\u003e - A new array with the element removed.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| array | \u003ccode\u003eArray\u003c/code\u003e | The original array. |\n| index | \u003ccode\u003eNumber\u003c/code\u003e | The index of the element to delete in the original array. If index is a negative number, a copy of the original array is returned. |\n\n**Example**  \n```js\nconst originalArray = ['a', 'b', 'c', 'd', 'e'];\nconst resultArray = del(originalArray, 2);\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray ['a', 'b', 'd', 'e']\n\nconst resultArray2 = del(originalArray, -1);\n// -\u003e originalArray ['a', 'b', 'c', 'd', 'e']\n// -\u003e resultArray2 ['a', 'b', 'c', 'd', 'e']\n```\n\n## For developers\n\n### Build the library\n\n```sh\n$ npm run dev\n```\nBuilds the library and watches for changes while developing. If you want to build only for a specific format, there are other npm scripts available; check in `package.json`.\n\n```sh\n$ npm run build\n```\nBuilds the library for production.\n\n### Run the tests\n\n```sh\n$ npm run test\n```\n\n### Tests coverage\n\n```sh\n$ npm run coverage\n```\n\n## Changelog\n\nFor API updates and breaking changes, check the [CHANGELOG](https://github.com/georapbox/immutable-arrays/blob/master/CHANGELOG.md).\n\n## License\n\n[The MIT License (MIT)](https://georapbox.mit-license.org/@2017)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorapbox%2Fimmutable-arrays","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeorapbox%2Fimmutable-arrays","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeorapbox%2Fimmutable-arrays/lists"}