string-split-by-whitespace 3.0.4 → 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/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-%YEAR% Roy Revelt and other contributors
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
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 and examples.
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,57 +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
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 { isIndexWithin } from 'ranges-is-index-within';
11
-
12
- var version$1 = "3.0.4";
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,
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;
41
- }
42
- if (nonWhitespaceSubStringStartsAt !== null) {
43
- if (!str[i].trim()) {
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
- }
52
- }
53
- }
54
- return res;
55
- }
56
-
57
- 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
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
- !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 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.4
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
- */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.4",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.4",
3
+ "version": "3.0.10",
4
4
  "description": "Split string into array by chunks of whitespace",
5
5
  "keywords": [
6
6
  "alt",
@@ -37,97 +37,40 @@
37
37
  },
38
38
  "types": "types/index.d.ts",
39
39
  "scripts": {
40
- "build": "rollup -c",
41
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
42
- "clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
43
- "clean_types": "../../scripts/cleanTypes.js",
44
- "dev": "rollup -c --dev",
45
- "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
- "format": "npm run lect && npm run prettier && npm run lint",
49
- "lect": "lect",
50
- "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
51
- "perf": "node perf/check",
52
- "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
53
- "republish": "npm publish || :",
54
- "tap": "tap",
55
- "pretest": "npm run build",
56
- "test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
57
- "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
58
- "tsc": "tsc",
59
- "unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
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
- "tap": {
62
- "check-coverage": false,
63
- "coverage-report": [
64
- "json-summary",
65
- "text"
66
- ],
67
- "node-arg": [
68
- "--no-warnings",
69
- "--experimental-loader",
70
- "@istanbuljs/esm-loader-hook"
53
+ "engines": {
54
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
55
+ },
56
+ "c8": {
57
+ "check-coverage": true,
58
+ "exclude": [
59
+ "**/test/**/*.*"
71
60
  ],
72
- "timeout": 0
61
+ "lines": 100
73
62
  },
74
63
  "lect": {
75
64
  "licence": {
76
65
  "extras": [
77
66
  ""
78
67
  ]
79
- },
80
- "req": "{ splitByW }",
81
- "various": {
82
- "devDependencies": [
83
- "string-find-heads-tails"
84
- ]
85
68
  }
86
69
  },
87
70
  "dependencies": {
88
- "@babel/runtime": "^7.16.0",
89
- "ranges-is-index-within": "^3.0.4"
71
+ "ranges-is-index-within": "^3.0.10"
90
72
  },
91
73
  "devDependencies": {
92
- "@babel/cli": "^7.16.0",
93
- "@babel/core": "^7.16.0",
94
- "@babel/node": "^7.16.0",
95
- "@babel/plugin-external-helpers": "^7.16.0",
96
- "@babel/plugin-proposal-class-properties": "^7.16.0",
97
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
98
- "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
99
- "@babel/plugin-proposal-optional-chaining": "^7.16.0",
100
- "@babel/plugin-transform-runtime": "^7.16.0",
101
- "@babel/preset-env": "^7.16.0",
102
- "@babel/preset-typescript": "^7.16.0",
103
- "@babel/register": "^7.16.0",
104
- "@istanbuljs/esm-loader-hook": "^0.1.2",
105
- "@rollup/plugin-babel": "^5.3.0",
106
- "@rollup/plugin-commonjs": "^21.0.1",
107
- "@rollup/plugin-json": "^4.1.0",
108
- "@rollup/plugin-node-resolve": "^13.0.6",
109
- "@rollup/plugin-strip": "^2.1.0",
110
- "@rollup/plugin-typescript": "^8.3.0",
111
- "@types/node": "^16.11.6",
112
- "@types/tap": "^15.0.5",
113
- "@typescript-eslint/eslint-plugin": "^5.3.0",
114
- "@typescript-eslint/parser": "^5.3.0",
115
- "core-js": "^3.19.1",
116
- "cross-env": "^7.0.3",
117
- "eslint": "^8.1.0",
118
- "lect": "^0.18.4",
119
- "rollup": "^2.59.0",
120
- "rollup-plugin-ascii": "^0.0.3",
121
- "rollup-plugin-banner": "^0.2.1",
122
- "rollup-plugin-cleanup": "^3.2.1",
123
- "rollup-plugin-dts": "^4.0.0",
124
- "rollup-plugin-terser": "^7.0.2",
125
- "string-find-heads-tails": "^5.0.4",
126
- "tap": "^15.0.10",
127
- "tslib": "^2.3.1",
128
- "typescript": "^4.4.4"
129
- },
130
- "engines": {
131
- "node": ">=12"
74
+ "string-find-heads-tails": "^5.0.10"
132
75
  }
133
76
  }
package/types/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  declare type Range = [from: number, to: number] | [from: number, to: number, whatToInsert: string | null | undefined];
2
2
 
3
3
  declare const version: string;
4
-
5
4
  interface Opts {
6
5
  ignoreRanges: Range[];
7
6
  }
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);"}}