@tolki/str 1.0.1 → 1.0.3
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/dist/ascii/index.d.ts +2 -0
- package/dist/ascii/index.d.ts.map +1 -1
- package/dist/ascii/index.js +23 -28
- package/dist/base64/index.d.ts +2 -0
- package/dist/base64/index.d.ts.map +1 -1
- package/dist/convertcase/index.d.ts +2 -8
- package/dist/convertcase/index.d.ts.map +1 -1
- package/dist/markdown/index.d.ts +1 -1
- package/dist/markdown/index.d.ts.map +1 -1
- package/dist/markdown/index.js +12 -11
- package/dist/pluralizer/index.d.ts +8 -14
- package/dist/pluralizer/index.d.ts.map +1 -1
- package/dist/replacer/index.d.ts +8 -0
- package/dist/replacer/index.d.ts.map +1 -1
- package/dist/replacer/index.js +31 -27
- package/dist/str.d.ts +50 -136
- package/dist/str.d.ts.map +1 -1
- package/dist/str.js +371 -375
- package/dist/stringable/index.d.ts +5 -9
- package/dist/stringable/index.d.ts.map +1 -1
- package/dist/stringable/index.js +109 -118
- package/dist/transliterate/index.d.ts +1 -3
- package/dist/transliterate/index.d.ts.map +1 -1
- package/dist/trimmer/index.d.ts +6 -0
- package/dist/trimmer/index.d.ts.map +1 -1
- package/dist/ulid/index.d.ts +8 -14
- package/dist/ulid/index.d.ts.map +1 -1
- package/dist/ulid/index.js +8 -8
- package/dist/uuid/index.d.ts +9 -17
- package/dist/uuid/index.d.ts.map +1 -1
- package/dist/uuid/index.js +6 -6
- package/package.json +3 -3
package/dist/ascii/index.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export declare function ascii(value: string): string;
|
|
|
17
17
|
* @param dictionary - An optional dictionary of replacements
|
|
18
18
|
* @returns The generated slug string
|
|
19
19
|
*
|
|
20
|
+
* @see https://tolki.abe.dev/strings/string-utilities-list.html#slug
|
|
21
|
+
*
|
|
20
22
|
* @requires {@link https://www.npmjs.com/package/transliteration transliteration package}
|
|
21
23
|
*/
|
|
22
24
|
export declare function slug(title: string, separator?: string, dictionary?: Record<string, string>): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ascii/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ascii/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;;;;;;;GAWG;AACH,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,46 +1,41 @@
|
|
|
1
|
-
import { lower as
|
|
2
|
-
import { transliterate as
|
|
3
|
-
function
|
|
4
|
-
return
|
|
1
|
+
import { lower as y } from "@tolki/str";
|
|
2
|
+
import { transliterate as h } from "transliteration";
|
|
3
|
+
function k(n) {
|
|
4
|
+
return h(n);
|
|
5
5
|
}
|
|
6
|
-
function
|
|
7
|
-
const s =
|
|
6
|
+
function j(n, u = "-", p = { "@": "at" }) {
|
|
7
|
+
const s = u, r = (t) => t.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&"), a = (t) => t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), l = (t) => {
|
|
8
8
|
let e = t;
|
|
9
|
-
const $ = s === "-" ? "_" : "-";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
o[c] = (s ?? "") + n + (s ?? "");
|
|
18
|
-
for (const [c, n] of Object.entries(o))
|
|
19
|
-
c !== "" && (e = e.split(c).join(n));
|
|
20
|
-
}
|
|
21
|
-
if (e = m(e), s === "")
|
|
9
|
+
const $ = s === "-" ? "_" : "-", m = new RegExp(`[${r($)}]+`, "gu");
|
|
10
|
+
e = e.replace(m, s);
|
|
11
|
+
const i = {};
|
|
12
|
+
for (const [o, c] of Object.entries(p))
|
|
13
|
+
i[o] = s + c + s;
|
|
14
|
+
for (const [o, c] of Object.entries(i))
|
|
15
|
+
o !== "" && (e = e.split(o).join(c));
|
|
16
|
+
if (e = y(e), s === "")
|
|
22
17
|
return e = e.replace(/[^\p{L}\p{N}\s]+/gu, ""), e = e.replace(/[\s]+/gu, ""), e;
|
|
23
18
|
{
|
|
24
19
|
const o = new RegExp(
|
|
25
|
-
`[^${
|
|
20
|
+
`[^${r(s)}\\p{L}\\p{N}\\s]+`,
|
|
26
21
|
"gu"
|
|
27
22
|
);
|
|
28
23
|
e = e.replace(o, "");
|
|
29
24
|
const c = new RegExp(
|
|
30
|
-
`[${
|
|
25
|
+
`[${r(s)}\\s]+`,
|
|
31
26
|
"gu"
|
|
32
27
|
);
|
|
33
28
|
e = e.replace(c, s);
|
|
34
|
-
const
|
|
35
|
-
`^${
|
|
29
|
+
const w = new RegExp(
|
|
30
|
+
`^${a(s)}+|${a(s)}+$`,
|
|
36
31
|
"gu"
|
|
37
32
|
);
|
|
38
|
-
return e = e.replace(
|
|
33
|
+
return e = e.replace(w, ""), e;
|
|
39
34
|
}
|
|
40
|
-
},
|
|
41
|
-
return Object.keys(p
|
|
35
|
+
}, g = l(n), f = l(k(n));
|
|
36
|
+
return Object.keys(p).some((t) => /[A-Za-z0-9]/.test(t)) ? f : g;
|
|
42
37
|
}
|
|
43
38
|
export {
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
k as ascii,
|
|
40
|
+
j as slug
|
|
46
41
|
};
|
package/dist/base64/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base64/index.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base64/index.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgC9C;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAsBvD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACtB,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,OAAe,GACxB,MAAM,GAAG,KAAK,CAqEhB"}
|
|
@@ -27,10 +27,7 @@ export declare function convertCase(value: string, mode?: ConvertCaseMode): stri
|
|
|
27
27
|
* @param value - The string to convert.
|
|
28
28
|
* @returns The upper-case string.
|
|
29
29
|
*
|
|
30
|
-
* @
|
|
31
|
-
*
|
|
32
|
-
* upper("foo bar baz"); -> "FOO BAR BAZ"
|
|
33
|
-
* upper("foO bAr BaZ"); -> "FOO BAR BAZ"
|
|
30
|
+
* @see https://tolki.abe.dev/strings/string-utilities-list.html#upper
|
|
34
31
|
*/
|
|
35
32
|
export declare function upper(value: string): string;
|
|
36
33
|
/**
|
|
@@ -39,10 +36,7 @@ export declare function upper(value: string): string;
|
|
|
39
36
|
* @param value - The string to convert.
|
|
40
37
|
* @returns The proper-case string.
|
|
41
38
|
*
|
|
42
|
-
* @
|
|
43
|
-
*
|
|
44
|
-
* title("foo bar baz"); -> "Foo Bar Baz"
|
|
45
|
-
* title("foO bAr BaZ"); -> "Foo Bar Baz"
|
|
39
|
+
* @see https://tolki.abe.dev/strings/string-utilities-list.html#title
|
|
46
40
|
*/
|
|
47
41
|
export declare function title(value: string): string;
|
|
48
42
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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;AACH,wBAAgB,WAAW,CACvB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,eAAgC,GACvC,MAAM,CAER;AAED
|
|
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;AACH,wBAAgB,WAAW,CACvB,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,eAAgC,GACvC,MAAM,CAER;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3C"}
|
package/dist/markdown/index.d.ts
CHANGED
|
@@ -42,5 +42,5 @@ export declare function inlineMarkdown(value: string, options?: MarkDownOptions,
|
|
|
42
42
|
*
|
|
43
43
|
* @requires {@link https://www.npmjs.com/package/markdown-it markdown-it package}
|
|
44
44
|
*/
|
|
45
|
-
export declare function markDownRenderer(options
|
|
45
|
+
export declare function markDownRenderer(options: MarkDownOptions, extensions: MarkDownExtensions): MarkdownIt;
|
|
46
46
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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;AACH,wBAAgB,QAAQ,CACpB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAA+C,EACxD,UAAU,GAAE,kBAAuB,GACpC,MAAM,CAER;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAA+B,EACxC,UAAU,GAAE,kBAAuB,GACpC,MAAM,CAER;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC5B,OAAO,
|
|
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;AACH,wBAAgB,QAAQ,CACpB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAA+C,EACxD,UAAU,GAAE,kBAAuB,GACpC,MAAM,CAER;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,eAA+B,EACxC,UAAU,GAAE,kBAAuB,GACpC,MAAM,CAER;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC5B,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,kBAAkB,cAqCjC"}
|
package/dist/markdown/index.js
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
import { isArray as d } from "@tolki/utils";
|
|
2
2
|
import p from "markdown-it";
|
|
3
3
|
import w from "markdown-it-anchor";
|
|
4
|
-
import
|
|
4
|
+
import b from "markdown-it-task-lists";
|
|
5
5
|
function A(e, n = { gfm: !0, anchors: !1 }, t = []) {
|
|
6
6
|
return s(n, t).render(e);
|
|
7
7
|
}
|
|
8
8
|
function L(e, n = { gfm: !0 }, t = []) {
|
|
9
9
|
return s(n, t).renderInline(e);
|
|
10
10
|
}
|
|
11
|
-
function s(e
|
|
11
|
+
function s(e, n) {
|
|
12
12
|
const {
|
|
13
13
|
html: t = !1,
|
|
14
|
-
linkify:
|
|
15
|
-
breaks:
|
|
14
|
+
linkify: i = !0,
|
|
15
|
+
breaks: a = !0,
|
|
16
16
|
gfm: u = !0,
|
|
17
|
-
anchors:
|
|
17
|
+
anchors: o = !1,
|
|
18
18
|
allowUnsafeLinks: l = !1,
|
|
19
19
|
...m
|
|
20
|
-
} = e, r = new p({ html: t, linkify:
|
|
21
|
-
l && (r.validateLink = () => !0), u && r.use(
|
|
22
|
-
for (const
|
|
23
|
-
if (d(
|
|
24
|
-
const [c, k] =
|
|
20
|
+
} = e, r = new p({ html: t, linkify: i, breaks: a, ...m });
|
|
21
|
+
l && (r.validateLink = () => !0), u && r.use(b, { label: !0, labelAfter: !0 }), o && r.use(w, typeof o == "object" ? o : {});
|
|
22
|
+
for (const f of n)
|
|
23
|
+
if (d(f)) {
|
|
24
|
+
const [c, k] = f;
|
|
25
25
|
r.use(c, k);
|
|
26
|
-
} else
|
|
26
|
+
} else
|
|
27
|
+
r.use(f);
|
|
27
28
|
return r;
|
|
28
29
|
}
|
|
29
30
|
export {
|
|
@@ -9,11 +9,9 @@ export interface PluralizerRules {
|
|
|
9
9
|
* @param count - The count to determine pluralization (default: 2)
|
|
10
10
|
* @returns The pluralized studly caps case string
|
|
11
11
|
*
|
|
12
|
-
* @
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
12
|
+
* @see https://tolki.abe.dev/strings/string-utilities-list.html#pluralstudly
|
|
15
13
|
*
|
|
16
|
-
*
|
|
14
|
+
* @requires {@link https://www.npmjs.com/package/pluralize pluralize package}
|
|
17
15
|
*/
|
|
18
16
|
export declare function pluralStudly(value: string, count?: number): string;
|
|
19
17
|
/**
|
|
@@ -23,11 +21,9 @@ export declare function pluralStudly(value: string, count?: number): string;
|
|
|
23
21
|
* @param count - The count to determine pluralization (default: 2)
|
|
24
22
|
* @returns The pluralized Pascal caps case string
|
|
25
23
|
*
|
|
26
|
-
* @
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
24
|
+
* @see https://tolki.abe.dev/strings/string-utilities-list.html#pluralpascal
|
|
29
25
|
*
|
|
30
|
-
*
|
|
26
|
+
* @requires {@link https://www.npmjs.com/package/pluralize pluralize package}
|
|
31
27
|
*/
|
|
32
28
|
export declare function pluralPascal(value: string, count?: number): string;
|
|
33
29
|
/**
|
|
@@ -38,13 +34,9 @@ export declare function pluralPascal(value: string, count?: number): string;
|
|
|
38
34
|
* @param prependCount - Whether to prepend the count to the result (default: false)
|
|
39
35
|
* @returns The pluralized word, optionally with the count prepended.
|
|
40
36
|
*
|
|
41
|
-
* @
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
37
|
+
* @see https://tolki.abe.dev/strings/string-utilities-list.html#plural
|
|
44
38
|
*
|
|
45
|
-
*
|
|
46
|
-
* plural("apple", 1); -> "apple"
|
|
47
|
-
* plural("apple", 2, true); -> "2 apples"
|
|
39
|
+
* @requires {@link https://www.npmjs.com/package/pluralize pluralize package}
|
|
48
40
|
*/
|
|
49
41
|
export declare function plural(value: string, count?: number, prependCount?: boolean): string;
|
|
50
42
|
/**
|
|
@@ -53,6 +45,8 @@ export declare function plural(value: string, count?: number, prependCount?: boo
|
|
|
53
45
|
* @param value - The word to singularize.
|
|
54
46
|
* @returns The singular form of the word.
|
|
55
47
|
*
|
|
48
|
+
* @see https://tolki.abe.dev/strings/string-utilities-list.html#singular
|
|
49
|
+
*
|
|
56
50
|
* @requires {@link https://www.npmjs.com/package/pluralize pluralize package}
|
|
57
51
|
*/
|
|
58
52
|
export declare function singular(value: string): string;
|
|
@@ -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
|
|
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;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,MAAM,CAKrE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,MAAM,CAErE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CAClB,KAAK,EAAE,MAAM,EACb,KAAK,GAAE,MAAU,EACjB,YAAY,GAAE,OAAe,GAC9B,MAAM,CAKR;AAqBD;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAI9C;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAElD;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,GAAE,MAAW,GAAG,OAAO,CAEpD;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,GAAE,MAAW,GAAG,OAAO,CAEtD;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAiBnE;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,OAAO,SAAS,CAU5C"}
|
package/dist/replacer/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
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
|
+
*
|
|
9
|
+
* @see https://tolki.abe.dev/strings/string-utilities-list.html#substr
|
|
8
10
|
*/
|
|
9
11
|
export declare function substr(string: string, start: number, length?: number | null): string;
|
|
10
12
|
/**
|
|
@@ -15,6 +17,8 @@ export declare function substr(string: string, start: number, length?: number |
|
|
|
15
17
|
* @param offset - The starting position for the search. If negative, it starts that many characters from the end of the string.
|
|
16
18
|
* @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.
|
|
17
19
|
* @returns The number of occurrences of the substring within the specified segment.
|
|
20
|
+
*
|
|
21
|
+
* @see https://tolki.abe.dev/strings/string-utilities-list.html#substrcount
|
|
18
22
|
*/
|
|
19
23
|
export declare function substrCount(haystack: string, needle: string, offset?: number, length?: number | null): number;
|
|
20
24
|
/**
|
|
@@ -26,6 +30,10 @@ export declare function substrCount(haystack: string, needle: string, offset?: n
|
|
|
26
30
|
* @param offset - The starting position for the replacement. If negative, it starts that many characters from the end of the string.
|
|
27
31
|
* @param length - The number of characters to replace. If omitted or null, replaces all characters from offset to the end of the string. If negative, omits that many characters from the end.
|
|
28
32
|
* @returns The modified string or an array of modified strings if multiple replacements are provided.
|
|
33
|
+
*
|
|
34
|
+
* @see https://tolki.abe.dev/strings/string-utilities-list.html#substrreplace
|
|
29
35
|
*/
|
|
36
|
+
export declare function substrReplace(value: string, replace: string, offset?: number | number[], length?: number | number[] | null): string;
|
|
37
|
+
export declare function substrReplace(value: string, replace: string[], offset?: number | number[], length?: number | number[] | null): string[];
|
|
30
38
|
export declare function substrReplace(value: string, replace: string | string[], offset?: number | number[], length?: number | number[] | null): string | string[];
|
|
31
39
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAClB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,CAWR;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACvB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,MAAU,EAClB,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,CAgBR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CACzB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,GAClC,MAAM,CAAC;AACV,wBAAgB,aAAa,CACzB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,GAClC,MAAM,EAAE,CAAC;AACZ,wBAAgB,aAAa,CACzB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,GAClC,MAAM,GAAG,MAAM,EAAE,CAAC"}
|
package/dist/replacer/index.js
CHANGED
|
@@ -1,42 +1,46 @@
|
|
|
1
|
-
import { isArray as
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
return
|
|
1
|
+
import { isArray as m } from "@tolki/utils";
|
|
2
|
+
function g(i, o, r = null) {
|
|
3
|
+
const t = Array.from(i), n = t.length, { start: s, end: c } = d(n, o, r);
|
|
4
|
+
return s >= n || c <= s ? "" : t.slice(s, c).join("");
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function j(i, o, r = 0, t = null) {
|
|
7
7
|
if (o === "")
|
|
8
8
|
return 0;
|
|
9
|
-
const
|
|
10
|
-
if (c >=
|
|
9
|
+
const n = Array.from(i), s = n.length, { start: c, end: e } = d(s, r, t);
|
|
10
|
+
if (c >= s || e <= c)
|
|
11
11
|
return 0;
|
|
12
|
-
const
|
|
13
|
-
return A(
|
|
12
|
+
const l = n.slice(c, e).join("");
|
|
13
|
+
return A(l, o);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
15
|
+
function x(i, o, r = 0, t = null) {
|
|
16
|
+
const n = m(r) ? r[0] ?? 0 : r, s = m(t) ? t[0] ?? null : t, c = (e) => {
|
|
17
|
+
const l = Array.from(i), a = l.length;
|
|
18
|
+
let u = n >= 0 ? n : a + n;
|
|
19
|
+
u < 0 && (u = 0), u > a && (u = a);
|
|
20
|
+
const p = l.slice(0, u).join(""), h = l.slice(u);
|
|
21
|
+
let f;
|
|
22
|
+
return s == null ? f = "" : f = h.slice(s).join(""), p + e + f;
|
|
19
23
|
};
|
|
20
|
-
return
|
|
24
|
+
return m(o) ? o.map((e) => c(String(e))) : c(String(o));
|
|
21
25
|
}
|
|
22
|
-
function
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
let
|
|
26
|
-
return r == null ?
|
|
26
|
+
function d(i, o, r) {
|
|
27
|
+
let t = o >= 0 ? o : i + o;
|
|
28
|
+
t < 0 && (t = 0), t > i && (t = i);
|
|
29
|
+
let n;
|
|
30
|
+
return r == null ? n = i : r < 0 ? n = i + r : n = t + r, n = Math.max(0, Math.min(n, i)), { start: t, end: n };
|
|
27
31
|
}
|
|
28
|
-
function A(
|
|
29
|
-
let r = 0,
|
|
32
|
+
function A(i, o) {
|
|
33
|
+
let r = 0, t = 0;
|
|
30
34
|
for (; ; ) {
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
35
|
+
const n = i.indexOf(o, t);
|
|
36
|
+
if (n === -1)
|
|
33
37
|
break;
|
|
34
|
-
r++,
|
|
38
|
+
r++, t = n + o.length;
|
|
35
39
|
}
|
|
36
40
|
return r;
|
|
37
41
|
}
|
|
38
42
|
export {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
g as substr,
|
|
44
|
+
j as substrCount,
|
|
45
|
+
x as substrReplace
|
|
42
46
|
};
|