Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 7.6KB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. > Split a string on a character except when the character is escaped.
  3. Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
  4. ## Install
  5. Install with [npm](https://www.npmjs.com/):
  6. ```sh
  7. $ npm install --save split-string
  8. ```
  9. <!-- section: Why use this? -->
  10. <details>
  11. <summary><strong>Why use this?</strong></summary>
  12. <br>
  13. Although it's easy to split on a string:
  14. ```js
  15. console.log('a.b.c'.split('.'));
  16. //=> ['a', 'b', 'c']
  17. ```
  18. It's more challenging to split a string whilst respecting escaped or quoted characters.
  19. **Bad**
  20. ```js
  21. console.log('a\\.b.c'.split('.'));
  22. //=> ['a\\', 'b', 'c']
  23. console.log('"a.b.c".d'.split('.'));
  24. //=> ['"a', 'b', 'c"', 'd']
  25. ```
  26. **Good**
  27. ```js
  28. var split = require('split-string');
  29. console.log(split('a\\.b.c'));
  30. //=> ['a.b', 'c']
  31. console.log(split('"a.b.c".d'));
  32. //=> ['a.b.c', 'd']
  33. ```
  34. See the [options](#options) to learn how to choose the separator or retain quotes or escaping.
  35. <br>
  36. </details>
  37. ## Usage
  38. ```js
  39. var split = require('split-string');
  40. split('a.b.c');
  41. //=> ['a', 'b', 'c']
  42. // respects escaped characters
  43. split('a.b.c\\.d');
  44. //=> ['a', 'b', 'c.d']
  45. // respects double-quoted strings
  46. split('a."b.c.d".e');
  47. //=> ['a', 'b.c.d', 'e']
  48. ```
  49. **Brackets**
  50. Also respects brackets [unless disabled](#optionsbrackets):
  51. ```js
  52. split('a (b c d) e', ' ');
  53. //=> ['a', '(b c d)', 'e']
  54. ```
  55. ## Options
  56. ### options.brackets
  57. **Type**: `object|boolean`
  58. **Default**: `undefined`
  59. **Description**
  60. If enabled, split-string will not split inside brackets. The following brackets types are supported when `options.brackets` is `true`,
  61. ```js
  62. {
  63. '<': '>',
  64. '(': ')',
  65. '[': ']',
  66. '{': '}'
  67. }
  68. ```
  69. Or, 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.
  70. **Examples**
  71. ```js
  72. // no bracket support by default
  73. split('a.{b.c}');
  74. //=> [ 'a', '{b', 'c}' ]
  75. // support all basic bracket types: "<>{}[]()"
  76. split('a.{b.c}', {brackets: true});
  77. //=> [ 'a', '{b.c}' ]
  78. // also supports nested brackets
  79. split('a.{b.{c.d}.e}.f', {brackets: true});
  80. //=> [ 'a', '{b.{c.d}.e}', 'f' ]
  81. // support only the specified brackets
  82. split('[a.b].(c.d)', {brackets: {'[': ']'}});
  83. //=> [ '[a.b]', '(c', 'd)' ]
  84. ```
  85. ### options.sep
  86. **Type**: `string`
  87. **Default**: `.`
  88. The separator/character to split on.
  89. **Example**
  90. ```js
  91. split('a.b,c', {sep: ','});
  92. //=> ['a.b', 'c']
  93. // you can also pass the separator as string as the last argument
  94. split('a.b,c', ',');
  95. //=> ['a.b', 'c']
  96. ```
  97. ### options.keepEscaping
  98. **Type**: `boolean`
  99. **Default**: `undefined`
  100. Keep backslashes in the result.
  101. **Example**
  102. ```js
  103. split('a.b\\.c');
  104. //=> ['a', 'b.c']
  105. split('a.b.\\c', {keepEscaping: true});
  106. //=> ['a', 'b\.c']
  107. ```
  108. ### options.keepQuotes
  109. **Type**: `boolean`
  110. **Default**: `undefined`
  111. Keep single- or double-quotes in the result.
  112. **Example**
  113. ```js
  114. split('a."b.c.d".e');
  115. //=> ['a', 'b.c.d', 'e']
  116. split('a."b.c.d".e', {keepQuotes: true});
  117. //=> ['a', '"b.c.d"', 'e']
  118. split('a.\'b.c.d\'.e', {keepQuotes: true});
  119. //=> ['a', '\'b.c.d\'', 'e']
  120. ```
  121. ### options.keepDoubleQuotes
  122. **Type**: `boolean`
  123. **Default**: `undefined`
  124. Keep double-quotes in the result.
  125. **Example**
  126. ```js
  127. split('a."b.c.d".e');
  128. //=> ['a', 'b.c.d', 'e']
  129. split('a."b.c.d".e', {keepDoubleQuotes: true});
  130. //=> ['a', '"b.c.d"', 'e']
  131. ```
  132. ### options.keepSingleQuotes
  133. **Type**: `boolean`
  134. **Default**: `undefined`
  135. Keep single-quotes in the result.
  136. **Example**
  137. ```js
  138. split('a.\'b.c.d\'.e');
  139. //=> ['a', 'b.c.d', 'e']
  140. split('a.\'b.c.d\'.e', {keepSingleQuotes: true});
  141. //=> ['a', '\'b.c.d\'', 'e']
  142. ```
  143. ## Customizer
  144. **Type**: `function`
  145. **Default**: `undefined`
  146. Pass a function as the last argument to customize how tokens are added to the array.
  147. **Example**
  148. ```js
  149. var arr = split('a.b', function(tok) {
  150. if (tok.arr[tok.arr.length - 1] === 'a') {
  151. tok.split = false;
  152. }
  153. });
  154. console.log(arr);
  155. //=> ['a.b']
  156. ```
  157. **Properties**
  158. The `tok` object has the following properties:
  159. * `tok.val` (string) The current value about to be pushed onto the result array
  160. * `tok.idx` (number) the current index in the string
  161. * `tok.str` (string) the entire string
  162. * `tok.arr` (array) the result array
  163. ## Release history
  164. ### v3.0.0 - 2017-06-17
  165. **Added**
  166. * adds support for brackets
  167. ## About
  168. <details>
  169. <summary><strong>Contributing</strong></summary>
  170. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
  171. </details>
  172. <details>
  173. <summary><strong>Running Tests</strong></summary>
  174. 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:
  175. ```sh
  176. $ npm install && npm test
  177. ```
  178. </details>
  179. <details>
  180. <summary><strong>Building docs</strong></summary>
  181. _(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.)_
  182. To generate the readme, run the following command:
  183. ```sh
  184. $ npm install -g verbose/verb#dev verb-generate-readme && verb
  185. ```
  186. </details>
  187. ### Related projects
  188. You might also be interested in these projects:
  189. * [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)")
  190. * [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.")
  191. * [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.")
  192. * [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)")
  193. ### Contributors
  194. | **Commits** | **Contributor** |
  195. | --- | --- |
  196. | 28 | [jonschlinkert](https://github.com/jonschlinkert) |
  197. | 9 | [doowb](https://github.com/doowb) |
  198. ### Author
  199. **Jon Schlinkert**
  200. * [github/jonschlinkert](https://github.com/jonschlinkert)
  201. * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
  202. ### License
  203. Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
  204. Released under the [MIT License](LICENSE).
  205. ***
  206. _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 19, 2017._