source: trip-planner-front/node_modules/split-string/README.md@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 7.6 KB
Line 
1# 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)
2
3> Split a string on a character except when the character is escaped.
4
5Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
6
7## Install
8
9Install with [npm](https://www.npmjs.com/):
10
11```sh
12$ npm install --save split-string
13```
14
15<!-- section: Why use this? -->
16
17<details>
18<summary><strong>Why use this?</strong></summary>
19
20<br>
21
22Although it's easy to split on a string:
23
24```js
25console.log('a.b.c'.split('.'));
26//=> ['a', 'b', 'c']
27```
28
29It's more challenging to split a string whilst respecting escaped or quoted characters.
30
31**Bad**
32
33```js
34console.log('a\\.b.c'.split('.'));
35//=> ['a\\', 'b', 'c']
36
37console.log('"a.b.c".d'.split('.'));
38//=> ['"a', 'b', 'c"', 'd']
39```
40
41**Good**
42
43```js
44var split = require('split-string');
45console.log(split('a\\.b.c'));
46//=> ['a.b', 'c']
47
48console.log(split('"a.b.c".d'));
49//=> ['a.b.c', 'd']
50```
51
52See the [options](#options) to learn how to choose the separator or retain quotes or escaping.
53
54<br>
55
56</details>
57
58## Usage
59
60```js
61var split = require('split-string');
62
63split('a.b.c');
64//=> ['a', 'b', 'c']
65
66// respects escaped characters
67split('a.b.c\\.d');
68//=> ['a', 'b', 'c.d']
69
70// respects double-quoted strings
71split('a."b.c.d".e');
72//=> ['a', 'b.c.d', 'e']
73```
74
75**Brackets**
76
77Also respects brackets [unless disabled](#optionsbrackets):
78
79```js
80split('a (b c d) e', ' ');
81//=> ['a', '(b c d)', 'e']
82```
83
84## Options
85
86### options.brackets
87
88**Type**: `object|boolean`
89
90**Default**: `undefined`
91
92**Description**
93
94If enabled, split-string will not split inside brackets. The following brackets types are supported when `options.brackets` is `true`,
95
96```js
97{
98 '<': '>',
99 '(': ')',
100 '[': ']',
101 '{': '}'
102}
103```
104
105Or, if object of brackets must be passed, each property on the object must be a bracket type, where the property key is the opening delimiter and property value is the closing delimiter.
106
107**Examples**
108
109```js
110// no bracket support by default
111split('a.{b.c}');
112//=> [ 'a', '{b', 'c}' ]
113
114// support all basic bracket types: "<>{}[]()"
115split('a.{b.c}', {brackets: true});
116//=> [ 'a', '{b.c}' ]
117
118// also supports nested brackets
119split('a.{b.{c.d}.e}.f', {brackets: true});
120//=> [ 'a', '{b.{c.d}.e}', 'f' ]
121
122// support only the specified brackets
123split('[a.b].(c.d)', {brackets: {'[': ']'}});
124//=> [ '[a.b]', '(c', 'd)' ]
125```
126
127### options.sep
128
129**Type**: `string`
130
131**Default**: `.`
132
133The separator/character to split on.
134
135**Example**
136
137```js
138split('a.b,c', {sep: ','});
139//=> ['a.b', 'c']
140
141// you can also pass the separator as string as the last argument
142split('a.b,c', ',');
143//=> ['a.b', 'c']
144```
145
146### options.keepEscaping
147
148**Type**: `boolean`
149
150**Default**: `undefined`
151
152Keep backslashes in the result.
153
154**Example**
155
156```js
157split('a.b\\.c');
158//=> ['a', 'b.c']
159
160split('a.b.\\c', {keepEscaping: true});
161//=> ['a', 'b\.c']
162```
163
164### options.keepQuotes
165
166**Type**: `boolean`
167
168**Default**: `undefined`
169
170Keep single- or double-quotes in the result.
171
172**Example**
173
174```js
175split('a."b.c.d".e');
176//=> ['a', 'b.c.d', 'e']
177
178split('a."b.c.d".e', {keepQuotes: true});
179//=> ['a', '"b.c.d"', 'e']
180
181split('a.\'b.c.d\'.e', {keepQuotes: true});
182//=> ['a', '\'b.c.d\'', 'e']
183```
184
185### options.keepDoubleQuotes
186
187**Type**: `boolean`
188
189**Default**: `undefined`
190
191Keep double-quotes in the result.
192
193**Example**
194
195```js
196split('a."b.c.d".e');
197//=> ['a', 'b.c.d', 'e']
198
199split('a."b.c.d".e', {keepDoubleQuotes: true});
200//=> ['a', '"b.c.d"', 'e']
201```
202
203### options.keepSingleQuotes
204
205**Type**: `boolean`
206
207**Default**: `undefined`
208
209Keep single-quotes in the result.
210
211**Example**
212
213```js
214split('a.\'b.c.d\'.e');
215//=> ['a', 'b.c.d', 'e']
216
217split('a.\'b.c.d\'.e', {keepSingleQuotes: true});
218//=> ['a', '\'b.c.d\'', 'e']
219```
220
221## Customizer
222
223**Type**: `function`
224
225**Default**: `undefined`
226
227Pass a function as the last argument to customize how tokens are added to the array.
228
229**Example**
230
231```js
232var arr = split('a.b', function(tok) {
233 if (tok.arr[tok.arr.length - 1] === 'a') {
234 tok.split = false;
235 }
236});
237console.log(arr);
238//=> ['a.b']
239```
240
241**Properties**
242
243The `tok` object has the following properties:
244
245* `tok.val` (string) The current value about to be pushed onto the result array
246* `tok.idx` (number) the current index in the string
247* `tok.str` (string) the entire string
248* `tok.arr` (array) the result array
249
250## Release history
251
252### v3.0.0 - 2017-06-17
253
254**Added**
255
256* adds support for brackets
257
258## About
259
260<details>
261<summary><strong>Contributing</strong></summary>
262
263Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
264
265</details>
266
267<details>
268<summary><strong>Running Tests</strong></summary>
269
270Running 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:
271
272```sh
273$ npm install && npm test
274```
275
276</details>
277
278<details>
279<summary><strong>Building docs</strong></summary>
280
281_(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.)_
282
283To generate the readme, run the following command:
284
285```sh
286$ npm install -g verbose/verb#dev verb-generate-readme && verb
287```
288
289</details>
290
291### Related projects
292
293You might also be interested in these projects:
294
295* [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)")
296* [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.")
297* [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.")
298* [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)")
299
300### Contributors
301
302| **Commits** | **Contributor** |
303| --- | --- |
304| 28 | [jonschlinkert](https://github.com/jonschlinkert) |
305| 9 | [doowb](https://github.com/doowb) |
306
307### Author
308
309**Jon Schlinkert**
310
311* [github/jonschlinkert](https://github.com/jonschlinkert)
312* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
313
314### License
315
316Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
317Released under the [MIT License](LICENSE).
318
319***
320
321_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 19, 2017._
Note: See TracBrowser for help on using the repository browser.