string-trim-spaces-only 4.0.2 → 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.
- package/CHANGELOG.md +0 -6
- package/LICENSE +1 -1
- package/dist/string-trim-spaces-only.esm.js +68 -61
- package/dist/string-trim-spaces-only.umd.js +2 -2
- package/package.json +36 -40
package/CHANGELOG.md
CHANGED
|
@@ -3,12 +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
|
-
## 4.0.1 (2021-09-13)
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
- bump TS and separate ESLint plugins away from this monorepo ([2e07d42](https://github.com/codsen/codsen/commit/2e07d424222b6ffedf5fb45c83ad453627ec2904))
|
|
11
|
-
|
|
12
6
|
## 4.0.0 (2021-09-09)
|
|
13
7
|
|
|
14
8
|
### Features
|
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2010
|
|
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
|
|
@@ -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.
|
|
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.
|
|
10
|
+
var version$1 = "4.0.6";
|
|
11
11
|
|
|
12
12
|
const version = version$1;
|
|
13
13
|
const defaults = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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 (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
60
|
-
|
|
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
|
-
|
|
76
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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,9 +34,10 @@
|
|
|
34
34
|
"types": "types/index.d.ts",
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "rollup -c",
|
|
37
|
-
"esbuild": "node '../../scripts/esbuild.js'",
|
|
38
|
-
"
|
|
39
|
-
"ci_test": "npm run build && npm run format && tap --no-only --reporter=silent
|
|
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",
|
|
40
|
+
"clean_types": "../../scripts/cleanTypes.js",
|
|
40
41
|
"dev": "rollup -c --dev",
|
|
41
42
|
"devunittest": "npm run dev && tap --only -R 'base'",
|
|
42
43
|
"format": "npm run lect && npm run prettier && npm run lint",
|
|
@@ -46,20 +47,15 @@
|
|
|
46
47
|
"prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
|
|
47
48
|
"republish": "npm publish || :",
|
|
48
49
|
"tap": "tap",
|
|
49
|
-
"tsc": "tsc",
|
|
50
50
|
"pretest": "npm run build",
|
|
51
|
-
"test": "npm run
|
|
51
|
+
"test": "npm run test:ci && npm run perf",
|
|
52
|
+
"test:ci": "npm run unittest && npm run test:examples && npm run format",
|
|
52
53
|
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"clean_types": "../../scripts/cleanTypes.js"
|
|
54
|
+
"tsc": "tsc",
|
|
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,47 +75,47 @@
|
|
|
79
75
|
}
|
|
80
76
|
},
|
|
81
77
|
"dependencies": {
|
|
82
|
-
"@babel/runtime": "^7.
|
|
78
|
+
"@babel/runtime": "^7.16.3"
|
|
83
79
|
},
|
|
84
80
|
"devDependencies": {
|
|
85
|
-
"@babel/cli": "^7.
|
|
86
|
-
"@babel/core": "^7.
|
|
87
|
-
"@babel/node": "^7.
|
|
88
|
-
"@babel/plugin-external-helpers": "^7.
|
|
89
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
90
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.
|
|
91
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.
|
|
92
|
-
"@babel/plugin-proposal-optional-chaining": "^7.
|
|
93
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
94
|
-
"@babel/preset-env": "^7.
|
|
95
|
-
"@babel/preset-typescript": "^7.
|
|
96
|
-
"@babel/register": "^7.
|
|
81
|
+
"@babel/cli": "^7.16.0",
|
|
82
|
+
"@babel/core": "^7.16.0",
|
|
83
|
+
"@babel/node": "^7.16.0",
|
|
84
|
+
"@babel/plugin-external-helpers": "^7.16.0",
|
|
85
|
+
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
86
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
87
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
88
|
+
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
89
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
90
|
+
"@babel/preset-env": "^7.16.4",
|
|
91
|
+
"@babel/preset-typescript": "^7.16.0",
|
|
92
|
+
"@babel/register": "^7.16.0",
|
|
97
93
|
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
98
94
|
"@rollup/plugin-babel": "^5.3.0",
|
|
99
|
-
"@rollup/plugin-commonjs": "^
|
|
95
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
100
96
|
"@rollup/plugin-json": "^4.1.0",
|
|
101
|
-
"@rollup/plugin-node-resolve": "^13.0.
|
|
97
|
+
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
102
98
|
"@rollup/plugin-strip": "^2.1.0",
|
|
103
|
-
"@rollup/plugin-typescript": "^8.
|
|
104
|
-
"@types/node": "^16.9
|
|
99
|
+
"@rollup/plugin-typescript": "^8.3.0",
|
|
100
|
+
"@types/node": "^16.11.9",
|
|
105
101
|
"@types/tap": "^15.0.5",
|
|
106
|
-
"@typescript-eslint/eslint-plugin": "^4.
|
|
107
|
-
"@typescript-eslint/parser": "^4.
|
|
108
|
-
"core-js": "^3.
|
|
102
|
+
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
103
|
+
"@typescript-eslint/parser": "^5.4.0",
|
|
104
|
+
"core-js": "^3.19.1",
|
|
109
105
|
"cross-env": "^7.0.3",
|
|
110
|
-
"eslint": "^
|
|
111
|
-
"lect": "^0.18.
|
|
112
|
-
"rollup": "^2.
|
|
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
|
-
"rollup-plugin-dts": "^4.0.
|
|
112
|
+
"rollup-plugin-dts": "^4.0.1",
|
|
117
113
|
"rollup-plugin-terser": "^7.0.2",
|
|
118
|
-
"tap": "^15.
|
|
114
|
+
"tap": "^15.1.2",
|
|
119
115
|
"tslib": "^2.3.1",
|
|
120
|
-
"typescript": "^4.
|
|
116
|
+
"typescript": "^4.5.2"
|
|
121
117
|
},
|
|
122
118
|
"engines": {
|
|
123
|
-
"node": ">=
|
|
119
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
124
120
|
}
|
|
125
121
|
}
|