🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

split-on-first

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

split-on-first

Split a string on the first occurance of a given separator

latest
Source
npmnpm
Version
4.0.0
Version published
Weekly downloads
7.2M
-15.88%
Maintainers
1
Weekly downloads
 
Created
Source

split-on-first

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.

Install

npm install split-on-first

Usage

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.

  • split-at - Split a string at one or more indices

Keywords

split

FAQs

Package last updated on 20 Aug 2025

Did you know?

Socket

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.

Install

Related posts