@zinaid/str 0.0.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.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/dist/base64.d.ts +7 -0
- package/dist/base64.d.ts.map +1 -0
- package/dist/base64.js +123 -0
- package/dist/convertcase.d.ts +38 -0
- package/dist/convertcase.d.ts.map +1 -0
- package/dist/convertcase.js +49 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +133 -0
- package/dist/markdown.d.ts +26 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +32 -0
- package/dist/pluralizer.d.ts +39 -0
- package/dist/pluralizer.d.ts.map +1 -0
- package/dist/pluralizer.js +90 -0
- package/dist/random.d.ts +28 -0
- package/dist/random.d.ts.map +1 -0
- package/dist/random.js +44 -0
- package/dist/replacer.d.ts +31 -0
- package/dist/replacer.d.ts.map +1 -0
- package/dist/replacer.js +42 -0
- package/dist/str.d.ts +846 -0
- package/dist/str.d.ts.map +1 -0
- package/dist/str.js +1096 -0
- package/dist/stringable.d.ts +555 -0
- package/dist/stringable.d.ts.map +1 -0
- package/dist/stringable.js +862 -0
- package/dist/trimmer.d.ts +4 -0
- package/dist/trimmer.d.ts.map +1 -0
- package/dist/trimmer.js +128 -0
- package/package.json +43 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the portion of the string specified by the start and length parameters.
|
|
3
|
+
*
|
|
4
|
+
* @param string
|
|
5
|
+
* @param start
|
|
6
|
+
* @param length
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function substr(string: string, start: number, length?: number | null): string;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the number of substring occurrences.
|
|
12
|
+
*
|
|
13
|
+
* @param haystack
|
|
14
|
+
* @param needle
|
|
15
|
+
* @param offset
|
|
16
|
+
* @param length
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export declare function substrCount(haystack: string, needle: string, offset?: number, length?: number | null): number;
|
|
20
|
+
/**
|
|
21
|
+
* Replace text within a portion of a string.
|
|
22
|
+
* Properly handles multibyte characters.
|
|
23
|
+
*
|
|
24
|
+
* @param value
|
|
25
|
+
* @param replace
|
|
26
|
+
* @param offset
|
|
27
|
+
* @param length
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
export declare function substrReplace(value: string, replace: string | string[], offset?: number | number[], length?: number | number[] | null): string | string[];
|
|
31
|
+
//# sourceMappingURL=replacer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replacer.d.ts","sourceRoot":"","sources":["../src/replacer.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAClB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,MAAM,GAAE,MAAM,GAAG,IAAW,GAC7B,MAAM,CAWR;AAED;;;;;;;;GAQG;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;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CACzB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,MAAM,GAAE,MAAM,GAAG,MAAM,EAAM,EAC7B,MAAM,GAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAW,GACxC,MAAM,GAAG,MAAM,EAAE,CAyBnB"}
|
package/dist/replacer.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isArray as l } from "@zinaid/utils";
|
|
2
|
+
function j(s, o, r = null) {
|
|
3
|
+
const n = Array.from(s), t = n.length, { start: i, end: c } = a(t, o, r);
|
|
4
|
+
return i >= t || c <= i ? "" : n.slice(i, c).join("");
|
|
5
|
+
}
|
|
6
|
+
function x(s, o, r = 0, n = null) {
|
|
7
|
+
if (o === "")
|
|
8
|
+
return 0;
|
|
9
|
+
const t = Array.from(s), i = t.length, { start: c, end: u } = a(i, r, n);
|
|
10
|
+
if (c >= i || u <= c)
|
|
11
|
+
return 0;
|
|
12
|
+
const e = t.slice(c, u).join("");
|
|
13
|
+
return A(e, o);
|
|
14
|
+
}
|
|
15
|
+
function y(s, o, r = 0, n = null) {
|
|
16
|
+
const t = l(r) ? r[0] ?? 0 : r, i = l(n) ? n[0] ?? null : n, c = (u) => {
|
|
17
|
+
const e = Array.from(s), f = e.length, m = i ?? f, { start: d, end: p } = a(f, t, m), h = e.slice(0, d).join(""), g = e.slice(p).join("");
|
|
18
|
+
return h + u + g;
|
|
19
|
+
};
|
|
20
|
+
return l(o) ? o.map((u) => c(String(u))) : c(String(o));
|
|
21
|
+
}
|
|
22
|
+
function a(s, o, r) {
|
|
23
|
+
let n = o >= 0 ? o : s + o;
|
|
24
|
+
n < 0 && (n = 0), n > s && (n = s);
|
|
25
|
+
let t;
|
|
26
|
+
return r == null ? t = s : r < 0 ? t = s + r : t = n + r, t = Math.max(0, Math.min(t, s)), { start: n, end: t };
|
|
27
|
+
}
|
|
28
|
+
function A(s, o) {
|
|
29
|
+
let r = 0, n = 0;
|
|
30
|
+
for (; ; ) {
|
|
31
|
+
const t = s.indexOf(o, n);
|
|
32
|
+
if (t === -1)
|
|
33
|
+
break;
|
|
34
|
+
r++, n = t + o.length;
|
|
35
|
+
}
|
|
36
|
+
return r;
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
j as substr,
|
|
40
|
+
x as substrCount,
|
|
41
|
+
y as substrReplace
|
|
42
|
+
};
|