string-trim-spaces-only 4.0.6 → 4.0.12

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2010-2021 Roy Revelt and other contributors
3
+ Copyright (c) 2010-2022 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
@@ -26,18 +26,17 @@
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:
29
+ The latest version is **ESM only**: Node 12+ is needed to use it and it must be `import`ed instead of `require`d. If your project is not on ESM yet and you want to use `require`, use an older version of this program, `3.1.0`.
30
30
 
31
31
  ```bash
32
32
  npm i string-trim-spaces-only
33
33
  ```
34
34
 
35
- If you need a legacy version which works with `require`, use version 3.1.0
36
-
37
35
  ## Quick Take
38
36
 
39
37
  ```js
40
38
  import { strict as assert } from "assert";
39
+
41
40
  import { trimSpaces } from "string-trim-spaces-only";
42
41
 
43
42
  assert.deepEqual(trimSpaces(" aaa "), {
@@ -59,7 +58,7 @@ assert.deepEqual(trimSpaces(" \t zz \n "), {
59
58
 
60
59
  ## Documentation
61
60
 
62
- Please [visit codsen.com](https://codsen.com/os/string-trim-spaces-only/) for a full description of the API and examples.
61
+ Please [visit codsen.com](https://codsen.com/os/string-trim-spaces-only/) for a full description of the API.
63
62
 
64
63
  ## Contributing
65
64
 
@@ -69,6 +68,6 @@ To report bugs or request features or assistance, [raise an issue](https://githu
69
68
 
70
69
  MIT License
71
70
 
72
- Copyright (c) 2010-2021 Roy Revelt and other contributors
71
+ Copyright (c) 2010-2022 Roy Revelt and other contributors
73
72
 
74
73
  <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">
@@ -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.6
4
+ * @version 4.0.12
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.6";
11
-
12
- const version = version$1;
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 i="4.0.12";var g=i,u={classicTrim:!1,cr:!1,lf:!1,tab:!1,space:!0,nbsp:!1};function d(e,l){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={...u,...l};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,s;if(e.length){if(o(e[0]))for(let t=0,a=e.length;t<a;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])){s=t+1;break}}return r?s?{res:e.slice(r,s),ranges:[[0,r],[s,e.length]]}:{res:e.slice(r),ranges:[[0,r]]}:s?{res:e.slice(0,s),ranges:[[s,e.length]]}:{res:e,ranges:[]}}return{res:"",ranges:[]}}export{u as defaults,d as trimSpaces,g 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.6
4
+ * @version 4.0.12
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.6",Object.defineProperty(e,"__esModule",{value:!0})}));
10
+ var stringTrimSpacesOnly=(()=>{var l=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames,c=Object.getOwnPropertySymbols;var u=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable;var p=(e,n,t)=>n in e?l(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,a=(e,n)=>{for(var t in n||(n={}))u.call(n,t)&&p(e,t,n[t]);if(c)for(var t of c(n))f.call(n,t)&&p(e,t,n[t]);return e};var y=e=>l(e,"__esModule",{value:!0});var h=(e,n)=>{for(var t in n)l(e,t,{get:n[t],enumerable:!0})},E=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of $(n))!u.call(e,r)&&(t||r!=="default")&&l(e,r,{get:()=>n[r],enumerable:!(o=b(n,r))||o.enumerable});return e};var w=(e=>(n,t)=>e&&e.get(n)||(t=E(y({}),n,1),e&&e.set(n,t),t))(typeof WeakMap!="undefined"?new WeakMap:0);var R={};h(R,{defaults:()=>g,trimSpaces:()=>V,version:()=>S});var m="4.0.12";var S=m,g={classicTrim:!1,cr:!1,lf:!1,tab:!1,space:!0,nbsp:!1};function V(e,n){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 t=a(a({},g),n);function o(s){return t.classicTrim&&!s.trim()||!t.classicTrim&&(t.space&&s===" "||t.cr&&s==="\r"||t.lf&&s===`
12
+ `||t.tab&&s===" "||t.nbsp&&s==="\xA0")}let r,i;if(e.length){if(o(e[0]))for(let s=0,d=e.length;s<d;s++){if(!o(e[s])){r=s;break}if(s===e.length-1)return{res:"",ranges:[[0,e.length]]}}if(o(e[e.length-1])){for(let s=e.length;s--;)if(!o(e[s])){i=s+1;break}}return r?i?{res:e.slice(r,i),ranges:[[0,r],[i,e.length]]}:{res:e.slice(r),ranges:[[0,r]]}:i?{res:e.slice(0,i),ranges:[[i,e.length]]}:{res:e,ranges:[]}}return{res:"",ranges:[]}}return w(R);})();
@@ -1,6 +1,7 @@
1
1
  // Quick Take
2
2
 
3
3
  import { strict as assert } from "assert";
4
+
4
5
  import { trimSpaces } from "../dist/string-trim-spaces-only.esm.js";
5
6
 
6
7
  assert.deepEqual(trimSpaces(" aaa "), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-trim-spaces-only",
3
- "version": "4.0.6",
3
+ "version": "4.0.12",
4
4
  "description": "Like String.trim() but you can choose granularly what to trim",
5
5
  "keywords": [
6
6
  "characters",
@@ -33,89 +33,37 @@
33
33
  },
34
34
  "types": "types/index.d.ts",
35
35
  "scripts": {
36
- "build": "rollup -c",
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",
41
- "dev": "rollup -c --dev",
42
- "devunittest": "npm run dev && tap --only -R 'base'",
43
- "format": "npm run lect && npm run prettier && npm run lint",
44
- "lect": "lect",
45
- "lint": "../../node_modules/eslint/bin/eslint.js . --ext .js --ext .ts --fix --config \"../../.eslintrc.json\" --quiet",
46
- "perf": "node perf/check",
47
- "prettier": "../../node_modules/prettier/bin-prettier.js '*.{js,css,scss,vue,md,ts}' --write --loglevel silent",
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
+ "devtest": "c8 yarn run unit && yarn run examples && yarn run lint",
39
+ "dts": "rollup -c && yarn run prettier 'types/index.d.ts' --write",
40
+ "examples": "node '../../ops/scripts/run-examples.js'",
41
+ "lect": "node '../../ops/lect/lect.js' && yarn run prettier 'README.md' '.all-contributorsrc' 'rollup.config.js' --write",
42
+ "letspublish": "yarn publish || :",
43
+ "lint": "eslint . --fix",
44
+ "perf": "node perf/check.js",
45
+ "prepare": "echo 'ready'",
46
+ "prettier": "prettier",
47
+ "prettier:format": "prettier --write '**/*.{ts,tsx,md}' --no-error-on-unmatched-pattern",
48
+ "pretest": "yarn run lect && yarn run build",
49
+ "test": "yarn run devtest",
50
+ "unit": "uvu test"
56
51
  },
57
- "tap": {
58
- "check-coverage": false,
59
- "node-arg": [
60
- "--no-warnings",
61
- "--experimental-loader",
62
- "@istanbuljs/esm-loader-hook"
52
+ "engines": {
53
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
54
+ },
55
+ "c8": {
56
+ "check-coverage": true,
57
+ "exclude": [
58
+ "**/test/**/*.*"
63
59
  ],
64
- "timeout": 0
60
+ "lines": 100
65
61
  },
66
62
  "lect": {
67
63
  "licence": {
68
64
  "extras": [
69
65
  ""
70
66
  ]
71
- },
72
- "req": "{ trimSpaces }",
73
- "various": {
74
- "devDependencies": []
75
67
  }
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.9",
101
- "@types/tap": "^15.0.5",
102
- "@typescript-eslint/eslint-plugin": "^5.4.0",
103
- "@typescript-eslint/parser": "^5.4.0",
104
- "core-js": "^3.19.1",
105
- "cross-env": "^7.0.3",
106
- "eslint": "^8.3.0",
107
- "lect": "^0.18.6",
108
- "rollup": "^2.60.0",
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.2",
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
68
  }
121
69
  }
package/types/index.d.ts CHANGED
@@ -1,20 +1,21 @@
1
- declare type Range = [from: number, to: number] | [from: number, to: number, whatToInsert: string | null | undefined];
1
+ declare type Range =
2
+ | [from: number, to: number]
3
+ | [from: number, to: number, whatToInsert: string | null | undefined];
2
4
  declare type Ranges = Range[] | null;
3
5
 
4
6
  declare const version: string;
5
-
6
7
  interface Opts {
7
- classicTrim: boolean;
8
- cr: boolean;
9
- lf: boolean;
10
- tab: boolean;
11
- space: boolean;
12
- nbsp: boolean;
8
+ classicTrim: boolean;
9
+ cr: boolean;
10
+ lf: boolean;
11
+ tab: boolean;
12
+ space: boolean;
13
+ nbsp: boolean;
13
14
  }
14
15
  declare const defaults: Opts;
15
16
  interface Res {
16
- res: string;
17
- ranges: Ranges;
17
+ res: string;
18
+ ranges: Ranges;
18
19
  }
19
20
  declare function trimSpaces(str: string, originalOpts?: Partial<Opts>): Res;
20
21
 
package/examples/api.json DELETED
@@ -1 +0,0 @@
1
- {"_quickTake.js":{"title":"Quick Take","content":"import &#x7B; strict as assert &#x7D; from \"assert\";\nimport &#x7B; trimSpaces &#x7D; from \"string-trim-spaces-only\";\n\nassert.deepEqual(trimSpaces(\" aaa \"), &#x7B;\n res: \"aaa\",\n ranges: [\n [0, 2],\n [5, 8],\n ],\n&#x7D;);\n\nassert.deepEqual(trimSpaces(\" \\t zz \\n \"), &#x7B;\n res: \"\\t zz \\n\",\n ranges: [\n [0, 3],\n [12, 16],\n ],\n&#x7D;);"}}