string-split-by-whitespace 3.0.3 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -20
- package/LICENSE +1 -1
- package/dist/string-split-by-whitespace.esm.js +47 -39
- package/dist/string-split-by-whitespace.umd.js +3 -3
- package/package.json +23 -27
package/CHANGELOG.md
CHANGED
|
@@ -3,26 +3,6 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## 3.0.3 (2021-11-02)
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
- bump TS and separate ESLint plugins away from this monorepo ([b1ebce1](https://github.com/codsen/codsen/commit/b1ebce1637d8c41c2d848fc24b0ba4058865bd5d))
|
|
11
|
-
|
|
12
|
-
### Features
|
|
13
|
-
|
|
14
|
-
- migrate to ES Modules ([c579dff](https://github.com/codsen/codsen/commit/c579dff3b23205e383035ca10ddcec671e35d0fe))
|
|
15
|
-
|
|
16
|
-
### BREAKING CHANGES
|
|
17
|
-
|
|
18
|
-
- programs now are in ES Modules and won't work with Common JS require()
|
|
19
|
-
|
|
20
|
-
## 3.0.1 (2021-09-13)
|
|
21
|
-
|
|
22
|
-
### Bug Fixes
|
|
23
|
-
|
|
24
|
-
- bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
|
|
25
|
-
|
|
26
6
|
## 3.0.0 (2021-09-09)
|
|
27
7
|
|
|
28
8
|
### Features
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010
|
|
3
|
+
Copyright (c) 2010-2021 Roy Revelt and other contributors
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name string-split-by-whitespace
|
|
3
3
|
* @fileoverview Split string into array by chunks of whitespace
|
|
4
|
-
* @version 3.0.
|
|
4
|
+
* @version 3.0.7
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-split-by-whitespace/}
|
|
@@ -9,49 +9,57 @@
|
|
|
9
9
|
|
|
10
10
|
import { isIndexWithin } from 'ranges-is-index-within';
|
|
11
11
|
|
|
12
|
-
var version$1 = "3.0.
|
|
12
|
+
var version$1 = "3.0.7";
|
|
13
13
|
|
|
14
14
|
const version = version$1;
|
|
15
15
|
function splitByW(str, originalOpts) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
if (typeof str !== "string") {
|
|
20
|
-
return str;
|
|
21
|
-
}
|
|
22
|
-
if (str.trim() === "") {
|
|
23
|
-
return [];
|
|
24
|
-
}
|
|
25
|
-
const defaults = {
|
|
26
|
-
ignoreRanges: []
|
|
27
|
-
};
|
|
28
|
-
const opts = { ...defaults,
|
|
29
|
-
...originalOpts
|
|
30
|
-
};
|
|
31
|
-
if (opts.ignoreRanges.length > 0 && !opts.ignoreRanges.every(arr => Array.isArray(arr))) {
|
|
32
|
-
throw new Error("string-split-by-whitespace: [THROW_ID_03] The opts.ignoreRanges contains elements which are not arrays!");
|
|
33
|
-
}
|
|
34
|
-
let nonWhitespaceSubStringStartsAt = null;
|
|
35
|
-
const res = [];
|
|
36
|
-
for (let i = 0, len = str.length; i < len; i++) {
|
|
37
|
-
if (nonWhitespaceSubStringStartsAt === null && str[i].trim() && (!opts || !opts.ignoreRanges || !opts.ignoreRanges.length || opts.ignoreRanges.length && !isIndexWithin(i, opts.ignoreRanges.map(arr => [arr[0], arr[1] - 1]), {
|
|
38
|
-
inclusiveRangeEnds: true
|
|
39
|
-
}))) {
|
|
40
|
-
nonWhitespaceSubStringStartsAt = i;
|
|
16
|
+
if (str === undefined) {
|
|
17
|
+
throw new Error("string-split-by-whitespace: [THROW_ID_01] The input is missing!");
|
|
41
18
|
}
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
res.push(str.slice(nonWhitespaceSubStringStartsAt, i));
|
|
45
|
-
nonWhitespaceSubStringStartsAt = null;
|
|
46
|
-
} else if (opts.ignoreRanges.length && isIndexWithin(i, opts.ignoreRanges)) {
|
|
47
|
-
res.push(str.slice(nonWhitespaceSubStringStartsAt, i - 1));
|
|
48
|
-
nonWhitespaceSubStringStartsAt = null;
|
|
49
|
-
} else if (str[i + 1] === undefined) {
|
|
50
|
-
res.push(str.slice(nonWhitespaceSubStringStartsAt, i + 1));
|
|
51
|
-
}
|
|
19
|
+
if (typeof str !== "string") {
|
|
20
|
+
return str;
|
|
52
21
|
}
|
|
53
|
-
|
|
54
|
-
|
|
22
|
+
if (str.trim() === "") {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
const defaults = {
|
|
26
|
+
ignoreRanges: [],
|
|
27
|
+
};
|
|
28
|
+
const opts = { ...defaults, ...originalOpts };
|
|
29
|
+
if (opts.ignoreRanges.length > 0 &&
|
|
30
|
+
!opts.ignoreRanges.every((arr) => Array.isArray(arr))) {
|
|
31
|
+
throw new Error("string-split-by-whitespace: [THROW_ID_03] The opts.ignoreRanges contains elements which are not arrays!");
|
|
32
|
+
}
|
|
33
|
+
let nonWhitespaceSubStringStartsAt = null;
|
|
34
|
+
const res = [];
|
|
35
|
+
for (let i = 0, len = str.length; i < len; i++) {
|
|
36
|
+
if (nonWhitespaceSubStringStartsAt === null &&
|
|
37
|
+
str[i].trim() &&
|
|
38
|
+
(!opts ||
|
|
39
|
+
!opts.ignoreRanges ||
|
|
40
|
+
!opts.ignoreRanges.length ||
|
|
41
|
+
(opts.ignoreRanges.length &&
|
|
42
|
+
!isIndexWithin(i, opts.ignoreRanges.map((arr) => [arr[0], arr[1] - 1]), {
|
|
43
|
+
inclusiveRangeEnds: true,
|
|
44
|
+
})))) {
|
|
45
|
+
nonWhitespaceSubStringStartsAt = i;
|
|
46
|
+
}
|
|
47
|
+
if (nonWhitespaceSubStringStartsAt !== null) {
|
|
48
|
+
if (!str[i].trim()) {
|
|
49
|
+
res.push(str.slice(nonWhitespaceSubStringStartsAt, i));
|
|
50
|
+
nonWhitespaceSubStringStartsAt = null;
|
|
51
|
+
}
|
|
52
|
+
else if (opts.ignoreRanges.length &&
|
|
53
|
+
isIndexWithin(i, opts.ignoreRanges)) {
|
|
54
|
+
res.push(str.slice(nonWhitespaceSubStringStartsAt, i - 1));
|
|
55
|
+
nonWhitespaceSubStringStartsAt = null;
|
|
56
|
+
}
|
|
57
|
+
else if (str[i + 1] === undefined) {
|
|
58
|
+
res.push(str.slice(nonWhitespaceSubStringStartsAt, i + 1));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return res;
|
|
55
63
|
}
|
|
56
64
|
|
|
57
65
|
export { splitByW, version };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name string-split-by-whitespace
|
|
3
3
|
* @fileoverview Split string into array by chunks of whitespace
|
|
4
|
-
* @version 3.0.
|
|
4
|
+
* @version 3.0.7
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-split-by-whitespace/}
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
/**
|
|
12
12
|
* @name ranges-is-index-within
|
|
13
13
|
* @fileoverview Checks if index is within any of the given string index ranges
|
|
14
|
-
* @version 3.0.
|
|
14
|
+
* @version 3.0.7
|
|
15
15
|
* @author Roy Revelt, Codsen Ltd
|
|
16
16
|
* @license MIT
|
|
17
17
|
* {@link https://codsen.com/os/ranges-is-index-within/}
|
|
18
|
-
*/const n={inclusiveRangeEnds:!1,returnMatchedRangeInsteadOfTrue:!1};function i(e,i,r){const t={...n,...r};if(!Number.isInteger(e))throw new Error(`ranges-is-index-within: [THROW_ID_01] the first input argument should be string index, a natural number (or zero). It was given as ${e} (type ${typeof e})`);return!!Array.isArray(i)&&(t.returnMatchedRangeInsteadOfTrue?i.find((n=>t.inclusiveRangeEnds?e>=n[0]&&e<=n[1]:e>n[0]&&e<n[1]))||!1:i.some((n=>t.inclusiveRangeEnds?e>=n[0]&&e<=n[1]:e>n[0]&&e<n[1])))}e.splitByW=function(e,n){if(void 0===e)throw new Error("string-split-by-whitespace: [THROW_ID_01] The input is missing!");if("string"!=typeof e)return e;if(""===e.trim())return[];const r={ignoreRanges:[],...n};if(r.ignoreRanges.length>0&&!r.ignoreRanges.every((e=>Array.isArray(e))))throw new Error("string-split-by-whitespace: [THROW_ID_03] The opts.ignoreRanges contains elements which are not arrays!");let t=null;const s=[];for(let n=0,o=e.length;n<o;n++)null!==t||!e[n].trim()||r&&r.ignoreRanges&&r.ignoreRanges.length&&(!r.ignoreRanges.length||i(n,r.ignoreRanges.map((e=>[e[0],e[1]-1])),{inclusiveRangeEnds:!0}))||(t=n),null!==t&&(e[n].trim()?r.ignoreRanges.length&&i(n,r.ignoreRanges)?(s.push(e.slice(t,n-1)),t=null):void 0===e[n+1]&&s.push(e.slice(t,n+1)):(s.push(e.slice(t,n)),t=null));return s},e.version="3.0.
|
|
18
|
+
*/const n={inclusiveRangeEnds:!1,returnMatchedRangeInsteadOfTrue:!1};function i(e,i,r){const t={...n,...r};if(!Number.isInteger(e))throw new Error(`ranges-is-index-within: [THROW_ID_01] the first input argument should be string index, a natural number (or zero). It was given as ${e} (type ${typeof e})`);return!!Array.isArray(i)&&(t.returnMatchedRangeInsteadOfTrue?i.find((n=>t.inclusiveRangeEnds?e>=n[0]&&e<=n[1]:e>n[0]&&e<n[1]))||!1:i.some((n=>t.inclusiveRangeEnds?e>=n[0]&&e<=n[1]:e>n[0]&&e<n[1])))}e.splitByW=function(e,n){if(void 0===e)throw new Error("string-split-by-whitespace: [THROW_ID_01] The input is missing!");if("string"!=typeof e)return e;if(""===e.trim())return[];const r={ignoreRanges:[],...n};if(r.ignoreRanges.length>0&&!r.ignoreRanges.every((e=>Array.isArray(e))))throw new Error("string-split-by-whitespace: [THROW_ID_03] The opts.ignoreRanges contains elements which are not arrays!");let t=null;const s=[];for(let n=0,o=e.length;n<o;n++)null!==t||!e[n].trim()||r&&r.ignoreRanges&&r.ignoreRanges.length&&(!r.ignoreRanges.length||i(n,r.ignoreRanges.map((e=>[e[0],e[1]-1])),{inclusiveRangeEnds:!0}))||(t=n),null!==t&&(e[n].trim()?r.ignoreRanges.length&&i(n,r.ignoreRanges)?(s.push(e.slice(t,n-1)),t=null):void 0===e[n+1]&&s.push(e.slice(t,n+1)):(s.push(e.slice(t,n)),t=null));return s},e.version="3.0.7",Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "string-split-by-whitespace",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"description": "Split string into array by chunks of whitespace",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"alt",
|
|
@@ -38,13 +38,12 @@
|
|
|
38
38
|
"types": "types/index.d.ts",
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "rollup -c",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
41
|
+
"build:esbuild": "node '../../scripts/esbuild.js'",
|
|
42
|
+
"build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
43
|
+
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
|
|
43
44
|
"clean_types": "../../scripts/cleanTypes.js",
|
|
44
45
|
"dev": "rollup -c --dev",
|
|
45
46
|
"devunittest": "npm run dev && tap --only -R 'base'",
|
|
46
|
-
"esbuild": "node '../../scripts/esbuild.js'",
|
|
47
|
-
"esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
48
47
|
"format": "npm run lect && npm run prettier && npm run lint",
|
|
49
48
|
"lect": "lect",
|
|
50
49
|
"lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
|
|
@@ -53,17 +52,14 @@
|
|
|
53
52
|
"republish": "npm publish || :",
|
|
54
53
|
"tap": "tap",
|
|
55
54
|
"pretest": "npm run build",
|
|
56
|
-
"test": "npm run
|
|
55
|
+
"test": "npm run test:ci && npm run perf",
|
|
56
|
+
"test:ci": "npm run unittest && npm run test:examples && npm run format",
|
|
57
57
|
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
58
58
|
"tsc": "tsc",
|
|
59
|
-
"unittest": "tap --no-only --
|
|
59
|
+
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
|
|
60
60
|
},
|
|
61
61
|
"tap": {
|
|
62
62
|
"check-coverage": false,
|
|
63
|
-
"coverage-report": [
|
|
64
|
-
"json-summary",
|
|
65
|
-
"text"
|
|
66
|
-
],
|
|
67
63
|
"node-arg": [
|
|
68
64
|
"--no-warnings",
|
|
69
65
|
"--experimental-loader",
|
|
@@ -85,8 +81,8 @@
|
|
|
85
81
|
}
|
|
86
82
|
},
|
|
87
83
|
"dependencies": {
|
|
88
|
-
"@babel/runtime": "^7.16.
|
|
89
|
-
"ranges-is-index-within": "^3.0.
|
|
84
|
+
"@babel/runtime": "^7.16.3",
|
|
85
|
+
"ranges-is-index-within": "^3.0.7"
|
|
90
86
|
},
|
|
91
87
|
"devDependencies": {
|
|
92
88
|
"@babel/cli": "^7.16.0",
|
|
@@ -97,8 +93,8 @@
|
|
|
97
93
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
98
94
|
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
99
95
|
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
100
|
-
"@babel/plugin-transform-runtime": "^7.16.
|
|
101
|
-
"@babel/preset-env": "^7.16.
|
|
96
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
97
|
+
"@babel/preset-env": "^7.16.4",
|
|
102
98
|
"@babel/preset-typescript": "^7.16.0",
|
|
103
99
|
"@babel/register": "^7.16.0",
|
|
104
100
|
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
@@ -108,26 +104,26 @@
|
|
|
108
104
|
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
109
105
|
"@rollup/plugin-strip": "^2.1.0",
|
|
110
106
|
"@rollup/plugin-typescript": "^8.3.0",
|
|
111
|
-
"@types/node": "^16.11.
|
|
107
|
+
"@types/node": "^16.11.10",
|
|
112
108
|
"@types/tap": "^15.0.5",
|
|
113
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
114
|
-
"@typescript-eslint/parser": "^5.
|
|
115
|
-
"core-js": "^3.19.
|
|
109
|
+
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
110
|
+
"@typescript-eslint/parser": "^5.5.0",
|
|
111
|
+
"core-js": "^3.19.2",
|
|
116
112
|
"cross-env": "^7.0.3",
|
|
117
|
-
"eslint": "^8.
|
|
118
|
-
"lect": "^0.18.
|
|
119
|
-
"rollup": "^2.
|
|
113
|
+
"eslint": "^8.3.0",
|
|
114
|
+
"lect": "^0.18.7",
|
|
115
|
+
"rollup": "^2.60.1",
|
|
120
116
|
"rollup-plugin-ascii": "^0.0.3",
|
|
121
117
|
"rollup-plugin-banner": "^0.2.1",
|
|
122
118
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
123
|
-
"rollup-plugin-dts": "^4.0.
|
|
119
|
+
"rollup-plugin-dts": "^4.0.1",
|
|
124
120
|
"rollup-plugin-terser": "^7.0.2",
|
|
125
|
-
"string-find-heads-tails": "^5.0.
|
|
126
|
-
"tap": "^15.
|
|
121
|
+
"string-find-heads-tails": "^5.0.7",
|
|
122
|
+
"tap": "^15.1.5",
|
|
127
123
|
"tslib": "^2.3.1",
|
|
128
|
-
"typescript": "^4.
|
|
124
|
+
"typescript": "^4.5.2"
|
|
129
125
|
},
|
|
130
126
|
"engines": {
|
|
131
|
-
"node": ">=
|
|
127
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
132
128
|
}
|
|
133
129
|
}
|