{"id":30181005,"url":"https://github.com/streamich/modern-pick","last_synced_at":"2025-08-23T19:32:08.255Z","repository":{"id":33940086,"uuid":"163761947","full_name":"streamich/modern-pick","owner":"streamich","description":"Template string accessors to the selector rescue","archived":false,"fork":false,"pushed_at":"2023-12-15T02:28:44.000Z","size":1843,"stargazers_count":11,"open_issues_count":22,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-04T10:07:23.512Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/streamich.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-01-01T19:43:00.000Z","updated_at":"2023-08-31T13:02:29.000Z","dependencies_parsed_at":"2024-02-05T10:14:43.058Z","dependency_job_id":null,"html_url":"https://github.com/streamich/modern-pick","commit_stats":{"total_commits":36,"total_committers":4,"mean_commits":9.0,"dds":0.2222222222222222,"last_synced_commit":"5ec5fa4ec60f53889cfbad2017ac92f238993a3b"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/streamich/modern-pick","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamich%2Fmodern-pick","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamich%2Fmodern-pick/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamich%2Fmodern-pick/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamich%2Fmodern-pick/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/streamich","download_url":"https://codeload.github.com/streamich/modern-pick/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamich%2Fmodern-pick/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270024697,"owners_count":24514054,"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-08-12T02:00:09.011Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":[],"created_at":"2025-08-12T08:06:28.471Z","updated_at":"2025-08-12T08:07:00.263Z","avatar_url":"https://github.com/streamich.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# modern-pick\n\nModern selector/picker library utilizing JavaScript template literals.\n\n```js\nconst data = {\n  weather: {\n    data: {\n      days: [{\n        conditions: {temperatuer: 26}\n      }]\n    }\n  }\n});\npick`weather.data.days[0].conditions.temperature`()(data);\n// 👉 26\n```\n\nLet's say you have a normalized Redux store.\n\n```js\n{\n  users: {\n    byId: {\n      // 1: {}\n      // 2: {}\n      // 3: {}\n    }\n  }\n}\n```\n\nAnd you want to select all users aged over 18.\n\n```js\nconst getUsersOver18 = pick`users.byId${({age}) =\u003e age \u003e 18}`();\n```\n\nLet's make the age threshold variable.\n\n```js\nconst getUsersOver = pick`users.byId${({age}) =\u003e over =\u003e u.age \u003e over}`;\nconst getUsersOver18 = getUsersOver(18);\n```\n\nLet's limit the number of users to only first five.\n\n```js\nconst getUsersOver = pick`users.byId${u =\u003e over =\u003e u.age \u003e over}${'0:5'}`;\n```\n\nLet's select only `id` and `name` fields.\n\n```js\nconst getUsersOver = pick`users.byId${u =\u003e over =\u003e u.age \u003e over}${'0:5'}-\u003e{id,name}`;\n```\n\nLet's instead select only the last user and reformat our query to make it look smart.\n\n```js\nconst getUsersOver = pick`\n  users.byId\n  ${u =\u003e over =\u003e u.age \u003e over}\n  ${'-1:'}\n  -\u003e{id,name}\n`;\n```\n\nLet's break it down.\n\n- `users.byId` \u0026mdash; this is an *accessor*, it is compiled to `state = state.users.byId`.\n- `${u =\u003e over =\u003e u.age \u003e over}` \u0026mdash; this *filter* expression is compiled to `state = state.filter(u =\u003e u.age \u003e over)`.\n- `${'-1:'}` \u0026mdash; this is a range expression in `start:end:step` format, it is compiled internally to a *filter*, too.\n- `-\u003e` \u0026mdash; *map* operator `-\u003e` tells us to do `state = state.map(...)` over the result set.\n- `{id,name}` \u0026mdash; *destructuring accessor* is internally compiled to `state = (({id, name}) =\u003e ({id, name})(state)`.\n\nAll-in-all the above query is compiled to a JavaScript function like this:\n\n```js\nconst getUsersOver = (over) =\u003e (state, def) =\u003e {\n  try {\n    state = state.users.byId;\n    state = Object.values(state);\n    state = state.filter(u =\u003e u.age \u003e over);\n    state = state.filter((_, i) =\u003e i === state.length - 1);\n    state = state.map(({id, name}) =\u003e ({id, name}));\n    return state;\n  } catch {\n    return def;\n  }\n};\n```\n\n\n## Usage\n\nInstall.\n\n```shell\nnpm i modern-pick\n```\n\nImport.\n\n```js\nimport {id, idx, pick} from 'modern-pick';\n```\n\n\n## Reference\n\n- [`id`](./docs/id.md) \u0026mdash; identity function\n- [`idx`](./docs/idx.md) \u0026mdash; basic accessors\n- [`pick`](./docs/pick.md) \u0026mdash; pimped accessors\n\n\n## License\n\n[Unlicense](LICENSE) \u0026mdash; public domain.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamich%2Fmodern-pick","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstreamich%2Fmodern-pick","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamich%2Fmodern-pick/lists"}