split-at
Split a string at one or more indices
Last updated 9 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install split-at 
SYNC missed versions from official npm registry.

split-at

Split a string at one or more indices

Install

$ npm install split-at

Usage

import splitAt from 'split-at';

splitAt('unicorn', 2);
//=> ['uni', 'corn']

splitAt('unicorn', -2);
//=> ['unico', 'rn']

splitAt('unicorn&rainbow', [6, 7]);
//=> ['unicorn', '&', 'rainbow']

splitAt('unicorn&rainbow', 7, {remove: true});
//=> ['unicorn', 'rainbow']

API

splitAt(string, index, options?)

string

Type: string

String to be split.

index

Type: number | number[]

One or more indices. A negative index is a 1-based position from the end of the string. For example, -1 is the index of the last place in the string. Duplicate indices are removed from the index array. A negative index and positive index that refer to the same position in the string are treated as duplicates.

options

Type: object

remove

Type: boolean
Default: false

Remove the chosen indices.

Similar to the default String#split behaviour.

Related

  • split-on-first - Split a string on the first occurrence of a given separator

Current Tags

  • 3.0.0                                ...           latest (4 years ago)

6 Versions

  • 3.0.0                                ...           4 years ago
  • 2.0.0                                ...           6 years ago
  • 1.2.0                                ...           9 years ago
  • 1.1.0                                ...           9 years ago
  • 1.0.1                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (1)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |