{"id":15395043,"url":"https://github.com/goto-bus-stop/item-selection","last_synced_at":"2025-04-16T00:03:18.171Z","repository":{"id":2035771,"uuid":"45600530","full_name":"goto-bus-stop/item-selection","owner":"goto-bus-stop","description":"Manage multi-`\u003cselect\u003e` style array selection state.","archived":false,"fork":false,"pushed_at":"2024-04-29T04:17:39.000Z","size":176,"stargazers_count":6,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"default","last_synced_at":"2025-03-29T03:06:20.816Z","etag":null,"topics":["collection","list","range","selection"],"latest_commit_sha":null,"homepage":"https://goto-bus-stop.github.io/item-selection","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/goto-bus-stop.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-05T09:19:26.000Z","updated_at":"2021-10-05T08:29:15.000Z","dependencies_parsed_at":"2022-09-15T23:40:17.700Z","dependency_job_id":"ebcc60bc-d1fe-4f1e-a956-e1e5c8a71d81","html_url":"https://github.com/goto-bus-stop/item-selection","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Fitem-selection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Fitem-selection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Fitem-selection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Fitem-selection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goto-bus-stop","download_url":"https://codeload.github.com/goto-bus-stop/item-selection/tar.gz/refs/heads/default","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249173072,"owners_count":21224483,"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":["collection","list","range","selection"],"created_at":"2024-10-01T15:25:28.309Z","updated_at":"2025-04-16T00:03:18.131Z","avatar_url":"https://github.com/goto-bus-stop.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# item-selection\n\nManage multi-`\u003cselect\u003e` style selections in arrays.\n\n## Usage\n\n[Demo](https://goto-bus-stop.github.io/item-selection) - [Demo source code](./example.js)\n\n```js\nimport itemSelection from 'item-selection'\n\nconst sourceList = [ 'a', 'b', 'c', 'd' ]\n\nlet selection = itemSelection(sourceList)\n\n// Methods behave similarly to selection operations in a \u003cselect multiple\u003e, or\n// eg. your average file manager:\n\nselection = selection.select(0) // like clicking\nselection.get() // ['a']\nselection = selection.selectRange(2) // like shift+clicking\nselection.get() // ['a', 'b', 'c']\nselection = selection.selectToggle(1) // like ctrl+clicking\nselection.get() // ['a', 'c']\n```\n\nAn `itemSelection` is immutable by default, i.e. it returns a new selection\nobject. Use `import itemSelection from 'item-selection/mutable'` if you want to\nmutate the current selection object instead.\n\n## API\n\n### selection = itemSelection(sourceList)\n\nCreates a new selection manager object.\n\n**All mutation methods return a new selection manager object by default. If you\nwant to mutate and reuse the same object, use\n`import itemSelection from 'item-selection/mutable'`.**\n\n### selection = selection.select(index)\n\nCreates a selection with _just_ the item at the given `index` selected. Akin to\nclicking an item in a `\u003cselect multiple\u003e` element.\n\nIf you want to _add_ an item to the selection, use [`selection.add(index)`](#selection--selection-addindex)\ninstead.\n\nAlso sets the initial range index to `index`.\n\n### selection = selection.deselect(index)\n\nDeselects the item at `index`.\n\n### selection = selection.selectToggle(index)\n\nSelects or deselects the item at `index`. Akin to Ctrl+clicking.\n\nAlso sets the initial range index to `index` if a new item was selected.\nOtherwise, unsets the initial range index.\n\n### selection = selection.selectRange(start, end)\n\nSelects the given range. Inclusive. (NB: That's different from what Array.slice\ndoes!)\n\n### selection = selection.selectRange(index)\n\nSelects a range based on the initial range index and the `index`. Akin to\nShift+clicking. Previously selected items that fall _outside_ the range will be\ndeselected.\n\nIf the initial range index was not set using `select(index)` or\n`selectToggle(index)`, `selectRange` only selects the given index.\n\n### selection = selection.selectAll()\n\nAdds all items to the selection.\n\n### selection = selection.add(index)\n\nAdds the item at `index` to the selection.\n\nAlso sets the initial range index to `index`.\n\n### selection = selection.remove(index)\n\nRemoves the item at `index` from the selection.\n\n### selection = selection.clear()\n\nDeselect all items.\n\n### selectedItems = selection.get()\n\nGet an array of the selected _items_.\n\n### selectedIndices = selection.getIndices()\n\nGet an array of the selected indices.\n\n### selection = selection.set(indices)\n\nSet a custom array of selected indices.\n\n## Licence\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoto-bus-stop%2Fitem-selection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoto-bus-stop%2Fitem-selection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoto-bus-stop%2Fitem-selection/lists"}