pax_global_header00006660000000000000000000000064134574440220014517gustar00rootroot0000000000000052 comment=757bdcb3bd110e8dfb55ae35d2856b6875692aad split-string-6.1.0/000077500000000000000000000000001345744402200141625ustar00rootroot00000000000000split-string-6.1.0/.editorconfig000066400000000000000000000004411345744402200166360ustar00rootroot00000000000000# http://editorconfig.org/ root = true [*] charset = utf-8 end_of_line = lf indent_size = 2 indent_style = space insert_final_newline = true trim_trailing_whitespace = true [{**/{actual,fixtures,expected,templates}/**,*.md}] trim_trailing_whitespace = false insert_final_newline = false split-string-6.1.0/.eslintrc.json000066400000000000000000000073251345744402200167650ustar00rootroot00000000000000{ "extends": [ "eslint:recommended" ], "env": { "browser": false, "es6": true, "node": true, "mocha": true }, "parserOptions":{ "ecmaVersion": 9, "sourceType": "module", "ecmaFeatures": { "modules": true, "experimentalObjectRestSpread": true } }, "globals": { "document": false, "navigator": false, "window": false }, "rules": { "accessor-pairs": 2, "arrow-spacing": [2, { "before": true, "after": true }], "block-spacing": [2, "always"], "brace-style": [2, "1tbs", { "allowSingleLine": true }], "comma-dangle": [2, "never"], "comma-spacing": [2, { "before": false, "after": true }], "comma-style": [2, "last"], "constructor-super": 2, "curly": [2, "multi-line"], "dot-location": [2, "property"], "eol-last": 2, "eqeqeq": [2, "allow-null"], "generator-star-spacing": [2, { "before": true, "after": true }], "handle-callback-err": [2, "^(err|error)$" ], "indent": [2, 2, { "SwitchCase": 1 }], "key-spacing": [2, { "beforeColon": false, "afterColon": true }], "keyword-spacing": [2, { "before": true, "after": true }], "new-cap": [2, { "newIsCap": true, "capIsNew": false }], "new-parens": 2, "no-array-constructor": 2, "no-caller": 2, "no-class-assign": 2, "no-cond-assign": 2, "no-const-assign": 2, "no-control-regex": 2, "no-debugger": 2, "no-delete-var": 2, "no-dupe-args": 2, "no-dupe-class-members": 2, "no-dupe-keys": 2, "no-duplicate-case": 2, "no-empty-character-class": 2, "no-eval": 2, "no-ex-assign": 2, "no-extend-native": 2, "no-extra-bind": 2, "no-extra-boolean-cast": 2, "no-extra-parens": [2, "functions"], "no-fallthrough": 2, "no-floating-decimal": 2, "no-func-assign": 2, "no-implied-eval": 2, "no-inner-declarations": [2, "functions"], "no-invalid-regexp": 2, "no-irregular-whitespace": 2, "no-iterator": 2, "no-label-var": 2, "no-labels": 2, "no-lone-blocks": 2, "no-mixed-spaces-and-tabs": 2, "no-multi-spaces": 2, "no-multi-str": 2, "no-multiple-empty-lines": [2, { "max": 1 }], "no-native-reassign": 0, "no-negated-in-lhs": 2, "no-new": 2, "no-new-func": 2, "no-new-object": 2, "no-new-require": 2, "no-new-wrappers": 2, "no-obj-calls": 2, "no-octal": 2, "no-octal-escape": 2, "no-proto": 0, "no-redeclare": 2, "no-regex-spaces": 2, "no-return-assign": 2, "no-self-compare": 2, "no-sequences": 2, "no-shadow-restricted-names": 2, "no-spaced-func": 2, "no-sparse-arrays": 2, "no-this-before-super": 2, "no-throw-literal": 2, "no-trailing-spaces": 0, "no-undef": 2, "no-undef-init": 2, "no-unexpected-multiline": 2, "no-unneeded-ternary": [2, { "defaultAssignment": false }], "no-unreachable": 2, "no-unused-vars": [2, { "vars": "all", "args": "none" }], "no-useless-call": 0, "no-with": 2, "one-var": [0, { "initialized": "never" }], "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], "padded-blocks": [0, "never"], "quotes": [2, "single", "avoid-escape"], "radix": 2, "semi": [2, "always"], "semi-spacing": [2, { "before": false, "after": true }], "space-before-blocks": [2, "always"], "space-before-function-paren": [2, "never"], "space-in-parens": [2, "never"], "space-infix-ops": 2, "space-unary-ops": [2, { "words": true, "nonwords": false }], "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], "use-isnan": 2, "valid-typeof": 2, "wrap-iife": [2, "any"], "yoda": [2, "never"] } } split-string-6.1.0/.gitattributes000066400000000000000000000002001345744402200170450ustar00rootroot00000000000000# Enforce Unix newlines * text eol=lf # binaries *.ai binary *.psd binary *.jpg binary *.gif binary *.png binary *.jpeg binary split-string-6.1.0/.gitignore000066400000000000000000000004561345744402200161570ustar00rootroot00000000000000# always ignore files *.DS_Store .idea .vscode *.sublime-* # test related, or directories generated by tests test/actual actual coverage .nyc* # npm node_modules npm-debug.log # yarn yarn.lock yarn-error.log # misc _gh_pages _draft _drafts bower_components vendor temp tmp TODO.md package-lock.jsonsplit-string-6.1.0/.npmrc000066400000000000000000000000231345744402200152750ustar00rootroot00000000000000package-lock=false split-string-6.1.0/.travis.yml000066400000000000000000000002151345744402200162710ustar00rootroot00000000000000sudo: false os: - linux - osx language: node_js node_js: - node - '8.6' - '10' - '9' script: - npm test - npm run test:types split-string-6.1.0/.verb.md000066400000000000000000000106131345744402200155210ustar00rootroot00000000000000## Usage ```js const split = require('{%= name %}'); console.log(split('a.b.c')); //=> ['a', 'b', 'c'] // respects escaped characters console.log(split('a.b.c\\.d')); //=> ['a', 'b', 'c.d'] // respects double-quoted strings console.log(split('a."b.c.d".e')); //=> ['a', '"b.c.d"', 'e'] ``` ## Options ### options.quotes **Type**: `Array|Boolean` **Default**: `[]` **Description** Tell 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. ```js // default behavior console.log(split('a.b."c.d.e.f.g".h.i')); //=> [ 'a', 'b', '"c', 'd', 'e', 'f', 'g"', 'h', 'i' ] // with quotes console.log(split('a.b."c.d.e.f.g".h.i', { quotes: ['"'] })); //=> [ 'a', 'b', '"c.d.e.f.g"', 'h', 'i' ] // escaped quotes will be ignored console.log(split('a.b.\\"c.d."e.f.g".h.i', { quotes: ['"'] })); //=> [ 'a', 'b', '"c', 'd', '"e.f.g"', 'h', 'i' ] // example of how to exclude non-escaped quotes from the result let keep = (value, state) => { return value !== '\\' && (value !== '"' || state.prev() === '\\'); }; console.log(split('a.b.\\"c.d."e.f.g".h.i', { quotes: ['"'], keep })); //=> [ 'a', 'b', '"c', 'd', 'e.f.g', 'h', 'i' ] ``` ## Options ### options.brackets **Type**: `Object|Boolean` **Default**: `{}` **Description** By default, no special significance is given to bracket-like characters (such as square brackets, curly braces, angle brackets, and so on). ```js // default behavior console.log(split('a.{b.c}.{d.e}')); //=> [ 'a', '{b', 'c}', '{d', 'e}' ] ``` When `options.brackets` is `true`, the following brackets types are supported: ```js { '<': '>', '(': ')', '[': ']', '{': '}' } ``` For example: ```js console.log(split('a.{b.c}.{d.e}', { brackets: true })); //=> [ 'a', '{b.c}', '{d.e}' ] ``` Alternatively, 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). **Examples** ```js // no bracket support by default console.log(split('a.{b.c}.[d.e].f')); //=> [ 'a', '{b', 'c}', '[d', 'e]', 'f' ] // tell split-string not to split inside curly braces console.log(split('a.{b.c}.[d.e].f', { brackets: { '{': '}' }})); //=> [ 'a', '{b.c}', '[d', 'e]', 'f' ] // tell split-string not to split inside any of these types: "<>{}[]()" console.log(split('a.{b.c}.[d.e].f', { brackets: true })); //=> [ 'a', '{b.c}', '[d.e]', 'f' ] // ...nested brackets are also supported console.log(split('a.{b.{c.d}.e}.f', { brackets: true })); //=> [ 'a', '{b.{c.d}.e}', 'f' ] // tell split-string not to split inside the given custom types console.log(split('«a.b».⟨c.d⟩.[e.f]', { brackets: { '«': '»', '⟨': '⟩' } })); //=> [ '«a.b»', '⟨c.d⟩', '[e', 'f]' ] ``` ### options.keep **Type**: `function` **Default**: Function that returns true if the character is not `\\`. Function that returns true when a character should be retained in the result. **Example** ```js console.log(split('a.b\\.c')); //=> ['a', 'b.c'] // keep all characters console.log(split('a.b.\\c', { keep: () => true })); //=> ['a', 'b\.c'] ``` ### options.separator **Type**: `string` **Default**: `.` The character to split on. **Example** ```js console.log(split('a.b,c', { separator: ',' })); //=> ['a.b', 'c'] ``` ## Split function Optionally pass a function as the last argument to tell split-string whether or not to split when the specified separator is encountered. **Example** ```js // only split on "." when the "previous" character is "a" console.log(split('a.b.c.a.d.e', state => state.prev() === 'a')); //=> [ 'a', 'b.c.a', 'd.e' ] ``` The `state` object exposes the following properties: - `input` - (String) The un-modified, user-defined input string - `separator` - (String) the specified separator to split on. - `index` - (Number) The current cursor position - `value` - (String) The character at the current index - `bos` - (Function) Returns true if position is at the beginning-of-string - `eos` - (Function) Returns true if position is at the end-of-string - `prev` - (Function) Returns the previously scanned character - `next` - (Function) Returns the next character after the current position - `block` - (Object) The "current" AST node. - `stack` - (Array) AST nodes split-string-6.1.0/CHANGELOG.md000066400000000000000000000076451345744402200160070ustar00rootroot00000000000000# Release history All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
Guiding Principles - Changelogs are for humans, not machines. - There should be an entry for every single version. - The same types of changes should be grouped. - Versions and sections should be linkable. - The latest version comes first. - The release date of each versions is displayed. - Mention whether you follow Semantic Versioning.
Types of changes Changelog entries are classified using the following labels _(from [keep-a-changelog](http://keepachangelog.com/)_): - `Added` for new features. - `Changed` for changes in existing functionality. - `Deprecated` for soon-to-be removed features. - `Removed` for now removed features. - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities.
## [6.1.0] - 2019-04-22 **Added** - Add TypeScript definitions and tests. ## [6.0.0] - 2018-08-14 - Refactor to use faster scanner **Removed** The following options were all removed: - `options.split` - support for the `split` option was removed, but you may still pass a custom function for this as the last argument. - `options.keepQuotes` - `options.keepSmartQuotes` - `options.keepDoubleQuotes` - `options.keepSingleQuotes` - `options.keepBackticks` **Added** - `options.keep` - function for determining whether or not to keep a character. ## [5.0.1] - 2018-01-08 - update engine versions ## [5.0.0] - 2018-01-08 - tweak quotes handling - refactor to use snapdragon-lexer - Merge pull request #5 from jonschlinkert/refactor ## [4.0.0] - 2017-11-22 - allow options.quotes to be an object - Merge pull request #4 from jonschlinkert/quotes-object ## [3.1.0] - 2017-11-19 - support `keepEscaping` as a function - run `lint-deps` to upgrade deps ## [3.0.2] - 2017-06-21 - fix examples ## [3.0.1] - 2017-06-15 - fix examples - remove unnecessary brackets ## [3.0.0] - 2017-06-15 - support brackets - support nested brackets - update release history, run verb ## [2.1.1] - 2017-05-30 - call custom function on escaped tokens ## [2.1.0] - 2017-04-27 - support backticks - update docs ## [2.0.0] - 2017-04-11 - example callback - adds support for a sync callback - update docs, run verb ## [1.0.1] - 2017-04-11 - fix error message for unclosed quote - allow disabling strict closing of quotes - add tests for errors and strict option - Merge pull request #2 from jonschlinkert/strict - add documentation on options.strict ## [1.0.0] - 2017-02-21 - refactor - update docs, run `verb` ## [0.1.1] - 2015-08-27 - first commit - only use 1 nonchar instead of entire array - Merge pull request #1 from doowb/master [5.0.1]: https://github.com/jonschlinkert/split-string/compare/5.0.0...5.0.1 [5.0.0]: https://github.com/jonschlinkert/split-string/compare/4.0.0...5.0.0 [4.0.0]: https://github.com/jonschlinkert/split-string/compare/3.1.0...4.0.0 [3.1.0]: https://github.com/jonschlinkert/split-string/compare/3.0.2...3.1.0 [3.0.2]: https://github.com/jonschlinkert/split-string/compare/3.0.1...3.0.2 [3.0.1]: https://github.com/jonschlinkert/split-string/compare/3.0.0...3.0.1 [3.0.0]: https://github.com/jonschlinkert/split-string/compare/2.1.1...3.0.0 [2.1.1]: https://github.com/jonschlinkert/split-string/compare/2.1.0...2.1.1 [2.1.0]: https://github.com/jonschlinkert/split-string/compare/2.0.0...2.1.0 [2.0.0]: https://github.com/jonschlinkert/split-string/compare/1.0.1...2.0.0 [1.0.1]: https://github.com/jonschlinkert/split-string/compare/1.0.0...1.0.1 [1.0.0]: https://github.com/jonschlinkert/split-string/compare/0.1.1...1.0.0 [Unreleased]: https://github.com/jonschlinkert/split-string/compare/0.1.1...HEAD [keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelogsplit-string-6.1.0/LICENSE000066400000000000000000000021031345744402200151630ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015-present, Jon Schlinkert. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. split-string-6.1.0/README.md000066400000000000000000000202631345744402200154440ustar00rootroot00000000000000# 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&label=Travis)](https://travis-ci.org/jonschlinkert/split-string) > Easy way to split a string on a given character unless it's quoted or escaped. Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. ## Install Install with [npm](https://www.npmjs.com/): ```sh $ npm install --save split-string ``` ## Usage ```js const split = require('split-string'); console.log(split('a.b.c')); //=> ['a', 'b', 'c'] // respects escaped characters console.log(split('a.b.c\\.d')); //=> ['a', 'b', 'c.d'] // respects double-quoted strings console.log(split('a."b.c.d".e')); //=> ['a', '"b.c.d"', 'e'] ``` ## Options ### options.quotes **Type**: `Array|Boolean` **Default**: `[]` **Description** Tell 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. ```js // default behavior console.log(split('a.b."c.d.e.f.g".h.i')); //=> [ 'a', 'b', '"c', 'd', 'e', 'f', 'g"', 'h', 'i' ] // with quotes console.log(split('a.b."c.d.e.f.g".h.i', { quotes: ['"'] })); //=> [ 'a', 'b', '"c.d.e.f.g"', 'h', 'i' ] // escaped quotes will be ignored console.log(split('a.b.\\"c.d."e.f.g".h.i', { quotes: ['"'] })); //=> [ 'a', 'b', '"c', 'd', '"e.f.g"', 'h', 'i' ] // example of how to exclude non-escaped quotes from the result let keep = (value, state) => { return value !== '\\' && (value !== '"' || state.prev() === '\\'); }; console.log(split('a.b.\\"c.d."e.f.g".h.i', { quotes: ['"'], keep })); //=> [ 'a', 'b', '"c', 'd', 'e.f.g', 'h', 'i' ] ``` ## Options ### options.brackets **Type**: `Object|Boolean` **Default**: `{}` **Description** By default, no special significance is given to bracket-like characters (such as square brackets, curly braces, angle brackets, and so on). ```js // default behavior console.log(split('a.{b.c}.{d.e}')); //=> [ 'a', '{b', 'c}', '{d', 'e}' ] ``` When `options.brackets` is `true`, the following brackets types are supported: ```js { '<': '>', '(': ')', '[': ']', '{': '}' } ``` For example: ```js console.log(split('a.{b.c}.{d.e}', { brackets: true })); //=> [ 'a', '{b.c}', '{d.e}' ] ``` Alternatively, 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). **Examples** ```js // no bracket support by default console.log(split('a.{b.c}.[d.e].f')); //=> [ 'a', '{b', 'c}', '[d', 'e]', 'f' ] // tell split-string not to split inside curly braces console.log(split('a.{b.c}.[d.e].f', { brackets: { '{': '}' }})); //=> [ 'a', '{b.c}', '[d', 'e]', 'f' ] // tell split-string not to split inside any of these types: "<>{}[]()" console.log(split('a.{b.c}.[d.e].f', { brackets: true })); //=> [ 'a', '{b.c}', '[d.e]', 'f' ] // ...nested brackets are also supported console.log(split('a.{b.{c.d}.e}.f', { brackets: true })); //=> [ 'a', '{b.{c.d}.e}', 'f' ] // tell split-string not to split inside the given custom types console.log(split('«a.b».⟨c.d⟩.[e.f]', { brackets: { '«': '»', '⟨': '⟩' } })); //=> [ '«a.b»', '⟨c.d⟩', '[e', 'f]' ] ``` ### options.keep **Type**: `function` **Default**: Function that returns true if the character is not `\\`. Function that returns true when a character should be retained in the result. **Example** ```js console.log(split('a.b\\.c')); //=> ['a', 'b.c'] // keep all characters console.log(split('a.b.\\c', { keep: () => true })); //=> ['a', 'b\.c'] ``` ### options.separator **Type**: `string` **Default**: `.` The character to split on. **Example** ```js console.log(split('a.b,c', { separator: ',' })); //=> ['a.b', 'c'] ``` ## Split function Optionally pass a function as the last argument to tell split-string whether or not to split when the specified separator is encountered. **Example** ```js // only split on "." when the "previous" character is "a" console.log(split('a.b.c.a.d.e', state => state.prev() === 'a')); //=> [ 'a', 'b.c.a', 'd.e' ] ``` The `state` object exposes the following properties: * `input` - (String) The un-modified, user-defined input string * `separator` - (String) the specified separator to split on. * `index` - (Number) The current cursor position * `value` - (String) The character at the current index * `bos` - (Function) Returns true if position is at the beginning-of-string * `eos` - (Function) Returns true if position is at the end-of-string * `prev` - (Function) Returns the previously scanned character * `next` - (Function) Returns the next character after the current position * `block` - (Object) The "current" AST node. * `stack` - (Array) AST nodes ## About
Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Running Tests Running 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: ```sh $ npm install && npm test ```
Building docs _(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.)_ To generate the readme, run the following command: ```sh $ npm install -g verbose/verb#dev verb-generate-readme && verb ```
### Related projects You might also be interested in these projects: * [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)") * [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.") * [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.") * [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)") ### Contributors | **Commits** | **Contributor** | | --- | --- | | 56 | [jonschlinkert](https://github.com/jonschlinkert) | | 12 | [doowb](https://github.com/doowb) | | 6 | [Ovyerus](https://github.com/Ovyerus) | | 1 | [silverwind](https://github.com/silverwind) | ### Author **Jon Schlinkert** * [GitHub Profile](https://github.com/jonschlinkert) * [Twitter Profile](https://twitter.com/jonschlinkert) * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) ### License Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert). Released under the [MIT License](LICENSE). *** _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 22, 2019._split-string-6.1.0/example.js000066400000000000000000000036011345744402200161530ustar00rootroot00000000000000const split = require('./'); console.log(split('a.b."c.d.e.f.g".h.i', { quotes: ['"'] })); //=> [ 'a', 'b', '"c.d.e.f.g"', 'h', 'i' ] console.log(split('a.b."c.d.e.f.g".h.i')); //=> [ 'a', 'b', '"c.d.e.f.g"', 'h', 'i' ] console.log(split('a.b.\\"c.d."e.f.g".h.i', { quotes: ['"']})); //=> [ 'a', 'b', '"c.d.e.f.g"', 'h', 'i' ] let keep = (value, state) => { return value !== '\\' && (value !== '"' || state.prev() === '\\'); }; console.log(split('a.b.\\"c.d."e.f.g".h.i', { quotes: ['"'], keep })); //=> [ 'a', 'b', '"c', 'd', 'e.f.g', 'h', 'i' ] // console.log(split('a.[{a.b}].e', { brackets: { '[': ']' } })); // console.log(split('a.[a.c.{d.e}].b', { brackets: { '[': ']' } })); // console.log(split('a\\.[a.c.{d.e}].b', { brackets: { '[': ']' } })); // console.log(split('...a.[a.c.{d.e}].b.s.s.s.s.s.', { brackets: { '[': ']' } })); //=> [ 'a', '{a', '[{b.c}]', 'd}', 'e' ] // console.log(split('a.{b.c}.[d.e].f', { brackets: true })); // //=> [ 'a', '{b.c}', '[d', 'e]', 'f' ] // console.log(split('«a.b».⟨c.d⟩.[e.f]', { brackets: { '«': '»', '⟨': '⟩' } })); // //=> [ '«a.b»', '⟨c.d⟩' ] // const arr = split('a.b.c.a.d.e', state => { // console.log(state) // return state.prev() === 'a'; // }); // console.log(arr) // // => [ 'a', 'b.c.a', 'd.e' ] // console.log(split('a.{a.{b.c.d}.c}', { brackets: true })); // //=> [ 'a', '{a.{b.c.d}.c}' ] // const stash1 = split('a.b.c', state => state.prev() !== 'a'); // console.log(stash1); // //=> ['a.b', 'c'] // console.log(split('zzz.{a.{b.{c.{d}.e}.f}.g}.xxx')); // console.log(split('a.{b.c}|{d.e}', { separator: '|' })); // console.log(split('a.{b.c}|{d.e}')); // console.log(split('a.{b.c}.{d.e}')); // console.log(split('a.{b.c}.{d.e}', { brackets: false })); // console.log(split('a.{b.c}\\.{d.e}')); // console.log(split('a.{b.c.[a-b]}.{d.e}')); // console.log(split('a."a.b.c"\\.{d.e}', { quotes: ['"'], keep: () => true })); split-string-6.1.0/index.js000066400000000000000000000073041345744402200156330ustar00rootroot00000000000000'use strict'; module.exports = (input, options = {}, fn) => { if (typeof input !== 'string') throw new TypeError('expected a string'); if (typeof options === 'function') { fn = options; options = {}; } let separator = options.separator || '.'; let ast = { type: 'root', nodes: [], stash: [''] }; let stack = [ast]; let state = { input, separator, stack }; let string = input; let value, node; let i = -1; state.bos = () => i === 0; state.eos = () => i === string.length; state.prev = () => string[i - 1]; state.next = () => string[i + 1]; let quotes = options.quotes || []; let openers = options.brackets || {}; if (options.brackets === true) { openers = { '[': ']', '(': ')', '{': '}', '<': '>' }; } if (options.quotes === true) { quotes = ['"', '\'', '`']; } let closers = invert(openers); let keep = options.keep || (value => value !== '\\'); const block = () => (state.block = stack[stack.length - 1]); const peek = () => string[i + 1]; const next = () => string[++i]; const append = value => { state.value = value; if (value && keep(value, state) !== false) { state.block.stash[state.block.stash.length - 1] += value; } }; const closeIndex = (value, startIdx) => { let idx = string.indexOf(value, startIdx); if (idx > -1 && string[idx - 1] === '\\') { idx = closeIndex(value, idx + 1); } return idx; }; for (; i < string.length - 1;) { state.value = value = next(); state.index = i; block(); // handle escaped characters if (value === '\\') { if (peek() === '\\') { append(value + next()); } else { // if the next char is not '\\', allow the "append" function // to determine if the backslashes should be added append(value); append(next()); } continue; } // handle quoted strings if (quotes.includes(value)) { let pos = i + 1; let idx = closeIndex(value, pos); if (idx > -1) { append(value); // append opening quote append(string.slice(pos, idx)); // append quoted string append(string[idx]); // append closing quote i = idx; continue; } append(value); continue; } // handle opening brackets, if not disabled if (options.brackets !== false && openers[value]) { node = { type: 'bracket', nodes: [] }; node.stash = keep(value) !== false ? [value] : ['']; node.parent = state.block; state.block.nodes.push(node); stack.push(node); continue; } // handle closing brackets, if not disabled if (options.brackets !== false && closers[value]) { if (stack.length === 1) { append(value); continue; } append(value); node = stack.pop(); block(); append(node.stash.join('')); continue; } // push separator onto stash if (value === separator && state.block.type === 'root') { if (typeof fn === 'function' && fn(state) === false) { append(value); continue; } state.block.stash.push(''); continue; } // append value onto the last string on the stash append(value); } node = stack.pop(); while (node !== ast) { if (options.strict === true) { let column = i - node.stash.length + 1; throw new SyntaxError(`Unmatched: "${node.stash[0]}", at column ${column}`); } value = (node.parent.stash.pop() + node.stash.join('.')); node.parent.stash = node.parent.stash.concat(value.split('.')); node = stack.pop(); } return node.stash; }; function invert(obj) { let inverted = {}; for (const key of Object.keys(obj)) inverted[obj[key]] = key; return inverted; } split-string-6.1.0/package.json000066400000000000000000000026711345744402200164560ustar00rootroot00000000000000{ "name": "split-string", "description": "Easy way to split a string on a given character unless it's quoted or escaped.", "version": "6.1.0", "homepage": "https://github.com/jonschlinkert/split-string", "author": "Jon Schlinkert (https://github.com/jonschlinkert)", "contributors": [ "Brian Woodward (https://twitter.com/doowb)", "Jon Schlinkert (http://twitter.com/jonschlinkert)" ], "repository": "jonschlinkert/split-string", "bugs": { "url": "https://github.com/jonschlinkert/split-string/issues" }, "license": "MIT", "files": [ "index.js", "types/index.d.ts" ], "main": "index.js", "types": "types/index.d.ts", "engines": { "node": ">=8.6" }, "scripts": { "test": "nyc mocha", "test:types": "dtslint types" }, "devDependencies": { "dtslint": "^0.7.0", "gulp-format-md": "^1.0.0", "mocha": "^5.2.0", "nyc": "^12.0.2" }, "keywords": [ "character", "escape", "split", "string" ], "nyc": { "reporter": [ "lcov", "text-summary" ] }, "verb": { "toc": false, "layout": "default", "titles": [ ".", "install", "Why use this?" ], "related": { "list": [ "deromanize", "randomatic", "repeat-string", "romanize" ] }, "tasks": [ "readme" ], "plugins": [ "gulp-format-md" ], "lint": { "reflinks": true } } } split-string-6.1.0/test/000077500000000000000000000000001345744402200151415ustar00rootroot00000000000000split-string-6.1.0/test/options.brackets.js000066400000000000000000000040411345744402200207660ustar00rootroot00000000000000'use strict'; require('mocha'); const assert = require('assert'); const split = require('..'); describe('options.brackets', () => { it('should throw when brackets are unclosed', () => { assert.throws(() => split('a.{a.{b.c.}.c', { brackets: true, strict: true }), /Unmatched/); }); it('should not split inside brackets', () => { let opts = { brackets: true }; assert.deepEqual(split('a.(b.c).d', opts), ['a', '(b.c)', 'd']); assert.deepEqual(split('a.[(b.c)].d', opts), ['a', '[(b.c)]', 'd']); assert.deepEqual(split('a.[b.c].d', opts), ['a', '[b.c]', 'd']); assert.deepEqual(split('a.{b.c}.d', opts), ['a', '{b.c}', 'd']); assert.deepEqual(split('a..d', opts), ['a', '', 'd']); }); it('should support nested brackets', () => { let opts = { brackets: true }; assert.deepEqual(split('a.{b.{c}.d}.e', opts), ['a', '{b.{c}.d}', 'e']); assert.deepEqual(split('a.{b.{c.d}.e}.f', opts), ['a', '{b.{c.d}.e}', 'f']); assert.deepEqual(split('a.{[b.{{c.d}}.e]}.f', opts), ['a', '{[b.{{c.d}}.e]}', 'f']); }); it('should support escaped brackets', () => { let opts = { brackets: true }; assert.deepEqual(split('a.\\{b.{c.c}.d}.e', opts), ['a', '{b', '{c.c}', 'd}', 'e']); assert.deepEqual(split('a.{b.c}.\\{d.e}.f', opts), ['a', '{b.c}', '{d', 'e}', 'f']); }); it('should support quoted brackets', () => { let opts = { brackets: true }; assert.deepEqual(split('a.{b.c}."{d.e}".f', opts), ['a', '{b.c}', '"{d.e}"', 'f']); assert.deepEqual(split('a.{b.c}.{"d.e"}.f', opts), ['a', '{b.c}', '{"d.e"}', 'f']); }); it('should ignore imbalanced brackets', () => { let opts = { brackets: true }; assert.deepEqual(split('a.{b.c}.{d.e', opts), ['a', '{b.c}', '{d', 'e']); assert.deepEqual(split('a.{b.c.{e.f}}.{g', opts), ['a', '{b.c.{e.f}}', '{g']); assert.deepEqual(split('a.{b.c', opts), ['a', '{b', 'c']); assert.deepEqual(split('a.{a.{b.c}.d', opts), ['a', '{a', '{b', 'c}', 'd']); assert.deepEqual(split('a.{a.{b.c.d', opts), ['a', '{a', '{b', 'c', 'd']); }); }); split-string-6.1.0/test/options.keep.js000066400000000000000000000010261345744402200201140ustar00rootroot00000000000000'use strict'; require('mocha'); const assert = require('assert'); const split = require('..'); describe('keep', () => { it('should keep all characters', () => { assert.deepEqual(split('a.b\\.c', { keep: () => true }), ['a', 'b\\.c']); }); it('should not keep backslashes', () => { assert.deepEqual(split('a.b\\.c', { keep: val => val !== '\\' }), ['a', 'b.c']); }); it('should not keep quotes', () => { assert.deepEqual(split('"a.b".c', { quotes: ['"'], keep: val => val !== '"' }), ['a.b', 'c']); }); }); split-string-6.1.0/test/options.quotes.js000066400000000000000000000070331345744402200205140ustar00rootroot00000000000000'use strict'; require('mocha'); const assert = require('assert'); const split = require('..'); describe('options.quotes', function() { let options = { quotes: ['"', "'", '`'] }; it('should disable quotes support', () => { assert.deepEqual(split('a.\'b.c\'."d"', { quotes: [] }), ['a', "'b", "c'", '"d"']); }); it('should keep single quotes', () => { let opts = { ...options, keep: val => val !== '"' }; assert.deepEqual(split('a.\'b.c\'."d"', opts), ['a', "'b.c'", 'd']); }); it('should keep "" double quotes', () => { let opts = { ...options, keep: () => true }; assert.deepEqual(split('a."b.c".d', { quotes: true, keep: () => true }), ['a', '"b.c"', 'd']); assert.deepEqual(split('a."b.c".d', options), ['a', '"b.c"', 'd']); assert.deepEqual(split('a."b.c".d', options), ['a', '"b.c"', 'd']); }); it('should keep “” smart quotes', () => { let opts = { brackets: { '“': '”' }, keep: () => true }; assert.deepEqual(split('a.“b.c”.d', opts), ['a', '“b.c”', 'd']); }); it('should keep backticks', () => { let opts = { ...options, keep: () => true }; assert.deepEqual(split('a.`b.c`.d', opts), ['a', '`b.c`', 'd']); }); it('should support custom brackets', () => { let keep = val => !/^[~$^“”]$/.test(val); let opts = { brackets: { '^': '$', '“': '”' }, keep } assert.deepEqual(split('a.^b.c$', opts), ['a', 'b.c']); assert.deepEqual(split('“b.c”', opts), ['b.c']); assert.deepEqual(split('a.“b.c”', opts), ['a', 'b.c']); assert.deepEqual(split('a.“b.c”.d', opts), ['a', 'b.c', 'd']); assert.deepEqual(split('a.“b.c”.d.“.e.f.g.”.h', opts), ['a', 'b.c', 'd', '.e.f.g.', 'h']); }); it('should support custom quotes', () => { let keep = val => val !== '^' && val !== '~'; assert.deepEqual(split('a.^b.c^', { quotes: ['^'], keep }), ['a', 'b.c']); assert.deepEqual(split('a.~b.c~', { quotes: ['~'], keep }), ['a', 'b.c']); }); it('should support double-quoted strings', function() { let keep = val => val !== '"'; let opts = { ...options, keep }; assert.deepEqual(split('"b.c"', opts), ['b.c']); assert.deepEqual(split('a."b.c"', opts), ['a', 'b.c']); assert.deepEqual(split('a".b.c"', opts), ['a.b.c']); assert.deepEqual(split('a."b.c".d', opts), ['a', 'b.c', 'd']); assert.deepEqual(split('a."b.c".d.".e.f.g.".h', opts), ['a', 'b.c', 'd', '.e.f.g.', 'h']); }); it('should respect single-quoted strings', function() { let keep = val => val !== '\''; let opts = { ...options, keep }; assert.deepEqual(split("'b.c'", opts), ['b.c']); assert.deepEqual(split("a.'b.c'", opts), ['a', 'b.c']); assert.deepEqual(split("a.'b.c'.d", opts), ['a', 'b.c', 'd']); assert.deepEqual(split("a.'b.c'.d.'.e.f.g.'.h", opts), ['a', 'b.c', 'd', '.e.f.g.', 'h']); }); it('should respect strings in backticks', function() { let keep = val => val !== '`'; let opts = { ...options, keep }; assert.deepEqual(split('`b.c`', opts), ['b.c']); assert.deepEqual(split('a.`b.c`', opts), ['a', 'b.c']); assert.deepEqual(split('a.`b.c`.d', opts), ['a', 'b.c', 'd']); assert.deepEqual(split('a.`b.c`.d.`.e.f.g.`.h', opts), ['a', 'b.c', 'd', '.e.f.g.', 'h']); }); it('should retain unclosed double quotes in the results', function() { assert.deepEqual(split('a."b.c'), ['a', '"b', 'c']); }); it('should retain unclosed single quotes in the results', function() { assert.deepEqual(split("brian's"), ["brian's"]); assert.deepEqual(split("a.'b.c"), ['a', "'b", 'c']); }); }); split-string-6.1.0/test/options.separator.js000066400000000000000000000022461345744402200211750ustar00rootroot00000000000000'use strict'; require('mocha'); const assert = require('assert'); const split = require('..'); describe('separator', () => { it('should split on a custom separator', () => { assert.deepEqual(split(',,,', { separator: ',' }), ['', '', '', '']); assert.deepEqual(split('||||', { separator: '|' }), ['', '', '', '', '']); assert.deepEqual(split('||||', { separator: ',' }), ['||||']); assert.deepEqual(split('|,|,|,|', { separator: ',' }), ['|', '|', '|', '|']); assert.deepEqual(split('a/b/c', { separator: '/' }), ['a', 'b', 'c']); assert.deepEqual(split('a,b,c', { separator: ',' }), ['a', 'b', 'c']); }); it('should not split on an escaped custom separator:', () => { assert.deepEqual(split('a/b/c\\/d', { separator: '/' }), ['a', 'b', 'c/d']); }); it('should take a custom function for splitting', () => { assert.deepEqual(split('.a.b.c', state => !state.bos()), ['.a', 'b', 'c']); assert.deepEqual(split('a.b.c', state => state.prev() !== 'a'), ['a.b', 'c']); assert.deepEqual(split('a.b.c', state => state.next() !== 'b'), ['a.b', 'c']); assert.deepEqual(split('a.b.c', state => state.next() !== 'c'), ['a', 'b.c']); }); }); split-string-6.1.0/test/test.js000066400000000000000000000012661345744402200164630ustar00rootroot00000000000000'use strict'; require('mocha'); const assert = require('assert'); const split = require('..'); describe('defaults', () => { it('should throw an error when arguments are invalid', () => { assert.throws(() => split(), /expected/); }); it('should not split on escaped dots:', () => { assert.deepEqual(split('a.b.c\\.d'), ['a', 'b', 'c.d']); }); it('should keep escaping when followed by a backslash:', () => { assert.deepEqual(split('a.b.c\\\\.d'), ['a', 'b', 'c\\\\', 'd']); assert.deepEqual(split('a.b.c\\\\d'), ['a', 'b', 'c\\\\d']); }); it('should split a string on dots by default:', () => { assert.deepEqual(split('a.b.c'), ['a', 'b', 'c']); }); }); split-string-6.1.0/types/000077500000000000000000000000001345744402200153265ustar00rootroot00000000000000split-string-6.1.0/types/index.d.ts000066400000000000000000000013111345744402200172230ustar00rootroot00000000000000// TypeScript Version: 3.0 export interface ASTNode { type: 'root' | 'bracket'; nodes: ASTNode[]; stash: string[]; } export interface State { input: string; separator: string; stack: ASTNode[]; bos(): boolean; eos(): boolean; prev(): string; next(): string; } export interface Options { brackets?: { [key: string]: string } | boolean; quotes?: string[] | boolean; separator?: string; strict?: boolean; keep?(value: string, state: State): boolean; } type SplitFunc = (state: State) => boolean; declare function split(input: string, options?: Options | SplitFunc): string[]; declare function split(input: string, options: Options, fn: SplitFunc): string[]; export default split; split-string-6.1.0/types/test.ts000066400000000000000000000015351345744402200166610ustar00rootroot00000000000000/** * Testing the TypeScript definitions for split-string. */ import split, { State } from '.'; function keep(value: string, state: State) { return value !== '\\' && (value !== '"' || state.prev() === '\\'); } function splitFunc(state: State) { console.log(state); return state.prev() === 'a'; } split('a.b."c.d.e.f.g".h.i'); split('a.b."c.d.e.f.g".h.i', { quotes: ['"'] }); split('a.b.\\"c.d.e.f.g".h.i', { quotes: ['"'], keep }); split('a.[{a.b}].e', { brackets: { '[': ']' } }); split('«a.b».⟨c.d⟩.[e.f]', { brackets: { '«': '»', '⟨': '⟩'}, quotes: ['"'], separator: '.', strict: false, keep }); split('a.b.c.a.d.e', splitFunc); split('a.b."c.d.e.f.g".h.i', { quotes: ['"'] }, splitFunc); // Make sure invalid calls fail split(); // $ExpectError split(splitFunc); // $ExpectError split({ quotes: ['"'] }); // $ExpectError split-string-6.1.0/types/tsconfig.json000066400000000000000000000003351345744402200200360ustar00rootroot00000000000000{ "compilerOptions": { "module": "commonjs", "lib": ["es6", "dom"], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, "strictFunctionTypes": true, "noEmit": true } } split-string-6.1.0/types/tslint.json000066400000000000000000000001421345744402200175330ustar00rootroot00000000000000{ "extends": "dtslint/dtslint.json", "rules": { "no-relative-import-in-test": false } }