1
1
const SPECIAL = [ '[' , '^' , '$' , '.' , '|' , '?' , '*' , '+' , '(' , ')' ] ;
2
2
3
- class Split {
3
+ const Split = {
4
4
/**
5
5
* The base method of the split-it library.
6
6
* Splits a given string on all "classic" delimiters:
7
7
* commas, colons, tabs, and returns
8
8
*
9
9
* @param {string } str the string to split
10
10
*/
11
- it = ( str ) => {
11
+ it : ( str ) => {
12
12
return str . split ( / , | : | \t | \r \n | \r | \n / g) ;
13
- } ;
13
+ } ,
14
14
15
15
/**
16
16
* Accepts an optional delimiter argument.
17
17
* Defaults to splitting on whitespace only
18
18
* @param {string } str the string to split
19
19
* @param {string } del the chosen delimiter on which to split the given string
20
20
*/
21
- onDelimiter = ( str , del = null ) => {
21
+ onDelimiter : ( str , del = null ) => {
22
22
if ( del ) {
23
23
let escape = SPECIAL . includes ( del ) ? '\\' : '' ;
24
24
let re = new RegExp ( escape + del , 'g' ) ;
25
25
return str . split ( re ) ;
26
26
} else {
27
27
return str . split ( / \s / g) ;
28
28
}
29
- } ;
29
+ } ,
30
30
31
31
/**
32
32
*
33
33
* @param {string } data the csv data to be manipulated
34
34
* @param options an object containing boolean values for "headings" and "splitOnColumns"
35
35
* @return {string[] } the passed in csv data will be split into an array of arrays, with each sub-array representing a single row or column of data.
36
36
*/
37
- csv = ( data , { headings = true , splitOnColumns = false } = { } ) => {
37
+ csv : ( data , { headings = true , splitOnColumns = false } = { } ) => {
38
38
let rows = data . split ( / \r \n | \n | \r / g) . map ( ( row ) => row . split ( / , \s + / g) ) ;
39
39
let returnData = [ ] ;
40
40
@@ -58,7 +58,7 @@ class Split {
58
58
}
59
59
60
60
return returnData ;
61
- } ;
61
+ } ,
62
62
}
63
63
64
- module . exports = new Split ( ) ;
64
+ module . exports = Split ;
0 commit comments