list-split
list-split is a toolkit for list/string splitting, it's inspired by Haskell's Data.List.Split
Installation
npm install --save list-split
Usage
// normal split// ["a=1", "b=2", "c=3"]// multi delimeter// ["11", "23", "5", "9"]// simple predicate// [[7,8], [9,6], [5]]// keep delimeters to the right// ["camel", "Case", "Hello", "World"]// remove heading and trailing blanks, and remove delimeters// ["a=1", "b=2", "c=3"]
API
Core
- split(postProcess, predicates, list)
- Split the list according to predicates, and do whatever you want in the postProcess
- param:
postProcess
{ Function } - param:
predicates
{ [Function] } - param:
list
{ Array | String }
for Predicates
-
##### oneOf(choices) Generate an array of one function based on the given choices
- param:
choices
{ Array | String }
- param:
-
##### onSubList(delim) Generate an array of functions based on the given delim. One function for one element in the delim.
- param:
delim
{ Array | String }
- param:
-
##### when(predicate) Just wrap the predicate in an array.
- param:
predicate
{ Function }
- param:
for postProcess
- dropInitialBlank
// ["","foo","bar"]// ["foo","bar"]
- dropFinalBlank
// ["foo","bar",""]// ["foo","bar"]
- insertBlanks
- insert a blank between two consecutive delimeters
// ["foo","bar"]// ["foo","","bar"]
-
dropDelims
- as default, we will keep the delimeters in the result, but you can easily remove them with dropDelims
-
condense
- combine consecutive delimeters into one element
// ["foo",";",";","bar"]// ["foo",";;","bar"]
- mergeDelimsLeft
- merge the left most delimeters in a row with the left element
// ["foo",";",";","bar"]// ["foo;", ";", "bar"]
- mergeDelimsRight
- merge the right most delimeters in a row with the right element
// ["foo",";",";","bar"]// ["foo", ";", ";bar"]
- dot
- combine the postProcess with
dot
(it's just function compose)
- combine the postProcess with
Licence
MIT