@tolki/str 1.1.0 → 1.2.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 -1
- package/dist/index.js +125 -124
- package/dist/pluralizer/index.d.ts +13 -1
- package/dist/pluralizer/index.d.ts.map +1 -1
- package/dist/pluralizer/index.js +44 -39
- package/dist/stringable/index.d.ts +9 -2
- package/dist/stringable/index.d.ts.map +1 -1
- package/dist/stringable/index.js +99 -90
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ However, if you are working on a backend project where bundle size is not a conc
|
|
|
62
62
|
|
|
63
63
|
These are the string utilities that can be used independently as single functions.
|
|
64
64
|
|
|
65
|
-
[after](#after) [afterLast](#afterlast) [apa](#apa) [ascii](#ascii) [before](#before) [beforeLast](#beforelast) [between](#between) [betweenFirst](#betweenfirst) [camel](#camel) [charAt](#charat) [chopEnd](#chopend) [chopStart](#chopstart) [contains](#contains) [containsAll](#containsall) [doesntContain](#doesntcontain) [deduplicate](#deduplicate) [doesntEndWith](#doesntendwith) [doesntStartWith](#doesntstartwith) [endsWith](#endswith) [excerpt](#excerpt) [finish](#finish) [fromBase64](#frombase64) [headline](#headline) [initials](#initials) [inlineMarkdown](#inlinemarkdown) [is](#is) [isAscii](#isascii) [isJson](#isjson) [isUrl](#isurl) [isUlid](#isulid) [isUuid](#isuuid) [kebab](#kebab) [lcfirst](#lcfirst) [length](#length) [limit](#limit) [lower](#lower) [markdown](#markdown) [mask](#mask) [match](#match) [matchAll](#matchall) [isMatch](#ismatch) [numbers](#numbers) [padBoth](#padboth) [padLeft](#padleft) [padRight](#padright) [pascal](#pascal) [pluralPascal](#pluralpascal) [password](#password) [plural](#plural) [pluralStudly](#pluralstudly) [position](#position) [random](#random) [remove](#remove) [repeat](#repeat) [replace](#replace) [replaceArray](#replacearray) [replaceFirst](#replacefirst) [replaceLast](#replacelast) [replaceMatches](#replacematches) [replaceStart](#replacestart) [replaceEnd](#replaceend) [reverse](#reverse) [singular](#singular) [slug](#slug) [snake](#snake) [squish](#squish) [start](#start) [startsWith](#startswith) [stripTags](#striptags) [studly](#studly) [substr](#substr) [substrCount](#substrcount) [substrReplace](#substrreplace) [swap](#swap) [take](#take) [title](#title) [toBase64](#tobase64) [transliterate](#transliterate) [trim](#trim) [ltrim](#ltrim) [rtrim](#rtrim) [ucfirst](#ucfirst) [ucsplit](#ucsplit) [ucwords](#ucwords) [upper](#upper) [ulid](#ulid) [unwrap](#unwrap) [uuid](#uuid) [uuid7](#uuid7) [wordCount](#wordcount) [wordWrap](#wordwrap) [words](#words) [wrap](#wrap) [str](#str) [of](#of)
|
|
65
|
+
[after](#after) [afterLast](#afterlast) [apa](#apa) [ascii](#ascii) [before](#before) [beforeLast](#beforelast) [between](#between) [betweenFirst](#betweenfirst) [camel](#camel) [charAt](#charat) [chopEnd](#chopend) [chopStart](#chopstart) [contains](#contains) [containsAll](#containsall) [counted](#counted) [doesntContain](#doesntcontain) [deduplicate](#deduplicate) [doesntEndWith](#doesntendwith) [doesntStartWith](#doesntstartwith) [endsWith](#endswith) [excerpt](#excerpt) [finish](#finish) [fromBase64](#frombase64) [headline](#headline) [initials](#initials) [inlineMarkdown](#inlinemarkdown) [is](#is) [isAscii](#isascii) [isJson](#isjson) [isUrl](#isurl) [isUlid](#isulid) [isUuid](#isuuid) [kebab](#kebab) [lcfirst](#lcfirst) [length](#length) [limit](#limit) [lower](#lower) [markdown](#markdown) [mask](#mask) [match](#match) [matchAll](#matchall) [isMatch](#ismatch) [numbers](#numbers) [padBoth](#padboth) [padLeft](#padleft) [padRight](#padright) [pascal](#pascal) [pluralPascal](#pluralpascal) [password](#password) [plural](#plural) [pluralStudly](#pluralstudly) [position](#position) [random](#random) [remove](#remove) [repeat](#repeat) [replace](#replace) [replaceArray](#replacearray) [replaceFirst](#replacefirst) [replaceLast](#replacelast) [replaceMatches](#replacematches) [replaceStart](#replacestart) [replaceEnd](#replaceend) [reverse](#reverse) [singular](#singular) [slug](#slug) [snake](#snake) [squish](#squish) [start](#start) [startsWith](#startswith) [stripTags](#striptags) [studly](#studly) [substr](#substr) [substrCount](#substrcount) [substrReplace](#substrreplace) [swap](#swap) [take](#take) [title](#title) [toBase64](#tobase64) [transliterate](#transliterate) [trim](#trim) [ltrim](#ltrim) [rtrim](#rtrim) [ucfirst](#ucfirst) [ucsplit](#ucsplit) [ucwords](#ucwords) [upper](#upper) [ulid](#ulid) [unwrap](#unwrap) [uuid](#uuid) [uuid7](#uuid7) [wordCount](#wordcount) [wordWrap](#wordwrap) [words](#words) [wrap](#wrap) [str](#str) [of](#of)
|
|
66
66
|
|
|
67
67
|
### String Utilities Details
|
|
68
68
|
|
|
@@ -286,6 +286,32 @@ const result = containsAll("This is my name", ["MY", "NAME"], true);
|
|
|
286
286
|
// result is true
|
|
287
287
|
```
|
|
288
288
|
|
|
289
|
+
#### counted
|
|
290
|
+
|
|
291
|
+
Get the plural form of an English word with the count prepended.
|
|
292
|
+
|
|
293
|
+
```javascript
|
|
294
|
+
import { counted } from "@tolki/str";
|
|
295
|
+
|
|
296
|
+
const result = counted("order", 1);
|
|
297
|
+
|
|
298
|
+
// result is "1 order"
|
|
299
|
+
|
|
300
|
+
const result2 = counted("order", 1000);
|
|
301
|
+
|
|
302
|
+
// result2 is "1,000 orders"
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
You may also pass an array as the count, in which case its length is used:
|
|
306
|
+
|
|
307
|
+
```javascript
|
|
308
|
+
import { counted } from "@tolki/str";
|
|
309
|
+
|
|
310
|
+
const result = counted("order", ["a", "b"]);
|
|
311
|
+
|
|
312
|
+
// result is "2 orders"
|
|
313
|
+
```
|
|
314
|
+
|
|
289
315
|
#### doesntContain
|
|
290
316
|
|
|
291
317
|
Determine if a given string doesn't contain a given substring.
|
|
@@ -1518,6 +1544,10 @@ const result = toBase64("Laravel");
|
|
|
1518
1544
|
// result is "TGFyYXZlbA=="
|
|
1519
1545
|
```
|
|
1520
1546
|
|
|
1547
|
+
#### trans
|
|
1548
|
+
|
|
1549
|
+
This function is purposely not implemented. Laravel's `Str::trans` resolves translation keys through the framework's localization system, which has no equivalent in this library. Use a JavaScript i18n library (such as [i18next](https://www.i18next.com/) or [FormatJS](https://formatjs.github.io/)) to translate strings instead.
|
|
1550
|
+
|
|
1521
1551
|
#### transliterate
|
|
1522
1552
|
|
|
1523
1553
|
Transliterate a string to its closest ASCII representation.
|
package/dist/index.js
CHANGED
|
@@ -1,140 +1,141 @@
|
|
|
1
1
|
import { ascii as t, slug as a } from "./ascii/index.js";
|
|
2
2
|
import { bytesToBase64 as i, fromBase64 as o, toBase64 as n } from "./base64/index.js";
|
|
3
|
-
import { CaseTypes as c, convertCase as
|
|
3
|
+
import { CaseTypes as c, convertCase as d, title as p, upper as u } from "./convertcase/index.js";
|
|
4
4
|
import { inlineMarkdown as f, markDownRenderer as h, markdown as g } from "./markdown/index.js";
|
|
5
|
-
import {
|
|
6
|
-
import { randomInt as
|
|
7
|
-
import { substr as
|
|
8
|
-
import { after as
|
|
9
|
-
import { Stringable as
|
|
10
|
-
import { transliterate as
|
|
11
|
-
import { ltrim as
|
|
12
|
-
import { createUlidsNormally as
|
|
13
|
-
import { createUuidsNormally as
|
|
5
|
+
import { counted as U, inflector as w, isPlural as x, isSingular as b, matchCase as y, plural as C, pluralPascal as k, pluralStudly as R, singular as z, uncountable as A } from "./pluralizer/index.js";
|
|
6
|
+
import { randomInt as q, randomString as B } from "./random/index.js";
|
|
7
|
+
import { substr as v, substrCount as E, substrReplace as F } from "./replacer/index.js";
|
|
8
|
+
import { after as N, afterLast as P, apa as T, before as D, beforeLast as I, between as J, betweenFirst as O, camel as j, camelCacheSize as G, charAt as H, chopEnd as K, chopStart as Q, contains as V, containsAll as X, createRandomStringsNormally as Y, createRandomStringsUsing as Z, createRandomStringsUsingSequence as _, deduplicate as $, doesntContain as ee, doesntEndWith as re, doesntStartWith as te, endsWith as ae, excerpt as se, finish as ie, flushCache as oe, headline as ne, initials as le, is as ce, isAscii as de, isJson as pe, isMatch as ue, isUrl as me, kebab as fe, lcfirst as he, length as ge, limit as Se, lower as Ue, makePad as we, mask as xe, match as be, matchAll as ye, numbers as Ce, padBoth as ke, padLeft as Re, padRight as ze, pascal as Ae, password as We, position as qe, random as Be, remove as Le, repeat as ve, replace as Ee, replaceArray as Fe, replaceEnd as Me, replaceFirst as Ne, replaceLast as Pe, replaceMatches as Te, replaceStart as De, resetFactoryState as Ie, reverse as Je, snake as Oe, snakeCacheSize as je, squish as Ge, start as He, startsWith as Ke, stripTags as Qe, studly as Ve, studlyCacheSize as Xe, swap as Ye, take as Ze, toStringOr as _e, ucfirst as $e, ucsplit as er, ucwords as rr, unwrap as tr, wordCount as ar, wordWrap as sr, words as ir, wrap as or } from "./str.js";
|
|
9
|
+
import { Stringable as lr, of as cr, str as dr } from "./stringable/index.js";
|
|
10
|
+
import { transliterate as ur } from "./transliterate/index.js";
|
|
11
|
+
import { ltrim as fr, rtrim as hr, trim as gr } from "./trimmer/index.js";
|
|
12
|
+
import { createUlidsNormally as Ur, createUlidsUsing as wr, createUlidsUsingSequence as xr, freezeUlids as br, isUlid as yr, ulid as Cr } from "./ulid/index.js";
|
|
13
|
+
import { createUuidsNormally as Rr, createUuidsUsing as zr, createUuidsUsingSequence as Ar, freezeUuids as Wr, isUuid as qr, uuid as Br, uuid7 as Lr } from "./uuid/index.js";
|
|
14
14
|
export {
|
|
15
15
|
c as CaseTypes,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
lr as Stringable,
|
|
17
|
+
N as after,
|
|
18
|
+
P as afterLast,
|
|
19
|
+
T as apa,
|
|
20
20
|
t as ascii,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
D as before,
|
|
22
|
+
I as beforeLast,
|
|
23
|
+
J as between,
|
|
24
|
+
O as betweenFirst,
|
|
25
25
|
i as bytesToBase64,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
Y as
|
|
36
|
-
Z as
|
|
37
|
-
|
|
38
|
-
Ur as
|
|
39
|
-
wr as
|
|
40
|
-
|
|
41
|
-
Rr as
|
|
42
|
-
zr as
|
|
43
|
-
|
|
44
|
-
$ as
|
|
45
|
-
ee as
|
|
46
|
-
re as
|
|
47
|
-
te as
|
|
48
|
-
ae as
|
|
49
|
-
se as
|
|
50
|
-
ie as
|
|
51
|
-
|
|
52
|
-
|
|
26
|
+
j as camel,
|
|
27
|
+
G as camelCacheSize,
|
|
28
|
+
H as charAt,
|
|
29
|
+
K as chopEnd,
|
|
30
|
+
Q as chopStart,
|
|
31
|
+
V as contains,
|
|
32
|
+
X as containsAll,
|
|
33
|
+
d as convertCase,
|
|
34
|
+
U as counted,
|
|
35
|
+
Y as createRandomStringsNormally,
|
|
36
|
+
Z as createRandomStringsUsing,
|
|
37
|
+
_ as createRandomStringsUsingSequence,
|
|
38
|
+
Ur as createUlidsNormally,
|
|
39
|
+
wr as createUlidsUsing,
|
|
40
|
+
xr as createUlidsUsingSequence,
|
|
41
|
+
Rr as createUuidsNormally,
|
|
42
|
+
zr as createUuidsUsing,
|
|
43
|
+
Ar as createUuidsUsingSequence,
|
|
44
|
+
$ as deduplicate,
|
|
45
|
+
ee as doesntContain,
|
|
46
|
+
re as doesntEndWith,
|
|
47
|
+
te as doesntStartWith,
|
|
48
|
+
ae as endsWith,
|
|
49
|
+
se as excerpt,
|
|
50
|
+
ie as finish,
|
|
51
|
+
oe as flushCache,
|
|
52
|
+
br as freezeUlids,
|
|
53
|
+
Wr as freezeUuids,
|
|
53
54
|
o as fromBase64,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
ne as headline,
|
|
56
|
+
w as inflector,
|
|
57
|
+
le as initials,
|
|
57
58
|
f as inlineMarkdown,
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
ce as is,
|
|
60
|
+
de as isAscii,
|
|
60
61
|
pe as isJson,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
ue as isMatch,
|
|
63
|
+
x as isPlural,
|
|
64
|
+
b as isSingular,
|
|
65
|
+
yr as isUlid,
|
|
66
|
+
me as isUrl,
|
|
67
|
+
qr as isUuid,
|
|
68
|
+
fe as kebab,
|
|
69
|
+
he as lcfirst,
|
|
70
|
+
ge as length,
|
|
71
|
+
Se as limit,
|
|
72
|
+
Ue as lower,
|
|
73
|
+
fr as ltrim,
|
|
74
|
+
we as makePad,
|
|
74
75
|
h as markDownRenderer,
|
|
75
76
|
g as markdown,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
77
|
+
xe as mask,
|
|
78
|
+
be as match,
|
|
79
|
+
ye as matchAll,
|
|
80
|
+
y as matchCase,
|
|
81
|
+
Ce as numbers,
|
|
82
|
+
cr as of,
|
|
83
|
+
ke as padBoth,
|
|
84
|
+
Re as padLeft,
|
|
85
|
+
ze as padRight,
|
|
86
|
+
Ae as pascal,
|
|
87
|
+
We as password,
|
|
88
|
+
C as plural,
|
|
89
|
+
k as pluralPascal,
|
|
90
|
+
R as pluralStudly,
|
|
91
|
+
qe as position,
|
|
92
|
+
Be as random,
|
|
93
|
+
q as randomInt,
|
|
94
|
+
B as randomString,
|
|
95
|
+
Le as remove,
|
|
96
|
+
ve as repeat,
|
|
97
|
+
Ee as replace,
|
|
98
|
+
Fe as replaceArray,
|
|
99
|
+
Me as replaceEnd,
|
|
100
|
+
Ne as replaceFirst,
|
|
101
|
+
Pe as replaceLast,
|
|
102
|
+
Te as replaceMatches,
|
|
103
|
+
De as replaceStart,
|
|
104
|
+
Ie as resetFactoryState,
|
|
105
|
+
Je as reverse,
|
|
106
|
+
hr as rtrim,
|
|
107
|
+
z as singular,
|
|
107
108
|
a as slug,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
109
|
+
Oe as snake,
|
|
110
|
+
je as snakeCacheSize,
|
|
111
|
+
Ge as squish,
|
|
112
|
+
He as start,
|
|
113
|
+
Ke as startsWith,
|
|
114
|
+
dr as str,
|
|
115
|
+
Qe as stripTags,
|
|
116
|
+
Ve as studly,
|
|
117
|
+
Xe as studlyCacheSize,
|
|
118
|
+
v as substr,
|
|
119
|
+
E as substrCount,
|
|
120
|
+
F as substrReplace,
|
|
121
|
+
Ye as swap,
|
|
122
|
+
Ze as take,
|
|
123
|
+
p as title,
|
|
123
124
|
n as toBase64,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
125
|
+
_e as toStringOr,
|
|
126
|
+
ur as transliterate,
|
|
127
|
+
gr as trim,
|
|
128
|
+
$e as ucfirst,
|
|
129
|
+
er as ucsplit,
|
|
130
|
+
rr as ucwords,
|
|
131
|
+
Cr as ulid,
|
|
132
|
+
A as uncountable,
|
|
133
|
+
tr as unwrap,
|
|
133
134
|
u as upper,
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
Br as uuid,
|
|
136
|
+
Lr as uuid7,
|
|
137
|
+
ar as wordCount,
|
|
138
|
+
sr as wordWrap,
|
|
139
|
+
ir as words,
|
|
140
|
+
or as wrap
|
|
140
141
|
};
|
|
@@ -38,7 +38,19 @@ export declare function pluralPascal(value: string, count?: number): string;
|
|
|
38
38
|
*
|
|
39
39
|
* @requires {@link https://www.npmjs.com/package/pluralize pluralize package}
|
|
40
40
|
*/
|
|
41
|
-
export declare function plural(value: string, count?: number, prependCount?: boolean): string;
|
|
41
|
+
export declare function plural(value: string, count?: number | unknown[], prependCount?: boolean): string;
|
|
42
|
+
/**
|
|
43
|
+
* Get the plural form of an English word with the count prepended.
|
|
44
|
+
*
|
|
45
|
+
* @param value - The word to pluralize.
|
|
46
|
+
* @param count - The count to determine pluralization. Arrays are counted by length.
|
|
47
|
+
* @returns The pluralized word with the formatted count prepended.
|
|
48
|
+
*
|
|
49
|
+
* @see https://tolki.abe.dev/strings/string-utilities-list.html#counted
|
|
50
|
+
*
|
|
51
|
+
* @requires {@link https://www.npmjs.com/package/pluralize pluralize package}
|
|
52
|
+
*/
|
|
53
|
+
export declare function counted(value: string, count: number | unknown[]): string;
|
|
42
54
|
/**
|
|
43
55
|
* Get the singular form of an English word.
|
|
44
56
|
*
|
|
@@ -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;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,MAAU,GAAG,MAAM,CAKrE;AAED;;;;;;;;;;GAUG;AAC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,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAiBnE;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,OAAO,SAAS,CAU5C"}
|
package/dist/pluralizer/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { format as
|
|
2
|
-
import { isUndefined as
|
|
3
|
-
import
|
|
4
|
-
let
|
|
5
|
-
const
|
|
1
|
+
import { format as l } from "@tolki/num";
|
|
2
|
+
import { isUndefined as f, isNumber as c } from "@tolki/utils";
|
|
3
|
+
import p from "pluralize";
|
|
4
|
+
let i;
|
|
5
|
+
const u = {
|
|
6
6
|
uncountable: [
|
|
7
7
|
"audio",
|
|
8
8
|
"bison",
|
|
@@ -49,51 +49,56 @@ const o = {
|
|
|
49
49
|
"wheat"
|
|
50
50
|
]
|
|
51
51
|
};
|
|
52
|
-
function
|
|
53
|
-
const
|
|
54
|
-
return
|
|
52
|
+
function d(e, n = 2) {
|
|
53
|
+
const t = e.split(/(?=[A-Z])/), r = String(t.pop());
|
|
54
|
+
return t.join("") + a(r, n);
|
|
55
55
|
}
|
|
56
|
-
function
|
|
57
|
-
return
|
|
56
|
+
function C(e, n = 2) {
|
|
57
|
+
return d(e, n);
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
59
|
+
function a(e, n = 2, t = !1) {
|
|
60
|
+
const r = c(n) ? n : n.length;
|
|
61
|
+
return (t ? l(r) + " " : "") + m(e, r);
|
|
61
62
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
63
|
+
function U(e, n) {
|
|
64
|
+
return a(e, n, !0);
|
|
65
|
+
}
|
|
66
|
+
function m(e, n) {
|
|
67
|
+
if (Math.abs(n) === 1 || g(e))
|
|
64
68
|
return e;
|
|
65
|
-
const
|
|
66
|
-
return
|
|
69
|
+
const t = o().plural(e);
|
|
70
|
+
return s(t, e);
|
|
67
71
|
}
|
|
68
|
-
function
|
|
69
|
-
const n =
|
|
70
|
-
return
|
|
72
|
+
function k(e) {
|
|
73
|
+
const n = o().singular(e);
|
|
74
|
+
return s(n, e);
|
|
71
75
|
}
|
|
72
|
-
function
|
|
73
|
-
return
|
|
76
|
+
function g(e) {
|
|
77
|
+
return u.uncountable.includes(e.toLowerCase());
|
|
74
78
|
}
|
|
75
|
-
function
|
|
76
|
-
return
|
|
79
|
+
function S(e = "") {
|
|
80
|
+
return o().isPlural(e);
|
|
77
81
|
}
|
|
78
|
-
function
|
|
79
|
-
return
|
|
82
|
+
function j(e = "") {
|
|
83
|
+
return o().isSingular(e);
|
|
80
84
|
}
|
|
81
|
-
function
|
|
85
|
+
function s(e, n) {
|
|
82
86
|
return n.toLowerCase() === n ? e.toLowerCase() : n.toUpperCase() === n ? e.toUpperCase() : n[0] && n[0].toUpperCase() + n.slice(1) === n ? (e[0] ?? "").toUpperCase() + e.slice(1) : e;
|
|
83
87
|
}
|
|
84
|
-
function
|
|
85
|
-
return
|
|
86
|
-
(e) =>
|
|
87
|
-
)),
|
|
88
|
+
function o() {
|
|
89
|
+
return f(i) && (i = p, u.uncountable.forEach(
|
|
90
|
+
(e) => i.addUncountableRule(e)
|
|
91
|
+
)), i;
|
|
88
92
|
}
|
|
89
93
|
export {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
U as counted,
|
|
95
|
+
o as inflector,
|
|
96
|
+
S as isPlural,
|
|
97
|
+
j as isSingular,
|
|
98
|
+
s as matchCase,
|
|
99
|
+
a as plural,
|
|
100
|
+
C as pluralPascal,
|
|
101
|
+
d as pluralStudly,
|
|
102
|
+
k as singular,
|
|
103
|
+
g as uncountable
|
|
99
104
|
};
|
|
@@ -150,6 +150,13 @@ export declare class Stringable {
|
|
|
150
150
|
* @returns The converted string as a new Stringable instance.
|
|
151
151
|
*/
|
|
152
152
|
convertCase(mode: ConvertCaseMode): Stringable;
|
|
153
|
+
/**
|
|
154
|
+
* Get the plural form of an English word with the count prepended.
|
|
155
|
+
*
|
|
156
|
+
* @param count - The count to determine pluralization. Arrays are counted by length.
|
|
157
|
+
* @returns The pluralized string with the formatted count prepended, as a new Stringable instance.
|
|
158
|
+
*/
|
|
159
|
+
counted(count: number | unknown[]): Stringable;
|
|
153
160
|
/**
|
|
154
161
|
* Replace consecutive instances of a given character with a single character.
|
|
155
162
|
*
|
|
@@ -383,11 +390,11 @@ export declare class Stringable {
|
|
|
383
390
|
/**
|
|
384
391
|
* Get the plural form of an English word.
|
|
385
392
|
*
|
|
386
|
-
* @param count - The count to determine singular or plural form. Defaults to 2.
|
|
393
|
+
* @param count - The count to determine singular or plural form. Arrays are counted by length. Defaults to 2.
|
|
387
394
|
* @param prependCount - Whether to prepend the count to the result. Defaults to false.
|
|
388
395
|
* @returns The pluralized string as a new Stringable instance.
|
|
389
396
|
*/
|
|
390
|
-
plural(count?: number, prependCount?: boolean): Stringable;
|
|
397
|
+
plural(count?: number | unknown[], prependCount?: boolean): Stringable;
|
|
391
398
|
/**
|
|
392
399
|
* Pluralize the last word of an English, studly caps case string.
|
|
393
400
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stringable/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stringable/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAoFvE,MAAM,MAAM,kBAAkB,GACxB,MAAM,GACN,MAAM,GACN,OAAO,GACP,CAAC,CAAC,QAAQ,EAAE,UAAU,KAAK,M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AK;IAK9C;;;;OAIG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;;OAIG;IACH,KAAK,IAAI,MAAM;IAIf;;;;;OAKG;IACH,SAAS,CAAC,IAAI,SAAK,GAAG,MAAM;IAK5B;;;;OAIG;IACH,OAAO,IAAI,MAAM;IAIjB;;;;OAIG;IACH,SAAS,IAAI,OAAO;IAMpB;;;;OAIG;IACH,MAAM,IAAI,IAAI,GAAG,IAAI;IAKrB;;;;OAIG;IACH,aAAa,IAAI,MAAM;CAG1B"}
|
package/dist/stringable/index.js
CHANGED
|
@@ -3,17 +3,17 @@ import { ascii as c, slug as p } from "../ascii/index.js";
|
|
|
3
3
|
import { toBase64 as d, fromBase64 as f } from "../base64/index.js";
|
|
4
4
|
import { convertCase as m, upper as _, title as E } from "../convertcase/index.js";
|
|
5
5
|
import { markdown as y, inlineMarkdown as A } from "../markdown/index.js";
|
|
6
|
-
import {
|
|
7
|
-
import { substr as
|
|
8
|
-
import { after as
|
|
9
|
-
import { transliterate as
|
|
10
|
-
import { trim as o, ltrim as
|
|
11
|
-
import { isUlid as
|
|
12
|
-
import { isUuid as
|
|
13
|
-
function
|
|
6
|
+
import { counted as W, plural as x, pluralStudly as k, pluralPascal as N, singular as U } from "../pluralizer/index.js";
|
|
7
|
+
import { substr as C, substrCount as L, substrReplace as M } from "../replacer/index.js";
|
|
8
|
+
import { after as F, afterLast as I, before as B, beforeLast as R, between as j, betweenFirst as D, camel as T, charAt as P, chopStart as q, chopEnd as J, contains as V, containsAll as $, doesntContain as z, deduplicate as G, endsWith as X, doesntEndWith as H, excerpt as K, finish as O, is as Q, isAscii as Y, isJson as Z, isUrl as g, kebab as b, length as S, limit as ee, lower as a, mask as te, match as se, isMatch as re, matchAll as ne, numbers as ue, padBoth as ie, padLeft as he, padRight as le, position as ae, remove as oe, reverse as we, repeat as ve, replace as ce, replaceArray as pe, replaceFirst as de, replaceStart as fe, replaceLast as me, replaceEnd as _e, replaceMatches as Ee, squish as ye, start as Ae, stripTags as We, headline as xe, initials as ke, apa as Ne, snake as Ue, startsWith as Ce, doesntStartWith as Le, studly as Me, pascal as Fe, swap as Ie, take as Be, lcfirst as Re, ucfirst as je, ucsplit as De, ucwords as Te, words as Pe, wordCount as qe, wordWrap as Je, wrap as Ve, unwrap as $e } from "../str.js";
|
|
9
|
+
import { transliterate as ze } from "../transliterate/index.js";
|
|
10
|
+
import { trim as o, ltrim as Ge, rtrim as Xe } from "../trimmer/index.js";
|
|
11
|
+
import { isUlid as He } from "../ulid/index.js";
|
|
12
|
+
import { isUuid as Ke } from "../uuid/index.js";
|
|
13
|
+
function ut(h = "") {
|
|
14
14
|
return new s(h);
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function it(h = "") {
|
|
17
17
|
return new s(h);
|
|
18
18
|
}
|
|
19
19
|
class s {
|
|
@@ -33,7 +33,7 @@ class s {
|
|
|
33
33
|
* @returns The portion of the string after the first occurrence of the search value.
|
|
34
34
|
*/
|
|
35
35
|
after(e) {
|
|
36
|
-
return new s(
|
|
36
|
+
return new s(F(this._value, e));
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Return the remainder of a string after the last occurrence of a given value
|
|
@@ -42,7 +42,7 @@ class s {
|
|
|
42
42
|
* @returns The portion of the string after the last occurrence of the search value.
|
|
43
43
|
*/
|
|
44
44
|
afterLast(e) {
|
|
45
|
-
return new s(
|
|
45
|
+
return new s(I(this._value, e));
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Append the given values to the string.
|
|
@@ -78,7 +78,7 @@ class s {
|
|
|
78
78
|
* @returns The portion of the string before the first occurrence of the search value.
|
|
79
79
|
*/
|
|
80
80
|
before(e) {
|
|
81
|
-
return new s(
|
|
81
|
+
return new s(B(this._value, e));
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* Get the portion of a string before the last occurrence of a given value.
|
|
@@ -87,7 +87,7 @@ class s {
|
|
|
87
87
|
* @returns The portion of the string before the last occurrence of the search value.
|
|
88
88
|
*/
|
|
89
89
|
beforeLast(e) {
|
|
90
|
-
return new s(
|
|
90
|
+
return new s(R(this._value, e));
|
|
91
91
|
}
|
|
92
92
|
/**
|
|
93
93
|
* Get the portion of a string between two given values.
|
|
@@ -97,7 +97,7 @@ class s {
|
|
|
97
97
|
* @returns The portion of the string between the two given values.
|
|
98
98
|
*/
|
|
99
99
|
between(e, t) {
|
|
100
|
-
return new s(
|
|
100
|
+
return new s(j(this._value, e, t));
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
103
|
* Get the smallest possible portion of a string between two given values.
|
|
@@ -107,7 +107,7 @@ class s {
|
|
|
107
107
|
* @returns The smallest possible portion of the string between the two given values.
|
|
108
108
|
*/
|
|
109
109
|
betweenFirst(e, t) {
|
|
110
|
-
return new s(
|
|
110
|
+
return new s(D(this._value, e, t));
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* Convert a value to camel case.
|
|
@@ -115,7 +115,7 @@ class s {
|
|
|
115
115
|
* @returns The camel-cased string as a new Stringable instance.
|
|
116
116
|
*/
|
|
117
117
|
camel() {
|
|
118
|
-
return new s(
|
|
118
|
+
return new s(T(this._value));
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
121
121
|
* Get the character at the specified index.
|
|
@@ -124,7 +124,7 @@ class s {
|
|
|
124
124
|
* @returns The character at the specified index, or false if the index is out of bounds.
|
|
125
125
|
*/
|
|
126
126
|
charAt(e) {
|
|
127
|
-
return
|
|
127
|
+
return P(this._value, e);
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
130
|
* Remove the given string if it exists at the start of the current string.
|
|
@@ -133,7 +133,7 @@ class s {
|
|
|
133
133
|
* @returns The updated Stringable instance.
|
|
134
134
|
*/
|
|
135
135
|
chopStart(e) {
|
|
136
|
-
return new s(
|
|
136
|
+
return new s(q(this._value, e));
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* Remove the given string if it exists at the end of the current string.
|
|
@@ -142,7 +142,7 @@ class s {
|
|
|
142
142
|
* @returns The updated Stringable instance.
|
|
143
143
|
*/
|
|
144
144
|
chopEnd(e) {
|
|
145
|
-
return new s(
|
|
145
|
+
return new s(J(this._value, e));
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* Determine if a given string contains a given substring.
|
|
@@ -152,7 +152,7 @@ class s {
|
|
|
152
152
|
* @returns boolean - True if the substring(s) are found, false otherwise
|
|
153
153
|
*/
|
|
154
154
|
contains(e, t = !1) {
|
|
155
|
-
return
|
|
155
|
+
return V(this._value, e, t);
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
158
158
|
* Determine if a given string contains all array values.
|
|
@@ -162,7 +162,7 @@ class s {
|
|
|
162
162
|
* @returns boolean - True if all substring(s) are found, false otherwise
|
|
163
163
|
*/
|
|
164
164
|
containsAll(e, t = !1) {
|
|
165
|
-
return
|
|
165
|
+
return $(this._value, e, t);
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
168
|
* Determine if a given string doesn't contain a given substring.
|
|
@@ -172,7 +172,7 @@ class s {
|
|
|
172
172
|
* @returns boolean - True if the substring(s) are not found, false otherwise
|
|
173
173
|
*/
|
|
174
174
|
doesntContain(e, t = !1) {
|
|
175
|
-
return
|
|
175
|
+
return z(this._value, e, t);
|
|
176
176
|
}
|
|
177
177
|
/**
|
|
178
178
|
* Convert the case of a string.
|
|
@@ -183,6 +183,15 @@ class s {
|
|
|
183
183
|
convertCase(e) {
|
|
184
184
|
return new s(m(this._value, e));
|
|
185
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Get the plural form of an English word with the count prepended.
|
|
188
|
+
*
|
|
189
|
+
* @param count - The count to determine pluralization. Arrays are counted by length.
|
|
190
|
+
* @returns The pluralized string with the formatted count prepended, as a new Stringable instance.
|
|
191
|
+
*/
|
|
192
|
+
counted(e) {
|
|
193
|
+
return new s(W(this._value, e));
|
|
194
|
+
}
|
|
186
195
|
/**
|
|
187
196
|
* Replace consecutive instances of a given character with a single character.
|
|
188
197
|
*
|
|
@@ -190,7 +199,7 @@ class s {
|
|
|
190
199
|
* @returns The updated Stringable instance.
|
|
191
200
|
*/
|
|
192
201
|
deduplicate(e = " ") {
|
|
193
|
-
return new s(
|
|
202
|
+
return new s(G(this._value, e));
|
|
194
203
|
}
|
|
195
204
|
/**
|
|
196
205
|
* Determine if a given string ends with a given substring.
|
|
@@ -199,7 +208,7 @@ class s {
|
|
|
199
208
|
* @returns boolean - True if the substring(s) are found, false otherwise
|
|
200
209
|
*/
|
|
201
210
|
endsWith(e) {
|
|
202
|
-
return
|
|
211
|
+
return X(this._value, e);
|
|
203
212
|
}
|
|
204
213
|
/**
|
|
205
214
|
* Determine if a given string doesn't end with a given substring.
|
|
@@ -208,7 +217,7 @@ class s {
|
|
|
208
217
|
* @returns boolean - True if the substring(s) are not found, false otherwise
|
|
209
218
|
*/
|
|
210
219
|
doesntEndWith(e) {
|
|
211
|
-
return
|
|
220
|
+
return H(this._value, e);
|
|
212
221
|
}
|
|
213
222
|
/**
|
|
214
223
|
* Determine if the string is an exact match with the given value.
|
|
@@ -228,7 +237,7 @@ class s {
|
|
|
228
237
|
* @returns The extracted excerpt or null if the phrase is not found.
|
|
229
238
|
*/
|
|
230
239
|
excerpt(e = "", t = {}) {
|
|
231
|
-
return
|
|
240
|
+
return K(this._value, e, t);
|
|
232
241
|
}
|
|
233
242
|
/**
|
|
234
243
|
* Explode the string into an array
|
|
@@ -272,7 +281,7 @@ class s {
|
|
|
272
281
|
* @returns The updated Stringable instance.
|
|
273
282
|
*/
|
|
274
283
|
finish(e) {
|
|
275
|
-
return new s(
|
|
284
|
+
return new s(O(this._value, e));
|
|
276
285
|
}
|
|
277
286
|
/**
|
|
278
287
|
* Determine if a given string matches a given pattern.
|
|
@@ -281,7 +290,7 @@ class s {
|
|
|
281
290
|
* @returns boolean - True if the pattern(s) match, false otherwise
|
|
282
291
|
*/
|
|
283
292
|
is(e, t = !1) {
|
|
284
|
-
return
|
|
293
|
+
return Q(e, this._value, t);
|
|
285
294
|
}
|
|
286
295
|
/**
|
|
287
296
|
* Determine if a given string is 7 bit ASCII.
|
|
@@ -289,7 +298,7 @@ class s {
|
|
|
289
298
|
* @returns True if the string is ASCII, false otherwise.
|
|
290
299
|
*/
|
|
291
300
|
isAscii() {
|
|
292
|
-
return
|
|
301
|
+
return Y(this._value);
|
|
293
302
|
}
|
|
294
303
|
/**
|
|
295
304
|
* Determine if a given string is valid JSON.
|
|
@@ -297,7 +306,7 @@ class s {
|
|
|
297
306
|
* @returns True if the string is valid JSON, false otherwise.
|
|
298
307
|
*/
|
|
299
308
|
isJson() {
|
|
300
|
-
return
|
|
309
|
+
return Z(this._value);
|
|
301
310
|
}
|
|
302
311
|
/**
|
|
303
312
|
* Determine if a given value is a valid URL.
|
|
@@ -306,7 +315,7 @@ class s {
|
|
|
306
315
|
* @returns True if the string is a valid URL, false otherwise.
|
|
307
316
|
*/
|
|
308
317
|
isUrl(e = []) {
|
|
309
|
-
return
|
|
318
|
+
return g(this._value, e);
|
|
310
319
|
}
|
|
311
320
|
/**
|
|
312
321
|
* Determine if a given string is a valid UUID.
|
|
@@ -315,7 +324,7 @@ class s {
|
|
|
315
324
|
* @returns True if the string is a valid UUID, false otherwise.
|
|
316
325
|
*/
|
|
317
326
|
isUuid(e = null) {
|
|
318
|
-
return
|
|
327
|
+
return Ke(this._value, e);
|
|
319
328
|
}
|
|
320
329
|
/**
|
|
321
330
|
* Determine if a given string is a valid ULID.
|
|
@@ -323,7 +332,7 @@ class s {
|
|
|
323
332
|
* @return True if the string is a valid ULID, false otherwise.
|
|
324
333
|
*/
|
|
325
334
|
isUlid() {
|
|
326
|
-
return
|
|
335
|
+
return He(this._value);
|
|
327
336
|
}
|
|
328
337
|
/**
|
|
329
338
|
* Determine if the given string is empty.
|
|
@@ -347,7 +356,7 @@ class s {
|
|
|
347
356
|
* @returns The kebab-cased string as a new Stringable instance.
|
|
348
357
|
*/
|
|
349
358
|
kebab() {
|
|
350
|
-
return new s(
|
|
359
|
+
return new s(b(this._value));
|
|
351
360
|
}
|
|
352
361
|
/**
|
|
353
362
|
* Return the length of the given string.
|
|
@@ -355,7 +364,7 @@ class s {
|
|
|
355
364
|
* @returns The length of the string.
|
|
356
365
|
*/
|
|
357
366
|
length() {
|
|
358
|
-
return
|
|
367
|
+
return S(this._value);
|
|
359
368
|
}
|
|
360
369
|
/**
|
|
361
370
|
* Limit the number of characters in a string.
|
|
@@ -367,7 +376,7 @@ class s {
|
|
|
367
376
|
*/
|
|
368
377
|
limit(e = 100, t = "...", r = !1) {
|
|
369
378
|
return new s(
|
|
370
|
-
|
|
379
|
+
ee(this._value, e, t, r)
|
|
371
380
|
);
|
|
372
381
|
}
|
|
373
382
|
/**
|
|
@@ -407,7 +416,7 @@ class s {
|
|
|
407
416
|
* @returns The masked string as a new Stringable instance.
|
|
408
417
|
*/
|
|
409
418
|
mask(e, t, r = null) {
|
|
410
|
-
return new s(
|
|
419
|
+
return new s(te(this._value, e, t, r));
|
|
411
420
|
}
|
|
412
421
|
/**
|
|
413
422
|
* Get the string matching the given pattern.
|
|
@@ -416,7 +425,7 @@ class s {
|
|
|
416
425
|
* @returns A new Stringable instance containing the matched string.
|
|
417
426
|
*/
|
|
418
427
|
match(e) {
|
|
419
|
-
return new s(
|
|
428
|
+
return new s(se(e, this._value));
|
|
420
429
|
}
|
|
421
430
|
/**
|
|
422
431
|
* Determine if a given string matches a given pattern.
|
|
@@ -425,7 +434,7 @@ class s {
|
|
|
425
434
|
* @returns boolean - True if the pattern(s) match, false otherwise
|
|
426
435
|
*/
|
|
427
436
|
isMatch(e) {
|
|
428
|
-
return
|
|
437
|
+
return re(e, this._value);
|
|
429
438
|
}
|
|
430
439
|
/**
|
|
431
440
|
* Get the string matching the given pattern.
|
|
@@ -434,7 +443,7 @@ class s {
|
|
|
434
443
|
* @returns An array of all matched strings.
|
|
435
444
|
*/
|
|
436
445
|
matchAll(e) {
|
|
437
|
-
return
|
|
446
|
+
return ne(e, this._value);
|
|
438
447
|
}
|
|
439
448
|
/**
|
|
440
449
|
* Determine if the string matches the given pattern.
|
|
@@ -451,7 +460,7 @@ class s {
|
|
|
451
460
|
* @returns The numeric string as a new Stringable instance.
|
|
452
461
|
*/
|
|
453
462
|
numbers() {
|
|
454
|
-
return new s(
|
|
463
|
+
return new s(ue(this._value));
|
|
455
464
|
}
|
|
456
465
|
/**
|
|
457
466
|
* Pad both sides of the string with another.
|
|
@@ -461,7 +470,7 @@ class s {
|
|
|
461
470
|
* @returns The padded string as a new Stringable instance.
|
|
462
471
|
*/
|
|
463
472
|
padBoth(e, t = " ") {
|
|
464
|
-
return new s(
|
|
473
|
+
return new s(ie(this._value, e, t));
|
|
465
474
|
}
|
|
466
475
|
/**
|
|
467
476
|
* Pad the left side of the string with another.
|
|
@@ -471,7 +480,7 @@ class s {
|
|
|
471
480
|
* @returns The padded string as a new Stringable instance.
|
|
472
481
|
*/
|
|
473
482
|
padLeft(e, t = " ") {
|
|
474
|
-
return new s(
|
|
483
|
+
return new s(he(this._value, e, t));
|
|
475
484
|
}
|
|
476
485
|
/**
|
|
477
486
|
* Pad the right side of the string with another.
|
|
@@ -481,7 +490,7 @@ class s {
|
|
|
481
490
|
* @returns The padded string as a new Stringable instance.
|
|
482
491
|
*/
|
|
483
492
|
padRight(e, t = " ") {
|
|
484
|
-
return new s(
|
|
493
|
+
return new s(le(this._value, e, t));
|
|
485
494
|
}
|
|
486
495
|
/**
|
|
487
496
|
* Call the given callback and return a new string.
|
|
@@ -496,12 +505,12 @@ class s {
|
|
|
496
505
|
/**
|
|
497
506
|
* Get the plural form of an English word.
|
|
498
507
|
*
|
|
499
|
-
* @param count - The count to determine singular or plural form. Defaults to 2.
|
|
508
|
+
* @param count - The count to determine singular or plural form. Arrays are counted by length. Defaults to 2.
|
|
500
509
|
* @param prependCount - Whether to prepend the count to the result. Defaults to false.
|
|
501
510
|
* @returns The pluralized string as a new Stringable instance.
|
|
502
511
|
*/
|
|
503
512
|
plural(e = 2, t = !1) {
|
|
504
|
-
return new s(
|
|
513
|
+
return new s(x(this._value, e, t));
|
|
505
514
|
}
|
|
506
515
|
/**
|
|
507
516
|
* Pluralize the last word of an English, studly caps case string.
|
|
@@ -510,7 +519,7 @@ class s {
|
|
|
510
519
|
* @returns The pluralized string as a new Stringable instance.
|
|
511
520
|
*/
|
|
512
521
|
pluralStudly(e = 2) {
|
|
513
|
-
return new s(
|
|
522
|
+
return new s(k(this._value, e));
|
|
514
523
|
}
|
|
515
524
|
/**
|
|
516
525
|
* Pluralize the last word of an English, Pascal caps case string.
|
|
@@ -519,7 +528,7 @@ class s {
|
|
|
519
528
|
* @returns The pluralized string as a new Stringable instance.
|
|
520
529
|
*/
|
|
521
530
|
pluralPascal(e = 2) {
|
|
522
|
-
return new s(
|
|
531
|
+
return new s(N(this._value, e));
|
|
523
532
|
}
|
|
524
533
|
/**
|
|
525
534
|
* Find the multi-byte safe position of the first occurrence of the given substring.
|
|
@@ -529,7 +538,7 @@ class s {
|
|
|
529
538
|
* @returns The position of the first occurrence of the substring, or false if not found.
|
|
530
539
|
*/
|
|
531
540
|
position(e, t = 0) {
|
|
532
|
-
return
|
|
541
|
+
return ae(this._value, e, t);
|
|
533
542
|
}
|
|
534
543
|
/**
|
|
535
544
|
* Prepend the given values to the string.
|
|
@@ -549,7 +558,7 @@ class s {
|
|
|
549
558
|
*/
|
|
550
559
|
remove(e, t = !0) {
|
|
551
560
|
return new s(
|
|
552
|
-
|
|
561
|
+
oe(e, this._value, t)
|
|
553
562
|
);
|
|
554
563
|
}
|
|
555
564
|
/**
|
|
@@ -558,7 +567,7 @@ class s {
|
|
|
558
567
|
* @returns The reversed string as a new Stringable instance.
|
|
559
568
|
*/
|
|
560
569
|
reverse() {
|
|
561
|
-
return new s(
|
|
570
|
+
return new s(we(this._value));
|
|
562
571
|
}
|
|
563
572
|
/**
|
|
564
573
|
* Repeat the string.
|
|
@@ -567,7 +576,7 @@ class s {
|
|
|
567
576
|
* @returns The repeated string as a new Stringable instance.
|
|
568
577
|
*/
|
|
569
578
|
repeat(e) {
|
|
570
|
-
return new s(
|
|
579
|
+
return new s(ve(this._value, e));
|
|
571
580
|
}
|
|
572
581
|
/**
|
|
573
582
|
* Replace the given value in the given string.
|
|
@@ -579,7 +588,7 @@ class s {
|
|
|
579
588
|
*/
|
|
580
589
|
replace(e, t, r = !0) {
|
|
581
590
|
return new s(
|
|
582
|
-
|
|
591
|
+
ce(e, t, this._value, r)
|
|
583
592
|
);
|
|
584
593
|
}
|
|
585
594
|
/**
|
|
@@ -590,7 +599,7 @@ class s {
|
|
|
590
599
|
* @returns The updated Stringable instance.
|
|
591
600
|
*/
|
|
592
601
|
replaceArray(e, t) {
|
|
593
|
-
return new s(
|
|
602
|
+
return new s(pe(e, t, this._value));
|
|
594
603
|
}
|
|
595
604
|
/**
|
|
596
605
|
* Replace the first occurrence of a given value in the string.
|
|
@@ -600,7 +609,7 @@ class s {
|
|
|
600
609
|
* @returns The updated Stringable instance.
|
|
601
610
|
*/
|
|
602
611
|
replaceFirst(e, t) {
|
|
603
|
-
return new s(
|
|
612
|
+
return new s(de(e, t, this._value));
|
|
604
613
|
}
|
|
605
614
|
/**
|
|
606
615
|
* Replace the first occurrence of the given value if it appears at the start of the string.
|
|
@@ -610,7 +619,7 @@ class s {
|
|
|
610
619
|
* @returns The updated Stringable instance.
|
|
611
620
|
*/
|
|
612
621
|
replaceStart(e, t) {
|
|
613
|
-
return new s(
|
|
622
|
+
return new s(fe(e, t, this._value));
|
|
614
623
|
}
|
|
615
624
|
/**
|
|
616
625
|
* Replace the last occurrence of a given value in the string.
|
|
@@ -620,7 +629,7 @@ class s {
|
|
|
620
629
|
* @returns The updated Stringable instance.
|
|
621
630
|
*/
|
|
622
631
|
replaceLast(e, t) {
|
|
623
|
-
return new s(
|
|
632
|
+
return new s(me(e, t, this._value));
|
|
624
633
|
}
|
|
625
634
|
/**
|
|
626
635
|
* Replace the last occurrence of a given value if it appears at the end of the string.
|
|
@@ -630,7 +639,7 @@ class s {
|
|
|
630
639
|
* @returns The updated Stringable instance.
|
|
631
640
|
*/
|
|
632
641
|
replaceEnd(e, t) {
|
|
633
|
-
return new s(
|
|
642
|
+
return new s(_e(e, t, this._value));
|
|
634
643
|
}
|
|
635
644
|
/**
|
|
636
645
|
* Replace the patterns matching the given regular expression.
|
|
@@ -641,7 +650,7 @@ class s {
|
|
|
641
650
|
* @returns The updated Stringable instance.
|
|
642
651
|
*/
|
|
643
652
|
replaceMatches(e, t, r = -1) {
|
|
644
|
-
const n =
|
|
653
|
+
const n = Ee(e, t, this._value, r);
|
|
645
654
|
return new s(n);
|
|
646
655
|
}
|
|
647
656
|
/**
|
|
@@ -680,7 +689,7 @@ class s {
|
|
|
680
689
|
* @returns The updated Stringable instance.
|
|
681
690
|
*/
|
|
682
691
|
squish() {
|
|
683
|
-
return new s(
|
|
692
|
+
return new s(ye(this._value));
|
|
684
693
|
}
|
|
685
694
|
/**
|
|
686
695
|
* Begin a string with a single instance of a given value.
|
|
@@ -689,7 +698,7 @@ class s {
|
|
|
689
698
|
* @returns The updated Stringable instance.
|
|
690
699
|
*/
|
|
691
700
|
start(e) {
|
|
692
|
-
return new s(
|
|
701
|
+
return new s(Ae(this._value, e));
|
|
693
702
|
}
|
|
694
703
|
/**
|
|
695
704
|
* Strip HTML and PHP tags from the given string.
|
|
@@ -697,7 +706,7 @@ class s {
|
|
|
697
706
|
* @returns The updated Stringable instance.
|
|
698
707
|
*/
|
|
699
708
|
stripTags() {
|
|
700
|
-
return new s(
|
|
709
|
+
return new s(We(this._value));
|
|
701
710
|
}
|
|
702
711
|
/**
|
|
703
712
|
* Convert the given string to upper-case.
|
|
@@ -721,7 +730,7 @@ class s {
|
|
|
721
730
|
* @returns The headline-cased string as a new Stringable instance.
|
|
722
731
|
*/
|
|
723
732
|
headline() {
|
|
724
|
-
return new s(
|
|
733
|
+
return new s(xe(this._value));
|
|
725
734
|
}
|
|
726
735
|
/**
|
|
727
736
|
* Convert the given string to only its initials.
|
|
@@ -730,7 +739,7 @@ class s {
|
|
|
730
739
|
* @returns The initials of the string as a new Stringable instance.
|
|
731
740
|
*/
|
|
732
741
|
initials(e = !1) {
|
|
733
|
-
return new s(
|
|
742
|
+
return new s(ke(this._value, e));
|
|
734
743
|
}
|
|
735
744
|
/**
|
|
736
745
|
* Convert the given string to APA-style title case.
|
|
@@ -738,7 +747,7 @@ class s {
|
|
|
738
747
|
* @returns The APA title-cased string as a new Stringable instance.
|
|
739
748
|
*/
|
|
740
749
|
apa() {
|
|
741
|
-
return new s(
|
|
750
|
+
return new s(Ne(this._value));
|
|
742
751
|
}
|
|
743
752
|
/**
|
|
744
753
|
* Transliterate a string to its closest ASCII representation.
|
|
@@ -746,7 +755,7 @@ class s {
|
|
|
746
755
|
* @returns The transliterated string as a new Stringable instance.
|
|
747
756
|
*/
|
|
748
757
|
transliterate() {
|
|
749
|
-
return new s(
|
|
758
|
+
return new s(ze(this._value));
|
|
750
759
|
}
|
|
751
760
|
/**
|
|
752
761
|
* Get the singular form of an English word.
|
|
@@ -754,7 +763,7 @@ class s {
|
|
|
754
763
|
* @returns The singularized string as a new Stringable instance.
|
|
755
764
|
*/
|
|
756
765
|
singular() {
|
|
757
|
-
return new s(
|
|
766
|
+
return new s(U(this._value));
|
|
758
767
|
}
|
|
759
768
|
/**
|
|
760
769
|
* Generate a URL friendly "slug" from a given string.
|
|
@@ -773,7 +782,7 @@ class s {
|
|
|
773
782
|
* @returns The snake-cased string as a new Stringable instance.
|
|
774
783
|
*/
|
|
775
784
|
snake(e = "_") {
|
|
776
|
-
return new s(
|
|
785
|
+
return new s(Ue(this._value, e));
|
|
777
786
|
}
|
|
778
787
|
/**
|
|
779
788
|
* Determine if a given string starts with a given substring.
|
|
@@ -782,7 +791,7 @@ class s {
|
|
|
782
791
|
* @returns boolean - True if the substring(s) are found, false otherwise
|
|
783
792
|
*/
|
|
784
793
|
startsWith(e) {
|
|
785
|
-
return
|
|
794
|
+
return Ce(this._value, e);
|
|
786
795
|
}
|
|
787
796
|
/**
|
|
788
797
|
* Determine if a given string doesn't start with a given substring.
|
|
@@ -791,7 +800,7 @@ class s {
|
|
|
791
800
|
* @returns boolean - True if the substring(s) are not found, false otherwise
|
|
792
801
|
*/
|
|
793
802
|
doesntStartWith(e) {
|
|
794
|
-
return
|
|
803
|
+
return Le(this._value, e);
|
|
795
804
|
}
|
|
796
805
|
/**
|
|
797
806
|
* Convert a value to studly caps case.
|
|
@@ -800,7 +809,7 @@ class s {
|
|
|
800
809
|
* @returns The studly-cased string as a new Stringable instance.
|
|
801
810
|
*/
|
|
802
811
|
studly(e = !1) {
|
|
803
|
-
return new s(
|
|
812
|
+
return new s(Me(this._value, e));
|
|
804
813
|
}
|
|
805
814
|
/**
|
|
806
815
|
* Convert the string to Pascal case.
|
|
@@ -809,7 +818,7 @@ class s {
|
|
|
809
818
|
* @returns The pascal-cased string as a new Stringable instance.
|
|
810
819
|
*/
|
|
811
820
|
pascal(e = !1) {
|
|
812
|
-
return new s(
|
|
821
|
+
return new s(Fe(this._value, e));
|
|
813
822
|
}
|
|
814
823
|
/**
|
|
815
824
|
* Returns the portion of the string specified by the start and length parameters.
|
|
@@ -819,7 +828,7 @@ class s {
|
|
|
819
828
|
* @returns The extracted substring as a new Stringable instance.
|
|
820
829
|
*/
|
|
821
830
|
substr(e, t = null) {
|
|
822
|
-
return new s(
|
|
831
|
+
return new s(C(this._value, e, t));
|
|
823
832
|
}
|
|
824
833
|
/**
|
|
825
834
|
* Returns the number of substring occurrences.
|
|
@@ -830,7 +839,7 @@ class s {
|
|
|
830
839
|
* @returns The number of occurrences of the substring.
|
|
831
840
|
*/
|
|
832
841
|
substrCount(e, t = 0, r = null) {
|
|
833
|
-
return
|
|
842
|
+
return L(this._value, e, t, r);
|
|
834
843
|
}
|
|
835
844
|
/**
|
|
836
845
|
* Replace text within a portion of a string.
|
|
@@ -842,7 +851,7 @@ class s {
|
|
|
842
851
|
*/
|
|
843
852
|
substrReplace(e, t = 0, r = null) {
|
|
844
853
|
return new s(
|
|
845
|
-
|
|
854
|
+
M(this._value, e, t, r)
|
|
846
855
|
);
|
|
847
856
|
}
|
|
848
857
|
/**
|
|
@@ -852,7 +861,7 @@ class s {
|
|
|
852
861
|
* @returns The updated Stringable instance.
|
|
853
862
|
*/
|
|
854
863
|
swap(e) {
|
|
855
|
-
return new s(
|
|
864
|
+
return new s(Ie(e, this._value));
|
|
856
865
|
}
|
|
857
866
|
/**
|
|
858
867
|
* Take the first or last {$limit} characters.
|
|
@@ -861,7 +870,7 @@ class s {
|
|
|
861
870
|
* @returns The resulting substring as a new Stringable instance.
|
|
862
871
|
*/
|
|
863
872
|
take(e) {
|
|
864
|
-
return new s(
|
|
873
|
+
return new s(Be(this._value, e));
|
|
865
874
|
}
|
|
866
875
|
/**
|
|
867
876
|
* Trim the string of the given characters.
|
|
@@ -879,7 +888,7 @@ class s {
|
|
|
879
888
|
* @returns The left-trimmed string as a new Stringable instance.
|
|
880
889
|
*/
|
|
881
890
|
ltrim(e = null) {
|
|
882
|
-
return new s(
|
|
891
|
+
return new s(Ge(this._value, e));
|
|
883
892
|
}
|
|
884
893
|
/**
|
|
885
894
|
* Right trim the string of the given characters.
|
|
@@ -888,7 +897,7 @@ class s {
|
|
|
888
897
|
* @returns The right-trimmed string as a new Stringable instance.
|
|
889
898
|
*/
|
|
890
899
|
rtrim(e = null) {
|
|
891
|
-
return new s(
|
|
900
|
+
return new s(Xe(this._value, e));
|
|
892
901
|
}
|
|
893
902
|
/**
|
|
894
903
|
* Make a string's first character lowercase.
|
|
@@ -896,7 +905,7 @@ class s {
|
|
|
896
905
|
* @returns The updated Stringable instance.
|
|
897
906
|
*/
|
|
898
907
|
lcfirst() {
|
|
899
|
-
return new s(
|
|
908
|
+
return new s(Re(this._value));
|
|
900
909
|
}
|
|
901
910
|
/**
|
|
902
911
|
* Make a string's first character uppercase.
|
|
@@ -904,7 +913,7 @@ class s {
|
|
|
904
913
|
* @returns The updated Stringable instance.
|
|
905
914
|
*/
|
|
906
915
|
ucfirst() {
|
|
907
|
-
return new s(
|
|
916
|
+
return new s(je(this._value));
|
|
908
917
|
}
|
|
909
918
|
/**
|
|
910
919
|
* Split a string by uppercase characters.
|
|
@@ -912,7 +921,7 @@ class s {
|
|
|
912
921
|
* @returns An array of substrings split at uppercase characters.
|
|
913
922
|
*/
|
|
914
923
|
ucsplit() {
|
|
915
|
-
return
|
|
924
|
+
return De(this._value);
|
|
916
925
|
}
|
|
917
926
|
/**
|
|
918
927
|
* Uppercase the first character of each word in a string.
|
|
@@ -920,7 +929,7 @@ class s {
|
|
|
920
929
|
* @returns The updated Stringable instance.
|
|
921
930
|
*/
|
|
922
931
|
ucwords() {
|
|
923
|
-
return new s(
|
|
932
|
+
return new s(Te(this._value));
|
|
924
933
|
}
|
|
925
934
|
/**
|
|
926
935
|
* Apply the callback if the given "value" is (or resolves to) truthy.
|
|
@@ -1131,7 +1140,7 @@ class s {
|
|
|
1131
1140
|
* @returns The truncated string as a new Stringable instance.
|
|
1132
1141
|
*/
|
|
1133
1142
|
words(e = 100, t = "...") {
|
|
1134
|
-
return new s(
|
|
1143
|
+
return new s(Pe(this._value, e, t));
|
|
1135
1144
|
}
|
|
1136
1145
|
/**
|
|
1137
1146
|
* Get the number of words a string contains.
|
|
@@ -1140,7 +1149,7 @@ class s {
|
|
|
1140
1149
|
* @returns The number of words in the string.
|
|
1141
1150
|
*/
|
|
1142
1151
|
wordCount(e = null) {
|
|
1143
|
-
return
|
|
1152
|
+
return qe(this._value, e);
|
|
1144
1153
|
}
|
|
1145
1154
|
/**
|
|
1146
1155
|
* Wrap a string to a given number of characters.
|
|
@@ -1153,7 +1162,7 @@ class s {
|
|
|
1153
1162
|
wordWrap(e = 75, t = `
|
|
1154
1163
|
`, r = !1) {
|
|
1155
1164
|
return new s(
|
|
1156
|
-
|
|
1165
|
+
Je(this._value, e, t, r)
|
|
1157
1166
|
);
|
|
1158
1167
|
}
|
|
1159
1168
|
/**
|
|
@@ -1164,7 +1173,7 @@ class s {
|
|
|
1164
1173
|
* @returns The wrapped string as a new Stringable instance.
|
|
1165
1174
|
*/
|
|
1166
1175
|
wrap(e, t = null) {
|
|
1167
|
-
return new s(
|
|
1176
|
+
return new s(Ve(this._value, e, t));
|
|
1168
1177
|
}
|
|
1169
1178
|
/**
|
|
1170
1179
|
* Unwrap the string with the given strings.
|
|
@@ -1174,7 +1183,7 @@ class s {
|
|
|
1174
1183
|
* @returns The unwrapped string as a new Stringable instance.
|
|
1175
1184
|
*/
|
|
1176
1185
|
unwrap(e, t = null) {
|
|
1177
|
-
return new s(
|
|
1186
|
+
return new s($e(this._value, e, t));
|
|
1178
1187
|
}
|
|
1179
1188
|
/**
|
|
1180
1189
|
* Convert the string to Base64 encoding.
|
|
@@ -1257,6 +1266,6 @@ class s {
|
|
|
1257
1266
|
}
|
|
1258
1267
|
export {
|
|
1259
1268
|
s as Stringable,
|
|
1260
|
-
|
|
1261
|
-
|
|
1269
|
+
ut as of,
|
|
1270
|
+
it as str
|
|
1262
1271
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolki/str",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"transliteration": "^2.6.0",
|
|
37
37
|
"ulid": "^2.4.0",
|
|
38
38
|
"uuid": "^11.1.0",
|
|
39
|
-
"@tolki/num": "^2.0
|
|
39
|
+
"@tolki/num": "^2.2.0",
|
|
40
40
|
"@tolki/utils": "^1.0.2"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|