string-trim-spaces-only 4.0.4 → 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/CHANGELOG.md +0 -20
- package/LICENSE +1 -1
- package/README.md +4 -1
- package/dist/string-trim-spaces-only.esm.js +4 -77
- package/dist/string-trim-spaces-only.umd.js +4 -2
- package/examples/_quickTake.js +1 -0
- package/package.json +21 -80
- package/types/index.d.ts +0 -1
- package/examples/api.json +0 -1
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
|
-
## 4.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
|
-
## 4.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
|
## 4.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
|
|
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 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,85 +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,
|
|
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;
|
|
39
|
-
}
|
|
40
|
-
if (i === str.length - 1) {
|
|
41
|
-
return {
|
|
42
|
-
res: "",
|
|
43
|
-
ranges: [[0, str.length]]
|
|
44
|
-
};
|
|
45
|
-
}
|
|
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;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (newStart) {
|
|
57
|
-
if (newEnd) {
|
|
58
|
-
return {
|
|
59
|
-
res: str.slice(newStart, newEnd),
|
|
60
|
-
ranges: [[0, newStart], [newEnd, str.length]]
|
|
61
|
-
};
|
|
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
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
res: str,
|
|
76
|
-
ranges: []
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
return {
|
|
80
|
-
res: "",
|
|
81
|
-
ranges: []
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
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,93 +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
|
-
"prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
|
|
49
|
-
"republish": "npm publish || :",
|
|
50
|
-
"tap": "tap",
|
|
51
|
-
"pretest": "npm run build",
|
|
52
|
-
"test": "npm run lint && npm run unittest && npm run test:examples && npm run clean_cov && npm run format",
|
|
53
|
-
"test:examples": "../../scripts/test-examples.js && npm run lect && npm run prettier",
|
|
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"
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
"--no-warnings",
|
|
65
|
-
"--experimental-loader",
|
|
66
|
-
"@istanbuljs/esm-loader-hook"
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
51
|
+
},
|
|
52
|
+
"c8": {
|
|
53
|
+
"check-coverage": true,
|
|
54
|
+
"exclude": [
|
|
55
|
+
"**/test/**/*.*"
|
|
67
56
|
],
|
|
68
|
-
"
|
|
57
|
+
"lines": 100
|
|
69
58
|
},
|
|
70
59
|
"lect": {
|
|
71
60
|
"licence": {
|
|
72
61
|
"extras": [
|
|
73
62
|
""
|
|
74
63
|
]
|
|
75
|
-
},
|
|
76
|
-
"req": "{ trimSpaces }",
|
|
77
|
-
"various": {
|
|
78
|
-
"devDependencies": []
|
|
79
64
|
}
|
|
80
|
-
},
|
|
81
|
-
"dependencies": {
|
|
82
|
-
"@babel/runtime": "^7.16.0"
|
|
83
|
-
},
|
|
84
|
-
"devDependencies": {
|
|
85
|
-
"@babel/cli": "^7.16.0",
|
|
86
|
-
"@babel/core": "^7.16.0",
|
|
87
|
-
"@babel/node": "^7.16.0",
|
|
88
|
-
"@babel/plugin-external-helpers": "^7.16.0",
|
|
89
|
-
"@babel/plugin-proposal-class-properties": "^7.16.0",
|
|
90
|
-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
|
|
91
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.16.0",
|
|
92
|
-
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
|
|
93
|
-
"@babel/plugin-transform-runtime": "^7.16.0",
|
|
94
|
-
"@babel/preset-env": "^7.16.0",
|
|
95
|
-
"@babel/preset-typescript": "^7.16.0",
|
|
96
|
-
"@babel/register": "^7.16.0",
|
|
97
|
-
"@istanbuljs/esm-loader-hook": "^0.1.2",
|
|
98
|
-
"@rollup/plugin-babel": "^5.3.0",
|
|
99
|
-
"@rollup/plugin-commonjs": "^21.0.1",
|
|
100
|
-
"@rollup/plugin-json": "^4.1.0",
|
|
101
|
-
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
102
|
-
"@rollup/plugin-strip": "^2.1.0",
|
|
103
|
-
"@rollup/plugin-typescript": "^8.3.0",
|
|
104
|
-
"@types/node": "^16.11.6",
|
|
105
|
-
"@types/tap": "^15.0.5",
|
|
106
|
-
"@typescript-eslint/eslint-plugin": "^5.3.0",
|
|
107
|
-
"@typescript-eslint/parser": "^5.3.0",
|
|
108
|
-
"core-js": "^3.19.1",
|
|
109
|
-
"cross-env": "^7.0.3",
|
|
110
|
-
"eslint": "^8.1.0",
|
|
111
|
-
"lect": "^0.18.4",
|
|
112
|
-
"rollup": "^2.59.0",
|
|
113
|
-
"rollup-plugin-ascii": "^0.0.3",
|
|
114
|
-
"rollup-plugin-banner": "^0.2.1",
|
|
115
|
-
"rollup-plugin-cleanup": "^3.2.1",
|
|
116
|
-
"rollup-plugin-dts": "^4.0.0",
|
|
117
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
118
|
-
"tap": "^15.0.10",
|
|
119
|
-
"tslib": "^2.3.1",
|
|
120
|
-
"typescript": "^4.4.4"
|
|
121
|
-
},
|
|
122
|
-
"engines": {
|
|
123
|
-
"node": ">=12"
|
|
124
65
|
}
|
|
125
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});"}}
|