https://github.com/dy/string-split-by
Split a string on a given character or characters, with support for escaping.
https://github.com/dy/string-split-by
Last synced: 5 months ago
JSON representation
Split a string on a given character or characters, with support for escaping.
- Host: GitHub
- URL: https://github.com/dy/string-split-by
- Owner: dy
- Fork: true (jonschlinkert/split-string)
- Created: 2018-05-28T03:11:40.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-28T20:11:40.000Z (about 8 years ago)
- Last Synced: 2025-10-22T16:22:59.231Z (8 months ago)
- Language: JavaScript
- Size: 59.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# string-split-by [](http://github.com/badges/stability-badges) [](https://travis-ci.org/dy/string-split-by)
Split string by a separator with respect to brackets, quotes and escape markers. Optimized version of [string-split](https://github.com/jonschlinkert/split-string).
## Usage
[](https://npmjs.org/package/string-split-by/)
```js
var split = require('string-split-by')
split('a."b.c".d.{.e.f.g.}.h', '.')
// ['a', '"b.c"', 'd', '{.e.f.g.}', 'h']
split('a."b.c".d.{.e.f.g.}.h', '.', {ignore: '""'})
// ['a', '"b.c"', 'd', '{', 'e', 'f', 'g', '}', 'h']
```
## API
### parts = splitBy(string, separator, options?)
Return array with parts split from string by a separator, which can be whether _String_ or _RegExp_. Options can define:
Option | Default | Meaning
---|---|---
`ignore` | ``['"', "'", '`', '“”', '«»', '[]', '()', '{}']`` | Avoid splitting content enclosed in the character pairs. Can be a string or a list of strings.
`escape` | `true` | Avoid splitting at the escaped separator, eg. `\.` won't be separated by `'.'` separator.
## Related
* [parenthesis](http://npmjs.org/package/parenthesis)
## License
© 2018 Dmitry Yv. MIT License