{"id":19749335,"url":"https://github.com/lucagoslar/fast-unset","last_synced_at":"2025-04-30T09:30:56.264Z","repository":{"id":42486586,"uuid":"447715542","full_name":"lucagoslar/fast-unset","owner":"lucagoslar","description":"🪄 Efficiently remove, replace, set or default object properties.","archived":false,"fork":false,"pushed_at":"2022-08-09T20:27:19.000Z","size":190,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-18T11:31:12.369Z","etag":null,"topics":["default","delete","filter","json","key","nested","object","omit","property","redact","typescript"],"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/lucagoslar.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":null,"security":null,"support":null}},"created_at":"2022-01-13T18:51:05.000Z","updated_at":"2024-05-12T19:44:35.000Z","dependencies_parsed_at":"2022-08-31T14:11:18.530Z","dependency_job_id":null,"html_url":"https://github.com/lucagoslar/fast-unset","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":"lucagoslar/ts-pkg","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucagoslar%2Ffast-unset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucagoslar%2Ffast-unset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucagoslar%2Ffast-unset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucagoslar%2Ffast-unset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucagoslar","download_url":"https://codeload.github.com/lucagoslar/fast-unset/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224204674,"owners_count":17273161,"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":["default","delete","filter","json","key","nested","object","omit","property","redact","typescript"],"created_at":"2024-11-12T02:26:05.288Z","updated_at":"2024-11-12T02:26:06.182Z","avatar_url":"https://github.com/lucagoslar.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 📎 Note\n\nVersion 2.0.0 contains a bug fix. Therefore, please update to the latest version.\n\n## fast-unset\n\n🪄 Efficiently remove, replace, set or default object properties.\n\n[![build package and run tests](https://github.com/lucagoslar/fast-unset/actions/workflows/main.yml/badge.svg)](https://github.com/lucagoslar/fast-unset/actions/workflows/main.yml)\n\n### Index\n\n- [Note](#)\n- [fast-unset](#fast-unset)\n  - [Index](#index)\n- [Usage](#usage)\n  - [Deleting properties](#deleting-properties)\n  - [Setting values](#setting-values)\n  - [Modifiers](#modifiers)\n    - [rule](#rule)\n    - [value](#value)\n  - [Flags](#flags)\n    - [deep](#deep)\n    - [default](#default)\n    - [direct](#direct)\n  - [Working with arrays](#working-with-arrays)\n  - [Known limitattions](#known-limitattions)\n- [Example](#example)\n- [Benchmarking](#benchmarking)\n- [Tests](#tests)\n- [Treeshaking](#treeshaking)\n- [API Reference](#api-reference)\n- [Contribute](#contribute)\n  - [Getting started](#getting-started)\n\n## Usage\n\n_Generally speaking_ - mimic the structure of the object to be mutated.\n\nTo [remove a property](#deleting-properties), set its value to null or pass an object containing the property `rule` set to null. \\\nTo [set a property](#setting-values), pass it an object containing a `value` property set to your desired value.\n\n### Deleting properties\n\n```js\nfunset(object, { prop: { nestedprop: null } }); // Short for …\nfunset(object, {\n\tprop: { rule: { nestedprop: { rule: null } } },\n});\n```\n\n### Setting values\n\n```js\nfunset(object, {\n\tprop: { value: new Date() },\n});\n```\n\n### Modifiers\n\n#### rule\n\n`rule` accepts either an array of objects, an object or `null`. \\\nWhen passing `null`, the property will get removed. Otherwise, the object or the array passed will get treated as a path to an object.\n\n#### value\n\n`value` holds what will get set to the property.\n\n### Flags\n\nThe value of a property may contain flags, such as `deep` or `default`, and the available modifies `rule` and `value`.\n\n#### deep\n\nApplies your rule globally while only looking into the object of the property it got defined in.\n\n_Example:_\n\n```js\nfunset(object, { prop: { deep: true, rule: null } });\n```\n\n**The passed object** will get searched for occurrences of property `prop`. Findings will get removed - nested ones included. \\\nThe `deep` flag may get used in combination with the `default` flag.\n\n#### default\n\nOnly sets the value if the property did not occur at the position of your property.\n\n```js\nfunset(object, { prop: { default: true, value: null } });\n```\n\n#### direct\n\nTreats the values of your property as if they were in a `rule` modifier.\n\nPassing the `direct` flag **will only be neccessary** in the case of a nested property called `value` or `rule`. Otherwise, it is not required.\n\n```js\nfunset(object, { prop: { direct: true, value: null } });\n```\n\nThe property `value` of `prop` will get removed.\n\nThe same behaviour can get achieved with the following.\n\n```js\nfunset(object, { prop: { rule: { value: null } } });\n```\n\n### Working with arrays\n\n```js\nlet object = { value: [[{ prop: 1 }]] };\n\nfunset(object, { value: { rule: { prop: null } } });\n```\n\nAs seen in this example, brackets must not necessarily get set.\n\n### Known limitattions\n\nYou cannot access the properties \"direct\" and \"value\" or \"rule\" in combination if nested. Alternatively, wrap them in a `rule` modifier.\n\n_Example:_\n\n```js\nfunset(\n\t{ value: 1, rule: 1, direct: 1 }, // Object\n\t{ value: null, rule: null, direct: null } // Modifier\n); // No action required\n\nfunset(\n\t{ prop: { value: 1, rule: 1, direct: 1 } }, // Object\n\t{ prop: { rule: { value: null, rule: null, direct: null } } } // Modifier\n); // See the modifier \"rule\" containing another set of modifiers\n```\n\n## Example\n\nFind further examples at [/src/\\_\\_tests\\_\\_/](/src/__tests__/) or jump to section [Usage](#usage).\n\n```js\nimport funset from 'fast-unset';\n// const funset = require('fast-unset');\n\nlet object = {\n\tsecret: 'shhh',\n\tmorning: false,\n\tchild: [\n\t\t[\n\t\t\t{\n\t\t\t\tmorning: false,\n\t\t\t\tsecret: 'shhh',\n\t\t\t\tchild: {\n\t\t\t\t\tmorning: false,\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t],\n\tnested: {\n\t\tpin: 1234,\n\t\tnested: {\n\t\t\tanothersecret: 'shh',\n\t\t},\n\t},\n};\n\nlet mofifier = {\n\tsecret: { deep: true, rule: null }, // Will remove all occurrences of property \"secret\"\n\tchild: { morning: { deep: true, rule: null } }, // Will remove all occurrences of property \"morning\" starting at property \"child\"\n\n\tnested: {\n\t\tpin: { value: null }, // Removes property \"pin\" of property \"nested\"\n\t\tnested: { anothersecret: null }, // Will remove nested property \"anothersecret\"\n\t},\n\n\t// nested: {\n\t// \trule: [\n\t// \t\t{ pin: { value: null } },\n\t// \t\t{ nested: { rule: { anothersecret: { rule: null } } } },\n\t// \t],\n\t// }, //! Also valid, though not recommended due to performance impact\n};\nlet settings = {\n\tclone: false, // Instead, working on a deep clone of the object\n}; // Optional though\n\nfunset(object, mofifier, settings);\n\nconsole.log(object);\n\n/* Outputs the following …\n\n  {\n\t\tmorning: false,\n\t\tchild: [\n\t\t\t[\n\t\t\t\t{\n\t\t\t\t\tchild: {},\n\t\t\t\t},\n\t\t\t],\n\t\t],\n\t\tnested: {\n\t\t\tpin: null,\n\t\t\tnested: {},\n\t\t},\n\t}\n\n*/\n```\n\n## [Benchmarking](/src/benchmark/index.ts)\n\n⚠️ **Note** that results may differ on different devices, runs and use cases. Also, when bundling packages, bundle sizes depend on the configuration you use.\n\n| library           | deep clone | result                   | runs sampled | performance | bundle size (min + gz) |\n| :---------------- | :--------: | :----------------------- | :----------- | :---------- | :--------------------- |\n| fast-redact       |   false    | 981,388 ops/sec ±0.57%   | 93           | 21.9%       | -                      |\n| unset-value       |   false    | 2,252,566 ops/sec ±0.49% | 95           | 50.2%       | 1.8 kB                 |\n| fast-unset        |    true    | 2,300,278 ops/sec ±0.49% | 96           | 51.3%       | 1.3 kB                 |\n| fast-unset        |   false    | 4,451,021 ops/sec ±0.46% | 95           | 99.3%       | 1.3 kB                 |\n| fast-unset (core) |   false    | 4,484,568 ops/sec ±0.40% | 92           | 100%        | 600 B                  |\n\n## [Tests](/src/__tests__/)\n\nThe [tests](/src/__tests__/) provided may not cover all edge cases. Feel free to suggest new ones or report missing ones.\n\n## Treeshaking\n\n```js\nimport { core } from 'fast-unset/dist/core';\n// Same usage as funset while dropping argument `settings` and all argument type checking\n```\n\n## API Reference\n\n```js\nimport funset from 'fast-unset';\n// const funset = require(\"fast-unset\");\n\nfunset(input, modifier, settings) =\u003e Object\n```\n\nThe function provided is constrained to the following arguments while always returning an object or throwing errors:\n\n- `input`\n  - required\n  - type: object or an array of objects\n- `modifier`\n  - required\n  - type: object or an array of objects\n- `settings`\n  - optional\n  - type: object\n  - valid options\n    - `clone`\n      - defaults to false\n      - type: boolean\n      - description: creates a deep clone of `object` before continuing with the process\n\n## Contribute\n\nNew ideas, as well as thoughts on this project and pull requests, are very welcome.\nPlease make sure all tests pass before creating a pull request.\n\n### Getting started\n\nAfter forking, install all (dev-)dependencies by running the following.\n\n```zsh\nnpm i\n```\n\nMake sure [husky](https://github.com/typicode/husky) is being installed too.\n\n```zsh\nnpm run prepare\n```\n\n\\\n_And off we go …_\n\nBuild this project with the following.\n\n```zsh\nnpm run build\n```\n\nEventually, run your tests.\n\n```zsh\nnpm run test\nnpm run test:watch\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucagoslar%2Ffast-unset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucagoslar%2Ffast-unset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucagoslar%2Ffast-unset/lists"}