{"id":19405814,"url":"https://github.com/vladkens/array-utils-ts","last_synced_at":"2025-04-24T09:31:01.930Z","repository":{"id":165953169,"uuid":"641354337","full_name":"vladkens/array-utils-ts","owner":"vladkens","description":"🔢🔧 A set of functions for working with arrays, often necessary but absent in lodash.","archived":false,"fork":false,"pushed_at":"2025-02-15T22:48:49.000Z","size":68,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-21T09:05:38.786Z","etag":null,"topics":["array","array-utils","cjs","esm","lodash","npm-package","typescript","utils"],"latest_commit_sha":null,"homepage":"https://npm.im/array-utils-ts","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/vladkens.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/codeowners","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"vladkens","buy_me_a_coffee":"vladkens"}},"created_at":"2023-05-16T09:48:29.000Z","updated_at":"2025-02-15T22:48:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"427c4788-68d5-4dad-b82b-4a5595543001","html_url":"https://github.com/vladkens/array-utils-ts","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"1db8e03b37f4e3a6ebaffc0ddbc548df83d3cb8b"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladkens%2Farray-utils-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladkens%2Farray-utils-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladkens%2Farray-utils-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladkens%2Farray-utils-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vladkens","download_url":"https://codeload.github.com/vladkens/array-utils-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250600614,"owners_count":21456995,"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","array-utils","cjs","esm","lodash","npm-package","typescript","utils"],"created_at":"2024-11-10T11:39:39.259Z","updated_at":"2025-04-24T09:31:01.922Z","avatar_url":"https://github.com/vladkens.png","language":"TypeScript","funding_links":["https://github.com/sponsors/vladkens","https://buymeacoffee.com/vladkens"],"categories":[],"sub_categories":[],"readme":"# array-utils-ts\n\n\u003cdiv align=\"center\"\u003e\n\n[\u003cimg src=\"https://badges.ws/npm/v/array-utils-ts\" alt=\"version\" /\u003e](https://npmjs.org/package/array-utils-ts)\n[\u003cimg src=\"https://badges.ws/packagephobia/publish/array-utils-ts\" alt=\"size\" /\u003e](https://packagephobia.now.sh/result?p=array-utils-ts)\n[\u003cimg src=\"https://badges.ws/npm/dm/array-utils-ts\" alt=\"downloads\" /\u003e](https://npmjs.org/package/array-utils-ts)\n[\u003cimg src=\"https://badges.ws/github/license/vladkens/array-utils-ts\" alt=\"license\" /\u003e](https://github.com/vladkens/array-utils-ts/blob/main/LICENSE)\n[\u003cimg src=\"https://badges.ws/badge/-/buy%20me%20a%20coffee/ff813f?icon=buymeacoffee\u0026label\" alt=\"donate\" /\u003e](https://buymeacoffee.com/vladkens)\n\n\u003c/div\u003e\n\nA set of functions for working with arrays, often necessary for working with state, but absent in lodash.\n\n## Install\n\n```sh\nnpm i array-utils-ts\n```\n\n```sh\nyarn add array-utils-ts\n```\n\n## Usage\n\n### filterNullable\n\n```typescript\nimport { filterNullable } from \"array-utils-ts\"\n\nfilterNullable([1, null, 2, undefined])\n// -\u003e [1, 2]\n```\n\n### filterEmpty\n\n```typescript\nimport { filterEmpty } from \"array-utils-ts\"\n\nfilterEmpty([1, null, 2, undefined, 3, \"\", \"a\"])\n// -\u003e [1, 2, 3, \"a\"]\n```\n\n### isUniq\n\n```typescript\nimport { isUniq } from \"array-utils-ts\"\n\nisUniq([1, 2, 3])\n// -\u003e true\n\nisUniq([1, 2, 1])\n// -\u003e false\n```\n\n### hasEmpty\n\n```typescript\nimport { hasEmpty } from \"array-utils-ts\"\n\nhasEmpty([\"a\", \"b\", \"c\"])\n// -\u003e false\n\nhasEmpty([\"a\", \"\", \"c\"])\n// -\u003e true\n\nhasEmpty([\"a\", undefined, \"c\"])\n// -\u003e true\n```\n\n### toggleItem\n\nFor example useful in `\u003cselect\u003e` component\n\n```typescript\nimport { toggleItem } from \"array-utils-ts\"\n\ntoggleItem([1, 2, 3], 4)\n// -\u003e [1, 2, 3, 4]\n\ntoggleItem([1, 2, 3], 3)\n// -\u003e [1, 2]\n```\n\n### updateByKey\n\n```typescript\nimport { updateByKey } from \"array-utils-ts\"\n\n// prettier-ignore\nconst arr1 = [{ id: 1, v: 1 }, { id: 2, v: 1 }]\n\nconst arr2 = updateByKey(arr1, \"id\", { id: 1, v: 2 })\n// -\u003e [{ id: 1, v: 2 }, { id: 2, v: 1 }]\n// arr1 !== arr2\n\nconst arr3 = updateByKey(arr2, \"id\", { id: 3, v: 1 })\n// -\u003e [{ id: 1, v: 2 }, { id: 2, v: 1 }]\n// arr2 === arr3 // note: item not found, nothing changed\n```\n\n### upsertByKey\n\n```typescript\nimport { upsertByKey } from \"array-utils-ts\"\n\n// prettier-ignore\nconst arr1 = [{ id: 1, v: 1 }, { id: 2, v: 1 }]\n\nconst arr2 = upsertByKey(arr1, \"id\", { id: 1, v: 2 })\n// -\u003e [{ id: 1, v: 2 }, { id: 2, v: 1 }]\n// arr1 !== arr2\n\nconst arr3 = upsertByKey(arr2, \"id\", { id: 3, v: 1 })\n// -\u003e [{ id: 1, v: 2 }, { id: 2, v: 1 }, { id: 3, v: 1 }]\n// arr2 !== arr3\n```\n\n### toggleByKey\n\n```typescript\nimport { toggleByKey } from \"array-utils-ts\"\n\n// prettier-ignore\nconst arr1 = [{ id: 1, v: 1 }, { id: 2, v: 1 }]\n\nconst arr2 = toggleByKey(arr1, \"id\", { id: 1, v: 2 })\n// -\u003e [{ id: 2, v: 1 }]; arr1 !== arr2\n\nconst arr3 = toggleByKey(arr2, \"id\", { id: 3, v: 1 })\n// -\u003e [{ id: 2, v: 1 }, { id: 3, v: 1 }]; arr2 !== arr3\n```\n\n### isFirstByKey\n\nCheck if given object is first in collection by some key.\n\n```typescript\nimport { isFirstByKey } from \"array-utils-ts\"\n\nconst arr = [{ id: 1 }, { id: 2 }, { id: 3 }]\nisFirstByKey(arr, \"id\", { id: 1 }) // -\u003e true\nisFirstByKey(arr, \"id\", { id: 2 }) // -\u003e false\nisFirstByKey(arr, \"id\", { id: 3 }) // -\u003e false\n```\n\n### isLastByKey\n\nCheck if given object is last in collection by some key.\n\n```typescript\nimport { isLastByKey } from \"array-utils-ts\"\n\nconst arr = [{ id: 1 }, { id: 2 }, { id: 3 }]\nisLastByKey(arr, \"id\", { id: 1 }) // -\u003e false\nisLastByKey(arr, \"id\", { id: 2 }) // -\u003e false\nisLastByKey(arr, \"id\", { id: 3 }) // -\u003e true\n```\n\n### enumerate\n\n```typescript\nimport { enumerate } from \"array-utils-ts\"\n\nconst arr = [\"a\", \"b\", \"c\"]\nenumerate(arr) // -\u003e [[0, \"a\"], [1, \"b\"], [2, \"c\"]]\nenumerate(arr, 1) // -\u003e [[1, \"a\"], [2, \"b\"], [3, \"c\"]]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvladkens%2Farray-utils-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvladkens%2Farray-utils-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvladkens%2Farray-utils-ts/lists"}