• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# split-on-first [![Build Status](https://travis-ci.com/sindresorhus/split-on-first.svg?branch=master)](https://travis-ci.com/sindresorhus/split-on-first)
2
3> Split a string on the first occurrence of a given separator
4
5This 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.
6
7
8## Install
9
10```
11$ npm install split-on-first
12```
13
14
15## Usage
16
17```js
18const splitOnFirst = require('split-on-first');
19
20splitOnFirst('a-b-c', '-');
21//=> ['a', 'b-c']
22
23splitOnFirst('key:value:value2', ':');
24//=> ['key', 'value:value2']
25
26splitOnFirst('a---b---c', '---');
27//=> ['a', 'b---c']
28
29splitOnFirst('a-b-c', '+');
30//=> ['a-b-c']
31```
32
33
34## API
35
36### splitOnFirst(string, separator)
37
38#### string
39
40Type: `string`
41
42The string to split.
43
44#### separator
45
46Type: `string`
47
48The separator to split on.
49
50
51## Related
52
53- [split-at](https://github.com/sindresorhus/split-at) - Split a string at one or more indices
54
55
56## License
57
58MIT © [Sindre Sorhus](https://sindresorhus.com)
59