split-on-first

Split a string on the first occurrence of a given separator

Github stars Tracking Chart

split-on-first Build Status

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

const splitOnFirst = require('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', '');
//=> []

API

splitOnFirst(string, separator)

string

Type: string

The string to split.

separator

Type: string

The separator to split on.

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

Main metrics

Overview
Name With Ownersindresorhus/split-on-first
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 2)
Platform
License:MIT License
所有者活动
Created At2019-02-07 10:21:41
Pushed At2022-07-08 13:05:26
Last Commit At
Release Count5
Last Release Namev3.0.0 (Posted on 2021-04-15 13:08:49)
First Release Namev1.0.0 (Posted on 2019-02-07 17:30:08)
用户参与
Stargazers Count73
Watchers Count2
Fork Count14
Commits Count17
Has Issues Enabled
Issues Count5
Issue Open Count1
Pull Requests Count6
Pull Requests Open Count0
Pull Requests Close Count2
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private