{"id":16231543,"url":"https://github.com/hustcc/immutability-util","last_synced_at":"2025-03-19T14:30:40.472Z","repository":{"id":57272717,"uuid":"93372950","full_name":"hustcc/immutability-util","owner":"hustcc","description":":herb: Mutate a copy of data without changing the original source by path string, just like the get/set in lodash. Inspired by immutability-helper and rewrite with ES6.","archived":false,"fork":false,"pushed_at":"2017-08-18T08:29:22.000Z","size":15,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T19:12:01.222Z","etag":null,"topics":["chainable-methods","immutability","immutability-helper","immutability-util","lodash","path-string","performance","update"],"latest_commit_sha":null,"homepage":"https://github.com/hustcc/immutability-util","language":"JavaScript","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/hustcc.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}},"created_at":"2017-06-05T06:37:35.000Z","updated_at":"2023-12-05T06:28:54.000Z","dependencies_parsed_at":"2022-09-02T12:31:25.884Z","dependency_job_id":null,"html_url":"https://github.com/hustcc/immutability-util","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hustcc%2Fimmutability-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hustcc%2Fimmutability-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hustcc%2Fimmutability-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hustcc%2Fimmutability-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hustcc","download_url":"https://codeload.github.com/hustcc/immutability-util/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243997041,"owners_count":20380980,"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":["chainable-methods","immutability","immutability-helper","immutability-util","lodash","path-string","performance","update"],"created_at":"2024-10-10T13:06:01.599Z","updated_at":"2025-03-19T14:30:39.694Z","avatar_url":"https://github.com/hustcc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# immutability-util\n\n\u003e Mutate a copy of data without changing the original source. Inspired by [kolodny/immutability-helper](https://github.com/kolodny/immutability-helper) / [ProtoTeam/immutability-helper-x](https://github.com/ProtoTeam/immutability-helper-x) and rewrite with ES6 syntax for **convenient API** and **higher performance**.\n\n[![Build Status](https://travis-ci.org/hustcc/immutability-util.svg?branch=master)](https://travis-ci.org/hustcc/immutability-util) [![Coverage Status](https://coveralls.io/repos/github/hustcc/immutability-util/badge.svg?branch=master)](https://coveralls.io/github/hustcc/immutability-util?branch=master) [![npm](https://img.shields.io/npm/v/immutability-util.svg)](https://www.npmjs.com/package/immutability-util) [![npm download](https://img.shields.io/npm/dm/immutability-util.svg)](https://www.npmjs.com/package/immutability-util)\n\n\n## 1. Features\n\nFeatures or key points.\n\n1. Use **chainble API** to mutate a copy of object.\n2. Simplify your code by finding target to be updated with **path string**.\n3. Maybe can optimize your web app with a bit **higher performance**.\n\n\n## 2. Install \u0026 Usage\n\nInstall with NPM.\n\n```sh\nnpm install -S immutability-util\n```\n\nThen use it.\n\n```js\nconst iu = require('immutability-util');\n// or \nimport iu from 'immutability-util';\n\n// obj need to be mutated.\nvar obj = {\n  a: 1,\n  b: 2,\n  c: {\n    d: 3,\n    e: {\n      f: [4, 5, 6],\n      g: {\n        h: 'iu',\n      },\n    },\n    i: {\n      j: 'hello, world.',\n      k: [7, 8, 9],\n      l: [10, 11, 12],\n    }\n  },\n};\n\n// chainable usage.\nconst state = iu(obj)\n  .$apply(['a'], v =\u003e v + 1)\n  .$merge(['c', 'e', 'g'], { m: 'update'})\n  .$push(['c', 'e', 'f'], [7, 8, 9])\n  .$set(['c', 'i', 'j'], 'hello node 8.')\n  .$splice(['c', 'i', 'k'], [[1, 1, 10]])\n  .$unset(['c'], ['d'])\n  .$unshift(['c', 'i', 'l'], [13])\n  .value(); // then get the mutated copy.\n  \n// or use path string.\niu(obj).$set('c.i.j', 'hello node 8.').value();\n```\n\nAnd process array like this:\n\n```js\nconst obj = {\n  a: {\n    b: [{\n      c: [1, 2, 3],\n    }, {\n      d: 4,\n    }, {\n      e: [5, 6],\n    }]\n  }\n};\nconst state = iu(obj)\n  .$apply('a.b[1].d', v =\u003e v + 1)\n  .$push('a.b[0].c', [4])\n  .$set('a.b[2].e[0]', 'hello node 8.')\n  .value();\n```\n\n\n## 3. Available API\n\nAfter got the instance of `ImmutabilityUtil`, you can use the chainable methods below.\n\n - `$apply(path, function)`: passes in the current value to the function and updates it with the new returned value.\n - `$merge(path, object)`: merge the keys of object with the target.\n - `$push(path, array)`: push() all the items in array on the target.\n - `$set(path, any)`: replace the target entirely.\n - `$splice(path, array of arrays)`: call splice() with the array of arrays on the target with the parameters provided by the item.\n - `$unset(path, array of strings)`: remove the list of keys in array from the target object.\n - `$unshift(path, array)`: unshift() all the items in array on the target.\n\n~~~Also you can use API `update()`, and put **spec** into it, just like immutability-helper.~~~\n\nThen you can use API `value()` to get the immutable data copy. All the value of method are compatible with `immutability-helper`.\n\nYour pull requests are needed for more API.\n\n\n## 4. Build \u0026 Test\n\nYou can develop and test as below.\n```sh\nnpm run build\n# run the testcases\nnpm run test\n```\n\nYou can run `npm run benchmark` to get the comparison of performance.\n\n\n## 5. License\n\nMIT@[hustcc](https://github.com/hustcc).\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhustcc%2Fimmutability-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhustcc%2Fimmutability-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhustcc%2Fimmutability-util/lists"}