split-string-or-buffer-once-pmb
v1.0.2
Published
Generic splitOnce, using indexOf and slice so it can work on strings and buffers alike.
Readme
split-string-or-buffer-once-pmb
Generic splitOnce, using indexOf and slice so it can work on strings and buffers alike.
API
This module exports one function:
simple = splitOnce(sep, input)
input is the String, Buffer, or other compatible value you want to split.
sep is whatever input.indexOf() shall search for.
However, sep must have a number as its length property.
Returns an array with two slices of input if sep was found,
or false otherwise.
advanced = splitOnce(opt, input)
Similar as above, but with an options object opt.
Required properties on opt:
sep: Same as thesepabove.
Optional properties:
last: If set to a truthy value, uselastIndexOfto search forsep.
Confusing properties: If for some exotic reason your opt could
happen to have a length property, make sure it's set to undefined,
or the opt might be mistaken for sep.
simpleLast = splitOnce.last(sep, input)
A convenience alais for splitOnce({ sep, last: true }, input).
Usage
see test/usage.mjs.
Known issues
- Needs more/better tests and docs.
License
ISC
