split-at
Version:
Split a string at one or more indices
61 lines (35 loc) • 1.13 kB
Markdown
string at one or more indices
```
$ npm install split-at
```
```js
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']
```
Type: `string`
String to be split.
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.
Type: `object`
Type: `boolean`\
Default: `false`
Remove the chosen indices.
Similar to the default `String
- [split-on-first](https://github.com/sindresorhus/split-on-first) - Split a string on the first occurrence of a given separator
> Split a