string-split-by-whitespace
v4.0.19
Published
Split string into array by chunks of whitespace
Downloads
383
Maintainers
Readme
Install
This package is pure ESM. If you're not ready yet, install an older version of this program, 2.1.0 (npm i [email protected]
).
npm i string-split-by-whitespace
Quick Take
import { strict as assert } from "assert";
import { splitByW } from "string-split-by-whitespace";
// Split by whitespace is easy - use native String.prototype.split()
assert.deepEqual("abc def ghi".split(/\s+/), ["abc", "def", "ghi"]);
const source = "\n \n a\t \nb \n \t";
// this program is nearly equivalent to regex-based split:
assert.deepEqual(source.split(/\s+/), ["", "a", "b", ""]);
assert.deepEqual(splitByW(source), ["a", "b"]);
// regex-based split needs more filtration but it's native solution
// ADDITIONALLY...
// this program allows to exclude certain index ranges:
assert.deepEqual(
splitByW("a b c d e", {
ignoreRanges: [[0, 2]], // that's "a" and space after it
}),
["b", "c", "d", "e"],
);
Documentation
Please visit codsen.com for a full description of the API.
Contributing
To report bugs or request features or assistance, raise an issue on GitHub.
Licence
MIT License.
Copyright © 2010-2024 Roy Revelt and other contributors.