{"id":25879498,"url":"https://github.com/nyaomaru/divider","last_synced_at":"2026-03-14T18:00:07.987Z","repository":{"id":279605178,"uuid":"936028677","full_name":"nyaomaru/divider","owner":"nyaomaru","description":"Divide string or string[] with given indexes or delimiters. npm -\u003e https://www.npmjs.com/package/@nyaomaru/divider jsr -\u003e https://jsr.io/@nyaomaru/divider","archived":false,"fork":false,"pushed_at":"2026-03-08T05:10:36.000Z","size":2342,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-08T10:22:00.251Z","etag":null,"topics":["array-split","array-splitter","javascript","jsr-package","lightweight","nodejs","npm-package","open-source","string-manipulation","string-split","string-splitter","typescript","utility-library"],"latest_commit_sha":null,"homepage":"https://divider-docs.vercel.app","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/nyaomaru.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-02-20T12:15:04.000Z","updated_at":"2026-03-08T05:10:16.000Z","dependencies_parsed_at":"2025-02-26T13:24:40.662Z","dependency_job_id":"056677bc-9f64-4f29-ae02-02342ebab56a","html_url":"https://github.com/nyaomaru/divider","commit_stats":null,"previous_names":["nyaomaru/divider"],"tags_count":99,"template":false,"template_full_name":null,"purl":"pkg:github/nyaomaru/divider","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nyaomaru%2Fdivider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nyaomaru%2Fdivider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nyaomaru%2Fdivider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nyaomaru%2Fdivider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nyaomaru","download_url":"https://codeload.github.com/nyaomaru/divider/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nyaomaru%2Fdivider/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30511449,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-14T14:51:43.155Z","status":"ssl_error","status_checked_at":"2026-03-14T14:47:41.964Z","response_time":57,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":["array-split","array-splitter","javascript","jsr-package","lightweight","nodejs","npm-package","open-source","string-manipulation","string-split","string-splitter","typescript","utility-library"],"created_at":"2025-03-02T13:19:00.670Z","updated_at":"2026-03-14T18:00:07.937Z","avatar_url":"https://github.com/nyaomaru.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Divider\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/nyaomaru/divider/main/divider_image.png\" width=\"600px\" align=\"center\" alt=\"Divider logo\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://www.npmjs.com/package/@nyaomaru/divider\"\u003e\n        \u003cimg src=\"https://img.shields.io/npm/v/@nyaomaru/divider.svg?sanitize=true\" alt=\"npm version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://jsr.io/@nyaomaru/divider\"\u003e\n        \u003cimg src=\"https://img.shields.io/jsr/v/@nyaomaru/divider\" alt=\"JSR\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/nyaomaru/divider/blob/main/LICENSE\"\u003e\n        \u003cimg src=\"https://img.shields.io/npm/l/@nyaomaru/divider.svg?sanitize=true\" alt=\"License\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/@nyaomaru/divider\"\u003e\n        \u003cimg src=\"https://img.shields.io/npm/dt/@nyaomaru/divider.svg\" alt=\"npm downloads\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/nyaomaru/divider/actions\"\u003e\n        \u003cimg src=\"https://github.com/nyaomaru/divider/actions/workflows/release.yml/badge.svg\" alt=\"Build Status\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nA simple utility to divide a `string` or `string[]` based on given indexes or delimiters.\n\n## 🚀 Installation\n\nYou can install `@nyaomaru/divider` using your favorite package manager:\n\n```sh\n# Using pnpm (recommended)\npnpm install @nyaomaru/divider\n\n# Using npm\nnpm install @nyaomaru/divider\n\n# Using bun\nbun add @nyaomaru/divider\n\n# Using yarn\nyarn add @nyaomaru/divider\n```\n\n### Deno / Bun (via JSR)\n\nThis package is also published on JSR and works in Deno and Bun without a bundler.\n\n```ts\n// Deno/Bun: import directly from JSR\nimport { divider } from 'jsr:@nyaomaru/divider';\n```\n\nVersion pinning examples:\n\n```ts\n// Pin a major version (recommended)\nimport { divider } from 'jsr:@nyaomaru/divider@^1';\n\n// Or pin an exact version\nimport { divider } from 'jsr:@nyaomaru/divider@1.9.4';\n```\n\nFor Bun, you can also add it to your project manifest:\n\n```sh\n# Pin a major version in Bun\nbun add jsr:@nyaomaru/divider@^1\n```\n\n## 📖 Documentation\n\n- 📝 Guide: [https://divider-docs.vercel.app](https://divider-docs.vercel.app)\n- 🧪 API Reference: [https://nyaomaru.github.io/divider/](https://nyaomaru.github.io/divider/)\n\n## 📖 Usage\n\n👉 [Check out the full documentation here!](https://divider-docs.vercel.app/)\n\n`divider` allows you to divide a string or an array of strings using index positions or delimiters.\n\n### 📌 Basic Usage\n\n```ts\nimport { divider } from '@nyaomaru/divider';\n\n// Divide a string by index positions\nconst helloArray = divider('hello', 1, 3);\n// ['h', 'el', 'lo']\n\nconst [hello1, hello2, ...restHello] = divider('hello', 1, 3, 4);\n// hello1 = 'h'\n// hello2 = 'el'\n// restHello = ['l', 'o']\n\n// Divide a string using a character separator\nconst divideWithString = divider('hello', 'e');\n// ['h', 'llo']\n\nconst divideWithMultipleString = divider('hello', 'l');\n// ['he', 'o']\n\n// Divide an array of strings\nconst words = ['hello', 'world'];\nconst dividedWords = divider(words, 2);\n// [['he', 'llo'], ['wo', 'rld']]\nconst dividedWordsWithFlattenOption = divider(words, 2, { flatten: true });\n// ['he', 'llo', 'wo', 'rld']\n```\n\n### 📌 Advanced Usage\n\n```ts\n// Mixed usage of indexes and characters\nconst complexDivide = divider('hello world', 3, 'o');\n// ['hel', 'l', ' w', 'rld']\n\n// Nested array handling\nconst nestedArray = divider(['hello', 'new world'], ' ', 2);\n// [['he', 'llo'], ['ne', 'w wor', 'ld']]\n\n// Flatten option to get a single array\nconst flatArray = divider(['hello', 'new world'], ' ', 2, { flatten: true });\n// ['he', 'llo', 'ne', 'w', 'wor', 'ld']\n```\n\n### 📌 `dividerFirst()` Usage\n\n`dividerFirst()` returns only the first divided element from the result.\n\n```ts\nimport { dividerFirst } from '@nyaomaru/divider';\n\nconst firstElement = dividerFirst('hello world', ' ');\n// 'hello'\n\nconst firstArrayElement = dividerFirst(['hello', 'world'], 2);\n// 'he'\n```\n\n### 📌 `dividerLast()` Usage\n\n`dividerLast()` returns only the last divided element from the result.\n\n```ts\nimport { dividerLast } from '@nyaomaru/divider';\n\nconst lastElement = dividerLast('hello world', ' ');\n// 'world'\n\nconst lastArrayElement = dividerLast(['hello', 'world'], 2);\n// 'rld'\n```\n\n### 📌 `dividerLoop()` Usage\n\n```ts\nimport { dividerLoop } from '@nyaomaru/divider';\n\n// Divide string into chunks of given size\nconst result = dividerLoop('abcdefghij', 3);\n// ['abc', 'def', 'ghi', 'j']\n\n// Supports flatten option for string[]\nconst result2 = dividerLoop(['hello', 'world'], 2, { flatten: true });\n// ['he', 'll', 'ow', 'or', 'ld']\n\n// You can also control where to start dividing using `startOffset`\nconst result3 = dividerLoop('abcdefghij', 3, { startOffset: 1 });\n// ['abcd', 'efg', 'hij']\n\n// Combine with flatten and trim\nconst result4 = dividerLoop(['  hello ', 'world  '], 2, {\n  flatten: true,\n  trim: true,\n  startOffset: 1,\n});\n// ['h', 'el', 'lo', 'wor', 'ld']\n\n// Limit the number of chunks using maxChunks\nconst result5 = dividerLoop('abcdefghij', 3, { maxChunks: 2 });\n// ['abc', 'defghij']\n```\n\n### 📌 `dividerNumberString()` Usage\n\n```ts\nimport { dividerNumberString } from '@nyaomaru/divider';\n\n// Divide numbers and letters from a string\nconst result = dividerNumberString('abc123def456');\n// ['abc', '123', 'def', '456']\n\n// Divide each string in a string[]\nconst result2 = dividerNumberString(['abc123', '45z']);\n// [['abc', '123'], ['45', 'z']]\n\n// Flatten option\nconst result3 = dividerNumberString(['abc123', '45z'], { flatten: true });\n// ['abc', '123', '45', 'z']\n```\n\n### 📌 Presets\n\nSome common use cases are wrapped as presets for convenience.\n\n| Preset name    | Description                                               |\n| -------------- | --------------------------------------------------------- |\n| `emailDivider` | Divide email into [local-part, domain] (by '@')           |\n| `csvDivider`   | Divide comma-separated strings, with quoted field support |\n| `pathDivider`  | Divide file paths by / or \\|                              |\n| `queryDivider` | Divide query strings into [key, value] pairs (URL-safe)   |\n\n[Presets detail](src/presets/README.md)\n\nExample:\n\n```ts\nimport { queryDivider } from '@nyaomaru/divider';\n\nqueryDivider('?q=hello+world');\n// [['q', 'hello world']] // default: '+' treated as space and % decoded\n\nqueryDivider('q=hello+world', { mode: 'raw' });\n// [['q', 'hello+world']] // raw mode keeps '+' and % as-is\n```\n\n## 🎯 General Options\n\n| Option          | Type                                 | Default  | Description                                                               |\n| --------------- | ------------------------------------ | -------- | ------------------------------------------------------------------------- |\n| `flatten`       | `boolean`                            | `false`  | If `true`, the resulting nested arrays are flattened into a single array. |\n| `trim`          | `boolean`                            | `false`  | If `true`, trims whitespace from each divided segment.                    |\n| `preserveEmpty` | `boolean`                            | `false`  | If `true`, keeps empty segments produced by the split.                    |\n| `exclude`       | `'none'  /  'empty'  / 'whitespace'` | `'none'` | See detailed explanation below                                            |\n\n### `flatten` (default: `false`)\n\n```ts\nconst words = ['hello', 'world'];\nconst result = divider(words, 2);\n// [['he', 'llo'], ['wo', 'rld']]\n\nconst result = divider(words, 2, { flatten: true });\n// ['he', 'llo', 'wo', 'rld']\n```\n\n### `trim` (default: `false`)\n\n```ts\nconst result = divider('  hello world  ', 7, { trim: true });\n// ['hello', 'world']\n\nconst result = divider(['  a  ', ' b  c '], ' ', {\n  flatten: true,\n  trim: true,\n});\n// ['a', 'b', 'c']\n```\n\n### `preserveEmpty` (default: `false`)\n\n```ts\nconst defaultResult = divider('foo,,bar,', ',');\n// ['foo', 'bar']\n\nconst preservedResult = divider('foo,,bar,', ',', { preserveEmpty: true });\n// ['foo', '', 'bar', '']\n```\n\nKeep placeholder blanks when they carry meaning (e.g., CSV cells, sparse logs, diff tooling). Combine with `exclude` to filter later in the pipeline.\n\n### `exclude` (default: `'none'`)\n\n| Option         | Description                                                              |\n| -------------- | ------------------------------------------------------------------------ |\n| `'none'`       | Do not exclude any segments (all results are kept).                      |\n| `'empty'`      | Exclude empty strings (`''`).                                            |\n| `'whitespace'` | Exclude strings that contain only whitespace characters (e.g., `'   '`). |\n\nControl how segments like empty strings (`''`) or whitespace-only strings (`'   '`) are handled.\n\n```ts\n// Remove truly empty strings\nconst result = divider('a,,b', ',', { exclude: 'empty' });\n// ['a', 'b']\n\n// Remove both empty and whitespace-only strings\nconst result = divider('a, ,b', ',', { exclude: 'whitespace' });\n// ['a', 'b']\n\n// You can combine with `trim` for clearer results (note the trailing space)\nconst result = divider('a, ,b ', ',', {\n  trim: true,\n  exclude: 'whitespace',\n});\n// ['a', 'b']\n```\n\n## Special Options\n\n| Option        | Type     | Default | Description                                                                                             |\n| ------------- | -------- | ------- | ------------------------------------------------------------------------------------------------------- |\n| `startOffset` | `number` | `0`     | Starting index offset when dividing into chunks (only for `dividerLoop`)                                |\n| `maxChunks`   | `number` | `∞`     | Maximum number of chunks allowed. Extra chunks are joined into the last chunk. (only for `dividerLoop`) |\n\n## 💡 Features\n\n- 🧩 Flexible Division: Index-based and string-based separators\n- 🧵 Handles Nested Input: Supports both string and string[]\n- 🎛️ Optional Behaviors: flatten, trim, preserveEmpty, exclude\n- 🎯 Targeted Extractors: dividerFirst(), dividerLast()\n- 🔁 Loop Support: dividerLoop() for chunked division\n- 🔢 Digit-Letter Splitter: dividerNumberString()\n\n## 🛠 Contributing\n\nWe welcome contributions!\n\nPlease read our [CONTRIBUTING.md](./CONTRIBUTING.md) guide before submitting a PR.\n\nThank you for your contribution. 😺\n\n## 📚 Additional Documents\n\n- [DEVELOPER.md](./DEVELOPER.md) — Development setup and contributor guide\n- [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md) — Community standards and conduct\n- [CHANGELOG.md](./CHANGELOG.md) — Version history and notable changes\n\n## 🟦 Deno / JSR Notes\n\n- Import path alias `@/` is supported in Deno via the included `deno.json` import map.\n- Type-check locally with Deno: `deno task check` (or `deno check ./src/index.ts`).\n- Publish to JSR from a tagged commit: `deno publish`.\n- CI: On PRs, we run `deno fmt --check` / `deno lint` / `deno check` / `deno test`.\n- CI JSR publish runs `deno publish` when a GitHub Release is published (OIDC-based; no personal token required).\n- `deno test` is configured to only target `tests-deno/**` (Bun/Jest tests are excluded).\n- For local development, Deno's `unstable` `sloppy-imports` is enabled to resolve the `@/` alias (this does not affect JSR publishing or consumers).\n- VSCode: to enable Bun type completions, add `bun-types` as a dev dependency and include `\"bun-types\"` in `tests-bun/tsconfig.json` `types` (this repo is preconfigured).\n- VSCode: the Deno extension is enabled only for `tests-deno/` (see `.vscode/settings.json`), which fixes typings for `jsr:@std/assert`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnyaomaru%2Fdivider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnyaomaru%2Fdivider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnyaomaru%2Fdivider/lists"}