{"id":20455886,"url":"https://github.com/nevoland/unchangeable","last_synced_at":"2025-07-24T06:05:14.498Z","repository":{"id":203398655,"uuid":"708811707","full_name":"nevoland/unchangeable","owner":"nevoland","description":"🧊 Tools for immutable values.","archived":false,"fork":false,"pushed_at":"2025-07-21T21:47:36.000Z","size":1783,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-21T23:25:38.098Z","etag":null,"topics":["data","datastructure","functional","immutable","persistent","pure","stateless"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nevoland.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-10-23T12:49:08.000Z","updated_at":"2025-07-21T21:47:40.000Z","dependencies_parsed_at":"2025-06-22T19:34:42.239Z","dependency_job_id":"1f22f767-8927-409a-b02e-2183a10b0ffc","html_url":"https://github.com/nevoland/unchangeable","commit_stats":{"total_commits":7,"total_committers":2,"mean_commits":3.5,"dds":0.1428571428571429,"last_synced_commit":"8ca12e201a90d920d464aa47696399b4d4aa9d49"},"previous_names":["nevoland/unchangeable"],"tags_count":13,"template":false,"template_full_name":"nevoland/foundation","purl":"pkg:github/nevoland/unchangeable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nevoland%2Funchangeable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nevoland%2Funchangeable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nevoland%2Funchangeable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nevoland%2Funchangeable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nevoland","download_url":"https://codeload.github.com/nevoland/unchangeable/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nevoland%2Funchangeable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266481732,"owners_count":23935938,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["data","datastructure","functional","immutable","persistent","pure","stateless"],"created_at":"2024-11-15T11:20:19.493Z","updated_at":"2025-07-24T06:05:14.479Z","avatar_url":"https://github.com/nevoland.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unchangeable\n\n🧊 Helpers for handling immutable values\n\n### Features\n\n- Provides tools to update immutable objects and arrays\n- Defines empty object and array\n- Includes helpers to check for object emptiness\n\n## Usage\n\nEverything is exported from the main entry-point through an ES6 module:\n\n```js\nimport {\n  setItem,\n  setProperty,\n  isEmpty,\n  EMPTY_OBJECT,\n  EMPTY_ARRAY,\n  PREPEND,\n  APPEND,\n  REMOVE,\n} from \"unchangeable\";\n```\n\n## Installation\n\nInstall with the [Node Package Manager](https://www.npmjs.com/package/unchangeable):\n\n```bash\nnpm install unchangeable\n```\n\n## Documentation\n\nDocumentation is generated [here](doc/README.md).\n\n## Guide\n\n### Updating an object\n\n#### Updating properties\n\nUse the `setProperty` tool to tupdate the property of an object:\n\n```js\nimport { setProperty } from \"unchangeable\";\n\nconst value = { level: 5 };\n// The property \"level\" is set to 6\nconst nextValue = setProperty(value, \"level\", 6);\n\nassert(value.level === 5);\nassert(nextValue.level === 6);\nassert(value !== nextValue);\n```\n\nThe same object is returned if the new value of the property is the same:\n\n```js\nimport { setProperty } from \"unchangeable\";\n\nconst value = { level: 5 };\n// The property \"level\" has the same value it is set to (5)\nconst nextValue = setProperty(value, \"level\", 5);\n\nassert(value === nextValue);\n```\n\n#### Removing properties\n\nUse `undefined` or the `REMOVE` symbol to remove a property:\n\n```js\nimport { setProperty, REMOVE, isEmpty, EMPTY_OBJECT } from \"unchangeable\";\n\nconst value = { level: 5 };\n// The property \"level\" is removed\nconst nextValue = setProperty(value, \"level\", REMOVE);\n// The property \"level\" is removed\nconst otherValue = setProperty(value, \"level\", undefined);\n\nassert(nextValue === otherValue);\nassert(!(\"level\" in nextValue) \u0026\u0026 !(\"level\" in otherValue));\n// If the object is empty, `EMPTY_OBJECT` is returned\nassert(nextValue === EMPTY_OBJECT \u0026\u0026 otherValue === EMPTY_OBJECT);\nassert(isEmpty(nextValue) \u0026\u0026 isEmpty(otherValue));\n```\n\n### Updating an array\n\n#### Updating items\n\nUse the `setItem` tool to update the item of an array:\n\n```js\nimport { setItem } from \"unchangeable\";\n\nconst value = [\"Alice\", \"Bob\"];\n// The item at index 1 is set to \"Chloe\"\nconst nextValue = setItem(value, 1, \"Chloe\");\n\nassert(nextValue[1] === \"Chloe);\nassert(value[1] === \"Bob\");\nassert(value !== nextValue);\n```\n\nThe same array is returned if the new value of the array is the same:\n\n```js\nimport { setItem } from \"unchangeable\";\n\nconst value = [\"Alice\", \"Chloe\"];\n// The item at index 1 has the same value as it is set to: \"Chloe\"\nconst nextValue = setItem(value, 1, \"Chloe\");\n\nassert(value === nextValue);\n```\n\nSetting an item at an index that does not exist does not affect the array:\n\n```js\nimport { setItem } from \"unchangeable\";\n\nconst value = [\"Alice\", \"Chloe\"];\n// Index 3 is not in the value and thus returns the same array\nconst nextValue = setItem(value, 3, \"Bob\");\n\nassert(value === nextValue);\nassert(nextValue.length === 2);\n```\n\n#### Adding items\n\nUse `APPEND` and `PREPEND` to add a value to the array:\n\n```js\nimport { setItem, APPEND, PREPEND } from \"unchangeable\";\n\nconst value = [\"Alice\", \"Bob\"];\n// Append\nconst nextValue = setItem(value, APPEND, \"Chloe\");\n// Prepend\nconst otherValue = setItem(value, PREPEND, \"Mathis\");\n\nassert(nextValue[2] === \"Chloe\");\nassert(nextValue.length === 3);\nassert(otherValue[0] === \"Mathis\");\nassert(otherValue.length === 3);\n```\n\nUse `APPEND` and `PREPEND` to insert a value into the array at a specific index:\n\n```js\nimport { setItem, APPEND, PREPEND } from \"unchangeable\";\n\nconst value = [\"Alice\", \"Bob\"];\n// Insert after index 0 (item will have index 1)\nconst nextValue = setItem(value, 0, APPEND, \"Chloe\");\n// Insert before index 1 (item will have index 1)\nconst otherValue = setItem(value, 1, PREPEND, \"Mathis\");\n\nassert(nextValue[1] === \"Chloe\");\nassert(nextValue.length === 3);\nassert(otherValue[1] === \"Mathis\");\nassert(otherValue.length === 3);\n```\n\n#### Removing items\n\nUse `REMOVE` to remove an item at a specific index or an item with a specific value:\n\n```js\nimport { setItem, REMOVE } from \"unchangeable\";\n\nconst value = [\"Alice\", \"Bob\"];\n// Remove at a specific index\nconst nextValue = setItem(value, 1, REMOVE);\n// Remove a specific value\nconst otherValue = setItem(value, REMOVE, \"Bob\");\n\nassert(nextValue.length === 1);\nassert(otherValue.length === 1);\n```\n\n### Updating a composite value\n\n#### Updating values\n\nUse `set` to update a composite value at a given path:\n\n```js\nimport { set } from \"unchangeable\";\n\nconst value = { level: 5, parent: { level: 6 } };\n// Set value.parent.level to `7`\nconst nextValue = set(value, [\"parent\", \"level\"], 7);\n\nassert(value.parent.level === 6);\nassert(nextValue.parent.level === 7);\n```\n\n#### Updating values using a function\n\nInstead of a value, a function can be used to update the value:\n\n```js\nimport { set } from \"unchangeable\";\n\nconst value = { level: 5, parent: { level: 6 } };\n\nfunction increment(value) {\n  return value + 1;\n}\n\n// Set value.parent.level to `7`\nconst nextValue = set(value, [\"parent\", \"level\"], increment);\n\nassert(value.parent.level === 6);\nassert(nextValue.parent.level === 7);\n```\n\n#### Removing values\n\nUse `REMOVE` to remove the value at the given path:\n\n```js\nimport { set, REMOVE } from \"unchangeable\";\n\nconst value = { level: 5, parent: { level: 6 } };\n// Removes `value.parent.level`\nconst nextValue = set(value, [\"parent\", \"level\"], REMOVE);\n\nassert(!(\"level\" in value.parent));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnevoland%2Funchangeable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnevoland%2Funchangeable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnevoland%2Funchangeable/lists"}