string-split-by-whitespace 3.0.2 → 3.0.6
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 -6
- 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 +38 -42
package/CHANGELOG.md
CHANGED
|
@@ -3,12 +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.1 (2021-09-13)
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
- bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
|
|
11
|
-
|
|
12
6
|
## 3.0.0 (2021-09-09)
|
|
13
7
|
|
|
14
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.6
|
|
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.6";
|
|
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.6
|
|
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.6
|
|
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.6",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.6",
|
|
4
4
|
"description": "Split string into array by chunks of whitespace",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"alt",
|
|
@@ -38,9 +38,10 @@
|
|
|
38
38
|
"types": "types/index.d.ts",
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "rollup -c",
|
|
41
|
-
"esbuild": "node '../../scripts/esbuild.js'",
|
|
42
|
-
"
|
|
43
|
-
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent
|
|
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",
|
|
44
|
+
"clean_types": "../../scripts/cleanTypes.js",
|
|
44
45
|
"dev": "rollup -c --dev",
|
|
45
46
|
"devunittest": "npm run dev && tap --only -R 'base'",
|
|
46
47
|
"format": "npm run lect && npm run prettier && npm run lint",
|
|
@@ -50,20 +51,15 @@
|
|
|
50
51
|
"prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
|
|
51
52
|
"republish": "npm publish || :",
|
|
52
53
|
"tap": "tap",
|
|
53
|
-
"tsc": "tsc",
|
|
54
54
|
"pretest": "npm run build",
|
|
55
|
-
"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",
|
|
56
57
|
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"clean_types": "../../scripts/cleanTypes.js"
|
|
58
|
+
"tsc": "tsc",
|
|
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,49 +81,49 @@
|
|
|
85
81
|
}
|
|
86
82
|
},
|
|
87
83
|
"dependencies": {
|
|
88
|
-
"@babel/runtime": "^7.
|
|
89
|
-
"ranges-is-index-within": "^3.0.
|
|
84
|
+
"@babel/runtime": "^7.16.3",
|
|
85
|
+
"ranges-is-index-within": "^3.0.6"
|
|
90
86
|
},
|
|
91
87
|
"devDependencies": {
|
|
92
|
-
"@babel/cli": "^7.
|
|
93
|
-
"@babel/core": "^7.
|
|
94
|
-
"@babel/node": "^7.
|
|
95
|
-
"@babel/plugin-external-helpers": "^7.
|
|
96
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
97
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.
|
|
98
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.
|
|
99
|
-
"@babel/plugin-proposal-optional-chaining": "^7.
|
|
100
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
101
|
-
"@babel/preset-env": "^7.
|
|
102
|
-
"@babel/preset-typescript": "^7.
|
|
103
|
-
"@babel/register": "^7.
|
|
88
|
+
"@babel/cli": "^7.16.0",
|
|
89
|
+
"@babel/core": "^7.16.0",
|
|
90
|
+
"@babel/node": "^7.16.0",
|
|
91
|
+
"@babel/plugin-external-helpers": "^7.16.0",
|
|
92
|
+
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
93
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
94
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
95
|
+
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
96
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
97
|
+
"@babel/preset-env": "^7.16.4",
|
|
98
|
+
"@babel/preset-typescript": "^7.16.0",
|
|
99
|
+
"@babel/register": "^7.16.0",
|
|
104
100
|
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
105
101
|
"@rollup/plugin-babel": "^5.3.0",
|
|
106
|
-
"@rollup/plugin-commonjs": "^
|
|
102
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
107
103
|
"@rollup/plugin-json": "^4.1.0",
|
|
108
|
-
"@rollup/plugin-node-resolve": "^13.0.
|
|
104
|
+
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
109
105
|
"@rollup/plugin-strip": "^2.1.0",
|
|
110
|
-
"@rollup/plugin-typescript": "^8.
|
|
111
|
-
"@types/node": "^16.9
|
|
106
|
+
"@rollup/plugin-typescript": "^8.3.0",
|
|
107
|
+
"@types/node": "^16.11.9",
|
|
112
108
|
"@types/tap": "^15.0.5",
|
|
113
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
|
114
|
-
"@typescript-eslint/parser": "^4.
|
|
115
|
-
"core-js": "^3.
|
|
109
|
+
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
110
|
+
"@typescript-eslint/parser": "^5.4.0",
|
|
111
|
+
"core-js": "^3.19.1",
|
|
116
112
|
"cross-env": "^7.0.3",
|
|
117
|
-
"eslint": "^
|
|
118
|
-
"lect": "^0.18.
|
|
119
|
-
"rollup": "^2.
|
|
113
|
+
"eslint": "^8.3.0",
|
|
114
|
+
"lect": "^0.18.6",
|
|
115
|
+
"rollup": "^2.60.0",
|
|
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.6",
|
|
122
|
+
"tap": "^15.1.2",
|
|
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
|
}
|