Split string and keep separators.
npm install split-split[![jsdelivr][jsdelivr-badge]][jsdelivr-link]
[![npm version][fury-badge]][fury-link]
[![test CI][test-badge]][test-link]
[![codecov][codecov-badge]][codecov-link]
Split string and keep separators.
npm
``sh`
npm install split-split
ESM:
`js
import { split, join } from "split-split";
const [substrings, separators] = split("split split\tsplit|split", [
" ",
"\t",
"|",
]);
console.log(substrings, separators); // => ["split", "split", "split", "split"] [" ", "\t", "|"]
const str = join(substrings, separators);
console.log(str); // => "split split\tsplit|split"
`
CJS:
`js
const { split, join } = require("split-split");
const [substrings, separators] = split("split split\tsplit|split", [
" ",
"\t",
"|",
]);
console.log(substrings, separators); // => ["split", "split", "split", "split"] [" ", "\t", "|"]
const str = join(substrings, separators);
console.log(str); // => "split split\tsplit|split"
`
CDN:
`html`
The split() method divides the given string into an ordered list of substring, puts these substrings into an array, and returns the substrings array and separators array. The division is done by searching for a pattern; where the pattern is provided as the second parameter in the method's call.
#### Example
`js
const [substrings1, separators1] = split("split split\tsplit|split", [
" ",
"\t",
"|",
]);
console.log(substrings1, separators1); // => ["split", "split", "split", "split"] [" ", "\t", "|"]
const [substrings2, separators2] = split("split split\tsplit|split", /[ \t|]/g);
console.log(substrings2, separators2); // => ["split", "split", "split", "split"] [" ", "\t", "|"]
`
#### Parameters
- string (string) — String being split.separator
- (Array) - Separator to divide the given string.
#### Returns
An array, the first item is an array of substrings, the second item is an array of separators.
The join() method creates and returns a new string by concatenating all of the elements in substrings, separated by separators.
#### Example
`js`
const string = join(["split", "split", "split", "split"], [" ", "\t", "|"]);
console.log(string); // => "split split\tsplit|split"
#### Parameters
- strings (Array) — Substrings being join.separators
- (Array
#### Returns
A string consisting of the separators inserted into the substrings.
- Fix typescript exports.
- Added features split and join.
[split-split]: https://zjffun.github.io/split-split/
[fury-link]: https://badge.fury.io/js/split-split
[fury-badge]: https://badge.fury.io/js/split-split.svg
[jsdelivr-link]: https://www.jsdelivr.com/package/npm/split-split
[jsdelivr-badge]: https://data.jsdelivr.com/v1/package/npm/split-split/badge
[test-badge]: https://github.com/zjffun/split-split/workflows/test%20CI/badge.svg
[test-link]: https://github.com/zjffun/split-split/actions
[codecov-badge]: https://codecov.io/gh/zjffun/split-split/branch/main/graph/badge.svg
[codecov-link]: https://codecov.io/gh/zjffun/split-split