string-split-by-whitespace 3.0.6 → 3.0.12

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2010-2021 Roy Revelt and other contributors
3
+ Copyright (c) 2010-2022 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
package/README.md CHANGED
@@ -26,18 +26,17 @@
26
26
 
27
27
  ## Install
28
28
 
29
- This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required:
29
+ The latest version is **ESM only**: Node 12+ is needed to use it and it must be `import`ed instead of `require`d. If your project is not on ESM yet and you want to use `require`, use an older version of this program, `2.1.0`.
30
30
 
31
31
  ```bash
32
32
  npm i string-split-by-whitespace
33
33
  ```
34
34
 
35
- If you need a legacy version which works with `require`, use version 2.1.0
36
-
37
35
  ## Quick Take
38
36
 
39
37
  ```js
40
38
  import { strict as assert } from "assert";
39
+
41
40
  import { splitByW } from "string-split-by-whitespace";
42
41
 
43
42
  // Split by whitespace is easy - use native String.prototype.split()
@@ -63,7 +62,7 @@ assert.deepEqual(
63
62
 
64
63
  ## Documentation
65
64
 
66
- Please [visit codsen.com](https://codsen.com/os/string-split-by-whitespace/) for a full description of the API and examples.
65
+ Please [visit codsen.com](https://codsen.com/os/string-split-by-whitespace/) for a full description of the API.
67
66
 
68
67
  ## Contributing
69
68
 
@@ -73,6 +72,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
73
72
 
74
73
  MIT License
75
74
 
76
- Copyright (c) 2010-2021 Roy Revelt and other contributors
75
+ Copyright (c) 2010-2022 Roy Revelt and other contributors
77
76
 
78
77
  <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">
@@ -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.6
4
+ * @version 3.0.12
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 { isIndexWithin } from 'ranges-is-index-within';
11
-
12
- var version$1 = "3.0.6";
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 o}from"ranges-is-index-within";var a="3.0.12";var y=a;function m(t,l){if(t===void 0)throw new Error("string-split-by-whitespace: [THROW_ID_01] The input is missing!");if(typeof t!="string")return t;if(t.trim()==="")return[];let n={...{ignoreRanges:[]},...l};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 s=null,i=[];for(let e=0,p=t.length;e<p;e++)s===null&&t[e].trim()&&(!n||!n.ignoreRanges||!n.ignoreRanges.length||n.ignoreRanges.length&&!o(e,n.ignoreRanges.map(r=>[r[0],r[1]-1]),{inclusiveRangeEnds:!0}))&&(s=e),s!==null&&(t[e].trim()?n.ignoreRanges.length&&o(e,n.ignoreRanges)?(i.push(t.slice(s,e-1)),s=null):t[e+1]===void 0&&i.push(t.slice(s,e+1)):(i.push(t.slice(s,e)),s=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.6
4
+ * @version 3.0.12
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
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).stringSplitByWhitespace={})}(this,(function(e){"use strict";
10
+ var stringSplitByWhitespace=(()=>{var l=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames,c=Object.getOwnPropertySymbols;var d=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable;var g=(e,n,r)=>n in e?l(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r,a=(e,n)=>{for(var r in n||(n={}))d.call(n,r)&&g(e,r,n[r]);if(c)for(var r of c(n))R.call(n,r)&&g(e,r,n[r]);return e};var w=e=>l(e,"__esModule",{value:!0});var b=(e,n)=>{for(var r in n)l(e,r,{get:n[r],enumerable:!0})},v=(e,n,r,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of f(n))!d.call(e,t)&&(r||t!=="default")&&l(e,t,{get:()=>n[t],enumerable:!(s=m(n,t))||s.enumerable});return e};var x=(e=>(n,r)=>e&&e.get(n)||(r=v(w({}),n,1),e&&e.set(n,r),r))(typeof WeakMap!="undefined"?new WeakMap:0);var T={};b(T,{splitByW:()=>O,version:()=>j});var E={inclusiveRangeEnds:!1,returnMatchedRangeInsteadOfTrue:!1};function p(e,n,r){let s=a(a({},E),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(n)?s.returnMatchedRangeInsteadOfTrue?n.find(t=>s.inclusiveRangeEnds?e>=t[0]&&e<=t[1]:e>t[0]&&e<t[1])||!1:n.some(t=>s.inclusiveRangeEnds?e>=t[0]&&e<=t[1]:e>t[0]&&e<t[1]):!1}var h="3.0.12";var j=h;function O(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 s=a(a({},{ignoreRanges:[]}),n);if(s.ignoreRanges.length>0&&!s.ignoreRanges.every(i=>Array.isArray(i)))throw new Error("string-split-by-whitespace: [THROW_ID_03] The opts.ignoreRanges contains elements which are not arrays!");let t=null,o=[];for(let i=0,y=e.length;i<y;i++)t===null&&e[i].trim()&&(!s||!s.ignoreRanges||!s.ignoreRanges.length||s.ignoreRanges.length&&!p(i,s.ignoreRanges.map(u=>[u[0],u[1]-1]),{inclusiveRangeEnds:!0}))&&(t=i),t!==null&&(e[i].trim()?s.ignoreRanges.length&&p(i,s.ignoreRanges)?(o.push(e.slice(t,i-1)),t=null):e[i+1]===void 0&&o.push(e.slice(t,i+1)):(o.push(e.slice(t,i)),t=null));return o}return x(T);})();
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.6
14
+ * @version 3.0.12
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.6",Object.defineProperty(e,"__esModule",{value:!0})}));
18
+ */
@@ -1,6 +1,7 @@
1
1
  // Quick Take
2
2
 
3
3
  import { strict as assert } from "assert";
4
+
4
5
  import { splitByW } from "../dist/string-split-by-whitespace.esm.js";
5
6
 
6
7
  // Split by whitespace is easy - use native String.prototype.split()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-split-by-whitespace",
3
- "version": "3.0.6",
3
+ "version": "3.0.12",
4
4
  "description": "Split string into array by chunks of whitespace",
5
5
  "keywords": [
6
6
  "alt",
@@ -37,93 +37,43 @@
37
37
  },
38
38
  "types": "types/index.d.ts",
39
39
  "scripts": {
40
- "build": "rollup -c",
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",
45
- "dev": "rollup -c --dev",
46
- "devunittest": "npm run dev && tap --only -R 'base'",
47
- "format": "npm run lect && npm run prettier && npm run lint",
48
- "lect": "lect",
49
- "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
50
- "perf": "node perf/check",
51
- "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
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
+ "devtest": "c8 yarn run unit && yarn run examples && yarn run lint",
43
+ "dts": "rollup -c && yarn run prettier 'types/index.d.ts' --write",
44
+ "examples": "node '../../ops/scripts/run-examples.js'",
45
+ "lect": "node '../../ops/lect/lect.js' && yarn run prettier 'README.md' '.all-contributorsrc' 'rollup.config.js' --write",
46
+ "letspublish": "yarn publish || :",
47
+ "lint": "eslint . --fix",
48
+ "perf": "node perf/check.js",
49
+ "prepare": "echo 'ready'",
50
+ "prettier": "prettier",
51
+ "prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
52
+ "pretest": "yarn run lect && yarn run build",
53
+ "test": "yarn run devtest",
54
+ "unit": "uvu test"
60
55
  },
61
- "tap": {
62
- "check-coverage": false,
63
- "node-arg": [
64
- "--no-warnings",
65
- "--experimental-loader",
66
- "@istanbuljs/esm-loader-hook"
56
+ "engines": {
57
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
58
+ },
59
+ "c8": {
60
+ "check-coverage": true,
61
+ "exclude": [
62
+ "**/test/**/*.*"
67
63
  ],
68
- "timeout": 0
64
+ "lines": 100
69
65
  },
70
66
  "lect": {
71
67
  "licence": {
72
68
  "extras": [
73
69
  ""
74
70
  ]
75
- },
76
- "req": "{ splitByW }",
77
- "various": {
78
- "devDependencies": [
79
- "string-find-heads-tails"
80
- ]
81
71
  }
82
72
  },
83
73
  "dependencies": {
84
- "@babel/runtime": "^7.16.3",
85
- "ranges-is-index-within": "^3.0.6"
74
+ "ranges-is-index-within": "^3.0.12"
86
75
  },
87
76
  "devDependencies": {
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",
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.9",
108
- "@types/tap": "^15.0.5",
109
- "@typescript-eslint/eslint-plugin": "^5.4.0",
110
- "@typescript-eslint/parser": "^5.4.0",
111
- "core-js": "^3.19.1",
112
- "cross-env": "^7.0.3",
113
- "eslint": "^8.3.0",
114
- "lect": "^0.18.6",
115
- "rollup": "^2.60.0",
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.6",
122
- "tap": "^15.1.2",
123
- "tslib": "^2.3.1",
124
- "typescript": "^4.5.2"
125
- },
126
- "engines": {
127
- "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
77
+ "string-find-heads-tails": "^5.0.12"
128
78
  }
129
79
  }
package/types/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- declare type Range = [from: number, to: number] | [from: number, to: number, whatToInsert: string | null | undefined];
1
+ declare type Range =
2
+ | [from: number, to: number]
3
+ | [from: number, to: number, whatToInsert: string | null | undefined];
2
4
 
3
5
  declare const version: string;
4
-
5
6
  interface Opts {
6
- ignoreRanges: Range[];
7
+ ignoreRanges: Range[];
7
8
  }
8
9
  declare function splitByW(str: string, originalOpts?: Partial<Opts>): string[];
9
10
 
package/examples/api.json DELETED
@@ -1 +0,0 @@
1
- {"_quickTake.js":{"title":"Quick Take","content":"import &#x7B; strict as assert &#x7D; from \"assert\";\nimport &#x7B; splitByW &#x7D; 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\", &#x7B;\n ignoreRanges: [[0, 2]], // that's \"a\" and space after it\n &#x7D;),\n [\"b\", \"c\", \"d\", \"e\"]\n);"}}