
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
split-on-first
Advanced tools
Split a string on the first occurrence of a given separator
This is similar to String#split(), but that one splits on all the occurrences, not just the first one.
npm install split-on-first
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']
Type: string
The string to split.
Type: string | RegExp
The separator to split on. When a RegExp is provided, it splits on the first match.
The 'split' package offers functionality to split strings based on a delimiter, but it splits on every occurrence of the delimiter, not just the first. This makes 'split-on-first' more suitable for cases where only the first delimiter is significant.
This is the native JavaScript split method available on string instances. It also splits on every occurrence of the specified separator. Unlike 'split-on-first', it does not limit the split to the first occurrence, which can lead to different use cases.
FAQs
Split a string on the first occurance of a given separator
The npm package split-on-first receives a total of 5,739,813 weekly downloads. As such, split-on-first popularity was classified as popular.
We found that split-on-first demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.