@tolki/str 1.6.0 → 1.7.1

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.
@@ -1,7 +1,6 @@
1
- import t from "any-ascii";
2
- function i(r) {
3
- return r === null ? "" : t(r);
1
+ import e from "any-ascii";
2
+ // src/transliterate/index.ts
3
+ function t(t) {
4
+ return t === null ? "" : e(t);
4
5
  }
5
- export {
6
- i as transliterate
7
- };
6
+ export { t as transliterate };
@@ -2,7 +2,7 @@
2
2
  * Remove all whitespace from both ends of a string.
3
3
  *
4
4
  * @param value - The string to trim.
5
- * @param charlist - Optional list of characters to trim instead of whitespace.
5
+ * @param charlist - Optional list of characters to trim instead of whitespace; an empty string trims nothing.
6
6
  * @returns The trimmed string.
7
7
  *
8
8
  * @see https://tolki.abe.dev/strings/string-utilities-list.html#trim
@@ -12,7 +12,7 @@ export declare function trim(value: string, charlist?: string | null): string;
12
12
  * Remove all whitespace from the beginning of a string.
13
13
  *
14
14
  * @param value - The string to trim.
15
- * @param charlist - Optional list of characters to trim instead of whitespace.
15
+ * @param charlist - Optional list of characters to trim instead of whitespace; an empty string trims nothing.
16
16
  * @returns The left-trimmed string.
17
17
  *
18
18
  * @see https://tolki.abe.dev/strings/string-utilities-list.html#ltrim
@@ -22,7 +22,7 @@ export declare function ltrim(value: string, charlist?: string | null): string;
22
22
  * Remove all whitespace from the end of a string.
23
23
  *
24
24
  * @param value - The string to trim.
25
- * @param charlist - Optional list of characters to trim instead of whitespace.
25
+ * @param charlist - Optional list of characters to trim instead of whitespace; an empty string trims nothing.
26
26
  * @returns The right-trimmed string.
27
27
  *
28
28
  * @see https://tolki.abe.dev/strings/string-utilities-list.html#rtrim
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/trimmer/index.ts"],"names":[],"mappings":"AAkEA;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CA0B1E;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CAqB3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CAyB3E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/trimmer/index.ts"],"names":[],"mappings":"AAqFA;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CAI1E;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CAE3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,GAAG,IAAW,GAAG,MAAM,CAE3E"}
@@ -1,128 +1,91 @@
1
- const f = [
2
- 9,
3
- 32,
4
- 160,
5
- 173,
6
- 847,
7
- 1564,
8
- 4447,
9
- 4448,
10
- 6068,
11
- 6069,
12
- 6158,
13
- 8192,
14
- 8193,
15
- 8194,
16
- 8195,
17
- 8196,
18
- 8197,
19
- 8198,
20
- 8199,
21
- 8200,
22
- 8201,
23
- 8202,
24
- 8203,
25
- 8204,
26
- 8205,
27
- 8206,
28
- 8207,
29
- 8239,
30
- 8287,
31
- 8288,
32
- 8289,
33
- 8290,
34
- 8291,
35
- 8292,
36
- 8293,
37
- 8298,
38
- 8299,
39
- 8300,
40
- 8301,
41
- 8302,
42
- 8303,
43
- 12288,
44
- 10240,
45
- 12644,
46
- 65279,
47
- 65440,
48
- 119129,
49
- 119155,
50
- 119156,
51
- 119157,
52
- 119158,
53
- 119159,
54
- 119160,
55
- 119161,
56
- 119162,
57
- 917536
58
- ].map((n) => `\\u{${n.toString(16)}}`).join("");
59
- function a() {
60
- return `\\s${f}\\u0000`;
1
+ // src/trimmer/index.ts
2
+ var e = [
3
+ 9,
4
+ 32,
5
+ 160,
6
+ 173,
7
+ 847,
8
+ 1564,
9
+ 4447,
10
+ 4448,
11
+ 6068,
12
+ 6069,
13
+ 6158,
14
+ 8192,
15
+ 8193,
16
+ 8194,
17
+ 8195,
18
+ 8196,
19
+ 8197,
20
+ 8198,
21
+ 8199,
22
+ 8200,
23
+ 8201,
24
+ 8202,
25
+ 8203,
26
+ 8204,
27
+ 8205,
28
+ 8206,
29
+ 8207,
30
+ 8239,
31
+ 8287,
32
+ 8288,
33
+ 8289,
34
+ 8290,
35
+ 8291,
36
+ 8292,
37
+ 8293,
38
+ 8298,
39
+ 8299,
40
+ 8300,
41
+ 8301,
42
+ 8302,
43
+ 8303,
44
+ 12288,
45
+ 10240,
46
+ 12644,
47
+ 65279,
48
+ 65440,
49
+ 119129,
50
+ 119155,
51
+ 119156,
52
+ 119157,
53
+ 119158,
54
+ 119159,
55
+ 119160,
56
+ 119161,
57
+ 119162,
58
+ 917536
59
+ ].map((e) => `\\u{${e.toString(16)}}`).join("");
60
+ function t() {
61
+ return `\\s\\u0085${e}\\u0000`;
61
62
  }
62
- function u(t) {
63
- return t.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&");
63
+ function n(e) {
64
+ return e.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&");
64
65
  }
65
- function $(t) {
66
- let n = 0;
67
- const r = t.split(/\r?\n/);
68
- for (const c of r) {
69
- if (!/\S/.test(c))
70
- continue;
71
- n = c.match(/^[ \t]*/)[0].length;
72
- break;
73
- }
74
- const e = r[r.length - 1].match(/^[ \t]*/)[0].length;
75
- return { baseIndent: n, tailIndent: e };
66
+ function r(e, t) {
67
+ let n = RegExp(`[${t}]$`, "u"), r = e.length;
68
+ for (; r > 0;) {
69
+ let t = n.exec(e.slice(Math.max(r - 2, 0), r));
70
+ if (t === null) break;
71
+ r -= t[0].length;
72
+ }
73
+ return e.slice(0, r);
76
74
  }
77
- function m(t, n = null) {
78
- if (n == null || n === "") {
79
- const { baseIndent: i, tailIndent: l } = $(t), e = a(), c = new RegExp(`^[${e}]+|[${e}]+$`, "gu");
80
- let s = t.replace(c, "");
81
- const p = Math.max(0, i - l);
82
- if (p > 0 && s.includes(`
83
- `)) {
84
- const g = " ".repeat(p);
85
- s = s.split(/\r?\n/).map((o, d) => d === 0 || /^\s*$/.test(o) ? o : g + o).join(`
86
- `);
87
- }
88
- return s.length !== t.length ? s : t.trim();
89
- }
90
- const r = new RegExp(
91
- `^[${u(n)}]+|[${u(n)}]+$`,
92
- "gu"
93
- );
94
- return t.replace(r, "");
75
+ function i(e, t) {
76
+ return e.replace(RegExp(`^[${t}]+`, "u"), "");
95
77
  }
96
- function x(t, n = null) {
97
- if (n == null || n === "") {
98
- const i = a(), l = new RegExp(`^[${i}]+`, "gu");
99
- let e = t.replace(l, "");
100
- const c = String.raw` (?:\n|\r|\t|\v|\x00)$`;
101
- return e = e.replace(new RegExp(c, "u"), ""), t.endsWith(" ") && !t.endsWith(" ") && (e = e.replace(/ {2}$/u, "")), e.length !== t.length ? e : t.trimStart();
102
- }
103
- const r = new RegExp(`^[${u(n)}]+`, "gu");
104
- return t.replace(r, "");
78
+ function a(e) {
79
+ return e === null ? t() : n(e);
105
80
  }
106
- function h(t, n = null) {
107
- if (n == null || n === "") {
108
- const i = a(), l = new RegExp(`[${i}]+$`, "gu");
109
- let e = t.replace(l, "");
110
- if (e.includes(`
111
- `)) {
112
- const { baseIndent: c, tailIndent: s } = $(t), p = Math.max(0, s - c);
113
- if (p > 0) {
114
- const g = " ".repeat(p);
115
- e = e.split(/\r?\n/).map((o) => /\S/.test(o) ? g + o : o).join(`
116
- `);
117
- }
118
- }
119
- return e.length !== t.length ? e : t.trimEnd();
120
- }
121
- const r = new RegExp(`[${u(n)}]+$`, "gu");
122
- return t.replace(r, "");
81
+ function o(e, t = null) {
82
+ let n = a(t);
83
+ return r(i(e, n), n);
123
84
  }
124
- export {
125
- x as ltrim,
126
- h as rtrim,
127
- m as trim
128
- };
85
+ function s(e, t = null) {
86
+ return i(e, a(t));
87
+ }
88
+ function c(e, t = null) {
89
+ return r(e, a(t));
90
+ }
91
+ export { s as ltrim, c as rtrim, o as trim };
@@ -1,58 +1,48 @@
1
- import { isString as c } from "@tolki/utils";
2
- import { ulid as e } from "ulid";
3
- let l = null;
4
- function i(n = null) {
5
- if (l)
6
- return l();
7
- if (n == null)
8
- return e();
9
- let t;
10
- n instanceof Date ? t = n.getTime() : t = n;
11
- const r = Date.now;
12
- try {
13
- return Date.now = () => t, e();
14
- } finally {
15
- Date.now = r;
16
- }
1
+ import { isString as e } from "@tolki/utils";
2
+ import { ulid as t } from "ulid";
3
+ // src/ulid/index.ts
4
+ var n = null;
5
+ function r(e = null) {
6
+ if (n) return n();
7
+ if (e == null) return t();
8
+ let r;
9
+ r = e instanceof Date ? e.getTime() : e;
10
+ let i = Date.now;
11
+ try {
12
+ return Date.now = () => r, t();
13
+ } finally {
14
+ Date.now = i;
15
+ }
17
16
  }
18
- function a() {
19
- l = null;
17
+ function i() {
18
+ n = null;
20
19
  }
21
- function u(n) {
22
- l = n;
20
+ function a(e) {
21
+ n = e;
23
22
  }
24
- function U(n, t = null) {
25
- let r = 0;
26
- t ??= function() {
27
- const o = l;
28
- l = null;
29
- const f = i();
30
- return l = o, r++, f;
31
- }, u(function() {
32
- return r < n.length ? n[r++] : t();
33
- });
23
+ function o(e, t = null) {
24
+ let i = 0;
25
+ t ??= function() {
26
+ let e = n;
27
+ n = null;
28
+ let t = r();
29
+ return n = e, i++, t;
30
+ }, a(function() {
31
+ return i < e.length ? e[i++] : t();
32
+ });
34
33
  }
35
- function p(n = null) {
36
- const t = i();
37
- if (u(() => t), n !== null)
38
- try {
39
- n(t);
40
- } finally {
41
- a();
42
- }
43
- return t;
34
+ function s(e = null) {
35
+ let t = r();
36
+ if (a(() => t), e !== null) try {
37
+ e(t);
38
+ } finally {
39
+ i();
40
+ }
41
+ return t;
44
42
  }
45
- function y(n) {
46
- if (!c(n))
47
- return !1;
48
- const t = n.toUpperCase();
49
- return /^[0-9A-HJKMNP-TV-Z]{26}$/.test(t);
43
+ function c(t) {
44
+ if (!e(t)) return !1;
45
+ let n = t.toUpperCase();
46
+ return /^[0-9A-HJKMNP-TV-Z]{26}$/.test(n);
50
47
  }
51
- export {
52
- a as createUlidsNormally,
53
- u as createUlidsUsing,
54
- U as createUlidsUsingSequence,
55
- p as freezeUlids,
56
- y as isUlid,
57
- i as ulid
58
- };
48
+ export { i as createUlidsNormally, a as createUlidsUsing, o as createUlidsUsingSequence, s as freezeUlids, c as isUlid, r as ulid };
@@ -1,50 +1,40 @@
1
- import { isString as o } from "@tolki/utils";
2
- import { validate as a, NIL as c, MAX as d, version as s, v4 as U, v7 as m } from "uuid";
3
- let u = null;
4
- function f() {
5
- return u ? u() : U();
1
+ import { isString as e } from "@tolki/utils";
2
+ import { MAX as t, NIL as n, v4 as r, v7 as i, validate as a, version as o } from "uuid";
3
+ // src/uuid/index.ts
4
+ var s = null;
5
+ function c() {
6
+ return s ? s() : r();
6
7
  }
7
- function g() {
8
- return u ? u() : m();
8
+ function l() {
9
+ return s ? s() : i();
9
10
  }
10
- function e(n) {
11
- u = n;
11
+ function u(e) {
12
+ s = e;
12
13
  }
13
- function p(n, t = null) {
14
- let r = 0;
15
- t ??= function() {
16
- const i = u;
17
- u = null;
18
- const l = f();
19
- return u = i, r++, l;
20
- }, e(function() {
21
- return r < n.length ? n[r++] : t();
22
- });
14
+ function d(e, t = null) {
15
+ let n = 0;
16
+ t ??= function() {
17
+ let e = s;
18
+ s = null;
19
+ let t = c();
20
+ return s = e, n++, t;
21
+ }, u(function() {
22
+ return n < e.length ? e[n++] : t();
23
+ });
23
24
  }
24
- function x(n = null) {
25
- const t = f();
26
- if (e(() => t), n !== null)
27
- try {
28
- n(t);
29
- } finally {
30
- A();
31
- }
32
- return t;
25
+ function f(e = null) {
26
+ let t = c();
27
+ if (u(() => t), e !== null) try {
28
+ e(t);
29
+ } finally {
30
+ p();
31
+ }
32
+ return t;
33
33
  }
34
- function A() {
35
- u = null;
34
+ function p() {
35
+ s = null;
36
36
  }
37
- function C(n, t = null) {
38
- return !o(n) || t !== null && !a(n) ? !1 : t === null ? /^[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}$/.test(
39
- n
40
- ) : t === 0 || t === "nil" ? n.toLowerCase() === c : t === "max" ? n.toLowerCase() === d : t < 1 || t > 8 ? !1 : s(n) === t;
37
+ function m(r, i = null) {
38
+ return !e(r) || i !== null && !a(r) ? !1 : i === null ? /^[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}$/.test(r) : i === 0 || i === "nil" ? r.toLowerCase() === n : i === "max" ? r.toLowerCase() === t : i < 1 || i > 8 ? !1 : o(r) === i;
41
39
  }
42
- export {
43
- A as createUuidsNormally,
44
- e as createUuidsUsing,
45
- p as createUuidsUsingSequence,
46
- x as freezeUuids,
47
- C as isUuid,
48
- f as uuid,
49
- g as uuid7
50
- };
40
+ export { p as createUuidsNormally, u as createUuidsUsing, d as createUuidsUsingSequence, f as freezeUuids, m as isUuid, c as uuid, l as uuid7 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/str",
3
- "version": "1.6.0",
3
+ "version": "1.7.1",
4
4
  "description": "Utilities for working with strings similar to Laravel's Str & Stringable classes.",
5
5
  "author": "Abraham Arango <https://github.com/abetwothree>",
6
6
  "license": "MIT",
@@ -26,18 +26,18 @@
26
26
  ],
27
27
  "sideEffects": false,
28
28
  "dependencies": {
29
- "@types/markdown-it": "^14.1.2",
29
+ "@types/markdown-it": "^14.2.0",
30
30
  "@types/pluralize": "^0.0.33",
31
31
  "any-ascii": "^0.3.3",
32
- "markdown-it": "^14.1.0",
33
- "markdown-it-anchor": "^9.2.0",
32
+ "markdown-it": "^14.3.3",
33
+ "markdown-it-anchor": "^10.0.0",
34
34
  "markdown-it-task-lists": "^2.1.1",
35
35
  "pluralize": "^8.0.0",
36
- "transliteration": "^2.6.0",
37
- "ulid": "^2.4.0",
38
- "uuid": "^11.1.0",
39
- "@tolki/utils": "^1.4.0",
40
- "@tolki/num": "^2.2.3"
36
+ "transliteration": "^2.7.0",
37
+ "ulid": "^3.0.2",
38
+ "uuid": "^14.0.3",
39
+ "@tolki/utils": "^1.6.3",
40
+ "@tolki/num": "^2.2.5"
41
41
  },
42
42
  "files": [
43
43
  "dist"
@@ -66,56 +66,69 @@
66
66
  "types": "./dist/*"
67
67
  },
68
68
  "./ascii": {
69
+ "types": "./dist/ascii/index.d.ts",
69
70
  "import": "./dist/ascii/index.js",
70
- "types": "./dist/ascii/index.d.ts"
71
+ "default": "./dist/ascii/index.js"
71
72
  },
72
73
  "./base64": {
74
+ "types": "./dist/base64/index.d.ts",
73
75
  "import": "./dist/base64/index.js",
74
- "types": "./dist/base64/index.d.ts"
76
+ "default": "./dist/base64/index.js"
75
77
  },
76
78
  "./convertcase": {
79
+ "types": "./dist/convertcase/index.d.ts",
77
80
  "import": "./dist/convertcase/index.js",
78
- "types": "./dist/convertcase/index.d.ts"
81
+ "default": "./dist/convertcase/index.js"
79
82
  },
80
83
  "./markdown": {
84
+ "types": "./dist/markdown/index.d.ts",
81
85
  "import": "./dist/markdown/index.js",
82
- "types": "./dist/markdown/index.d.ts"
86
+ "default": "./dist/markdown/index.js"
83
87
  },
84
88
  "./pluralizer": {
89
+ "types": "./dist/pluralizer/index.d.ts",
85
90
  "import": "./dist/pluralizer/index.js",
86
- "types": "./dist/pluralizer/index.d.ts"
91
+ "default": "./dist/pluralizer/index.js"
87
92
  },
88
93
  "./random": {
94
+ "types": "./dist/random/index.d.ts",
89
95
  "import": "./dist/random/index.js",
90
- "types": "./dist/random/index.d.ts"
96
+ "default": "./dist/random/index.js"
91
97
  },
92
98
  "./replacer": {
99
+ "types": "./dist/replacer/index.d.ts",
93
100
  "import": "./dist/replacer/index.js",
94
- "types": "./dist/replacer/index.d.ts"
101
+ "default": "./dist/replacer/index.js"
95
102
  },
96
103
  "./str": {
104
+ "types": "./dist/str.d.ts",
97
105
  "import": "./dist/str.js",
98
- "types": "./dist/str.d.ts"
106
+ "default": "./dist/str.js"
99
107
  },
100
108
  "./stringable": {
109
+ "types": "./dist/stringable/index.d.ts",
101
110
  "import": "./dist/stringable/index.js",
102
- "types": "./dist/stringable/index.d.ts"
111
+ "default": "./dist/stringable/index.js"
103
112
  },
104
113
  "./transliterate": {
114
+ "types": "./dist/transliterate/index.d.ts",
105
115
  "import": "./dist/transliterate/index.js",
106
- "types": "./dist/transliterate/index.d.ts"
116
+ "default": "./dist/transliterate/index.js"
107
117
  },
108
118
  "./trimmer": {
119
+ "types": "./dist/trimmer/index.d.ts",
109
120
  "import": "./dist/trimmer/index.js",
110
- "types": "./dist/trimmer/index.d.ts"
121
+ "default": "./dist/trimmer/index.js"
111
122
  },
112
123
  "./ulid": {
124
+ "types": "./dist/ulid/index.d.ts",
113
125
  "import": "./dist/ulid/index.js",
114
- "types": "./dist/ulid/index.d.ts"
126
+ "default": "./dist/ulid/index.js"
115
127
  },
116
128
  "./uuid": {
129
+ "types": "./dist/uuid/index.d.ts",
117
130
  "import": "./dist/uuid/index.js",
118
- "types": "./dist/uuid/index.d.ts"
131
+ "default": "./dist/uuid/index.js"
119
132
  }
120
133
  }
121
134
  }