string-range-expander 2.1.0 → 3.0.3
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,6 +3,36 @@
|
|
|
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
|
+
## 3.0.0 (2021-09-09)
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
- migrate to ES Modules ([8c9d95d](https://github.com/codsen/codsen/commit/8c9d95d5dea0b769c2f070397141918a4893d575))
|
|
31
|
+
|
|
32
|
+
### BREAKING CHANGES
|
|
33
|
+
|
|
34
|
+
- programs now are in ES Modules and won't work with Common JS require()
|
|
35
|
+
|
|
6
36
|
## 2.1.0 (2021-05-24)
|
|
7
37
|
|
|
8
38
|
### Features
|
package/README.md
CHANGED
|
@@ -26,10 +26,14 @@
|
|
|
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:
|
|
30
|
+
|
|
29
31
|
```bash
|
|
30
32
|
npm i string-range-expander
|
|
31
33
|
```
|
|
32
34
|
|
|
35
|
+
If you need a legacy version which works with `require`, use version 2.1.0
|
|
36
|
+
|
|
33
37
|
## Quick Take
|
|
34
38
|
|
|
35
39
|
```js
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name string-range-expander
|
|
3
3
|
* @fileoverview Expands string index ranges within whitespace boundaries until letters are met
|
|
4
|
-
* @version
|
|
4
|
+
* @version 3.0.3
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-range-expander/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
var version$1 = "
|
|
10
|
+
var version$1 = "3.0.3";
|
|
11
11
|
|
|
12
12
|
const version = version$1;
|
|
13
13
|
const defaults = {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @name string-range-expander
|
|
3
3
|
* @fileoverview Expands string index ranges within whitespace boundaries until letters are met
|
|
4
|
-
* @version
|
|
4
|
+
* @version 3.0.3
|
|
5
5
|
* @author Roy Revelt, Codsen Ltd
|
|
6
6
|
* @license MIT
|
|
7
7
|
* {@link https://codsen.com/os/string-range-expander/}
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((e="undefined"!=typeof globalThis?globalThis:e||self).stringRangeExpander={})}(this,(function(e){"use strict";const i={str:"",from:0,to:0,ifLeftSideIncludesThisThenCropTightly:"",ifLeftSideIncludesThisCropItToo:"",ifRightSideIncludesThisThenCropTightly:"",ifRightSideIncludesThisCropItToo:"",extendToOneSide:!1,wipeAllWhitespaceOnLeft:!1,wipeAllWhitespaceOnRight:!1,addSingleSpaceToPreventAccidentalConcatenation:!1};e.defaults=i,e.expander=function(e){const t=/^[0-9a-zA-Z]+$/;function n(e){return!(!e||"string"!=typeof e)&&!e.trim()}function r(e){return"string"==typeof e}if(!e||"object"!=typeof e||Array.isArray(e)){let i;throw i=void 0===e?"but it is missing completely.":null===e?"but it was given as null.":`but it was given as ${typeof e}, equal to:\n${JSON.stringify(e,null,4)}.`,new Error(`string-range-expander: [THROW_ID_01] Input must be a plain object ${i}`)}if("object"==typeof e&&null!==e&&!Array.isArray(e)&&!Object.keys(e).length)throw new Error("string-range-expander: [THROW_ID_02] Input must be a plain object but it was given as a plain object without any keys.");if("number"!=typeof e.from)throw new Error(`string-range-expander: [THROW_ID_03] The input's "from" value opts.from, is not a number! Currently it's given as ${typeof e.from}, equal to ${JSON.stringify(e.from,null,0)}`);if("number"!=typeof e.to)throw new Error(`string-range-expander: [THROW_ID_04] The input's "to" value opts.to, is not a number! Currently it's given as ${typeof e.to}, equal to ${JSON.stringify(e.to,null,0)}`);if(e&&e.str&&!e.str[e.from]&&e.from!==e.to)throw new Error(`string-range-expander: [THROW_ID_05] The given input string opts.str ("${e.str}") must contain the character at index "from" ("${e.from}")`);if(e&&e.str&&!e.str[e.to-1])throw new Error(`string-range-expander: [THROW_ID_06] The given input string, opts.str ("${e.str}") must contain the character at index before "to" ("${e.to-1}")`);if(e.from>e.to)throw new Error(`string-range-expander: [THROW_ID_07] The given "from" index, "${e.from}" is greater than "to" index, "${e.to}". That's wrong!`);if(r(e.extendToOneSide)&&"left"!==e.extendToOneSide&&"right"!==e.extendToOneSide||!r(e.extendToOneSide)&&void 0!==e.extendToOneSide&&!1!==e.extendToOneSide)throw new Error(`string-range-expander: [THROW_ID_08] The opts.extendToOneSide value is not recogniseable! It's set to: "${e.extendToOneSide}" (${typeof e.extendToOneSide}). It has to be either Boolean "false" or strings "left" or "right"`);const o={...i,...e};if(Array.isArray(o.ifLeftSideIncludesThisThenCropTightly)){let e,i;if(!o.ifLeftSideIncludesThisThenCropTightly.every(((t,n)=>!!r(t)||(e=n,i=t,!1))))throw new Error(`string-range-expander: [THROW_ID_09] The opts.ifLeftSideIncludesThisThenCropTightly was set to an array:\n${JSON.stringify(o.ifLeftSideIncludesThisThenCropTightly,null,4)}. Now, that array contains not only string elements. For example, an element at index ${e} is of a type ${typeof i} (equal to ${JSON.stringify(i,null,0)}).`);o.ifLeftSideIncludesThisThenCropTightly=o.ifLeftSideIncludesThisThenCropTightly.join("")}const s=o.str;let l=o.from,d=o.to;if("right"!==o.extendToOneSide&&(n(s[l-1])&&(n(s[l-2])||o.ifLeftSideIncludesThisCropItToo.includes(s[l-2]))||s[l-1]&&o.ifLeftSideIncludesThisCropItToo.includes(s[l-1])||o.wipeAllWhitespaceOnLeft&&n(s[l-1])))for(let e=l;e--;)if(!o.ifLeftSideIncludesThisCropItToo.includes(s[e])){if(s[e].trim()){l=o.wipeAllWhitespaceOnLeft||o.ifLeftSideIncludesThisCropItToo.includes(s[e+1])?e+1:e+2;break}if(0===e){l=o.wipeAllWhitespaceOnLeft?0:1;break}}if("left"!==o.extendToOneSide&&(n(s[d])&&(o.wipeAllWhitespaceOnRight||n(s[d+1]))||o.ifRightSideIncludesThisCropItToo.includes(s[d])))for(let e=d,i=s.length;e<i;e++)if(!o.ifRightSideIncludesThisCropItToo.includes(s[e])&&(s[e]&&s[e].trim()||void 0===s[e])){d=o.wipeAllWhitespaceOnRight||o.ifRightSideIncludesThisCropItToo.includes(s[e-1])?e:e-1;break}return("right"!==o.extendToOneSide&&r(o.ifLeftSideIncludesThisThenCropTightly)&&o.ifLeftSideIncludesThisThenCropTightly&&(s[l-2]&&o.ifLeftSideIncludesThisThenCropTightly.includes(s[l-2])||s[l-1]&&o.ifLeftSideIncludesThisThenCropTightly.includes(s[l-1]))||"left"!==o.extendToOneSide&&r(o.ifRightSideIncludesThisThenCropTightly)&&o.ifRightSideIncludesThisThenCropTightly&&(s[d+1]&&o.ifRightSideIncludesThisThenCropTightly.includes(s[d+1])||s[d]&&o.ifRightSideIncludesThisThenCropTightly.includes(s[d])))&&("right"!==o.extendToOneSide&&n(s[l-1])&&!o.wipeAllWhitespaceOnLeft&&(l-=1),"left"!==o.extendToOneSide&&n(s[d])&&!o.wipeAllWhitespaceOnRight&&(d+=1)),o.addSingleSpaceToPreventAccidentalConcatenation&&s[l-1]&&s[l-1].trim()&&s[d]&&s[d].trim()&&(!o.ifLeftSideIncludesThisThenCropTightly&&!o.ifRightSideIncludesThisThenCropTightly||o.ifLeftSideIncludesThisThenCropTightly&&!o.ifLeftSideIncludesThisThenCropTightly.includes(s[l-1])||!(!o.ifRightSideIncludesThisThenCropTightly||s[d]&&o.ifRightSideIncludesThisThenCropTightly.includes(s[d])))&&(t.test(s[l-1])||t.test(s[d]))?[l,d," "]:[l,d]},e.version="
|
|
10
|
+
!function(e,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((e="undefined"!=typeof globalThis?globalThis:e||self).stringRangeExpander={})}(this,(function(e){"use strict";const i={str:"",from:0,to:0,ifLeftSideIncludesThisThenCropTightly:"",ifLeftSideIncludesThisCropItToo:"",ifRightSideIncludesThisThenCropTightly:"",ifRightSideIncludesThisCropItToo:"",extendToOneSide:!1,wipeAllWhitespaceOnLeft:!1,wipeAllWhitespaceOnRight:!1,addSingleSpaceToPreventAccidentalConcatenation:!1};e.defaults=i,e.expander=function(e){const t=/^[0-9a-zA-Z]+$/;function n(e){return!(!e||"string"!=typeof e)&&!e.trim()}function r(e){return"string"==typeof e}if(!e||"object"!=typeof e||Array.isArray(e)){let i;throw i=void 0===e?"but it is missing completely.":null===e?"but it was given as null.":`but it was given as ${typeof e}, equal to:\n${JSON.stringify(e,null,4)}.`,new Error(`string-range-expander: [THROW_ID_01] Input must be a plain object ${i}`)}if("object"==typeof e&&null!==e&&!Array.isArray(e)&&!Object.keys(e).length)throw new Error("string-range-expander: [THROW_ID_02] Input must be a plain object but it was given as a plain object without any keys.");if("number"!=typeof e.from)throw new Error(`string-range-expander: [THROW_ID_03] The input's "from" value opts.from, is not a number! Currently it's given as ${typeof e.from}, equal to ${JSON.stringify(e.from,null,0)}`);if("number"!=typeof e.to)throw new Error(`string-range-expander: [THROW_ID_04] The input's "to" value opts.to, is not a number! Currently it's given as ${typeof e.to}, equal to ${JSON.stringify(e.to,null,0)}`);if(e&&e.str&&!e.str[e.from]&&e.from!==e.to)throw new Error(`string-range-expander: [THROW_ID_05] The given input string opts.str ("${e.str}") must contain the character at index "from" ("${e.from}")`);if(e&&e.str&&!e.str[e.to-1])throw new Error(`string-range-expander: [THROW_ID_06] The given input string, opts.str ("${e.str}") must contain the character at index before "to" ("${e.to-1}")`);if(e.from>e.to)throw new Error(`string-range-expander: [THROW_ID_07] The given "from" index, "${e.from}" is greater than "to" index, "${e.to}". That's wrong!`);if(r(e.extendToOneSide)&&"left"!==e.extendToOneSide&&"right"!==e.extendToOneSide||!r(e.extendToOneSide)&&void 0!==e.extendToOneSide&&!1!==e.extendToOneSide)throw new Error(`string-range-expander: [THROW_ID_08] The opts.extendToOneSide value is not recogniseable! It's set to: "${e.extendToOneSide}" (${typeof e.extendToOneSide}). It has to be either Boolean "false" or strings "left" or "right"`);const o={...i,...e};if(Array.isArray(o.ifLeftSideIncludesThisThenCropTightly)){let e,i;if(!o.ifLeftSideIncludesThisThenCropTightly.every(((t,n)=>!!r(t)||(e=n,i=t,!1))))throw new Error(`string-range-expander: [THROW_ID_09] The opts.ifLeftSideIncludesThisThenCropTightly was set to an array:\n${JSON.stringify(o.ifLeftSideIncludesThisThenCropTightly,null,4)}. Now, that array contains not only string elements. For example, an element at index ${e} is of a type ${typeof i} (equal to ${JSON.stringify(i,null,0)}).`);o.ifLeftSideIncludesThisThenCropTightly=o.ifLeftSideIncludesThisThenCropTightly.join("")}const s=o.str;let l=o.from,d=o.to;if("right"!==o.extendToOneSide&&(n(s[l-1])&&(n(s[l-2])||o.ifLeftSideIncludesThisCropItToo.includes(s[l-2]))||s[l-1]&&o.ifLeftSideIncludesThisCropItToo.includes(s[l-1])||o.wipeAllWhitespaceOnLeft&&n(s[l-1])))for(let e=l;e--;)if(!o.ifLeftSideIncludesThisCropItToo.includes(s[e])){if(s[e].trim()){l=o.wipeAllWhitespaceOnLeft||o.ifLeftSideIncludesThisCropItToo.includes(s[e+1])?e+1:e+2;break}if(0===e){l=o.wipeAllWhitespaceOnLeft?0:1;break}}if("left"!==o.extendToOneSide&&(n(s[d])&&(o.wipeAllWhitespaceOnRight||n(s[d+1]))||o.ifRightSideIncludesThisCropItToo.includes(s[d])))for(let e=d,i=s.length;e<i;e++)if(!o.ifRightSideIncludesThisCropItToo.includes(s[e])&&(s[e]&&s[e].trim()||void 0===s[e])){d=o.wipeAllWhitespaceOnRight||o.ifRightSideIncludesThisCropItToo.includes(s[e-1])?e:e-1;break}return("right"!==o.extendToOneSide&&r(o.ifLeftSideIncludesThisThenCropTightly)&&o.ifLeftSideIncludesThisThenCropTightly&&(s[l-2]&&o.ifLeftSideIncludesThisThenCropTightly.includes(s[l-2])||s[l-1]&&o.ifLeftSideIncludesThisThenCropTightly.includes(s[l-1]))||"left"!==o.extendToOneSide&&r(o.ifRightSideIncludesThisThenCropTightly)&&o.ifRightSideIncludesThisThenCropTightly&&(s[d+1]&&o.ifRightSideIncludesThisThenCropTightly.includes(s[d+1])||s[d]&&o.ifRightSideIncludesThisThenCropTightly.includes(s[d])))&&("right"!==o.extendToOneSide&&n(s[l-1])&&!o.wipeAllWhitespaceOnLeft&&(l-=1),"left"!==o.extendToOneSide&&n(s[d])&&!o.wipeAllWhitespaceOnRight&&(d+=1)),o.addSingleSpaceToPreventAccidentalConcatenation&&s[l-1]&&s[l-1].trim()&&s[d]&&s[d].trim()&&(!o.ifLeftSideIncludesThisThenCropTightly&&!o.ifRightSideIncludesThisThenCropTightly||o.ifLeftSideIncludesThisThenCropTightly&&!o.ifLeftSideIncludesThisThenCropTightly.includes(s[l-1])||!(!o.ifRightSideIncludesThisThenCropTightly||s[d]&&o.ifRightSideIncludesThisThenCropTightly.includes(s[d])))&&(t.test(s[l-1])||t.test(s[d]))?[l,d," "]:[l,d]},e.version="3.0.3",Object.defineProperty(e,"__esModule",{value:!0})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "string-range-expander",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Expands string index ranges within whitespace boundaries until letters are met",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"expand",
|
|
@@ -25,17 +25,21 @@
|
|
|
25
25
|
"email": "roy@codsen.com",
|
|
26
26
|
"url": "https://codsen.com"
|
|
27
27
|
},
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
28
|
+
"type": "module",
|
|
29
|
+
"exports": {
|
|
30
|
+
"script": "./dist/string-range-expander.umd.js",
|
|
31
|
+
"default": "./dist/string-range-expander.esm.js"
|
|
32
|
+
},
|
|
31
33
|
"types": "types/index.d.ts",
|
|
32
34
|
"scripts": {
|
|
33
35
|
"build": "rollup -c",
|
|
34
|
-
"esbuild": "node '../../scripts/esbuild.js'",
|
|
35
|
-
"esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
36
36
|
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
|
|
37
|
+
"clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
|
|
38
|
+
"clean_types": "../../scripts/cleanTypes.js",
|
|
37
39
|
"dev": "rollup -c --dev",
|
|
38
40
|
"devunittest": "npm run dev && tap --only -R 'base'",
|
|
41
|
+
"esbuild": "node '../../scripts/esbuild.js'",
|
|
42
|
+
"esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
|
|
39
43
|
"format": "npm run lect && npm run prettier && npm run lint",
|
|
40
44
|
"lect": "lect",
|
|
41
45
|
"lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
|
|
@@ -43,22 +47,22 @@
|
|
|
43
47
|
"prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
|
|
44
48
|
"republish": "npm publish || :",
|
|
45
49
|
"tap": "tap",
|
|
46
|
-
"tsc": "tsc",
|
|
47
50
|
"pretest": "npm run build",
|
|
48
51
|
"test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
|
|
49
52
|
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"clean_types": "../../scripts/cleanTypes.js"
|
|
53
|
+
"tsc": "tsc",
|
|
54
|
+
"unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
|
|
53
55
|
},
|
|
54
56
|
"tap": {
|
|
57
|
+
"check-coverage": false,
|
|
55
58
|
"coverage-report": [
|
|
56
59
|
"json-summary",
|
|
57
60
|
"text"
|
|
58
61
|
],
|
|
59
|
-
"
|
|
60
|
-
"--
|
|
61
|
-
"--
|
|
62
|
+
"node-arg": [
|
|
63
|
+
"--no-warnings",
|
|
64
|
+
"--experimental-loader",
|
|
65
|
+
"@istanbuljs/esm-loader-hook"
|
|
62
66
|
],
|
|
63
67
|
"timeout": 0
|
|
64
68
|
},
|
|
@@ -74,43 +78,47 @@
|
|
|
74
78
|
}
|
|
75
79
|
},
|
|
76
80
|
"dependencies": {
|
|
77
|
-
"@babel/runtime": "^7.
|
|
81
|
+
"@babel/runtime": "^7.16.0"
|
|
78
82
|
},
|
|
79
83
|
"devDependencies": {
|
|
80
|
-
"@babel/cli": "^7.
|
|
81
|
-
"@babel/core": "^7.
|
|
82
|
-
"@babel/node": "^7.
|
|
83
|
-
"@babel/plugin-external-helpers": "^7.
|
|
84
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
85
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.
|
|
86
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.
|
|
87
|
-
"@babel/plugin-proposal-optional-chaining": "^7.
|
|
88
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
89
|
-
"@babel/preset-env": "^7.
|
|
90
|
-
"@babel/preset-typescript": "^7.
|
|
91
|
-
"@babel/register": "^7.
|
|
84
|
+
"@babel/cli": "^7.16.0",
|
|
85
|
+
"@babel/core": "^7.16.0",
|
|
86
|
+
"@babel/node": "^7.16.0",
|
|
87
|
+
"@babel/plugin-external-helpers": "^7.16.0",
|
|
88
|
+
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
89
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
90
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
91
|
+
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
92
|
+
"@babel/plugin-transform-runtime": "^7.16.0",
|
|
93
|
+
"@babel/preset-env": "^7.16.0",
|
|
94
|
+
"@babel/preset-typescript": "^7.16.0",
|
|
95
|
+
"@babel/register": "^7.16.0",
|
|
96
|
+
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
92
97
|
"@rollup/plugin-babel": "^5.3.0",
|
|
93
|
-
"@rollup/plugin-commonjs": "^
|
|
98
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
94
99
|
"@rollup/plugin-json": "^4.1.0",
|
|
95
|
-
"@rollup/plugin-node-resolve": "^13.0.
|
|
96
|
-
"@rollup/plugin-strip": "^2.0
|
|
97
|
-
"@rollup/plugin-typescript": "^8.
|
|
98
|
-
"@types/node": "^
|
|
99
|
-
"@types/tap": "^15.0.
|
|
100
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
101
|
-
"@typescript-eslint/parser": "^
|
|
102
|
-
"core-js": "^3.
|
|
100
|
+
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
101
|
+
"@rollup/plugin-strip": "^2.1.0",
|
|
102
|
+
"@rollup/plugin-typescript": "^8.3.0",
|
|
103
|
+
"@types/node": "^16.11.6",
|
|
104
|
+
"@types/tap": "^15.0.5",
|
|
105
|
+
"@typescript-eslint/eslint-plugin": "^5.2.0",
|
|
106
|
+
"@typescript-eslint/parser": "^5.2.0",
|
|
107
|
+
"core-js": "^3.19.0",
|
|
103
108
|
"cross-env": "^7.0.3",
|
|
104
|
-
"eslint": "^
|
|
105
|
-
"lect": "^0.
|
|
106
|
-
"rollup": "^2.
|
|
109
|
+
"eslint": "^8.1.0",
|
|
110
|
+
"lect": "^0.18.3",
|
|
111
|
+
"rollup": "^2.59.0",
|
|
107
112
|
"rollup-plugin-ascii": "^0.0.3",
|
|
108
113
|
"rollup-plugin-banner": "^0.2.1",
|
|
109
114
|
"rollup-plugin-cleanup": "^3.2.1",
|
|
110
|
-
"rollup-plugin-dts": "^
|
|
115
|
+
"rollup-plugin-dts": "^4.0.0",
|
|
111
116
|
"rollup-plugin-terser": "^7.0.2",
|
|
112
|
-
"tap": "^
|
|
113
|
-
"tslib": "^2.
|
|
114
|
-
"typescript": "^4.
|
|
117
|
+
"tap": "^15.0.10",
|
|
118
|
+
"tslib": "^2.3.1",
|
|
119
|
+
"typescript": "^4.4.4"
|
|
120
|
+
},
|
|
121
|
+
"engines": {
|
|
122
|
+
"node": ">=12"
|
|
115
123
|
}
|
|
116
124
|
}
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @name string-range-expander
|
|
3
|
-
* @fileoverview Expands string index ranges within whitespace boundaries until letters are met
|
|
4
|
-
* @version 2.1.0
|
|
5
|
-
* @author Roy Revelt, Codsen Ltd
|
|
6
|
-
* @license MIT
|
|
7
|
-
* {@link https://codsen.com/os/string-range-expander/}
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
13
|
-
|
|
14
|
-
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
15
|
-
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
16
|
-
|
|
17
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
18
|
-
|
|
19
|
-
var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread);
|
|
20
|
-
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
|
|
21
|
-
|
|
22
|
-
var version$1 = "2.1.0";
|
|
23
|
-
|
|
24
|
-
var version = version$1;
|
|
25
|
-
var defaults = {
|
|
26
|
-
str: "",
|
|
27
|
-
from: 0,
|
|
28
|
-
to: 0,
|
|
29
|
-
ifLeftSideIncludesThisThenCropTightly: "",
|
|
30
|
-
ifLeftSideIncludesThisCropItToo: "",
|
|
31
|
-
ifRightSideIncludesThisThenCropTightly: "",
|
|
32
|
-
ifRightSideIncludesThisCropItToo: "",
|
|
33
|
-
extendToOneSide: false,
|
|
34
|
-
wipeAllWhitespaceOnLeft: false,
|
|
35
|
-
wipeAllWhitespaceOnRight: false,
|
|
36
|
-
addSingleSpaceToPreventAccidentalConcatenation: false
|
|
37
|
-
};
|
|
38
|
-
function expander(originalOpts) {
|
|
39
|
-
var letterOrDigit = /^[0-9a-zA-Z]+$/;
|
|
40
|
-
function isWhitespace(_char) {
|
|
41
|
-
if (!_char || typeof _char !== "string") {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
return !_char.trim();
|
|
45
|
-
}
|
|
46
|
-
function isStr(something) {
|
|
47
|
-
return typeof something === "string";
|
|
48
|
-
}
|
|
49
|
-
if (!originalOpts || _typeof__default['default'](originalOpts) !== "object" || Array.isArray(originalOpts)) {
|
|
50
|
-
var supplementalString;
|
|
51
|
-
if (originalOpts === undefined) {
|
|
52
|
-
supplementalString = "but it is missing completely.";
|
|
53
|
-
} else if (originalOpts === null) {
|
|
54
|
-
supplementalString = "but it was given as null.";
|
|
55
|
-
} else {
|
|
56
|
-
supplementalString = "but it was given as ".concat(_typeof__default['default'](originalOpts), ", equal to:\n").concat(JSON.stringify(originalOpts, null, 4), ".");
|
|
57
|
-
}
|
|
58
|
-
throw new Error("string-range-expander: [THROW_ID_01] Input must be a plain object ".concat(supplementalString));
|
|
59
|
-
} else if (_typeof__default['default'](originalOpts) === "object" && originalOpts !== null && !Array.isArray(originalOpts) && !Object.keys(originalOpts).length) {
|
|
60
|
-
throw new Error("string-range-expander: [THROW_ID_02] Input must be a plain object but it was given as a plain object without any keys.");
|
|
61
|
-
}
|
|
62
|
-
if (typeof originalOpts.from !== "number") {
|
|
63
|
-
throw new Error("string-range-expander: [THROW_ID_03] The input's \"from\" value opts.from, is not a number! Currently it's given as ".concat(_typeof__default['default'](originalOpts.from), ", equal to ").concat(JSON.stringify(originalOpts.from, null, 0)));
|
|
64
|
-
}
|
|
65
|
-
if (typeof originalOpts.to !== "number") {
|
|
66
|
-
throw new Error("string-range-expander: [THROW_ID_04] The input's \"to\" value opts.to, is not a number! Currently it's given as ".concat(_typeof__default['default'](originalOpts.to), ", equal to ").concat(JSON.stringify(originalOpts.to, null, 0)));
|
|
67
|
-
}
|
|
68
|
-
if (originalOpts && originalOpts.str && !originalOpts.str[originalOpts.from] && originalOpts.from !== originalOpts.to) {
|
|
69
|
-
throw new Error("string-range-expander: [THROW_ID_05] The given input string opts.str (\"".concat(originalOpts.str, "\") must contain the character at index \"from\" (\"").concat(originalOpts.from, "\")"));
|
|
70
|
-
}
|
|
71
|
-
if (originalOpts && originalOpts.str && !originalOpts.str[originalOpts.to - 1]) {
|
|
72
|
-
throw new Error("string-range-expander: [THROW_ID_06] The given input string, opts.str (\"".concat(originalOpts.str, "\") must contain the character at index before \"to\" (\"").concat(originalOpts.to - 1, "\")"));
|
|
73
|
-
}
|
|
74
|
-
if (originalOpts.from > originalOpts.to) {
|
|
75
|
-
throw new Error("string-range-expander: [THROW_ID_07] The given \"from\" index, \"".concat(originalOpts.from, "\" is greater than \"to\" index, \"").concat(originalOpts.to, "\". That's wrong!"));
|
|
76
|
-
}
|
|
77
|
-
if (isStr(originalOpts.extendToOneSide) && originalOpts.extendToOneSide !== "left" && originalOpts.extendToOneSide !== "right" || !isStr(originalOpts.extendToOneSide) && originalOpts.extendToOneSide !== undefined && originalOpts.extendToOneSide !== false) {
|
|
78
|
-
throw new Error("string-range-expander: [THROW_ID_08] The opts.extendToOneSide value is not recogniseable! It's set to: \"".concat(originalOpts.extendToOneSide, "\" (").concat(_typeof__default['default'](originalOpts.extendToOneSide), "). It has to be either Boolean \"false\" or strings \"left\" or \"right\""));
|
|
79
|
-
}
|
|
80
|
-
var opts = _objectSpread__default['default'](_objectSpread__default['default']({}, defaults), originalOpts);
|
|
81
|
-
if (Array.isArray(opts.ifLeftSideIncludesThisThenCropTightly)) {
|
|
82
|
-
var culpritsIndex;
|
|
83
|
-
var culpritsValue;
|
|
84
|
-
if (opts.ifLeftSideIncludesThisThenCropTightly.every(function (val, i) {
|
|
85
|
-
if (!isStr(val)) {
|
|
86
|
-
culpritsIndex = i;
|
|
87
|
-
culpritsValue = val;
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
return true;
|
|
91
|
-
})) {
|
|
92
|
-
opts.ifLeftSideIncludesThisThenCropTightly = opts.ifLeftSideIncludesThisThenCropTightly.join("");
|
|
93
|
-
} else {
|
|
94
|
-
throw new Error("string-range-expander: [THROW_ID_09] The opts.ifLeftSideIncludesThisThenCropTightly was set to an array:\n".concat(JSON.stringify(opts.ifLeftSideIncludesThisThenCropTightly, null, 4), ". Now, that array contains not only string elements. For example, an element at index ").concat(culpritsIndex, " is of a type ").concat(_typeof__default['default'](culpritsValue), " (equal to ").concat(JSON.stringify(culpritsValue, null, 0), ")."));
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
var str = opts.str;
|
|
98
|
-
var from = opts.from;
|
|
99
|
-
var to = opts.to;
|
|
100
|
-
if (opts.extendToOneSide !== "right" && (isWhitespace(str[from - 1]) && (isWhitespace(str[from - 2]) || opts.ifLeftSideIncludesThisCropItToo.includes(str[from - 2])) || str[from - 1] && opts.ifLeftSideIncludesThisCropItToo.includes(str[from - 1]) || opts.wipeAllWhitespaceOnLeft && isWhitespace(str[from - 1]))) {
|
|
101
|
-
for (var i = from; i--;) {
|
|
102
|
-
if (!opts.ifLeftSideIncludesThisCropItToo.includes(str[i])) {
|
|
103
|
-
if (str[i].trim()) {
|
|
104
|
-
if (opts.wipeAllWhitespaceOnLeft || opts.ifLeftSideIncludesThisCropItToo.includes(str[i + 1])) {
|
|
105
|
-
from = i + 1;
|
|
106
|
-
} else {
|
|
107
|
-
from = i + 2;
|
|
108
|
-
}
|
|
109
|
-
break;
|
|
110
|
-
} else if (i === 0) {
|
|
111
|
-
if (opts.wipeAllWhitespaceOnLeft) {
|
|
112
|
-
from = 0;
|
|
113
|
-
} else {
|
|
114
|
-
from = 1;
|
|
115
|
-
}
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (opts.extendToOneSide !== "left" && (isWhitespace(str[to]) && (opts.wipeAllWhitespaceOnRight || isWhitespace(str[to + 1])) || opts.ifRightSideIncludesThisCropItToo.includes(str[to]))) {
|
|
122
|
-
for (var _i = to, len = str.length; _i < len; _i++) {
|
|
123
|
-
if (!opts.ifRightSideIncludesThisCropItToo.includes(str[_i]) && (str[_i] && str[_i].trim() || str[_i] === undefined)) {
|
|
124
|
-
if (opts.wipeAllWhitespaceOnRight || opts.ifRightSideIncludesThisCropItToo.includes(str[_i - 1])) {
|
|
125
|
-
to = _i;
|
|
126
|
-
} else {
|
|
127
|
-
to = _i - 1;
|
|
128
|
-
}
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (opts.extendToOneSide !== "right" && isStr(opts.ifLeftSideIncludesThisThenCropTightly) && opts.ifLeftSideIncludesThisThenCropTightly && (str[from - 2] && opts.ifLeftSideIncludesThisThenCropTightly.includes(str[from - 2]) || str[from - 1] && opts.ifLeftSideIncludesThisThenCropTightly.includes(str[from - 1])) || opts.extendToOneSide !== "left" && isStr(opts.ifRightSideIncludesThisThenCropTightly) && opts.ifRightSideIncludesThisThenCropTightly && (str[to + 1] && opts.ifRightSideIncludesThisThenCropTightly.includes(str[to + 1]) || str[to] && opts.ifRightSideIncludesThisThenCropTightly.includes(str[to]))) {
|
|
134
|
-
if (opts.extendToOneSide !== "right" && isWhitespace(str[from - 1]) && !opts.wipeAllWhitespaceOnLeft) {
|
|
135
|
-
from -= 1;
|
|
136
|
-
}
|
|
137
|
-
if (opts.extendToOneSide !== "left" && isWhitespace(str[to]) && !opts.wipeAllWhitespaceOnRight) {
|
|
138
|
-
to += 1;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (opts.addSingleSpaceToPreventAccidentalConcatenation && str[from - 1] && str[from - 1].trim() && str[to] && str[to].trim() && (!opts.ifLeftSideIncludesThisThenCropTightly && !opts.ifRightSideIncludesThisThenCropTightly || !((!opts.ifLeftSideIncludesThisThenCropTightly || opts.ifLeftSideIncludesThisThenCropTightly.includes(str[from - 1])) && (!opts.ifRightSideIncludesThisThenCropTightly || str[to] && opts.ifRightSideIncludesThisThenCropTightly.includes(str[to])))) && (letterOrDigit.test(str[from - 1]) || letterOrDigit.test(str[to]))) {
|
|
142
|
-
return [from, to, " "];
|
|
143
|
-
}
|
|
144
|
-
return [from, to];
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
exports.defaults = defaults;
|
|
148
|
-
exports.expander = expander;
|
|
149
|
-
exports.version = version;
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @name string-range-expander
|
|
3
|
-
* @fileoverview Expands string index ranges within whitespace boundaries until letters are met
|
|
4
|
-
* @version 2.1.0
|
|
5
|
-
* @author Roy Revelt, Codsen Ltd
|
|
6
|
-
* @license MIT
|
|
7
|
-
* {@link https://codsen.com/os/string-range-expander/}
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
(function (global, factory) {
|
|
11
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
12
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
13
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.stringRangeExpander = {}));
|
|
14
|
-
}(this, (function (exports) { 'use strict';
|
|
15
|
-
|
|
16
|
-
var version$1 = "2.1.0";
|
|
17
|
-
|
|
18
|
-
const version = version$1;
|
|
19
|
-
const defaults = {
|
|
20
|
-
str: "",
|
|
21
|
-
from: 0,
|
|
22
|
-
to: 0,
|
|
23
|
-
ifLeftSideIncludesThisThenCropTightly: "",
|
|
24
|
-
ifLeftSideIncludesThisCropItToo: "",
|
|
25
|
-
ifRightSideIncludesThisThenCropTightly: "",
|
|
26
|
-
ifRightSideIncludesThisCropItToo: "",
|
|
27
|
-
extendToOneSide: false,
|
|
28
|
-
wipeAllWhitespaceOnLeft: false,
|
|
29
|
-
wipeAllWhitespaceOnRight: false,
|
|
30
|
-
addSingleSpaceToPreventAccidentalConcatenation: false,
|
|
31
|
-
};
|
|
32
|
-
function expander(originalOpts) {
|
|
33
|
-
const letterOrDigit = /^[0-9a-zA-Z]+$/;
|
|
34
|
-
// Internal functions
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
function isWhitespace(char) {
|
|
37
|
-
if (!char || typeof char !== "string") {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
return !char.trim();
|
|
41
|
-
}
|
|
42
|
-
function isStr(something) {
|
|
43
|
-
return typeof something === "string";
|
|
44
|
-
}
|
|
45
|
-
// Sanitise the inputs
|
|
46
|
-
// ---------------------------------------------------------------------------
|
|
47
|
-
if (!originalOpts ||
|
|
48
|
-
typeof originalOpts !== "object" ||
|
|
49
|
-
Array.isArray(originalOpts)) {
|
|
50
|
-
let supplementalString;
|
|
51
|
-
if (originalOpts === undefined) {
|
|
52
|
-
supplementalString = "but it is missing completely.";
|
|
53
|
-
}
|
|
54
|
-
else if (originalOpts === null) {
|
|
55
|
-
supplementalString = "but it was given as null.";
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
supplementalString = `but it was given as ${typeof originalOpts}, equal to:\n${JSON.stringify(originalOpts, null, 4)}.`;
|
|
59
|
-
}
|
|
60
|
-
throw new Error(`string-range-expander: [THROW_ID_01] Input must be a plain object ${supplementalString}`);
|
|
61
|
-
}
|
|
62
|
-
else if (typeof originalOpts === "object" &&
|
|
63
|
-
originalOpts !== null &&
|
|
64
|
-
!Array.isArray(originalOpts) &&
|
|
65
|
-
!Object.keys(originalOpts).length) {
|
|
66
|
-
throw new Error(`string-range-expander: [THROW_ID_02] Input must be a plain object but it was given as a plain object without any keys.`);
|
|
67
|
-
}
|
|
68
|
-
if (typeof originalOpts.from !== "number") {
|
|
69
|
-
throw new Error(`string-range-expander: [THROW_ID_03] The input's "from" value opts.from, is not a number! Currently it's given as ${typeof originalOpts.from}, equal to ${JSON.stringify(originalOpts.from, null, 0)}`);
|
|
70
|
-
}
|
|
71
|
-
if (typeof originalOpts.to !== "number") {
|
|
72
|
-
throw new Error(`string-range-expander: [THROW_ID_04] The input's "to" value opts.to, is not a number! Currently it's given as ${typeof originalOpts.to}, equal to ${JSON.stringify(originalOpts.to, null, 0)}`);
|
|
73
|
-
}
|
|
74
|
-
if (originalOpts &&
|
|
75
|
-
originalOpts.str &&
|
|
76
|
-
!originalOpts.str[originalOpts.from] &&
|
|
77
|
-
originalOpts.from !== originalOpts.to) {
|
|
78
|
-
throw new Error(`string-range-expander: [THROW_ID_05] The given input string opts.str ("${originalOpts.str}") must contain the character at index "from" ("${originalOpts.from}")`);
|
|
79
|
-
}
|
|
80
|
-
if (originalOpts &&
|
|
81
|
-
originalOpts.str &&
|
|
82
|
-
!originalOpts.str[originalOpts.to - 1]) {
|
|
83
|
-
throw new Error(`string-range-expander: [THROW_ID_06] The given input string, opts.str ("${originalOpts.str}") must contain the character at index before "to" ("${originalOpts.to - 1}")`);
|
|
84
|
-
}
|
|
85
|
-
if (originalOpts.from > originalOpts.to) {
|
|
86
|
-
throw new Error(`string-range-expander: [THROW_ID_07] The given "from" index, "${originalOpts.from}" is greater than "to" index, "${originalOpts.to}". That's wrong!`);
|
|
87
|
-
}
|
|
88
|
-
if ((isStr(originalOpts.extendToOneSide) &&
|
|
89
|
-
originalOpts.extendToOneSide !== "left" &&
|
|
90
|
-
originalOpts.extendToOneSide !== "right") ||
|
|
91
|
-
(!isStr(originalOpts.extendToOneSide) &&
|
|
92
|
-
originalOpts.extendToOneSide !== undefined &&
|
|
93
|
-
originalOpts.extendToOneSide !== false)) {
|
|
94
|
-
throw new Error(`string-range-expander: [THROW_ID_08] The opts.extendToOneSide value is not recogniseable! It's set to: "${originalOpts.extendToOneSide}" (${typeof originalOpts.extendToOneSide}). It has to be either Boolean "false" or strings "left" or "right"`);
|
|
95
|
-
}
|
|
96
|
-
// Prepare the opts
|
|
97
|
-
// ---------------------------------------------------------------------------
|
|
98
|
-
const opts = { ...defaults, ...originalOpts };
|
|
99
|
-
if (Array.isArray(opts.ifLeftSideIncludesThisThenCropTightly)) {
|
|
100
|
-
let culpritsIndex;
|
|
101
|
-
let culpritsValue;
|
|
102
|
-
if (opts.ifLeftSideIncludesThisThenCropTightly.every((val, i) => {
|
|
103
|
-
if (!isStr(val)) {
|
|
104
|
-
culpritsIndex = i;
|
|
105
|
-
culpritsValue = val;
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
return true;
|
|
109
|
-
})) {
|
|
110
|
-
opts.ifLeftSideIncludesThisThenCropTightly =
|
|
111
|
-
opts.ifLeftSideIncludesThisThenCropTightly.join("");
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
throw new Error(`string-range-expander: [THROW_ID_09] The opts.ifLeftSideIncludesThisThenCropTightly was set to an array:\n${JSON.stringify(opts.ifLeftSideIncludesThisThenCropTightly, null, 4)}. Now, that array contains not only string elements. For example, an element at index ${culpritsIndex} is of a type ${typeof culpritsValue} (equal to ${JSON.stringify(culpritsValue, null, 0)}).`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
// Action
|
|
118
|
-
// ---------------------------------------------------------------------------
|
|
119
|
-
const str = opts.str; // convenience
|
|
120
|
-
let from = opts.from;
|
|
121
|
-
let to = opts.to;
|
|
122
|
-
// 1. expand the given range outwards and leave a single space or
|
|
123
|
-
// {single-of-whatever-there-was} (like line break, tab etc) on each side
|
|
124
|
-
if (opts.extendToOneSide !== "right" &&
|
|
125
|
-
((isWhitespace(str[from - 1]) &&
|
|
126
|
-
(isWhitespace(str[from - 2]) ||
|
|
127
|
-
opts.ifLeftSideIncludesThisCropItToo.includes(str[from - 2]))) ||
|
|
128
|
-
(str[from - 1] &&
|
|
129
|
-
opts.ifLeftSideIncludesThisCropItToo.includes(str[from - 1])) ||
|
|
130
|
-
(opts.wipeAllWhitespaceOnLeft && isWhitespace(str[from - 1])))) {
|
|
131
|
-
// loop backwards
|
|
132
|
-
for (let i = from; i--;) {
|
|
133
|
-
if (!opts.ifLeftSideIncludesThisCropItToo.includes(str[i])) {
|
|
134
|
-
if (str[i].trim()) {
|
|
135
|
-
if (opts.wipeAllWhitespaceOnLeft ||
|
|
136
|
-
opts.ifLeftSideIncludesThisCropItToo.includes(str[i + 1])) {
|
|
137
|
-
from = i + 1;
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
from = i + 2;
|
|
141
|
-
}
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
else if (i === 0) {
|
|
145
|
-
if (opts.wipeAllWhitespaceOnLeft) {
|
|
146
|
-
from = 0;
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
from = 1;
|
|
150
|
-
}
|
|
151
|
-
break;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
// 2. expand forward
|
|
157
|
-
if (opts.extendToOneSide !== "left" &&
|
|
158
|
-
((isWhitespace(str[to]) &&
|
|
159
|
-
(opts.wipeAllWhitespaceOnRight || isWhitespace(str[to + 1]))) ||
|
|
160
|
-
opts.ifRightSideIncludesThisCropItToo.includes(str[to]))) {
|
|
161
|
-
// loop forward
|
|
162
|
-
for (let i = to, len = str.length; i < len; i++) {
|
|
163
|
-
if (!opts.ifRightSideIncludesThisCropItToo.includes(str[i]) &&
|
|
164
|
-
((str[i] && str[i].trim()) || str[i] === undefined)) {
|
|
165
|
-
if (opts.wipeAllWhitespaceOnRight ||
|
|
166
|
-
opts.ifRightSideIncludesThisCropItToo.includes(str[i - 1])) {
|
|
167
|
-
to = i;
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
to = i - 1;
|
|
171
|
-
}
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
// 3. tight crop adjustments
|
|
177
|
-
if ((opts.extendToOneSide !== "right" &&
|
|
178
|
-
isStr(opts.ifLeftSideIncludesThisThenCropTightly) &&
|
|
179
|
-
opts.ifLeftSideIncludesThisThenCropTightly &&
|
|
180
|
-
((str[from - 2] &&
|
|
181
|
-
opts.ifLeftSideIncludesThisThenCropTightly.includes(str[from - 2])) ||
|
|
182
|
-
(str[from - 1] &&
|
|
183
|
-
opts.ifLeftSideIncludesThisThenCropTightly.includes(str[from - 1])))) ||
|
|
184
|
-
(opts.extendToOneSide !== "left" &&
|
|
185
|
-
isStr(opts.ifRightSideIncludesThisThenCropTightly) &&
|
|
186
|
-
opts.ifRightSideIncludesThisThenCropTightly &&
|
|
187
|
-
((str[to + 1] &&
|
|
188
|
-
opts.ifRightSideIncludesThisThenCropTightly.includes(str[to + 1])) ||
|
|
189
|
-
(str[to] &&
|
|
190
|
-
opts.ifRightSideIncludesThisThenCropTightly.includes(str[to]))))) {
|
|
191
|
-
if (opts.extendToOneSide !== "right" &&
|
|
192
|
-
isWhitespace(str[from - 1]) &&
|
|
193
|
-
!opts.wipeAllWhitespaceOnLeft) {
|
|
194
|
-
from -= 1;
|
|
195
|
-
}
|
|
196
|
-
if (opts.extendToOneSide !== "left" &&
|
|
197
|
-
isWhitespace(str[to]) &&
|
|
198
|
-
!opts.wipeAllWhitespaceOnRight) {
|
|
199
|
-
to += 1;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
if (opts.addSingleSpaceToPreventAccidentalConcatenation &&
|
|
203
|
-
str[from - 1] &&
|
|
204
|
-
str[from - 1].trim() &&
|
|
205
|
-
str[to] &&
|
|
206
|
-
str[to].trim() &&
|
|
207
|
-
((!opts.ifLeftSideIncludesThisThenCropTightly &&
|
|
208
|
-
!opts.ifRightSideIncludesThisThenCropTightly) ||
|
|
209
|
-
!((!opts.ifLeftSideIncludesThisThenCropTightly ||
|
|
210
|
-
opts.ifLeftSideIncludesThisThenCropTightly.includes(str[from - 1])) &&
|
|
211
|
-
(!opts.ifRightSideIncludesThisThenCropTightly ||
|
|
212
|
-
(str[to] &&
|
|
213
|
-
opts.ifRightSideIncludesThisThenCropTightly.includes(str[to]))))) &&
|
|
214
|
-
(letterOrDigit.test(str[from - 1]) || letterOrDigit.test(str[to]))) {
|
|
215
|
-
return [from, to, " "];
|
|
216
|
-
}
|
|
217
|
-
return [from, to];
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
exports.defaults = defaults;
|
|
221
|
-
exports.expander = expander;
|
|
222
|
-
exports.version = version;
|
|
223
|
-
|
|
224
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
225
|
-
|
|
226
|
-
})));
|