{"id":48394229,"url":"https://github.com/nanarino/list-slice","last_synced_at":"2026-04-06T01:16:43.092Z","repository":{"id":58456192,"uuid":"531866901","full_name":"nanarino/list-slice","owner":"nanarino","description":"implementation of Python built-in type : `list.__getitem__` and `list.__setitem__`","archived":false,"fork":false,"pushed_at":"2023-10-23T16:42:16.000Z","size":129,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-28T06:37:49.966Z","etag":null,"topics":["getitem","python","setitem","slice"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/list-slice","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/nanarino.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}},"created_at":"2022-09-02T09:42:37.000Z","updated_at":"2023-05-11T15:45:24.000Z","dependencies_parsed_at":"2023-01-21T16:16:31.327Z","dependency_job_id":"f06b8926-42f6-4df5-9e70-e7a980ca3a4f","html_url":"https://github.com/nanarino/list-slice","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"f966d14320ea4151116cc6ff545c2e65a5fbb438"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/nanarino/list-slice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanarino%2Flist-slice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanarino%2Flist-slice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanarino%2Flist-slice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanarino%2Flist-slice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nanarino","download_url":"https://codeload.github.com/nanarino/list-slice/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nanarino%2Flist-slice/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31455623,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T21:22:52.476Z","status":"ssl_error","status_checked_at":"2026-04-05T21:22:51.943Z","response_time":75,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["getitem","python","setitem","slice"],"created_at":"2026-04-06T01:16:43.034Z","updated_at":"2026-04-06T01:16:43.086Z","avatar_url":"https://github.com/nanarino.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# list-slice\n\n\u003e inspired by Python list method : `list.__getitem__` and `list.__setitem__`\n\n\n## Install\n\n```\n$ pnpm install list-slice\n```\n\n## Usage\n\n```js\nimport { getitem, setitem, pop } from \"list-slice\"\n```\n\n### getitem\n\n- `getitem(arr, index)`\n- `getitem(arr, [stop])`\n- `getitem(arr, [start, stop])`\n- `getitem(arr, [start, stop, step])`\n- `getitem(arr, { start, stop, step })`\n\n```js\nconst arr = [1, 2, 3, 4, 5]\n// python arr[2:]\ngetitem(arr, [2,,]) // [3, 4, 5]\n// python arr[3::-1]\ngetitem(arr, [3,,-1]) // [4, 3, 2, 1]\n```\n`[2,,]` is different than `[2,]` or you can just use `[2, null]`.\n\n\n### setitem\n\n- `setitem(arr, index, newItem)`\n- `setitem(arr, [stop], newArr)`\n- `setitem(arr, [start, stop], newArr)`\n- `setitem(arr, [start, stop, step], newArr)`\n- `setitem(arr, { start, stop, step }, newArr)`\n\n```js\nconst arr = [1, 3, 4, 5]\n\n// python arr[:] = [7, 8, 9]\nsetitem(arr, [], [7, 8, 9])\nconsole.log(arr) // [7, 8, 9]\n\n// python arr[2:] = [7, 8, 9]\nsetitem(arr, [2,,], [7, 8, 9])\nconsole.log(arr) // [7, 8, 7, 8, 9]\n```\n\n\n### pop\n\n- `pop(arr)`\n- `pop(arr, index)`\n\n```js\nconst arr = [1, 3, 4, 5]\n\n// python arr.pop(0)\nconst first = pop(arr, 0)\nconsole.log(first, arr) // 1 [3, 4, 5]\n```\n\n\n## Handling Errors\n\npython-like error name:\n\n```js\nconst a = getitem([1,2,3], 3)\n          ^\n\nSliceIndexError [RangeError]: array index out of range\n    at file:///c:/Users/Administrator/Desktop/test.mjs:3:11\n    at ModuleJob.run (internal/modules/esm/module_job.js:183:25)\n    at async Loader.import (internal/modules/esm/loader.js:178:24)\n    at async Object.loadESM (internal/process/esm_loader.js:68:5)\n    at async handleMainPromise (internal/modules/run_main.js:59:12)\n```\n\n\n\n## Bundler notes\n\nIt was exported with `cjs`,`esm`,`iife` format and named exports.\n\nNo export is transpiled for sake of modern syntax.\n\nIt can only run on node14+ and modern browsers.\n\n\n\n## Test\n\nCoverage 100%\n\n```shell\n------------|---------|----------|---------|---------|-------------------\nFile        | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s\n------------|---------|----------|---------|---------|-------------------\nAll files   |     100 |      100 |     100 |     100 | \n error.ts   |     100 |      100 |     100 |     100 | \n getitem.ts |     100 |      100 |     100 |     100 | \n index.ts   |     100 |      100 |     100 |     100 | \n pop.ts     |     100 |      100 |     100 |     100 | \n setitem.ts |     100 |      100 |     100 |     100 | \n slice.ts   |     100 |      100 |     100 |     100 | \n------------|---------|----------|---------|---------|-------------------\nTest Suites: 1 passed, 1 total\nTests:       47 passed, 47 total\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanarino%2Flist-slice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanarino%2Flist-slice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanarino%2Flist-slice/lists"}