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 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 and examples.
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.7
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 version$1 = "4.0.7";
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 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.7
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
- !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.7",Object.defineProperty(e,"__esModule",{value:!0})}));
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);})();
@@ -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.7",
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": "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
+ "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
- "tap": {
58
- "check-coverage": false,
59
- "node-arg": [
60
- "--no-warnings",
61
- "--experimental-loader",
62
- "@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/**/*.*"
63
56
  ],
64
- "timeout": 0
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
@@ -2,7 +2,6 @@ declare type Range = [from: number, to: number] | [from: number, to: number, wha
2
2
  declare type Ranges = Range[] | null;
3
3
 
4
4
  declare const version: string;
5
-
6
5
  interface Opts {
7
6
  classicTrim: boolean;
8
7
  cr: boolean;
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;);"}}