{"id":23545193,"url":"https://github.com/dgeibi/daify","last_synced_at":"2025-05-15T10:34:14.100Z","repository":{"id":57211364,"uuid":"130248949","full_name":"dgeibi/daify","owner":"dgeibi","description":null,"archived":false,"fork":false,"pushed_at":"2018-04-19T17:22:06.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-18T19:29:31.409Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/dgeibi.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":"2018-04-19T17:19:22.000Z","updated_at":"2018-04-19T17:22:07.000Z","dependencies_parsed_at":"2022-08-30T13:11:47.501Z","dependency_job_id":null,"html_url":"https://github.com/dgeibi/daify","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/dgeibi%2Fdaify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgeibi%2Fdaify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgeibi%2Fdaify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dgeibi%2Fdaify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dgeibi","download_url":"https://codeload.github.com/dgeibi/daify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254322914,"owners_count":22051683,"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":[],"created_at":"2024-12-26T08:15:24.150Z","updated_at":"2025-05-15T10:34:14.026Z","avatar_url":"https://github.com/dgeibi.png","language":"JavaScript","readme":"# daify\n\ndictify and arrayify\n\n## API\n\n### opts\n\n#### `Object`\n\n\u003cdl\u003e\n\u003cdt\u003e\u003ccode\u003eopts.by\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003ccode\u003estring\u003c/code\u003e: specify the path to get key of a item, example: \u003ccode\u003e`id`\u003c/code\u003e, \u003ccode\u003e`n.id`\u003c/code\u003e\u003c/dd\u003e\n\u003cdd\u003e\u003ccode\u003efunction\u003c/code\u003e: specify the function to get key of a item, example: \u003ccode\u003eitem =\u003e item.id\u003c/code\u003e\n\u003c/dd\u003e\n\n\u003cdt\u003e\u003ccode\u003eopts.include[path]\u003c/code\u003e\u003c/dt\u003e\n\u003cdd\u003e\u003ccode\u003eopts\u003c/code\u003e for inner object\u003c/dd\u003e\n\u003cdd\u003e\u003ccode\u003epath\u003c/code\u003e can have dot like \u003ccode\u003eopts.by\u003c/code\u003e, which specifies the path to a inner array or dict.\u003c/dd\u003e\n\u003c/dl\u003e\n\n#### `string`\n\nshortcut for `opts.by`\n\n### dictify(array, opts)\n\nMake `array` into `dict`\n\n```js\nconst opts = {\n  by: \"id\",\n  include: {\n    lists: \"id\",\n    \"namespace.inners\": \"id\"\n  }\n};\n\nconst array = [\n  { id: 1, lists: [{ id: 1 }] },\n  { id: 2, lists: [{ id: 1 }] },\n  {\n    id: 3,\n    lists: [{ id: 1 }],\n    namespace: {\n      inners: [{ id: 1 }, { id: 2 }, { id: 3 }]\n    }\n  }\n];\n\nlog(dictify(array, opts));\n/*\n{\n  \"1\": {\n    \"id\": 1,\n    \"lists\": {\n      \"1\": {\n        \"id\": 1\n      }\n    }\n  },\n  \"2\": {\n    \"id\": 2,\n    \"lists\": {\n      \"1\": {\n        \"id\": 1\n      }\n    }\n  },\n  \"3\": {\n    \"id\": 3,\n    \"lists\": {\n      \"1\": {\n        \"id\": 1\n      }\n    },\n    \"namespace\": {\n      \"inners\": {\n        \"1\": {\n          \"id\": 1\n        },\n        \"2\": {\n          \"id\": 2\n        },\n        \"3\": {\n          \"id\": 3\n        }\n      }\n    }\n  }\n}\n*/\n```\n\n### arrayify(dict, opts)\n\nMake `dict` into `array`\n\n```js\nconst opts = {\n  by: \"id\", // by is useless here\n  include: {\n    lists: \"id\",\n    \"namespace.inners\": \"id\"\n  }\n};\nconst dict = {\n  \"1\": {\n    id: 1,\n    lists: {\n      \"1\": { id: 1 }\n    }\n  },\n  \"2\": {\n    id: 2,\n    lists: {\n      \"1\": { id: 1 }\n    }\n  },\n  \"3\": {\n    id: 3,\n    lists: { \"1\": { id: 1 } },\n    namespace: {\n      inners: {\n        \"1\": { id: 1 },\n        \"2\": { id: 2 },\n        \"3\": { id: 3 }\n      }\n    }\n  }\n};\n\nlog(arrayify(dict, opts));\n/*\n[\n  {\n    \"id\": 1,\n    \"lists\": [\n      {\n        \"id\": 1\n      }\n    ]\n  },\n  {\n    \"id\": 2,\n    \"lists\": [\n      {\n        \"id\": 1\n      }\n    ]\n  },\n  {\n    \"id\": 3,\n    \"lists\": [\n      {\n        \"id\": 1\n      }\n    ],\n    \"namespace\": {\n      \"inners\": [\n        {\n          \"id\": 1\n        },\n        {\n          \"id\": 2\n        },\n        {\n          \"id\": 3\n        }\n      ]\n    }\n  }\n]\n*/\n```\n\n## LICENSE\n\n[MIT](LICENSE)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgeibi%2Fdaify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdgeibi%2Fdaify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdgeibi%2Fdaify/lists"}