Generic splitOnce, using indexOf and slice so it can work on strings and buffers alike.
npm install split-string-or-buffer-once-pmb
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:
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.
Similar as above, but with an options object opt.
Required properties on opt:
* sep: Same as the sep above.
Optional properties:
* last: If set to a truthy value, use lastIndexOf to search for sep.
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.
A convenience alais for splitOnce({ sep, last: true }, input).
Usage
-----
see test/usage.mjs.
Known issues
------------
* Needs more/better tests and docs.
License
-------
ISC