What is split-string?
The split-string npm package is used to split strings on a specified separator while respecting nested structures such as quotes, brackets, and parentheses. It provides a way to parse complex strings with multiple levels of nested delimiters.
What are split-string's main functionalities?
Basic string splitting
Splits a string into an array of substrings using the specified separator.
"a.b.c".split('.')
Splitting with escaped characters
Splits a string on a separator while allowing escaped characters to be included in the results.
splitString('a\.b.c', { separator: '.' })
Splitting with brackets
Splits a string on a separator while respecting nested brackets, keeping them as part of the split segments.
splitString('a.{b.c}.d', { brackets: true })
Customizing separators and brackets
Allows customization of separators and bracket pairs for more complex string splitting scenarios.
splitString('a.{b.c}.d', { separators: ['.', ' '], brackets: { '{': '}' } })
Other packages similar to split-string
string-split
This package offers similar functionality to split-string, allowing strings to be split into arrays of substrings. It does not, however, provide the same level of support for nested structures or escaped characters.
split
Split is another package that can turn a stream of text into a stream of lines. It's more focused on Node.js streams rather than simple string splitting and doesn't handle nested delimiters.
strsplit
Strsplit is a simple utility for splitting strings but lacks the advanced features of split-string, such as handling nested delimiters and escaped characters.
split-string
Split a string on a character except when the character is escaped.
Install
Install with npm
$ npm i split-string --save
Usage
var split = require('split-string');
split('a.b.c');
respects escaped characters
split('a.b.c\\.d');
Related projects
- deromanize: Convert roman numerals to arabic numbers (useful for books, outlines, documentation, slide decks, etc) | homepage
- randomatic: Generate randomized strings of a specified length, fast. Only the length is necessary, but you… more | homepage
- repeat-string: Repeat the given string n times. Fastest implementation for repeating a string. | homepage
- romanize: Convert numbers to roman numerals (useful for books, outlines, documentation, slide decks, etc) | homepage
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Jon Schlinkert
License
Copyright © 2015 Jon Schlinkert
Released under the MIT license.
This file was generated by verb-cli on August 27, 2015.