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?
已存档?
是复刻?
已锁定?
是镜像?
是私有?