{"id":15645095,"url":"https://github.com/jonschlinkert/split-string","last_synced_at":"2025-04-05T01:08:31.929Z","repository":{"id":44777460,"uuid":"41461783","full_name":"jonschlinkert/split-string","owner":"jonschlinkert","description":"Split a string on a given character or characters, with support for escaping.","archived":false,"fork":false,"pushed_at":"2022-03-29T23:11:51.000Z","size":78,"stargazers_count":57,"open_issues_count":8,"forks_count":17,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T00:11:18.530Z","etag":null,"topics":["javascript","jonschlinkert","js","node","nodejs","parse","parser","split","split-string","string","string-split","util"],"latest_commit_sha":null,"homepage":"https://github.com/jonschlinkert","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/jonschlinkert.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}},"created_at":"2015-08-27T02:41:40.000Z","updated_at":"2024-11-03T15:49:38.000Z","dependencies_parsed_at":"2022-07-20T17:18:33.026Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/split-string","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fsplit-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fsplit-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fsplit-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fsplit-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/split-string/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271532,"owners_count":20911587,"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":["javascript","jonschlinkert","js","node","nodejs","parse","parser","split","split-string","string","string-split","util"],"created_at":"2024-10-03T12:04:29.993Z","updated_at":"2025-04-05T01:08:31.913Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","readme":"# split-string [![NPM version](https://img.shields.io/npm/v/split-string.svg?style=flat)](https://www.npmjs.com/package/split-string) [![NPM monthly downloads](https://img.shields.io/npm/dm/split-string.svg?style=flat)](https://npmjs.org/package/split-string) [![NPM total downloads](https://img.shields.io/npm/dt/split-string.svg?style=flat)](https://npmjs.org/package/split-string) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/split-string.svg?style=flat\u0026label=Travis)](https://travis-ci.org/jonschlinkert/split-string)\n\n\u003e Easy way to split a string on a given character unless it's quoted or escaped.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save split-string\n```\n\n## Usage\n\n```js\nconst split = require('split-string');\n\nconsole.log(split('a.b.c'));\n//=\u003e ['a', 'b', 'c']\n\n// respects escaped characters\nconsole.log(split('a.b.c\\\\.d'));\n//=\u003e ['a', 'b', 'c.d']\n\n// respects double-quoted strings\nconsole.log(split('a.\"b.c.d\".e'));\n//=\u003e ['a', '\"b.c.d\"', 'e']\n```\n\n## Options\n\n### options.quotes\n\n**Type**: `Array|Boolean`\n\n**Default**: `[]`\n\n**Description**\n\nTell split-string not to split inside any of the quote characters specified on the quotes option. Each character signifies both the \"opening\" and \"closing\" character to use.\n\n```js\n// default behavior\nconsole.log(split('a.b.\"c.d.e.f.g\".h.i'));\n//=\u003e [ 'a', 'b', '\"c', 'd', 'e', 'f', 'g\"', 'h', 'i' ]\n\n// with quotes\nconsole.log(split('a.b.\"c.d.e.f.g\".h.i', { quotes: ['\"'] }));\n//=\u003e [ 'a', 'b', '\"c.d.e.f.g\"', 'h', 'i' ]\n\n// escaped quotes will be ignored\nconsole.log(split('a.b.\\\\\"c.d.\"e.f.g\".h.i', { quotes: ['\"'] }));\n//=\u003e [ 'a', 'b', '\"c', 'd', '\"e.f.g\"', 'h', 'i' ]\n\n// example of how to exclude non-escaped quotes from the result\nlet keep = (value, state) =\u003e {\n  return value !== '\\\\' \u0026\u0026 (value !== '\"' || state.prev() === '\\\\');\n};\nconsole.log(split('a.b.\\\\\"c.d.\"e.f.g\".h.i', { quotes: ['\"'], keep }));\n//=\u003e [ 'a', 'b', '\"c', 'd', 'e.f.g', 'h', 'i' ]\n```\n\n## Options\n\n### options.brackets\n\n**Type**: `Object|Boolean`\n\n**Default**: `{}`\n\n**Description**\n\nBy default, no special significance is given to bracket-like characters (such as square brackets, curly braces, angle brackets, and so on).\n\n```js\n// default behavior\nconsole.log(split('a.{b.c}.{d.e}'));\n//=\u003e [ 'a', '{b', 'c}', '{d', 'e}' ]\n```\n\nWhen `options.brackets` is `true`, the following brackets types are supported:\n\n```js\n{\n  '\u003c': '\u003e',\n  '(': ')',\n  '[': ']',\n  '{': '}'\n}\n```\n\nFor example:\n\n```js\nconsole.log(split('a.{b.c}.{d.e}', { brackets: true }));\n//=\u003e [ 'a', '{b.c}', '{d.e}' ]\n```\n\nAlternatively, an object of brackets may be passed, where each key is the _opening bracket_ and each value is the corresponding _closing bracket_. Note that the key and value **must be different characters**. If you want to use the same character for both open and close, use the [quotes option](#optionsquotes).\n\n**Examples**\n\n```js\n// no bracket support by default\nconsole.log(split('a.{b.c}.[d.e].f'));\n//=\u003e [ 'a', '{b', 'c}', '[d', 'e]', 'f' ]\n\n// tell split-string not to split inside curly braces\nconsole.log(split('a.{b.c}.[d.e].f', { brackets: { '{': '}' }}));\n//=\u003e [ 'a', '{b.c}', '[d', 'e]', 'f' ]\n\n// tell split-string not to split inside any of these types: \"\u003c\u003e{}[]()\"\nconsole.log(split('a.{b.c}.[d.e].f', { brackets: true }));\n//=\u003e [ 'a', '{b.c}', '[d.e]', 'f' ]\n\n// ...nested brackets are also supported\nconsole.log(split('a.{b.{c.d}.e}.f', { brackets: true }));\n//=\u003e [ 'a', '{b.{c.d}.e}', 'f' ]\n\n// tell split-string not to split inside the given custom types\nconsole.log(split('«a.b».⟨c.d⟩.[e.f]', { brackets: { '«': '»', '⟨': '⟩' } }));\n//=\u003e [ '«a.b»', '⟨c.d⟩', '[e', 'f]' ]\n```\n\n### options.keep\n\n**Type**: `function`\n\n**Default**: Function that returns true if the character is not `\\\\`.\n\nFunction that returns true when a character should be retained in the result.\n\n**Example**\n\n```js\nconsole.log(split('a.b\\\\.c')); //=\u003e ['a', 'b.c']\n\n// keep all characters\nconsole.log(split('a.b.\\\\c', { keep: () =\u003e true })); //=\u003e ['a', 'b\\.c']\n```\n\n### options.separator\n\n**Type**: `string`\n\n**Default**: `.`\n\nThe character to split on.\n\n**Example**\n\n```js\nconsole.log(split('a.b,c', { separator: ',' })); //=\u003e ['a.b', 'c']\n```\n\n## Split function\n\nOptionally pass a function as the last argument to tell split-string whether or not to split when the specified separator is encountered.\n\n**Example**\n\n```js\n// only split on \".\" when the \"previous\" character is \"a\"\nconsole.log(split('a.b.c.a.d.e', state =\u003e state.prev() === 'a'));\n//=\u003e [ 'a', 'b.c.a', 'd.e' ]\n```\n\nThe `state` object exposes the following properties:\n\n* `input` - (String) The un-modified, user-defined input string\n* `separator` - (String) the specified separator to split on.\n* `index` - (Number) The current cursor position\n* `value` - (String) The character at the current index\n* `bos` - (Function) Returns true if position is at the beginning-of-string\n* `eos` - (Function) Returns true if position is at the end-of-string\n* `prev` - (Function) Returns the previously scanned character\n* `next` - (Function) Returns the next character after the current position\n* `block` - (Object) The \"current\" AST node.\n* `stack` - (Array) AST nodes\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [deromanize](https://www.npmjs.com/package/deromanize): Convert roman numerals to arabic numbers (useful for books, outlines, documentation, slide decks, etc) | [homepage](https://github.com/jonschlinkert/deromanize \"Convert roman numerals to arabic numbers (useful for books, outlines, documentation, slide decks, etc)\")\n* [randomatic](https://www.npmjs.com/package/randomatic): Generate randomized strings of a specified length using simple character sequences. The original generate-password. | [homepage](https://github.com/jonschlinkert/randomatic \"Generate randomized strings of a specified length using simple character sequences. The original generate-password.\")\n* [repeat-string](https://www.npmjs.com/package/repeat-string): Repeat the given string n times. Fastest implementation for repeating a string. | [homepage](https://github.com/jonschlinkert/repeat-string \"Repeat the given string n times. Fastest implementation for repeating a string.\")\n* [romanize](https://www.npmjs.com/package/romanize): Convert numbers to roman numerals (useful for books, outlines, documentation, slide decks, etc) | [homepage](https://github.com/jonschlinkert/romanize \"Convert numbers to roman numerals (useful for books, outlines, documentation, slide decks, etc)\")\n\n### Contributors\n\n| **Commits** | **Contributor** |  \n| --- | --- |  \n| 56 | [jonschlinkert](https://github.com/jonschlinkert) |  \n| 12 | [doowb](https://github.com/doowb) |  \n| 6  | [Ovyerus](https://github.com/Ovyerus) |  \n| 1  | [silverwind](https://github.com/silverwind) |  \n\n### Author\n\n**Jon Schlinkert**\n\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\n### License\n\nCopyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 22, 2019._","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fsplit-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fsplit-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fsplit-string/lists"}