string-trim-spaces-only 4.0.5 → 4.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.
@@ -1,85 +1,92 @@
1
1
  /**
2
2
  * @name string-trim-spaces-only
3
3
  * @fileoverview Like String.trim() but you can choose granularly what to trim
4
- * @version 4.0.5
4
+ * @version 4.0.6
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/string-trim-spaces-only/}
8
8
  */
9
9
 
10
- var version$1 = "4.0.5";
10
+ var version$1 = "4.0.6";
11
11
 
12
12
  const version = version$1;
13
13
  const defaults = {
14
- classicTrim: false,
15
- cr: false,
16
- lf: false,
17
- tab: false,
18
- space: true,
19
- nbsp: false
14
+ classicTrim: false,
15
+ cr: false,
16
+ lf: false,
17
+ tab: false,
18
+ space: true,
19
+ nbsp: false,
20
20
  };
21
21
  function trimSpaces(str, originalOpts) {
22
- if (typeof str !== "string") {
23
- throw new Error(`string-trim-spaces-only: [THROW_ID_01] input must be string! It was given as ${typeof str}, equal to:\n${JSON.stringify(str, null, 4)}`);
24
- }
25
- const opts = { ...defaults,
26
- ...originalOpts
27
- };
28
- function check(char) {
29
- return opts.classicTrim && !char.trim() || !opts.classicTrim && (opts.space && char === " " || opts.cr && char === "\r" || opts.lf && char === "\n" || opts.tab && char === "\t" || opts.nbsp && char === "\u00a0");
30
- }
31
- let newStart;
32
- let newEnd;
33
- if (str.length) {
34
- if (check(str[0])) {
35
- for (let i = 0, len = str.length; i < len; i++) {
36
- if (!check(str[i])) {
37
- newStart = i;
38
- break;
22
+ if (typeof str !== "string") {
23
+ throw new Error(`string-trim-spaces-only: [THROW_ID_01] input must be string! It was given as ${typeof str}, equal to:\n${JSON.stringify(str, null, 4)}`);
24
+ }
25
+ const opts = { ...defaults, ...originalOpts };
26
+ function check(char) {
27
+ return ((opts.classicTrim && !char.trim()) ||
28
+ (!opts.classicTrim &&
29
+ ((opts.space && char === " ") ||
30
+ (opts.cr && char === "\r") ||
31
+ (opts.lf && char === "\n") ||
32
+ (opts.tab && char === "\t") ||
33
+ (opts.nbsp && char === "\u00a0"))));
34
+ }
35
+ let newStart;
36
+ let newEnd;
37
+ if (str.length) {
38
+ if (check(str[0])) {
39
+ for (let i = 0, len = str.length; i < len; i++) {
40
+ if (!check(str[i])) {
41
+ newStart = i;
42
+ break;
43
+ }
44
+ if (i === str.length - 1) {
45
+ return {
46
+ res: "",
47
+ ranges: [[0, str.length]],
48
+ };
49
+ }
50
+ }
39
51
  }
40
- if (i === str.length - 1) {
41
- return {
42
- res: "",
43
- ranges: [[0, str.length]]
44
- };
52
+ if (check(str[str.length - 1])) {
53
+ for (let i = str.length; i--;) {
54
+ if (!check(str[i])) {
55
+ newEnd = i + 1;
56
+ break;
57
+ }
58
+ }
45
59
  }
46
- }
47
- }
48
- if (check(str[str.length - 1])) {
49
- for (let i = str.length; i--;) {
50
- if (!check(str[i])) {
51
- newEnd = i + 1;
52
- break;
60
+ if (newStart) {
61
+ if (newEnd) {
62
+ return {
63
+ res: str.slice(newStart, newEnd),
64
+ ranges: [
65
+ [0, newStart],
66
+ [newEnd, str.length],
67
+ ],
68
+ };
69
+ }
70
+ return {
71
+ res: str.slice(newStart),
72
+ ranges: [[0, newStart]],
73
+ };
74
+ }
75
+ if (newEnd) {
76
+ return {
77
+ res: str.slice(0, newEnd),
78
+ ranges: [[newEnd, str.length]],
79
+ };
53
80
  }
54
- }
55
- }
56
- if (newStart) {
57
- if (newEnd) {
58
81
  return {
59
- res: str.slice(newStart, newEnd),
60
- ranges: [[0, newStart], [newEnd, str.length]]
82
+ res: str,
83
+ ranges: [],
61
84
  };
62
- }
63
- return {
64
- res: str.slice(newStart),
65
- ranges: [[0, newStart]]
66
- };
67
- }
68
- if (newEnd) {
69
- return {
70
- res: str.slice(0, newEnd),
71
- ranges: [[newEnd, str.length]]
72
- };
73
85
  }
74
86
  return {
75
- res: str,
76
- ranges: []
87
+ res: "",
88
+ ranges: [],
77
89
  };
78
- }
79
- return {
80
- res: "",
81
- ranges: []
82
- };
83
90
  }
84
91
 
85
92
  export { defaults, trimSpaces, version };
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * @name string-trim-spaces-only
3
3
  * @fileoverview Like String.trim() but you can choose granularly what to trim
4
- * @version 4.0.5
4
+ * @version 4.0.6
5
5
  * @author Roy Revelt, Codsen Ltd
6
6
  * @license MIT
7
7
  * {@link https://codsen.com/os/string-trim-spaces-only/}
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).stringTrimSpacesOnly={})}(this,(function(e){"use strict";const n={classicTrim:!1,cr:!1,lf:!1,tab:!1,space:!0,nbsp:!1};e.defaults=n,e.trimSpaces=function(e,t){if("string"!=typeof e)throw new Error(`string-trim-spaces-only: [THROW_ID_01] input must be string! It was given as ${typeof e}, equal to:\n${JSON.stringify(e,null,4)}`);const s={...n,...t};function r(e){return s.classicTrim&&!e.trim()||!s.classicTrim&&(s.space&&" "===e||s.cr&&"\r"===e||s.lf&&"\n"===e||s.tab&&"\t"===e||s.nbsp&&" "===e)}let i,l;if(e.length){if(r(e[0]))for(let n=0,t=e.length;n<t;n++){if(!r(e[n])){i=n;break}if(n===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(r(e[e.length-1]))for(let n=e.length;n--;)if(!r(e[n])){l=n+1;break}return i?l?{res:e.slice(i,l),ranges:[[0,i],[l,e.length]]}:{res:e.slice(i),ranges:[[0,i]]}:l?{res:e.slice(0,l),ranges:[[l,e.length]]}:{res:e,ranges:[]}}return{res:"",ranges:[]}},e.version="4.0.5",Object.defineProperty(e,"__esModule",{value:!0})}));
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).stringTrimSpacesOnly={})}(this,(function(e){"use strict";const n={classicTrim:!1,cr:!1,lf:!1,tab:!1,space:!0,nbsp:!1};e.defaults=n,e.trimSpaces=function(e,t){if("string"!=typeof e)throw new Error(`string-trim-spaces-only: [THROW_ID_01] input must be string! It was given as ${typeof e}, equal to:\n${JSON.stringify(e,null,4)}`);const s={...n,...t};function r(e){return s.classicTrim&&!e.trim()||!s.classicTrim&&(s.space&&" "===e||s.cr&&"\r"===e||s.lf&&"\n"===e||s.tab&&"\t"===e||s.nbsp&&" "===e)}let i,l;if(e.length){if(r(e[0]))for(let n=0,t=e.length;n<t;n++){if(!r(e[n])){i=n;break}if(n===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(r(e[e.length-1]))for(let n=e.length;n--;)if(!r(e[n])){l=n+1;break}return i?l?{res:e.slice(i,l),ranges:[[0,i],[l,e.length]]}:{res:e.slice(i),ranges:[[0,i]]}:l?{res:e.slice(0,l),ranges:[[l,e.length]]}:{res:e,ranges:[]}}return{res:"",ranges:[]}},e.version="4.0.6",Object.defineProperty(e,"__esModule",{value:!0})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-trim-spaces-only",
3
- "version": "4.0.5",
3
+ "version": "4.0.6",
4
4
  "description": "Like String.trim() but you can choose granularly what to trim",
5
5
  "keywords": [
6
6
  "characters",
@@ -34,13 +34,12 @@
34
34
  "types": "types/index.d.ts",
35
35
  "scripts": {
36
36
  "build": "rollup -c",
37
- "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent --output-file=testStats.md && npm run clean_cov",
38
- "clean_cov": "../../scripts/leaveCoverageTotalOnly.js",
37
+ "build:esbuild": "node '../../scripts/esbuild.js'",
38
+ "build:esbuild:dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
39
+ "ci_test": "npm run build && npm run format && tap --no-only --reporter=silent",
39
40
  "clean_types": "../../scripts/cleanTypes.js",
40
41
  "dev": "rollup -c --dev",
41
42
  "devunittest": "npm run dev && tap --only -R 'base'",
42
- "esbuild": "node '../../scripts/esbuild.js'",
43
- "esbuild_dev": "cross-env MODE=dev node '../../scripts/esbuild.js'",
44
43
  "format": "npm run lect && npm run prettier && npm run lint",
45
44
  "lect": "lect",
46
45
  "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
@@ -49,17 +48,14 @@
49
48
  "republish": "npm publish || :",
50
49
  "tap": "tap",
51
50
  "pretest": "npm run build",
52
- "test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
51
+ "test": "npm run test:ci && npm run perf",
52
+ "test:ci": "npm run unittest && npm run test:examples && npm run format",
53
53
  "test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
54
54
  "tsc": "tsc",
55
- "unittest": "tap --no-only --output-file=testStats.md --reporter=terse && tsc -p tsconfig.json --noEmit && npm run clean_cov && npm run perf"
55
+ "unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
56
56
  },
57
57
  "tap": {
58
58
  "check-coverage": false,
59
- "coverage-report": [
60
- "json-summary",
61
- "text"
62
- ],
63
59
  "node-arg": [
64
60
  "--no-warnings",
65
61
  "--experimental-loader",
@@ -79,7 +75,7 @@
79
75
  }
80
76
  },
81
77
  "dependencies": {
82
- "@babel/runtime": "^7.16.0"
78
+ "@babel/runtime": "^7.16.3"
83
79
  },
84
80
  "devDependencies": {
85
81
  "@babel/cli": "^7.16.0",
@@ -90,8 +86,8 @@
90
86
  "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
91
87
  "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
92
88
  "@babel/plugin-proposal-optional-chaining": "^7.16.0",
93
- "@babel/plugin-transform-runtime": "^7.16.0",
94
- "@babel/preset-env": "^7.16.0",
89
+ "@babel/plugin-transform-runtime": "^7.16.4",
90
+ "@babel/preset-env": "^7.16.4",
95
91
  "@babel/preset-typescript": "^7.16.0",
96
92
  "@babel/register": "^7.16.0",
97
93
  "@istanbuljs/esm-loader-hook": "^0.1.2",
@@ -101,25 +97,25 @@
101
97
  "@rollup/plugin-node-resolve": "^13.0.6",
102
98
  "@rollup/plugin-strip": "^2.1.0",
103
99
  "@rollup/plugin-typescript": "^8.3.0",
104
- "@types/node": "^16.11.6",
100
+ "@types/node": "^16.11.9",
105
101
  "@types/tap": "^15.0.5",
106
- "@typescript-eslint/eslint-plugin": "^5.3.0",
107
- "@typescript-eslint/parser": "^5.3.0",
102
+ "@typescript-eslint/eslint-plugin": "^5.4.0",
103
+ "@typescript-eslint/parser": "^5.4.0",
108
104
  "core-js": "^3.19.1",
109
105
  "cross-env": "^7.0.3",
110
- "eslint": "^8.2.0",
111
- "lect": "^0.18.5",
112
- "rollup": "^2.59.0",
106
+ "eslint": "^8.3.0",
107
+ "lect": "^0.18.6",
108
+ "rollup": "^2.60.0",
113
109
  "rollup-plugin-ascii": "^0.0.3",
114
110
  "rollup-plugin-banner": "^0.2.1",
115
111
  "rollup-plugin-cleanup": "^3.2.1",
116
112
  "rollup-plugin-dts": "^4.0.1",
117
113
  "rollup-plugin-terser": "^7.0.2",
118
- "tap": "^15.0.10",
114
+ "tap": "^15.1.2",
119
115
  "tslib": "^2.3.1",
120
- "typescript": "^4.4.4"
116
+ "typescript": "^4.5.2"
121
117
  },
122
118
  "engines": {
123
- "node": ">=12"
119
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
124
120
  }
125
121
  }