Skip to content

Commit fc53be2

Browse files
committed
Make Split an object instead of a class
1 parent d35bc88 commit fc53be2

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Diff for: CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
### Fixed
1010

11-
-
11+
- `Split` is now an object containing functions, instead of a class.
1212

1313
## v0.0.4 && v0.0.5
1414

Diff for: index.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
const SPECIAL = ['[', '^', '$', '.', '|', '?', '*', '+', '(', ')'];
22

3-
class Split {
3+
const Split = {
44
/**
55
* The base method of the split-it library.
66
* Splits a given string on all "classic" delimiters:
77
* commas, colons, tabs, and returns
88
*
99
* @param {string} str the string to split
1010
*/
11-
it = (str) => {
11+
it : (str) => {
1212
return str.split(/,|:|\t|\r\n|\r|\n/g);
13-
};
13+
},
1414

1515
/**
1616
* Accepts an optional delimiter argument.
1717
* Defaults to splitting on whitespace only
1818
* @param {string} str the string to split
1919
* @param {string} del the chosen delimiter on which to split the given string
2020
*/
21-
onDelimiter = (str, del = null) => {
21+
onDelimiter : (str, del = null) => {
2222
if (del) {
2323
let escape = SPECIAL.includes(del) ? '\\' : '';
2424
let re = new RegExp(escape + del, 'g');
2525
return str.split(re);
2626
} else {
2727
return str.split(/\s/g);
2828
}
29-
};
29+
},
3030

3131
/**
3232
*
3333
* @param {string} data the csv data to be manipulated
3434
* @param options an object containing boolean values for "headings" and "splitOnColumns"
3535
* @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.
3636
*/
37-
csv = (data, { headings = true, splitOnColumns = false } = {}) => {
37+
csv : (data, { headings = true, splitOnColumns = false } = {}) => {
3838
let rows = data.split(/\r\n|\n|\r/g).map((row) => row.split(/,\s+/g));
3939
let returnData = [];
4040

@@ -58,7 +58,7 @@ class Split {
5858
}
5959

6060
return returnData;
61-
};
61+
},
6262
}
6363

64-
module.exports = new Split();
64+
module.exports = Split;

0 commit comments

Comments
 (0)