# split-on-first

> Split a string on the first occurance of a given separator

Latest version **4.0.0** (published 2025-08-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install split-on-first
pnpm add split-on-first
yarn add split-on-first
bun add split-on-first
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2025-08-20 |
| First published | 2019-02-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 4.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 73 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | split, string, first, once, occurrence, separator, delimiter, text |

## Links

- npm: https://www.npmjs.com/package/split-on-first
- Repository: https://github.com/sindresorhus/split-on-first
- Homepage: https://github.com/sindresorhus/split-on-first#readme
- Issues: https://github.com/sindresorhus/split-on-first/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/split-on-first

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 4.0.0 (latest) — 2025-08-20
- 3.0.0 — 2021-04-15
- 2.0.1 — 2020-11-22
- 2.0.0 — 2019-11-13
- 1.1.0 — 2019-04-23
- 1.0.0 — 2019-02-07

## README

# split-on-first

> Split a string on the first occurrence of a given separator

This is similar to [`String#split()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split), but that one splits on all the occurrences, not just the first one.

## Install

```sh
npm install split-on-first
```

## Usage

```js
import splitOnFirst from 'split-on-first';

splitOnFirst('a-b-c', '-');
//=> ['a', 'b-c']

splitOnFirst('key:value:value2', ':');
//=> ['key', 'value:value2']

splitOnFirst('a---b---c', '---');
//=> ['a', 'b---c']

splitOnFirst('a-b-c', '+');
//=> []

splitOnFirst('abc', '');
//=> []

splitOnFirst('a,b.c', /[.,]/);
//=> ['a', 'b.c']
```

## API

### splitOnFirst(string, separator)

#### string

Type: `string`

The string to split.

#### separator

Type: `string | RegExp`

The separator to split on. When a `RegExp` is provided, it splits on the first match.

## Related

- [split-at](https://github.com/sindresorhus/split-at) - Split a string at one or more indices

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