split-on-first
Split a string on the first occurance of a given separator
Last updated 5 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install split-on-first 
SYNC missed versions from official npm registry.

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

API

splitOnFirst(string, separator)

string

Type: string

The string to split.

separator

Type: string

The separator to split on.

Related

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

Current Tags

  • 3.0.0                                ...           latest (3 years ago)

5 Versions

  • 3.0.0                                ...           3 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (3)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |