string-trim-spaces-only 4.0.7 → 4.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/README.md +4 -1
- package/dist/string-trim-spaces-only.esm.js +4 -84
- package/dist/string-trim-spaces-only.umd.js +4 -2
- package/examples/_quickTake.js +1 -0
- package/package.json +21 -76
- package/types/index.d.ts +0 -1
- package/examples/api.json +0 -1
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ If you need a legacy version which works with `require`, use version 3.1.0
|
|
|
38
38
|
|
|
39
39
|
```js
|
|
40
40
|
import { strict as assert } from "assert";
|
|
41
|
+
|
|
41
42
|
import { trimSpaces } from "string-trim-spaces-only";
|
|
42
43
|
|
|
43
44
|
assert.deepEqual(trimSpaces(" aaa "), {
|
|
@@ -59,7 +60,7 @@ assert.deepEqual(trimSpaces(" \t zz \n "), {
|
|
|
59
60
|
|
|
60
61
|
## Documentation
|
|
61
62
|
|
|
62
|
-
Please [visit codsen.com](https://codsen.com/os/string-trim-spaces-only/) for a full description of the API
|
|
63
|
+
Please [visit codsen.com](https://codsen.com/os/string-trim-spaces-only/) for a full description of the API.
|
|
63
64
|
|
|
64
65
|
## Contributing
|
|
65
66
|
|
|
@@ -71,4 +72,6 @@ MIT License
|
|
|
71
72
|
|
|
72
73
|
Copyright (c) 2010-2021 Roy Revelt and other contributors
|
|
73
74
|
|
|
75
|
+
|
|
74
76
|
<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">
|
|
77
|
+
|
|
@@ -1,92 +1,12 @@
|
|
|
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.10
|
|
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
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const defaults = {
|
|
14
|
-
classicTrim: false,
|
|
15
|
-
cr: false,
|
|
16
|
-
lf: false,
|
|
17
|
-
tab: false,
|
|
18
|
-
space: true,
|
|
19
|
-
nbsp: false,
|
|
20
|
-
};
|
|
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, ...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
|
-
}
|
|
51
|
-
}
|
|
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
|
-
}
|
|
59
|
-
}
|
|
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
|
-
};
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
res: str,
|
|
83
|
-
ranges: [],
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
res: "",
|
|
88
|
-
ranges: [],
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export { defaults, trimSpaces, version };
|
|
10
|
+
var l="4.0.10";var p=l,u={classicTrim:!1,cr:!1,lf:!1,tab:!1,space:!0,nbsp:!1};function d(e,i){if(typeof e!="string")throw new Error(`string-trim-spaces-only: [THROW_ID_01] input must be string! It was given as ${typeof e}, equal to:
|
|
11
|
+
${JSON.stringify(e,null,4)}`);let s={...u,...i};function o(n){return s.classicTrim&&!n.trim()||!s.classicTrim&&(s.space&&n===" "||s.cr&&n==="\r"||s.lf&&n===`
|
|
12
|
+
`||s.tab&&n===" "||s.nbsp&&n==="\xA0")}let r,t;if(e.length){if(o(e[0]))for(let n=0,a=e.length;n<a;n++){if(!o(e[n])){r=n;break}if(n===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(o(e[e.length-1])){for(let n=e.length;n--;)if(!o(e[n])){t=n+1;break}}return r?t?{res:e.slice(r,t),ranges:[[0,r],[t,e.length]]}:{res:e.slice(r),ranges:[[0,r]]}:t?{res:e.slice(0,t),ranges:[[t,e.length]]}:{res:e,ranges:[]}}return{res:"",ranges:[]}}export{u as defaults,d as trimSpaces,p as version};
|
|
@@ -1,10 +1,12 @@
|
|
|
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.10
|
|
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
|
-
|
|
10
|
+
var stringTrimSpacesOnly=(()=>{var i=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames,c=Object.getOwnPropertySymbols;var u=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable;var m=(e,s,n)=>s in e?i(e,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[s]=n,a=(e,s)=>{for(var n in s||(s={}))u.call(s,n)&&m(e,n,s[n]);if(c)for(var n of c(s))f.call(s,n)&&m(e,n,s[n]);return e};var y=e=>i(e,"__esModule",{value:!0});var h=(e,s)=>{for(var n in s)i(e,n,{get:s[n],enumerable:!0})},E=(e,s,n,o)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of $(s))!u.call(e,r)&&(n||r!=="default")&&i(e,r,{get:()=>s[r],enumerable:!(o=b(s,r))||o.enumerable});return e};var w=(e=>(s,n)=>e&&e.get(s)||(n=E(y({}),s,1),e&&e.set(s,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var R={};h(R,{defaults:()=>p,trimSpaces:()=>V,version:()=>S});var g="4.0.10";var S=g,p={classicTrim:!1,cr:!1,lf:!1,tab:!1,space:!0,nbsp:!1};function V(e,s){if(typeof e!="string")throw new Error(`string-trim-spaces-only: [THROW_ID_01] input must be string! It was given as ${typeof e}, equal to:
|
|
11
|
+
${JSON.stringify(e,null,4)}`);let n=a(a({},p),s);function o(t){return n.classicTrim&&!t.trim()||!n.classicTrim&&(n.space&&t===" "||n.cr&&t==="\r"||n.lf&&t===`
|
|
12
|
+
`||n.tab&&t===" "||n.nbsp&&t==="\xA0")}let r,l;if(e.length){if(o(e[0]))for(let t=0,d=e.length;t<d;t++){if(!o(e[t])){r=t;break}if(t===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(o(e[e.length-1])){for(let t=e.length;t--;)if(!o(e[t])){l=t+1;break}}return r?l?{res:e.slice(r,l),ranges:[[0,r],[l,e.length]]}:{res:e.slice(r),ranges:[[0,r]]}:l?{res:e.slice(0,l),ranges:[[l,e.length]]}:{res:e,ranges:[]}}return{res:"",ranges:[]}}return w(R);})();
|
package/examples/_quickTake.js
CHANGED
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.10",
|
|
4
4
|
"description": "Like String.trim() but you can choose granularly what to trim",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"characters",
|
|
@@ -33,89 +33,34 @@
|
|
|
33
33
|
},
|
|
34
34
|
"types": "types/index.d.ts",
|
|
35
35
|
"scripts": {
|
|
36
|
-
"build": "
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"republish": "npm publish || :",
|
|
49
|
-
"tap": "tap",
|
|
50
|
-
"pretest": "npm run build",
|
|
51
|
-
"test": "npm run test:ci && npm run perf",
|
|
52
|
-
"test:ci": "npm run unittest && npm run test:examples && npm run format",
|
|
53
|
-
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
54
|
-
"tsc": "tsc",
|
|
55
|
-
"unittest": "tap --no-only --reporter=terse && tsc -p tsconfig.json --noEmit"
|
|
36
|
+
"build": "node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
37
|
+
"dev": "DEV=true node '../../ops/scripts/esbuild.js' && yarn run dts",
|
|
38
|
+
"dts": "rollup -c",
|
|
39
|
+
"examples": "node '../../ops/scripts/run-examples.js'",
|
|
40
|
+
"lect": "node '../../ops/lect/lect.js'",
|
|
41
|
+
"letspublish": "yarn publish || :",
|
|
42
|
+
"lint": "eslint . --fix",
|
|
43
|
+
"perf": "node perf/check.js",
|
|
44
|
+
"prepare": "echo 'ready'",
|
|
45
|
+
"pretest": "yarn run lect && yarn run build",
|
|
46
|
+
"test": "c8 yarn run unit && yarn run examples && yarn run lint",
|
|
47
|
+
"unit": "uvu test"
|
|
56
48
|
},
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
51
|
+
},
|
|
52
|
+
"c8": {
|
|
53
|
+
"check-coverage": true,
|
|
54
|
+
"exclude": [
|
|
55
|
+
"**/test/**/*.*"
|
|
63
56
|
],
|
|
64
|
-
"
|
|
57
|
+
"lines": 100
|
|
65
58
|
},
|
|
66
59
|
"lect": {
|
|
67
60
|
"licence": {
|
|
68
61
|
"extras": [
|
|
69
62
|
""
|
|
70
63
|
]
|
|
71
|
-
},
|
|
72
|
-
"req": "{ trimSpaces }",
|
|
73
|
-
"various": {
|
|
74
|
-
"devDependencies": []
|
|
75
64
|
}
|
|
76
|
-
},
|
|
77
|
-
"dependencies": {
|
|
78
|
-
"@babel/runtime": "^7.16.3"
|
|
79
|
-
},
|
|
80
|
-
"devDependencies": {
|
|
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",
|
|
93
|
-
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
94
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
95
|
-
"@rollup/plugin-commonjs": "^21.0.1",
|
|
96
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
97
|
-
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
98
|
-
"@rollup/plugin-strip": "^2.1.0",
|
|
99
|
-
"@rollup/plugin-typescript": "^8.3.0",
|
|
100
|
-
"@types/node": "^16.11.10",
|
|
101
|
-
"@types/tap": "^15.0.5",
|
|
102
|
-
"@typescript-eslint/eslint-plugin": "^5.5.0",
|
|
103
|
-
"@typescript-eslint/parser": "^5.5.0",
|
|
104
|
-
"core-js": "^3.19.2",
|
|
105
|
-
"cross-env": "^7.0.3",
|
|
106
|
-
"eslint": "^8.3.0",
|
|
107
|
-
"lect": "^0.18.7",
|
|
108
|
-
"rollup": "^2.60.1",
|
|
109
|
-
"rollup-plugin-ascii": "^0.0.3",
|
|
110
|
-
"rollup-plugin-banner": "^0.2.1",
|
|
111
|
-
"rollup-plugin-cleanup": "^3.2.1",
|
|
112
|
-
"rollup-plugin-dts": "^4.0.1",
|
|
113
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
114
|
-
"tap": "^15.1.5",
|
|
115
|
-
"tslib": "^2.3.1",
|
|
116
|
-
"typescript": "^4.5.2"
|
|
117
|
-
},
|
|
118
|
-
"engines": {
|
|
119
|
-
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
120
65
|
}
|
|
121
66
|
}
|
package/types/index.d.ts
CHANGED
package/examples/api.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"_quickTake.js":{"title":"Quick Take","content":"import { strict as assert } from \"assert\";\nimport { trimSpaces } from \"string-trim-spaces-only\";\n\nassert.deepEqual(trimSpaces(\" aaa \"), {\n res: \"aaa\",\n ranges: [\n [0, 2],\n [5, 8],\n ],\n});\n\nassert.deepEqual(trimSpaces(\" \\t zz \\n \"), {\n res: \"\\t zz \\n\",\n ranges: [\n [0, 3],\n [12, 16],\n ],\n});"}}
|