{"id":35878074,"url":"https://github.com/nilscox/selektor","last_synced_at":"2026-01-08T17:06:43.291Z","repository":{"id":187858547,"uuid":"677703953","full_name":"nilscox/selektor","owner":"nilscox","description":"Create memoized selectors.","archived":false,"fork":false,"pushed_at":"2023-12-26T23:30:54.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-14T05:58:44.410Z","etag":null,"topics":["derived-states","memoization","memoize","redux","selector","selectors","state"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/nilscox.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-08-12T11:01:30.000Z","updated_at":"2023-12-27T13:21:38.000Z","dependencies_parsed_at":"2023-12-27T00:38:52.945Z","dependency_job_id":null,"html_url":"https://github.com/nilscox/selektor","commit_stats":null,"previous_names":["nilscox/selektor"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/nilscox/selektor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilscox%2Fselektor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilscox%2Fselektor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilscox%2Fselektor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilscox%2Fselektor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nilscox","download_url":"https://codeload.github.com/nilscox/selektor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nilscox%2Fselektor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28247005,"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":"2026-01-08T02:00:06.591Z","response_time":241,"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":["derived-states","memoization","memoize","redux","selector","selectors","state"],"created_at":"2026-01-08T17:02:22.517Z","updated_at":"2026-01-08T17:06:43.282Z","avatar_url":"https://github.com/nilscox.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Selektor\n\nCreate memoized selectors, an alternative to [reselect](https://github.com/reduxjs/reselect).\n\n## Usage\n\n```ts\nimport { createSelector, pipe, combine } from '@nilscox/selektor';\n\nconst state = {\n  todos: [\n    { id: 1, completed: true },\n    { id: 2, completed: false },\n  ],\n  currentTodoId: 2,\n};\n\ntype State = typeof state;\n\n// create a memoized selector\nconst selectTodos = createSelector((state: State) =\u003e state.todos);\n\n// create a new selector from another selector's output\nconst selectFirstTodo = pipe(selectTodos, (todos) =\u003e todos[0]);\n\nselectFirstTodo(state); // { id: 1, completed: true }\n\n// introduce extra parameters\nconst selectFilteredTodos = pipe(selectTodos, (todos, completed: boolean) =\u003e {\n  return todos.filter((todo) =\u003e todo.completed === completed);\n});\n\nselectFilteredTodos(state, false); // [{ id: 2, completed: false }]\n\nconst selectCurrentTodoId = createSelector((state) =\u003e state.currentTodoId);\n\n// combine outputs from multiple selectors\nconst selectCurrentTodo = combine(selectTodos, selectCurrentTodoId, (todos, currentTodoId) =\u003e {\n  return todos.find((todo) =\u003e todo.id === currentTodoId);\n});\n\nselectCurrentTodo(state); // { id: 2, completed: false }\n```\n\n## Installation\n\n```\n\u003cyour package manager's install command\u003e @nilscox/selektor\n```\n\n## API\n\n**createSelector(fn)**\n\nCreates a memoized selector. When the selector is called, the function `fn` is called and its returned value is cached. If the selector is called again with the same parameters, `fn` is not called and the cached value is returned.\n\n```ts\nconst state = { foo: 42 };\nconst selectFoo = createSelector((state) =\u003e state.foo);\n\nselectFoo(state); // 42\n```\n\n**pipe(input, output)**\n\nCreate a selector from another selector's output, optionally adding parameters.\n\n```ts\nconst state = { foo: { bar: 42 } };\nconst selectFoo = createSelector((state) =\u003e state.foo);\nconst selectBar = pipe(selectFoo, (foo) =\u003e foo.bar);\n\nselectBar(state); // 42\n\nconst selectBarPlusNum = pipe(selectFoo, (foo, num) =\u003e foo.bar + num);\n\nselectBarPlusNum(state, 9); // 51\n```\n\n**combine(...inputs, output)**\n\nCombine multiple selector's outputs into a new selector. The results of the input selectors will be given as parameters to the output selector.\n\n```ts\nconst state = { foo: 42, bar: 51 };\nconst selectFoo = createSelector((state) =\u003e state.foo);\nconst selectBar = createSelector((state) =\u003e state.bar);\nconst selectForPlusBar = combine(selectFoo, selectBar, (foo, bar) =\u003e foo + bar);\n\nselectFooPlusBar(state); // 93\n```\n\n## Custom memoization function\n\nThe default memoization only remembers the last call of the memoized function, similar to [memoize-one](https://github.com/alexreardon/memoize-one). Use `createPipe` and `createCombine` to create custom `pipe` and `combine` functions with a custom memoization function.\n\n```ts\nfunction memoize(fn) {\n  return (...params) =\u003e {\n    // custom memoization logic\n  };\n}\n\nconst pipe = createPipe(memoize);\nconst combine = createCombine(memoize);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnilscox%2Fselektor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnilscox%2Fselektor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnilscox%2Fselektor/lists"}