@tolki/str 1.8.0 → 1.9.0
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 +31 -7
- package/dist/ascii/index.d.ts.map +1 -1
- package/dist/ascii/index.js +4 -2
- package/dist/base64/index.d.ts.map +1 -1
- package/dist/base64/index.js +3 -0
- package/dist/convertcase/index.d.ts.map +1 -1
- package/dist/convertcase/index.js +7 -1
- package/dist/index.d.ts +13 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/markdown/index.d.ts.map +1 -1
- package/dist/markdown/index.js +5 -2
- package/dist/pluralizer/index.d.ts +2 -0
- package/dist/pluralizer/index.d.ts.map +1 -1
- package/dist/pluralizer/index.js +14 -5
- package/dist/random/index.d.ts.map +1 -1
- package/dist/random/index.js +3 -1
- package/dist/replacer/index.d.ts +3 -0
- package/dist/replacer/index.d.ts.map +1 -1
- package/dist/replacer/index.js +27 -24
- package/dist/str.d.ts +26 -2
- package/dist/str.d.ts.map +1 -1
- package/dist/str.js +291 -205
- package/dist/stringable/index.d.ts +20 -3
- package/dist/stringable/index.d.ts.map +1 -1
- package/dist/stringable/index.js +98 -94
- package/dist/transliterate/index.d.ts.map +1 -1
- package/dist/transliterate/index.js +1 -0
- package/dist/trimmer/index.d.ts.map +1 -1
- package/dist/trimmer/index.js +4 -1
- package/dist/ulid/index.d.ts +8 -0
- package/dist/ulid/index.d.ts.map +1 -1
- package/dist/ulid/index.js +4 -2
- package/dist/uuid/index.d.ts +8 -0
- package/dist/uuid/index.d.ts.map +1 -1
- package/dist/uuid/index.js +5 -2
- package/dist/width/index.d.ts +19 -0
- package/dist/width/index.d.ts.map +1 -0
- package/dist/width/index.js +155 -0
- package/package.json +8 -23
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ pnpm add @tolki/str
|
|
|
28
28
|
|
|
29
29
|
### Importing the Package
|
|
30
30
|
|
|
31
|
-
You can import individual functions
|
|
31
|
+
You can import individual functions or the whole package as a namespace. Both tree-shake the same way:
|
|
32
32
|
|
|
33
33
|
Importing individual functions:
|
|
34
34
|
|
|
@@ -41,10 +41,10 @@ const camelCaseString = camel("hello world"); // 'helloWorld'
|
|
|
41
41
|
const choppedString = chopEnd("HelloWorld", 5); // 'Hello'
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
Importing the
|
|
44
|
+
Importing the package as a namespace:
|
|
45
45
|
|
|
46
46
|
```typescript
|
|
47
|
-
// Import the
|
|
47
|
+
// Import the package as a namespace
|
|
48
48
|
import * as Str from "@tolki/str";
|
|
49
49
|
|
|
50
50
|
// Example usage
|
|
@@ -52,9 +52,21 @@ const camelCaseString = Str.camel("hello world"); // 'helloWorld'
|
|
|
52
52
|
const choppedString = Str.chopEnd("HelloWorld", 5); // 'Hello'
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
A namespace import that reads its members by name, such as `Str.camel(...)`, shakes exactly like named imports in Rollup, Rolldown (Vite 8), esbuild, webpack and Rspack: your bundle holds only the members you use. Passing the namespace object around, or reading a computed member such as `Str[name]`, keeps every function. See [Bundling and Tree-Shaking](https://tolki.abe.dev/tree-shaking.html#namespace-imports).
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
### Bundling
|
|
58
|
+
|
|
59
|
+
A helper call whose result nothing uses drops out of your bundle in Rollup, Rolldown (Vite 8), webpack and Rspack, because the helpers are marked as free of side effects. This holds for a call at the top level of a module too.
|
|
60
|
+
|
|
61
|
+
The exception is Vite 8 (Rolldown) and Rspack, where an unused top-level call to `uuid`, `uuid7`, `ulid`, `slug`, `ascii`, `markdown`, `inlineMarkdown`, `markDownRenderer`, `str`, `of`, `plural`, `singular`, `counted`, `isPlural`, `isSingular`, `pluralStudly`, `pluralPascal`, `matchCase` or `uncountable` drops the call but can keep the code of the package behind it (uuid, ulid, pluralize, markdown-it, transliteration). Writing `/* @__PURE__ */` before the call drops everything:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
export const id = /* @__PURE__ */ uuid();
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
esbuild doesn't follow the mark across files, so it needs the same comment on any helper call. [Bundling and Tree-Shaking](https://tolki.abe.dev/tree-shaking.html) covers every bundler.
|
|
68
|
+
|
|
69
|
+
The functions that set or clear a generator or the casing caches (`createRandomStringsUsing`, `createUuidsUsing`, `createUlidsUsing`, `freezeUuids`, `freezeUlids`, `flushCache`, `resetFactoryState` and the other `create*` helpers) change module state, and so does `inflector`, which registers the pluralizer's rules on the shared `pluralize` instance. A call to any of them is always kept.
|
|
58
70
|
|
|
59
71
|
## Tolki String Utilities List
|
|
60
72
|
|
|
@@ -758,6 +770,8 @@ const result = length("Tolki JS");
|
|
|
758
770
|
// result is 8
|
|
759
771
|
```
|
|
760
772
|
|
|
773
|
+
Characters are Unicode code points, as PHP's `mb_strlen` counts them, so an emoji counts as one.
|
|
774
|
+
|
|
761
775
|
#### limit
|
|
762
776
|
|
|
763
777
|
Limit the number of characters in a string.
|
|
@@ -770,6 +784,8 @@ const result = limit("The quick brown fox jumps over the lazy dog", 20);
|
|
|
770
784
|
// result is "The quick brown fox..."
|
|
771
785
|
```
|
|
772
786
|
|
|
787
|
+
The limit is a display width, as in Laravel: wide characters such as emoji and Chinese, Japanese or Korean characters count as two, so `limit("😀😀😀", 4)` gives `"😀😀..."`. A negative limit past the string's full width throws, as it does in PHP.
|
|
788
|
+
|
|
773
789
|
You may pass a third argument to specify the string to append to the truncated string (defaults to an ellipsis):
|
|
774
790
|
|
|
775
791
|
```javascript
|
|
@@ -955,13 +971,15 @@ import { padBoth } from "@tolki/str";
|
|
|
955
971
|
|
|
956
972
|
const result = padBoth("James", 10, "_");
|
|
957
973
|
|
|
958
|
-
// result is "
|
|
974
|
+
// result is "__James___"
|
|
959
975
|
|
|
960
976
|
const result2 = padBoth("James", 10);
|
|
961
977
|
|
|
962
978
|
// result2 is " James "
|
|
963
979
|
```
|
|
964
980
|
|
|
981
|
+
The length counts characters, so an emoji counts as one. An empty pad string throws when the value needs padding, as it does in PHP.
|
|
982
|
+
|
|
965
983
|
#### padLeft
|
|
966
984
|
|
|
967
985
|
Pad the left side of a string with another string to a certain length.
|
|
@@ -978,6 +996,8 @@ const result2 = padLeft("James", 10);
|
|
|
978
996
|
// result2 is " James"
|
|
979
997
|
```
|
|
980
998
|
|
|
999
|
+
The length counts characters, so an emoji counts as one. An empty pad string throws when the value needs padding, as it does in PHP.
|
|
1000
|
+
|
|
981
1001
|
#### padRight
|
|
982
1002
|
|
|
983
1003
|
Pad the right side of a string with another string to a certain length.
|
|
@@ -994,6 +1014,8 @@ const result2 = padRight("James", 10);
|
|
|
994
1014
|
// result2 is "James "
|
|
995
1015
|
```
|
|
996
1016
|
|
|
1017
|
+
The length counts characters, so an emoji counts as one. An empty pad string throws when the value needs padding, as it does in PHP.
|
|
1018
|
+
|
|
997
1019
|
#### pascal
|
|
998
1020
|
|
|
999
1021
|
Convert a value to Pascal case.
|
|
@@ -1110,6 +1132,8 @@ const result2 = position("Hello, World!", "W");
|
|
|
1110
1132
|
// result2 is 7
|
|
1111
1133
|
```
|
|
1112
1134
|
|
|
1135
|
+
Positions count characters, so an emoji counts as one. An empty needle returns the offset, and an offset outside the string throws, as in PHP.
|
|
1136
|
+
|
|
1113
1137
|
#### random
|
|
1114
1138
|
|
|
1115
1139
|
Generate a more truly "random" alpha-numeric string.
|
|
@@ -1910,7 +1934,7 @@ const result2 = wrap("is", "This ", " Laravel!");
|
|
|
1910
1934
|
|
|
1911
1935
|
Using the `str` or `of` functions is discouraged for frontend projects because it will import the entire `Stringable` class, all of its methods, and all 3rd party dependencies into your final bundle, which may significantly increase its size.
|
|
1912
1936
|
|
|
1913
|
-
For frontend projects, it is recommended to use the individual string functions instead for better tree-shaking and smaller bundle sizes.
|
|
1937
|
+
For frontend projects, it is recommended to use the individual string functions instead for better tree-shaking and smaller bundle sizes. In Rolldown and Rspack, even an unused top-level `str(...)` or `of(...)` call can leave the class behind unless the call is written `/* @__PURE__ */`; see [Bundling and Tree-Shaking](https://tolki.abe.dev/tree-shaking.html#dependency-residue).
|
|
1914
1938
|
|
|
1915
1939
|
Also unlike the standalone functions on this page, `str`/`of` return a `Stringable` class instance rather than a plain value, so there's no live playground for them here — try the fluent methods it exposes (like `.append()` or `.snake()`) directly in your own code instead.
|
|
1916
1940
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ascii/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ascii/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AAEH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;;;;;;;GAWG;AAEH,wBAAgB,IAAI,CAChB,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,MAAY,EACvB,UAAU,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAiB,GACnD,MAAM,CAsER"}
|
package/dist/ascii/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { lower as e } from "../str.js";
|
|
2
2
|
import { transliterate as t } from "transliteration";
|
|
3
3
|
// src/ascii/index.ts
|
|
4
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
4
5
|
function n(e) {
|
|
5
6
|
return t(e);
|
|
6
7
|
}
|
|
8
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
7
9
|
function r(t, r = "-", i = { "@": "at" }) {
|
|
8
10
|
let a = r, o = (e) => e.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&"), s = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), c = (t) => {
|
|
9
11
|
let n = t, r = RegExp(`[${o(a === "-" ? "_" : "-")}]+`, "gu");
|
|
@@ -11,7 +13,7 @@ function r(t, r = "-", i = { "@": "at" }) {
|
|
|
11
13
|
let c = {};
|
|
12
14
|
for (let [e, t] of Object.entries(i)) c[e] = a + t + a;
|
|
13
15
|
for (let [e, t] of Object.entries(c)) e !== "" && (n = n.split(e).join(t));
|
|
14
|
-
if (n = e(n), a === "") return n = n.replace(/[^\p{L}\p{N}\s]+/gu, ""), n = n.replace(/[\s]+/gu, ""), n;
|
|
16
|
+
if (n = /* @__PURE__ */ e(n), a === "") return n = n.replace(/[^\p{L}\p{N}\s]+/gu, ""), n = n.replace(/[\s]+/gu, ""), n;
|
|
15
17
|
{
|
|
16
18
|
let e = RegExp(`[^${o(a)}\\p{L}\\p{N}\\s]+`, "gu");
|
|
17
19
|
n = n.replace(e, "");
|
|
@@ -20,7 +22,7 @@ function r(t, r = "-", i = { "@": "at" }) {
|
|
|
20
22
|
let r = RegExp(`^${s(a)}+|${s(a)}+$`, "gu");
|
|
21
23
|
return n = n.replace(r, ""), n;
|
|
22
24
|
}
|
|
23
|
-
}, l = c(t), u = c(n(t));
|
|
25
|
+
}, l = c(t), u = c(/* @__PURE__ */ n(t));
|
|
24
26
|
return Object.keys(i).some((e) => /[A-Za-z0-9]/.test(e)) ? u : l;
|
|
25
27
|
}
|
|
26
28
|
export { n as ascii, r as slug };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base64/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base64/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgC9C;AAED;;;;;GAKG;AAEH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAsBvD;AAED;;;;;;;;GAQG;AAEH,wBAAgB,UAAU,CACtB,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,OAAe,GACxB,MAAM,GAAG,KAAK,CAqEhB"}
|
package/dist/base64/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isFunction as e } from "@tolki/utils";
|
|
2
2
|
// src/base64/index.ts
|
|
3
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
3
4
|
function t(t) {
|
|
4
5
|
let n = i();
|
|
5
6
|
if (n.Buffer && e(n.Buffer.from)) return n.Buffer.from(t, "utf8").toString("base64");
|
|
@@ -11,6 +12,7 @@ function t(t) {
|
|
|
11
12
|
}
|
|
12
13
|
return o(a(t));
|
|
13
14
|
}
|
|
15
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
14
16
|
function n(t) {
|
|
15
17
|
let n = i();
|
|
16
18
|
if (n.Buffer && e(n.Buffer.from)) return n.Buffer.from(t).toString("base64");
|
|
@@ -18,6 +20,7 @@ function n(t) {
|
|
|
18
20
|
for (let e = 0; e < t.length; e++) r += String.fromCharCode(t[e]);
|
|
19
21
|
return e(n.btoa) ? n.btoa(r) : o(r);
|
|
20
22
|
}
|
|
23
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
21
24
|
function r(t, n = !1) {
|
|
22
25
|
let r = i(), a = String(t);
|
|
23
26
|
if (n) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/convertcase/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS;;;;;;;;;CASZ,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAEzE;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/convertcase/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS;;;;;;;;;CASZ,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC;AAEzE;;;;;;;;;;GAUG;AAEH,wBAAgB,WAAW,CACvB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,eAAgC,GACvC,MAAM,CAER;AAED;;;;;;;GAOG;AAEH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;;;GAOG;AAEH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C"}
|
|
@@ -10,12 +10,15 @@ var i = {
|
|
|
10
10
|
title_simple: "title_simple",
|
|
11
11
|
fold_simple: "fold_simple"
|
|
12
12
|
};
|
|
13
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
13
14
|
function a(e, t = i.fold) {
|
|
14
15
|
return c(e, t);
|
|
15
16
|
}
|
|
17
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
16
18
|
function o(e) {
|
|
17
19
|
return c(e, i.upper);
|
|
18
20
|
}
|
|
21
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
19
22
|
function s(e) {
|
|
20
23
|
return c(e, i.title);
|
|
21
24
|
}
|
|
@@ -23,7 +26,10 @@ function c(a, o) {
|
|
|
23
26
|
switch (o) {
|
|
24
27
|
case i.upper: return n(a);
|
|
25
28
|
case i.lower: return t(a);
|
|
26
|
-
case i.title: return a.replace(/\p{L}[\p{L}\p{M}\p{N}]*/gu, (e) =>
|
|
29
|
+
case i.title: return a.replace(/\p{L}[\p{L}\p{M}\p{N}]*/gu, (e) => {
|
|
30
|
+
let t = Array.from(e);
|
|
31
|
+
return t.slice(0, 1).join("").toUpperCase() + t.slice(1).join("").toLowerCase();
|
|
32
|
+
});
|
|
27
33
|
case i.fold: return a.normalize("NFKD").toLowerCase();
|
|
28
34
|
case i.simple: return a.replace(/[^a-z0-9]+/g, " ").trim();
|
|
29
35
|
case i.lower_simple: return e(a).replace(/[^a-z0-9]+/g, " ").trim();
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export * from './ascii';
|
|
2
|
-
export * from './base64';
|
|
3
|
-
export * from './convertcase';
|
|
4
|
-
export * from './markdown';
|
|
5
|
-
export * from './pluralizer';
|
|
6
|
-
export * from './random';
|
|
7
|
-
export * from './replacer';
|
|
8
|
-
export * from './str';
|
|
9
|
-
export * from './stringable';
|
|
10
|
-
export * from './transliterate';
|
|
11
|
-
export * from './trimmer';
|
|
12
|
-
export * from './ulid';
|
|
13
|
-
export * from './uuid';
|
|
1
|
+
export * from './ascii/index.js';
|
|
2
|
+
export * from './base64/index.js';
|
|
3
|
+
export * from './convertcase/index.js';
|
|
4
|
+
export * from './markdown/index.js';
|
|
5
|
+
export * from './pluralizer/index.js';
|
|
6
|
+
export * from './random/index.js';
|
|
7
|
+
export * from './replacer/index.js';
|
|
8
|
+
export * from './str.js';
|
|
9
|
+
export * from './stringable/index.js';
|
|
10
|
+
export * from './transliterate/index.js';
|
|
11
|
+
export * from './trimmer/index.js';
|
|
12
|
+
export * from './ulid/index.js';
|
|
13
|
+
export * from './uuid/index.js';
|
|
14
14
|
export type { StringSubject, StringSubjectResult } from '@tolki/types';
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,EAAE,EACf,KAAK,OAAO,IAAI,iBAAiB,EACjC,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACzB,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACtD,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,MAAM,iBAAiB,GACvB,YAAY,GACZ,iBAAiB,CAAC,OAAO,CAAC,GAC1B,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;AAE5C,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,EAAE,CAAC;AAErD;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/markdown/index.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,EAAE,EACf,KAAK,OAAO,IAAI,iBAAiB,EACjC,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACzB,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACtD,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,MAAM,MAAM,iBAAiB,GACvB,YAAY,GACZ,iBAAiB,CAAC,OAAO,CAAC,GAC1B,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;AAE5C,MAAM,MAAM,kBAAkB,GAAG,iBAAiB,EAAE,CAAC;AAErD;;;;;;;;;;;GAWG;AAEH,wBAAgB,QAAQ,CACpB,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,OAAO,GAAE,eAA+C,EACxD,UAAU,GAAE,kBAAuB,GACpC,MAAM,CAMR;AAED;;;;;;;;;;;GAWG;AAEH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,OAAO,GAAE,eAA+B,EACxC,UAAU,GAAE,kBAAuB,GACpC,MAAM,CAMR;AAED;;;;;;;;GAQG;AAEH,wBAAgB,gBAAgB,CAC5B,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,kBAAkB,cAqCjC"}
|
package/dist/markdown/index.js
CHANGED
|
@@ -3,15 +3,18 @@ import t from "markdown-it";
|
|
|
3
3
|
import n from "markdown-it-anchor";
|
|
4
4
|
import r from "markdown-it-task-lists";
|
|
5
5
|
// src/markdown/index.ts
|
|
6
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
6
7
|
function i(e, t = {
|
|
7
8
|
gfm: !0,
|
|
8
9
|
anchors: !1
|
|
9
10
|
}, n = []) {
|
|
10
|
-
return e === null ? "" : o(t, n).render(e);
|
|
11
|
+
return e === null ? "" : (/* @__PURE__ */ o(t, n)).render(e);
|
|
11
12
|
}
|
|
13
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
12
14
|
function a(e, t = { gfm: !0 }, n = []) {
|
|
13
|
-
return e === null ? "" : o(t, n).renderInline(e);
|
|
15
|
+
return e === null ? "" : (/* @__PURE__ */ o(t, n)).renderInline(e);
|
|
14
16
|
}
|
|
17
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
15
18
|
function o(i, a) {
|
|
16
19
|
let { html: o = !1, linkify: s = !0, breaks: c = !0, gfm: l = !0, anchors: u = !1, allowUnsafeLinks: d = !1, ...f } = i, p = new t({
|
|
17
20
|
html: o,
|
|
@@ -100,6 +100,8 @@ export declare function matchCase(value: string, comparison: string): string;
|
|
|
100
100
|
/**
|
|
101
101
|
* Get the pluralize instance
|
|
102
102
|
*
|
|
103
|
+
* @sideEffects state - Registers tolki's uncountable rules on the shared pluralize instance.
|
|
104
|
+
*
|
|
103
105
|
* @returns The pluralize instance.
|
|
104
106
|
*/
|
|
105
107
|
export declare function inflector(): typeof pluralize;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pluralizer/index.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,MAAM,WAAW,eAAe;IAC5B,WAAW,EAAE,MAAM,EAAE,CAAC;CACzB;AAoDD;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pluralizer/index.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,MAAM,WAAW,eAAe;IAC5B,WAAW,EAAE,MAAM,EAAE,CAAC;CACzB;AAoDD;;;;;;;;;;GAUG;AAEH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,MAAM,CAKrE;AAED;;;;;;;;;;GAUG;AAEH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,MAAM,CAErE;AAED;;;;;;;;;;;GAWG;AAEH,wBAAgB,MAAM,CAClB,KAAK,EAAE,MAAM,EACb,KAAK,GAAE,MAAM,GAAG,OAAO,EAAM,EAC7B,YAAY,GAAE,OAAe,GAC9B,MAAM,CAOR;AAED;;;;;;;;;;GAUG;AAEH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,GAAG,MAAM,CAExE;AAqBD;;;;;;;;;GASG;AAEH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAI9C;AAED;;;;;;;GAOG;AAEH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;;;;GAOG;AAEH,wBAAgB,QAAQ,CAAC,KAAK,GAAE,MAAW,GAAG,OAAO,CAEpD;AAED;;;;;;;GAOG;AAEH,wBAAgB,UAAU,CAAC,KAAK,GAAE,MAAW,GAAG,OAAO,CAEtD;AAED;;;;;;GAMG;AAEH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAiBnE;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,IAAI,OAAO,SAAS,CAU5C"}
|
package/dist/pluralizer/index.js
CHANGED
|
@@ -3,35 +3,44 @@ import { format as n } from "@tolki/num";
|
|
|
3
3
|
import r from "pluralize";
|
|
4
4
|
// src/pluralizer/index.ts
|
|
5
5
|
var i, a = { uncountable: /* @__PURE__ */ "audio.bison.cattle.chassis.compensation.coreopsis.data.deer.education.emoji.equipment.evidence.feedback.firmware.fish.furniture.gold.hardware.information.jedi.kin.knowledge.love.metadata.money.moose.news.nutrition.offspring.plankton.pokemon.police.rain.recommended.related.rice.series.sheep.software.species.swine.traffic.wheat".split(".") };
|
|
6
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
6
7
|
function o(e, t = 2) {
|
|
7
8
|
let n = e.split(/(?=[A-Z])/), r = String(n.pop());
|
|
8
|
-
return n.join("") + c(r, t);
|
|
9
|
+
return n.join("") + /* @__PURE__ */ c(r, t);
|
|
9
10
|
}
|
|
11
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
10
12
|
function s(e, t = 2) {
|
|
11
|
-
return o(e, t);
|
|
13
|
+
return /* @__PURE__ */ o(e, t);
|
|
12
14
|
}
|
|
15
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
13
16
|
function c(t, r = 2, i = !1) {
|
|
14
17
|
let a = e(r) ? r : r.length;
|
|
15
18
|
return (i ? n(a) + " " : "") + u(t, a);
|
|
16
19
|
}
|
|
20
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
17
21
|
function l(e, t) {
|
|
18
|
-
return c(e, t, !0);
|
|
22
|
+
return /* @__PURE__ */ c(e, t, !0);
|
|
19
23
|
}
|
|
20
24
|
function u(e, t) {
|
|
21
|
-
return Math.abs(t) === 1 || f(e) ? e : h(g().plural(e), e);
|
|
25
|
+
return Math.abs(t) === 1 || /* @__PURE__ */ f(e) ? e : /* @__PURE__ */ h(g().plural(e), e);
|
|
22
26
|
}
|
|
27
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
23
28
|
function d(e) {
|
|
24
|
-
return h(g().singular(e), e);
|
|
29
|
+
return /* @__PURE__ */ h(g().singular(e), e);
|
|
25
30
|
}
|
|
31
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
26
32
|
function f(e) {
|
|
27
33
|
return a.uncountable.includes(e.toLowerCase());
|
|
28
34
|
}
|
|
35
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
29
36
|
function p(e = "") {
|
|
30
37
|
return g().isPlural(e);
|
|
31
38
|
}
|
|
39
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
32
40
|
function m(e = "") {
|
|
33
41
|
return g().isSingular(e);
|
|
34
42
|
}
|
|
43
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
35
44
|
function h(e, t) {
|
|
36
45
|
return t.toLowerCase() === t ? e.toLowerCase() : t.toUpperCase() === t ? e.toUpperCase() : t[0] && t[0].toUpperCase() + t.slice(1) === t ? (e[0] ?? "").toUpperCase() + e.slice(1) : e;
|
|
37
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/random/index.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/random/index.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH;;;;;;;;;GASG;AAEH,wBAAgB,YAAY,CAAC,MAAM,SAAK,GAAG,MAAM,CAehD;AAED;;;;;;;;;GASG;AAEH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CA4C1D"}
|
package/dist/random/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { bytesToBase64 as e } from "../base64/index.js";
|
|
2
2
|
// src/random/index.ts
|
|
3
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
3
4
|
function t(t = 16) {
|
|
4
5
|
if (!Number.isFinite(t) || t <= 0) return "";
|
|
5
6
|
let n = "";
|
|
6
7
|
for (; n.length < t;) {
|
|
7
|
-
let i = t - n.length, a = r(Math.ceil(i / 3) * 3), o = e(a).replace(/[/+=]/g, "");
|
|
8
|
+
let i = t - n.length, a = r(Math.ceil(i / 3) * 3), o = (/* @__PURE__ */ e(a)).replace(/[/+=]/g, "");
|
|
8
9
|
n += o.slice(0, i);
|
|
9
10
|
}
|
|
10
11
|
return n;
|
|
11
12
|
}
|
|
13
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
12
14
|
function n(e, t) {
|
|
13
15
|
if (!Number.isInteger(e) || !Number.isInteger(t)) throw TypeError("randomInt bounds must be safe integers");
|
|
14
16
|
if (e > t) throw RangeError("randomInt min must be <= max");
|
package/dist/replacer/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @param start - The starting position. If negative, it starts that many characters from the end of the string.
|
|
6
6
|
* @param length - The number of characters to return. If omitted or null, returns all characters from start to the end of the string. If negative, omits that many characters from the end.
|
|
7
7
|
* @returns The extracted substring.
|
|
8
|
+
* @throws TypeError for a NaN or infinite start or length, as PHP's mb_substr() does
|
|
8
9
|
*
|
|
9
10
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#substr
|
|
10
11
|
*/
|
|
@@ -18,6 +19,7 @@ export declare function substr(string: string, start: number, length?: number |
|
|
|
18
19
|
* @param length - The length of the segment to search within. If omitted or null, searches to the end of the string. If negative, omits that many characters from the end.
|
|
19
20
|
* @returns The number of occurrences of the substring within the specified segment.
|
|
20
21
|
* @throws Error for an empty needle, as PHP's substr_count() throws its ValueError
|
|
22
|
+
* @throws TypeError for a NaN or infinite offset or length, as PHP's mb_substr() does
|
|
21
23
|
*
|
|
22
24
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#substrcount
|
|
23
25
|
*/
|
|
@@ -31,6 +33,7 @@ export declare function substrCount(haystack: string, needle: string, offset?: n
|
|
|
31
33
|
* @param offset - The starting position for the replacement, or an array of positions applied positionally. If negative, it starts that many characters from the end of the string.
|
|
32
34
|
* @param length - The number of characters to replace, or an array of lengths applied positionally. If omitted or null, replaces all characters from offset to the end of the string. If negative, omits that many characters from the end.
|
|
33
35
|
* @returns The modified string, or an array/object of modified strings mirroring the subject's shape and keys.
|
|
36
|
+
* @throws TypeError for a NaN or infinite offset or length, as PHP's mb_substr() does
|
|
34
37
|
*
|
|
35
38
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#substrreplace
|
|
36
39
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/replacer/index.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/replacer/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,wBAAgB,MAAM,CAClB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,CAWR;AAED;;;;;;;;;;;;GAYG;AAEH,wBAAgB,WAAW,CACvB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,MAAU,EAClB,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,CAmBR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CACzB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnD,MAAM,CAAC,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GACvB,MAAM,CAAC;AACV,wBAAgB,aAAa,CACzB,MAAM,EAAE,MAAM,EAAE,EAChB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnD,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,GAClC,MAAM,EAAE,CAAC;AACZ,wBAAgB,aAAa,CAAC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACjE,MAAM,EAAE,QAAQ,EAChB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnD,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,GAClC,MAAM,CAAC,MAAM,QAAQ,EAAE,MAAM,CAAC,CAAC;AAClC,wBAAgB,aAAa,CACzB,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAClD,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACnD,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,GAClC,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC"}
|
package/dist/replacer/index.js
CHANGED
|
@@ -1,39 +1,42 @@
|
|
|
1
|
-
import { isArray as e, isObject as t, isString as n } from "@tolki/utils";
|
|
1
|
+
import { isArray as e, isObject as t, isString as n, phpIntArgument as r } from "@tolki/utils";
|
|
2
2
|
// src/replacer/index.ts
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
4
|
+
function i(e, t, n = null) {
|
|
5
|
+
let r = Array.from(e), i = r.length, { start: a, end: o } = c(i, t, n);
|
|
5
6
|
return a >= i || o <= a ? "" : r.slice(a, o).join("");
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
9
|
+
function a(e, t, n = 0, r = null) {
|
|
10
|
+
let i = Array.from(e), a = i.length, { start: o, end: s } = c(a, n, r);
|
|
8
11
|
if (t === "") throw Error("substr_count(): Argument #2 ($needle) must not be empty");
|
|
9
|
-
|
|
10
|
-
return o >= a || l <= o ? 0 : c(i.slice(o, l).join(""), t);
|
|
12
|
+
return o >= a || s <= o ? 0 : l(i.slice(o, s).join(""), t);
|
|
11
13
|
}
|
|
12
|
-
|
|
14
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
15
|
+
function o(r, i, a = 0, o = null) {
|
|
13
16
|
let c = e(i) ? i : t(i) ? Object.values(i) : null;
|
|
14
17
|
if (n(r)) {
|
|
15
|
-
if (e(a) || e(
|
|
16
|
-
return
|
|
18
|
+
if (e(a) || e(o)) throw TypeError("substrReplace(): offset and length must be numbers when the subject is a string");
|
|
19
|
+
return s(r, String(c === null ? i : c[0] ?? ""), a, o);
|
|
17
20
|
}
|
|
18
|
-
let l = e(a) ? a : null, u = e(
|
|
21
|
+
let l = e(a) ? a : null, u = e(o) ? o : null, d = (e, t) => s(e, String(c === null ? i : c[t] ?? ""), l === null ? a : l[t] ?? 0, u === null ? o : u[t] ?? null);
|
|
19
22
|
return e(r) ? r.map((e, t) => d(e, t)) : Object.fromEntries(Object.entries(r).map(([e, t], n) => [e, d(t, n)]));
|
|
20
23
|
}
|
|
21
|
-
function
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
let
|
|
25
|
-
return
|
|
24
|
+
function s(e, t, n, i) {
|
|
25
|
+
let a = Array.from(e), o = a.length, s = r(n, "mb_substr(): Argument #3 ($length) must be of type ?int, float given"), c = i === null ? null : r(i, "mb_substr(): Argument #2 ($start) must be of type int, float given"), l = s >= 0 ? s : o + s;
|
|
26
|
+
l < 0 && (l = 0), l > o && (l = o);
|
|
27
|
+
let u = a.slice(0, l).join(""), d = a.slice(l), f;
|
|
28
|
+
return f = c === null ? "" : d.slice(c).join(""), u + t + f;
|
|
26
29
|
}
|
|
27
|
-
function
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
let
|
|
31
|
-
return
|
|
32
|
-
start:
|
|
33
|
-
end:
|
|
30
|
+
function c(e, t, n) {
|
|
31
|
+
let i = r(t, "mb_substr(): Argument #2 ($start) must be of type int, float given"), a = n == null ? null : r(n, "mb_substr(): Argument #3 ($length) must be of type ?int, float given"), o = i >= 0 ? i : e + i;
|
|
32
|
+
o < 0 && (o = 0), o > e && (o = e);
|
|
33
|
+
let s;
|
|
34
|
+
return s = a === null ? e : a < 0 ? e + a : o + a, s = Math.max(0, Math.min(s, e)), {
|
|
35
|
+
start: o,
|
|
36
|
+
end: s
|
|
34
37
|
};
|
|
35
38
|
}
|
|
36
|
-
function
|
|
39
|
+
function l(e, t) {
|
|
37
40
|
let n = 0, r = 0;
|
|
38
41
|
for (;;) {
|
|
39
42
|
let i = e.indexOf(t, r);
|
|
@@ -42,4 +45,4 @@ function c(e, t) {
|
|
|
42
45
|
}
|
|
43
46
|
return n;
|
|
44
47
|
}
|
|
45
|
-
export {
|
|
48
|
+
export { i as substr, a as substrCount, o as substrReplace };
|
package/dist/str.d.ts
CHANGED
|
@@ -76,6 +76,7 @@ export declare function camel(value: string): string;
|
|
|
76
76
|
* @param subject - The string to get the character from
|
|
77
77
|
* @param index - The index of the character to get
|
|
78
78
|
* @returns The character at the specified index, or false if the index is out of bounds
|
|
79
|
+
* @throws TypeError for a NaN index, as PHP's mb_substr() does
|
|
79
80
|
*
|
|
80
81
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#charat
|
|
81
82
|
*/
|
|
@@ -152,6 +153,7 @@ export declare function doesntContain(haystack: string, needles: string | Iterab
|
|
|
152
153
|
* @param value - The string to process
|
|
153
154
|
* @param character - The character or characters to deduplicate
|
|
154
155
|
* @returns The string with consecutive instances of the character(s) replaced by a single instance
|
|
156
|
+
* @throws SyntaxError for an empty character
|
|
155
157
|
*
|
|
156
158
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#deduplicate
|
|
157
159
|
*/
|
|
@@ -260,7 +262,7 @@ export declare function kebab(value: string): string;
|
|
|
260
262
|
* Return the length of the given string.
|
|
261
263
|
*
|
|
262
264
|
* @param value - The string to measure
|
|
263
|
-
* @returns The
|
|
265
|
+
* @returns The number of Unicode code points in the string
|
|
264
266
|
*
|
|
265
267
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#length
|
|
266
268
|
*/
|
|
@@ -269,10 +271,12 @@ export declare function length(value: string): number;
|
|
|
269
271
|
* Limit the number of characters in a string.
|
|
270
272
|
*
|
|
271
273
|
* @param value - The string to limit
|
|
272
|
-
* @param limit - The maximum
|
|
274
|
+
* @param limit - The maximum display width, where an emoji or a Chinese, Japanese or Korean character counts as two
|
|
273
275
|
* @param end - The string to append if the value is truncated
|
|
274
276
|
* @param preserveWords - Whether to preserve whole words when truncating
|
|
275
277
|
* @returns The limited string
|
|
278
|
+
* @throws Error for a negative limit past the string's full width, as PHP's mb_strimwidth() throws its ValueError
|
|
279
|
+
* @throws TypeError for a NaN limit, as PHP's mb_strimwidth() does
|
|
276
280
|
*
|
|
277
281
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#limit
|
|
278
282
|
*/
|
|
@@ -305,6 +309,7 @@ export declare function words(value: string, words?: number, end?: string): stri
|
|
|
305
309
|
* @param index - The starting index to begin masking (can be negative)
|
|
306
310
|
* @param length - The number of characters to mask (if null, mask to the end of the string)
|
|
307
311
|
* @returns The masked string
|
|
312
|
+
* @throws TypeError for a NaN or infinite index or length, as PHP's mb_substr() does
|
|
308
313
|
*
|
|
309
314
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#mask
|
|
310
315
|
*/
|
|
@@ -357,6 +362,8 @@ export declare function numbers(value: string | string[]): string | string[];
|
|
|
357
362
|
* @param length - The desired total length after padding
|
|
358
363
|
* @param pad - The string to use for padding
|
|
359
364
|
* @returns The padded string
|
|
365
|
+
* @throws Error for an empty pad string when the value needs padding, as PHP's mb_str_pad() throws its ValueError
|
|
366
|
+
* @throws TypeError for a NaN or infinite length, as PHP's mb_str_pad() does
|
|
360
367
|
*
|
|
361
368
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#padboth
|
|
362
369
|
*/
|
|
@@ -368,6 +375,8 @@ export declare function padBoth(value: string, length: number, pad?: string): st
|
|
|
368
375
|
* @param length - The desired total length after padding
|
|
369
376
|
* @param pad - The string to use for padding
|
|
370
377
|
* @returns The padded string
|
|
378
|
+
* @throws Error for an empty pad string when the value needs padding, as PHP's mb_str_pad() throws its ValueError
|
|
379
|
+
* @throws TypeError for a NaN or infinite length, as PHP's mb_str_pad() does
|
|
371
380
|
*
|
|
372
381
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#padleft
|
|
373
382
|
*/
|
|
@@ -379,6 +388,8 @@ export declare function padLeft(value: string, length: number, pad?: string): st
|
|
|
379
388
|
* @param length - The desired total length after padding
|
|
380
389
|
* @param pad - The string to use for padding
|
|
381
390
|
* @returns The padded string
|
|
391
|
+
* @throws Error for an empty pad string when the value needs padding, as PHP's mb_str_pad() throws its ValueError
|
|
392
|
+
* @throws TypeError for a NaN or infinite length, as PHP's mb_str_pad() does
|
|
382
393
|
*
|
|
383
394
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#padright
|
|
384
395
|
*/
|
|
@@ -420,6 +431,8 @@ export declare function password(length?: number, letters?: boolean, numbers?: b
|
|
|
420
431
|
* @param needle - The substring to search for
|
|
421
432
|
* @param offset - The position to start searching from (can be negative)
|
|
422
433
|
* @returns The position of the first occurrence or false if not found
|
|
434
|
+
* @throws Error If the offset is outside the haystack, as mb_strpos() does
|
|
435
|
+
* @throws TypeError If the offset is NaN or infinite, as mb_strpos() does
|
|
423
436
|
*
|
|
424
437
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#position
|
|
425
438
|
*/
|
|
@@ -436,6 +449,8 @@ export declare function random(length?: number): string;
|
|
|
436
449
|
/**
|
|
437
450
|
* Set the callable that will be used to generate random strings.
|
|
438
451
|
*
|
|
452
|
+
* @sideEffects state - sets `randomStringFactory`.
|
|
453
|
+
*
|
|
439
454
|
* @param factory - The factory function to generate random strings
|
|
440
455
|
* @returns void
|
|
441
456
|
*
|
|
@@ -445,6 +460,8 @@ export declare function createRandomStringsUsing(factory: ((length: number) => s
|
|
|
445
460
|
/**
|
|
446
461
|
* Set the sequence that will be used to generate random strings.
|
|
447
462
|
*
|
|
463
|
+
* @sideEffects state - sets `randomStringFactory`.
|
|
464
|
+
*
|
|
448
465
|
* @param sequence - An array of strings to use in sequence
|
|
449
466
|
* @param whenMissing - An optional callable to generate strings when the sequence is exhausted
|
|
450
467
|
* @returns void
|
|
@@ -458,6 +475,8 @@ export declare function createRandomStringsUsingSequence(sequence: string[], whe
|
|
|
458
475
|
/**
|
|
459
476
|
* Indicate that random strings should be created normally and not using a custom factory.
|
|
460
477
|
*
|
|
478
|
+
* @sideEffects state - clears `randomStringFactory`.
|
|
479
|
+
*
|
|
461
480
|
* @returns void
|
|
462
481
|
*
|
|
463
482
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#random
|
|
@@ -720,6 +739,7 @@ export declare function swap(map: Record<string, string>, subject: string): stri
|
|
|
720
739
|
* @param value - The string to process
|
|
721
740
|
* @param limit - The number of characters to take (negative for from end)
|
|
722
741
|
* @returns The resulting substring
|
|
742
|
+
* @throws TypeError for a NaN or infinite limit, as Laravel's int $limit parameter does
|
|
723
743
|
*
|
|
724
744
|
* @see https://tolki.abe.dev/strings/string-utilities-list.html#take
|
|
725
745
|
*/
|
|
@@ -832,12 +852,16 @@ export declare function studlyCacheSize(): number;
|
|
|
832
852
|
/**
|
|
833
853
|
* Remove all strings from the casing caches.
|
|
834
854
|
*
|
|
855
|
+
* @sideEffects state - empties the snake, camel and studly caches.
|
|
856
|
+
*
|
|
835
857
|
* @returns void
|
|
836
858
|
*/
|
|
837
859
|
export declare function flushCache(): void;
|
|
838
860
|
/**
|
|
839
861
|
* Return all factory functions to their default state.
|
|
840
862
|
*
|
|
863
|
+
* @sideEffects state - clears the random string, ULID and UUID factories.
|
|
864
|
+
*
|
|
841
865
|
* @returns void
|
|
842
866
|
*/
|
|
843
867
|
export declare function resetFactoryState(): void;
|