{"id":16295125,"url":"https://github.com/wadackel/dot-wild","last_synced_at":"2025-03-20T04:30:47.017Z","repository":{"id":55094333,"uuid":"79804283","full_name":"wadackel/dot-wild","owner":"wadackel","description":"Use powerful dot notation (dot path + wildcard) to manipulate properties of JSON","archived":false,"fork":false,"pushed_at":"2021-01-11T07:11:32.000Z","size":199,"stargazers_count":33,"open_issues_count":6,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-16T12:06:34.872Z","etag":null,"topics":["dot-notation","immutable","json","typescript"],"latest_commit_sha":null,"homepage":"https://wadackel.github.io/dot-wild/","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/wadackel.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-01-23T12:56:56.000Z","updated_at":"2024-07-13T11:39:52.000Z","dependencies_parsed_at":"2022-08-14T11:50:16.487Z","dependency_job_id":null,"html_url":"https://github.com/wadackel/dot-wild","commit_stats":null,"previous_names":["tsuyoshiwada/dot-wild"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wadackel%2Fdot-wild","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wadackel%2Fdot-wild/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wadackel%2Fdot-wild/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wadackel%2Fdot-wild/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wadackel","download_url":"https://codeload.github.com/wadackel/dot-wild/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243864808,"owners_count":20360357,"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":["dot-notation","immutable","json","typescript"],"created_at":"2024-10-10T20:17:43.018Z","updated_at":"2025-03-20T04:30:45.723Z","avatar_url":"https://github.com/wadackel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dot-wild\n\n[![Build Status](http://img.shields.io/travis/tsuyoshiwada/dot-wild.svg?style=flat-square)](https://travis-ci.org/tsuyoshiwada/dot-wild)\n[![npm version](https://img.shields.io/npm/v/dot-wild.svg?style=flat-square)](http://badge.fury.io/js/dot-wild)\n\n\u003e Use powerful dot notation (dot path + wildcard) to manipulate properties of JSON.\n\n\n\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n    - [Basic](#basic)\n    - [Advanced](#advanced)\n- [API](#api)\n- [Contribute](#contribute)\n- [License](#license)\n\n\n\n\n## Install\n\n```bash\n$ npm install dot-wild --save\n\n# or\n\n$ yarn add dot-wild\n```\n\n\n\n\n## Usage\n\n### Basic\n\n```javascript\nimport * as dot from 'dot-wild';\n\n\n/**\n * Getter\n */\n\ndot.get({ foo: { bar: 'baz' } }, 'foo.bar');\n// =\u003e 'baz'\n\ndot.get({ 'foo.bar': 'baz' }, 'foo\\\\.bar');\n// =\u003e 'baz'\n\ndot.get({ 'foo.bar': 'baz' }, 'notfound', 'default');\n// =\u003e 'default'\n\nconst authorData = {\n  authors: [\n    { username: 'tsuyoshiwada', profile: { age: 24 } },\n    { username: 'sampleuser', profile: { age: 30 } },\n    { username: 'foobarbaz', profile: { age: 33 } }\n  ]\n};\n\ndot.get(authorData, 'authors.*.username');\n// =\u003e ['tsuyoshiwada', 'sampleuser', 'foobarbaz']\n\ndot.get(authorData, 'authors.*.profile.age');\n// =\u003e [24, 30, 33]\n\n\n/**\n * Setter\n */\ndot.set({ foo: { bar: 'baz' } }, 'foo.bar', 'newvalue');\n// =\u003e { foo: { bar: 'newvalue' } }\n\ndot.set([{ foo: {} }], '0.foo.bar.baz', 'value');\n// =\u003e [{ foo: { bar: { baz: 'value' } } }]\n\nconst members = [\n  { username: 'tsuyoshiwada', profile: { age: 24 } },\n  { username: 'sampleuser', profile: { age: 30 } },\n  { username: 'foobarbaz', profile: { age: 33 } }\n];\n\ndot.set(members, '*.id', 1);\n// =\u003e [ { username: 'tsuyoshiwada', profile: { age: 24 }, id: 1 },\n//      { username: 'sampleuser', profile: { age: 30 }, id: 1 },\n//      { username: 'foobarbaz', profile: { age: 33 }, id: 1 } ]\n\n\n/**\n * Deleter\n */\ndot.remove({ foo: { bar: 'baz' } }, 'foo.bar');\n// =\u003e { foo: {} }\n\ndot.remove(members, '*.profile');\n// =\u003e [ { username: 'tsuyoshiwada' },\n//      { username: 'sampleuser' },\n//      { username: 'foobarbaz' } ]\n\n\n/**\n * Has\n */\ndot.has({ foo: { bar: 'baz' } }, 'foo.bar');\ndot.has(members, '*.profile.age');\n// =\u003e true\n\ndot.has({ foo: { bar: 'baz' } }, 'foo\\\\.bar');\ndot.has(members, '*.notfound.key');\n// =\u003e false\n```\n\n\n### Advanced\n\n```javascript\nimport * as dot from 'dot-wild';\n\nconst postData = {\n  text: 'ok',\n  code: 200,\n  data: {\n    posts: [\n      { id: 1, title: 'post 1' },\n      { id: 2, title: 'post 2' }\n    ],\n    tags: [\n      { id: 1, name: 'tag 1' },\n      { id: 2, name: 'tag 2' }\n    ]\n  }\n};\n\n\n/**\n * Flatten values\n */\ndot.flatten(postData);\n// =\u003e {\n//      text: 'ok',\n//      code: 200,\n//      'data.posts.0.id': 1,\n//      'data.posts.0.title': 'post 1',\n//      'data.posts.1.id': 2,\n//      'data.posts.1.title': 'post 2',\n//      'data.tags.0.id': 1,\n//      'data.tags.0.name': 'tag 1',\n//      'data.tags.1.id': 2,\n//      'data.tags.1.name': 'tag 2'\n//    }\n\n\n/**\n * Expand values\n */\ndot.expand({ 'foo.bar': 'baz' });\n// =\u003e { foo: { bar: 'baz' } }\n\n\n/**\n * Collection helpers (forEach, map)\n */\ndot.forEach(postData, 'data.posts.*.id', (value, key, context, path, data) =\u003e {\n  // value   =\u003e 1, 2\n  // key     =\u003e 'id', 'id'\n  // context =\u003e { id: 1, title: 'post 1' }, { id: 2, title: 'post 2' }\n  // path    =\u003e 'data.posts.0.id', 'data.posts.1.id'\n  // data    =\u003e postData...\n});\n\ndot.map(postData, 'data.tags.*.name', (value, key, context, path, data) =\u003e {\n  return `${dot.get(data, path)} === ${value} (${key})`;\n});\n// =\u003e ['tag 1 === tag 1 (name)', 'tag 2 === tag 2 (name)']\n\n\n/**\n * String to Tokens\n */\ndot.tokenize('foo.bar.baz');\n// =\u003e ['foo', 'bar', 'baz']\n\ndot.tokenize('foo[1].2.*.bar\\\\.*.baz');\n// =\u003e [ 'foo', '1', '2', '*', 'bar.*', 'baz' ]\n\n\n/**\n * Match path (helper method)\n */\ndot.matchPath('foo.bar', 'foo.bar');\ndot.matchPath('foo.*.bar.*.baz', 'foo.5.bar.1.baz');\n// =\u003e true\n\n\n/**\n * Escape path string\n */\ndot.escapePath('foo.bar');\n// =\u003e 'foo\\\\.bar'\n\ndot.escapePath('foo\\\\.bar.baz');\n// =\u003e 'foo\\\\.bar\\\\.baz'\n\n\n/**\n * Build path from Tokens like array\n */\ndot.buildPath(['foo', 'bar', 'baz']);\n// =\u003e 'foo.bar.baz'\n\ndot.buildPath([1, '[2]', 3, '[\"foo\"]', 'bar.baz']);\n// =\u003e '1.2.3.foo.bar\\\\.baz'\n\n\n/**\n * Check contains wildcard token\n */\ndot.containWildcardToken('foo.*.bar');\ndot.containWildcardToken('*.foo.1');\n// =\u003e true\n\ndot.containWildcardToken('path.string');\ndot.containWildcardToken('foo*bar');\n// =\u003e false\n```\n\n\n\n\n## API\n\nSee [API Documetation](https://tsuyoshiwada.github.io/dot-wild/).\n\nAll methods return a new object or array. (immutable)\n\n* `get(data, path, [value, options]): Object | any[]`\n* `set(data, path, value): Object | any[]`\n* `remove(data, path): Object | any[]`\n* `has(data, path): boolean`\n* `flatten(data): Object`\n* `expand(data): Object | any[]`\n* `forEach(data, path, iteratee, options): void`\n* `map(data, path, iteratee, options): any[]`\n* `tokenize(path): string[]`\n* `matchPath(pathA, pathB): boolean`\n* `escapePath(path): string`\n* `buildPath(tokens)[]): string`\n* `containWilcardToken(path): boolean`\n\n\n#### data\n\n**type: `Object | any[]`**\n\nOriginal object or array. Destructive operation is not performed.\n\n\n#### path\n\n**type: `string`**\n\nPath of the property in JSON object. Use the `.` to select properties.  \nSeparator in path syntax can be escaped by using the `\\\\.`.\n\nAnd, you can match arrays by using `*` (wildcard).\n\n\n#### value\n\n**type: `any`**\n\nValue to set at path or optional default value to return from get.\n\n\n#### tokens\n\n**type: `(string | number)[]`**\n\nAn array of tokens that make up the path.\n\n\n#### options\n\nThis is an option for Getter method. (`get`, `forEach`. and `map`)\n\n```javascript\n{\n  iterateObject: true; // If it is `true`, it will enumerate the values of the object when using wildcards\n  iterateArray: true; // If it is `true`, it will enumerate the values of the array when using wildcards\n}\n```\n\n\n\n\n## Contribute\n\n1. Fork it!\n1. Create your feature branch: git checkout -b my-new-feature\n1. Commit your changes: git commit -am 'Add some feature'\n1. Push to the branch: git push origin my-new-feature\n1. Submit a pull request :D\n\nBugs, feature requests and comments are more than welcome in the [issues](https://github.com/tsuyoshiwada/dot-wild/issues).\n\n\n\n\n## Related projects\n\n* [dot-wild-tiny](https://github.com/tsuyoshiwada/dot-wild-tiny)\n\n\n\n\n## License\n\n[MIT © tsuyoshiwada](./LICENSE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwadackel%2Fdot-wild","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwadackel%2Fdot-wild","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwadackel%2Fdot-wild/lists"}