# split-string-or-buffer-once-pmb

> Generic splitOnce, using indexOf and slice so it can work on strings and buffers alike.

Latest version **1.0.2** (published 2025-06-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install split-string-or-buffer-once-pmb
pnpm add split-string-or-buffer-once-pmb
yarn add split-string-or-buffer-once-pmb
bun add split-string-or-buffer-once-pmb
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2025-06-16 |
| First published | 2019-03-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | M.K. |
| Maintainers | mk-pmb |
| Keywords | buffer, once, split, string |

## Links

- npm: https://www.npmjs.com/package/split-string-or-buffer-once-pmb
- Repository: https://github.com/mk-pmb/split-string-or-buffer-once-pmb-js
- Homepage: https://github.com/mk-pmb/split-string-or-buffer-once-pmb-js/#readme
- Issues: https://github.com/mk-pmb/split-string-or-buffer-once-pmb-js/issues
- npm.io page: https://npm.io/package/split-string-or-buffer-once-pmb

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2025-06-16
- 1.0.0 — 2019-03-12

## README

<!--#echo json="package.json" key="name" underline="=" -->
split-string-or-buffer-once-pmb
===============================
<!--/#echo -->

<!--#echo json="package.json" key="description" -->
Generic splitOnce, using indexOf and slice so it can work on strings and
buffers alike.
<!--/#echo -->



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 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`.


### simpleLast = splitOnce.last(sep, input)

A convenience alais for `splitOnce({ sep, last: true }, input)`.



Usage
-----

see [test/usage.mjs](test/usage.mjs).



<!--#toc stop="scan" -->



Known issues
------------

* Needs more/better tests and docs.




&nbsp;


License
-------
<!--#echo json="package.json" key=".license" -->
ISC
<!--/#echo -->

---
_Source: https://npm.io/package/split-string-or-buffer-once-pmb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
