string-split
v0.3.1
Published
A curried `String.prototype.split` with support for splitting by String, RegExp, or Function.
Downloads
232
Maintainers
Readme
string-split
A curried
String.prototype.split
with support for splitting by String, RegExp, or Function.
npm install string-split --save
npm stats
Examples
require
var split = require('string-split');
full application
split(".", "example.com");
//=> ["example", "com"]
partial application
var undot = split('.')
undot('example.com');
//=> ["example", "com"]
iteratee
var transform = split("::");
var foodtypes = ["Entree::Seafood", "Entree::Chicken"];
foodtypes.map(transform);
//=> [ ["Entree", "Seafood"], ["Entree", "Chicken"] ]
predicate
function isNumber (chr, _) {
return !!Number(chr)
}
split(isNumber, 'Hello1World2')
//=> ['Hello', 'World']
predicate using index
function odd (chr, idx) {
return idx % 2 !== 0
}
split(odd, 'AaBbCcDd')
//=> ['A', 'B', 'C', 'D']
Features
- Supports splitting by String, RegExp, or Function.
- Curried.
API
split(splitBy, string)
arguments
splitBy: (String|RegExp|Function)
String, RegExp, or Function to split by.string: (String)
String to split.
returns
(Array)
List of split string parts.
splitBy function signature
Return
true
to split by currentchr
oridx
.
chr: (String)
current character.idx: (Number)
current character index.