string-split-by-whitespace 3.0.7 → 3.0.10
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/README.md
CHANGED
|
@@ -38,6 +38,7 @@ If you need a legacy version which works with `require`, use version 2.1.0
|
|
|
38
38
|
|
|
39
39
|
```js
|
|
40
40
|
import { strict as assert } from "assert";
|
|
41
|
+
|
|
41
42
|
import { splitByW } from "string-split-by-whitespace";
|
|
42
43
|
|
|
43
44
|
// Split by whitespace is easy - use native String.prototype.split()
|
|
@@ -63,7 +64,7 @@ assert.deepEqual(
|
|
|
63
64
|
|
|
64
65
|
## Documentation
|
|
65
66
|
|
|
66
|
-
Please [visit codsen.com](https://codsen.com/os/string-split-by-whitespace/) for a full description of the API
|
|
67
|
+
Please [visit codsen.com](https://codsen.com/os/string-split-by-whitespace/) for a full description of the API.
|
|
67
68
|
|
|
68
69
|
## Contributing
|
|
69
70
|
|
|
@@ -75,4 +76,6 @@ MIT License
|
|
|
75
76
|
|
|
76
77
|
Copyright (c) 2010-2021 Roy Revelt and other contributors
|
|
77
78
|
|
|
79
|
+
|
|
78
80
|
<img src="https://codsen.com/images/png-codsen-ok.png" width="98" alt="ok" align="center"> <img src="https://codsen.com/images/png-codsen-1.png" width="148" alt="codsen" align="center"> <img src="https://codsen.com/images/png-codsen-star-small.png" width="32" alt="star" align="center">
|
|
81
|
+
|
|
@@ -1,65 +1,10 @@
|
|
|
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.10
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-split-by-whitespace/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
var version$1 = "3.0.7";
|
|
13
|
-
|
|
14
|
-
const version = version$1;
|
|
15
|
-
function splitByW(str, originalOpts) {
|
|
16
|
-
if (str === undefined) {
|
|
17
|
-
throw new Error("string-split-by-whitespace: [THROW_ID_01] The input is missing!");
|
|
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, ...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;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export { splitByW, version };
|
|
10
|
+
import{isIndexWithin as a}from"ranges-is-index-within";var l="3.0.10";var y=l;function m(s,o){if(s===void 0)throw new Error("string-split-by-whitespace: [THROW_ID_01] The input is missing!");if(typeof s!="string")return s;if(s.trim()==="")return[];let n={...{ignoreRanges:[]},...o};if(n.ignoreRanges.length>0&&!n.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,i=[];for(let e=0,p=s.length;e<p;e++)t===null&&s[e].trim()&&(!n||!n.ignoreRanges||!n.ignoreRanges.length||n.ignoreRanges.length&&!a(e,n.ignoreRanges.map(r=>[r[0],r[1]-1]),{inclusiveRangeEnds:!0}))&&(t=e),t!==null&&(s[e].trim()?n.ignoreRanges.length&&a(e,n.ignoreRanges)?(i.push(s.slice(t,e-1)),t=null):s[e+1]===void 0&&i.push(s.slice(t,e+1)):(i.push(s.slice(t,e)),t=null));return i}export{m as splitByW,y as version};
|
|
@@ -1,18 +1,18 @@
|
|
|
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.10
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-split-by-whitespace/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
var stringSplitByWhitespace=(()=>{var o=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames,c=Object.getOwnPropertySymbols;var g=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable;var d=(e,n,i)=>n in e?o(e,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[n]=i,a=(e,n)=>{for(var i in n||(n={}))g.call(n,i)&&d(e,i,n[i]);if(c)for(var i of c(n))R.call(n,i)&&d(e,i,n[i]);return e};var b=e=>o(e,"__esModule",{value:!0});var v=(e,n)=>{for(var i in n)o(e,i,{get:n[i],enumerable:!0})},w=(e,n,i,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let s of m(n))!g.call(e,s)&&(i||s!=="default")&&o(e,s,{get:()=>n[s],enumerable:!(t=f(n,s))||t.enumerable});return e};var x=(e=>(n,i)=>e&&e.get(n)||(i=w(b({}),n,1),e&&e.set(n,i),i))(typeof WeakMap!="undefined"?new WeakMap:0);var j={};v(j,{splitByW:()=>T,version:()=>O});var I={inclusiveRangeEnds:!1,returnMatchedRangeInsteadOfTrue:!1};function p(e,n,i){let t=a(a({},I),i);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(n)?t.returnMatchedRangeInsteadOfTrue?n.find(s=>t.inclusiveRangeEnds?e>=s[0]&&e<=s[1]:e>s[0]&&e<s[1])||!1:n.some(s=>t.inclusiveRangeEnds?e>=s[0]&&e<=s[1]:e>s[0]&&e<s[1]):!1}var h="3.0.10";var O=h;function T(e,n){if(e===void 0)throw new Error("string-split-by-whitespace: [THROW_ID_01] The input is missing!");if(typeof e!="string")return e;if(e.trim()==="")return[];let t=a(a({},{ignoreRanges:[]}),n);if(t.ignoreRanges.length>0&&!t.ignoreRanges.every(r=>Array.isArray(r)))throw new Error("string-split-by-whitespace: [THROW_ID_03] The opts.ignoreRanges contains elements which are not arrays!");let s=null,l=[];for(let r=0,y=e.length;r<y;r++)s===null&&e[r].trim()&&(!t||!t.ignoreRanges||!t.ignoreRanges.length||t.ignoreRanges.length&&!p(r,t.ignoreRanges.map(u=>[u[0],u[1]-1]),{inclusiveRangeEnds:!0}))&&(s=r),s!==null&&(e[r].trim()?t.ignoreRanges.length&&p(r,t.ignoreRanges)?(l.push(e.slice(s,r-1)),s=null):e[r+1]===void 0&&l.push(e.slice(s,r+1)):(l.push(e.slice(s,r)),s=null));return l}return x(j);})();
|
|
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.10
|
|
15
15
|
* @author Roy Revelt, Codsen Ltd
|
|
16
16
|
* @license MIT
|
|
17
17
|
* {@link https://codsen.com/os/ranges-is-index-within/}
|
|
18
|
-
*/
|
|
18
|
+
*/
|
package/examples/_quickTake.js
CHANGED
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.10",
|
|
4
4
|
"description": "Split string into array by chunks of whitespace",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"alt",
|
|
@@ -37,93 +37,40 @@
|
|
|
37
37
|
},
|
|
38
38
|
"types": "types/index.d.ts",
|
|
39
39
|
"scripts": {
|
|
40
|
-
"build": "
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"republish": "npm publish || :",
|
|
53
|
-
"tap": "tap",
|
|
54
|
-
"pretest": "npm run build",
|
|
55
|
-
"test": "npm run test:ci && npm run perf",
|
|
56
|
-
"test:ci": "npm run unittest && npm run test:examples && npm run format",
|
|
57
|
-
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
58
|
-
"tsc": "tsc",
|
|
59
|
-
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
|
|
40
|
+
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
41
|
+
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
42
|
+
"dts": "rollup -c",
|
|
43
|
+
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
44
|
+
"lect": "node '../../ops/lect/lect.js'",
|
|
45
|
+
"letspublish": "yarn publish || :",
|
|
46
|
+
"lint": "eslint . --fix",
|
|
47
|
+
"perf": "node perf/check.js",
|
|
48
|
+
"prepare": "echo 'ready'",
|
|
49
|
+
"pretest": "yarn run lect && yarn run build",
|
|
50
|
+
"test": "c8 yarn run unit && yarn run examples && yarn run lint",
|
|
51
|
+
"unit": "uvu test"
|
|
60
52
|
},
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
55
|
+
},
|
|
56
|
+
"c8": {
|
|
57
|
+
"check-coverage": true,
|
|
58
|
+
"exclude": [
|
|
59
|
+
"**/test/**/*.*"
|
|
67
60
|
],
|
|
68
|
-
"
|
|
61
|
+
"lines": 100
|
|
69
62
|
},
|
|
70
63
|
"lect": {
|
|
71
64
|
"licence": {
|
|
72
65
|
"extras": [
|
|
73
66
|
""
|
|
74
67
|
]
|
|
75
|
-
},
|
|
76
|
-
"req": "{ splitByW }",
|
|
77
|
-
"various": {
|
|
78
|
-
"devDependencies": [
|
|
79
|
-
"string-find-heads-tails"
|
|
80
|
-
]
|
|
81
68
|
}
|
|
82
69
|
},
|
|
83
70
|
"dependencies": {
|
|
84
|
-
"
|
|
85
|
-
"ranges-is-index-within": "^3.0.7"
|
|
71
|
+
"ranges-is-index-within": "^3.0.10"
|
|
86
72
|
},
|
|
87
73
|
"devDependencies": {
|
|
88
|
-
"
|
|
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",
|
|
100
|
-
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
101
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
102
|
-
"@rollup/plugin-commonjs": "^21.0.1",
|
|
103
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
104
|
-
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
105
|
-
"@rollup/plugin-strip": "^2.1.0",
|
|
106
|
-
"@rollup/plugin-typescript": "^8.3.0",
|
|
107
|
-
"@types/node": "^16.11.10",
|
|
108
|
-
"@types/tap": "^15.0.5",
|
|
109
|
-
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
110
|
-
"@typescript-eslint/parser": "^5.5.0",
|
|
111
|
-
"core-js": "^3.19.2",
|
|
112
|
-
"cross-env": "^7.0.3",
|
|
113
|
-
"eslint": "^8.3.0",
|
|
114
|
-
"lect": "^0.18.7",
|
|
115
|
-
"rollup": "^2.60.1",
|
|
116
|
-
"rollup-plugin-ascii": "^0.0.3",
|
|
117
|
-
"rollup-plugin-banner": "^0.2.1",
|
|
118
|
-
"rollup-plugin-cleanup": "^3.2.1",
|
|
119
|
-
"rollup-plugin-dts": "^4.0.1",
|
|
120
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
121
|
-
"string-find-heads-tails": "^5.0.7",
|
|
122
|
-
"tap": "^15.1.5",
|
|
123
|
-
"tslib": "^2.3.1",
|
|
124
|
-
"typescript": "^4.5.2"
|
|
125
|
-
},
|
|
126
|
-
"engines": {
|
|
127
|
-
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
74
|
+
"string-find-heads-tails": "^5.0.10"
|
|
128
75
|
}
|
|
129
76
|
}
|
package/types/index.d.ts
CHANGED
package/examples/api.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"_quickTake.js":{"title":"Quick Take","content":"import { strict as assert } from \"assert\";\nimport { splitByW } from \"string-split-by-whitespace\";\n\n// Split by whitespace is easy - use native String.prototype.split()\nassert.deepEqual(\"abc def ghi\".split(/\\s+/), [\"abc\", \"def\", \"ghi\"]);\n\nconst source = `\\n \\n a\\t \\nb \\n \\t`;\n\n// this program is nearly equivalent to regex-based split:\nassert.deepEqual(source.split(/\\s+/), [\"\", \"a\", \"b\", \"\"]);\nassert.deepEqual(splitByW(source), [\"a\", \"b\"]);\n// regex-based split needs more filtration but it's native solution\n\n// ADDITIONALLY...\n\n// this program allows to exclude certain index ranges:\nassert.deepEqual(\n splitByW(\"a b c d e\", {\n ignoreRanges: [[0, 2]], // that's \"a\" and space after it\n }),\n [\"b\", \"c\", \"d\", \"e\"]\n);"}}
|