split-on-first

Split a string on the first occurrence of a given separator

Github星跟蹤圖

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

主要指標

概覽
名稱與所有者sindresorhus/split-on-first
主編程語言JavaScript
編程語言JavaScript (語言數: 2)
平台
許可證MIT License
所有者活动
創建於2019-02-07 10:21:41
推送於2022-07-08 13:05:26
最后一次提交
發布數5
最新版本名稱v3.0.0 (發布於 2021-04-15 13:08:49)
第一版名稱v1.0.0 (發布於 2019-02-07 17:30:08)
用户参与
星數73
關注者數2
派生數14
提交數17
已啟用問題?
問題數5
打開的問題數1
拉請求數6
打開的拉請求數0
關閉的拉請求數2
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?