@stacksjs/strings 0.56.35 → 0.57.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/case.d.ts +11 -0
- package/dist/case.mjs +18 -0
- package/dist/index.d.ts +4 -136
- package/dist/index.mjs +4 -165
- package/dist/is.d.ts +43 -0
- package/dist/is.mjs +127 -0
- package/dist/macro.d.ts +40 -0
- package/dist/macro.mjs +105 -0
- package/dist/pluralize.d.ts +2 -0
- package/dist/pluralize.mjs +3 -0
- package/dist/utils.d.ts +69 -0
- package/dist/utils.mjs +46 -0
- package/package.json +5 -5
package/dist/case.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* First letter uppercase, other lowercase
|
|
3
|
+
* @category string
|
|
4
|
+
* @example
|
|
5
|
+
* ```
|
|
6
|
+
* capitalize('hello world') => 'Hello world'
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export declare function capitalize(str: string): string;
|
|
10
|
+
export { camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, paramCase as kebabCase, pascalCase, pathCase, sentenceCase, snakeCase, } from 'change-case';
|
|
11
|
+
export { titleCase } from 'title-case';
|
package/dist/case.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function capitalize(str) {
|
|
2
|
+
return str[0].toUpperCase() + str.slice(1).toLowerCase();
|
|
3
|
+
}
|
|
4
|
+
export {
|
|
5
|
+
camelCase,
|
|
6
|
+
capitalCase,
|
|
7
|
+
constantCase,
|
|
8
|
+
dotCase,
|
|
9
|
+
headerCase,
|
|
10
|
+
noCase,
|
|
11
|
+
paramCase,
|
|
12
|
+
paramCase as kebabCase,
|
|
13
|
+
pascalCase,
|
|
14
|
+
pathCase,
|
|
15
|
+
sentenceCase,
|
|
16
|
+
snakeCase
|
|
17
|
+
} from "change-case";
|
|
18
|
+
export { titleCase } from "title-case";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,136 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
export { detectNewline } from 'detect-newline';
|
|
6
|
-
export { camelCase, capitalCase, constantCase, dotCase, headerCase, paramCase as kebabCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase } from 'change-case';
|
|
7
|
-
export { titleCase } from 'title-case';
|
|
8
|
-
|
|
9
|
-
interface SlugOptions {
|
|
10
|
-
replacement?: string;
|
|
11
|
-
remove?: RegExp;
|
|
12
|
-
lower?: boolean;
|
|
13
|
-
strict?: boolean;
|
|
14
|
-
locale?: string;
|
|
15
|
-
trim?: boolean;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Replace backslash to slash
|
|
19
|
-
*
|
|
20
|
-
* @category String
|
|
21
|
-
* @example
|
|
22
|
-
* ```
|
|
23
|
-
* slash('C:\\Users\\Chris') => 'C:/Users/Chris'
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
declare function slash(str: string): string;
|
|
27
|
-
/**
|
|
28
|
-
* Ensure prefix of a string
|
|
29
|
-
*
|
|
30
|
-
* @category String
|
|
31
|
-
* @example
|
|
32
|
-
* ```
|
|
33
|
-
* ensurePrefix('https://', 'google.com') => 'https://google.com'
|
|
34
|
-
* ensurePrefix('https://', 'http://google.com') => 'https://google.com'
|
|
35
|
-
*/
|
|
36
|
-
declare function ensurePrefix(prefix: string, str: string): string;
|
|
37
|
-
/**
|
|
38
|
-
* Ensure suffix of a string
|
|
39
|
-
*
|
|
40
|
-
* @category String
|
|
41
|
-
* @example
|
|
42
|
-
* ```
|
|
43
|
-
* ensureSuffix('.js', 'index') => 'index.js'
|
|
44
|
-
* ensureSuffix('.js', 'index.js') => 'index.js'
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
declare function ensureSuffix(suffix: string, str: string): string;
|
|
48
|
-
/**
|
|
49
|
-
* Dead simple template engine, just like Python's `.format()`
|
|
50
|
-
*
|
|
51
|
-
* @category String
|
|
52
|
-
* @example
|
|
53
|
-
* ```
|
|
54
|
-
* const result = template('Hello {0}! My name is {1}.',
|
|
55
|
-
* 'Buddy',
|
|
56
|
-
* 'Chris'
|
|
57
|
-
* ) // Hello Buddy! My name is Chris.
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
declare function template(str: string, ...args: any[]): string;
|
|
61
|
-
declare function truncate(str: string, length: number, end?: string): string;
|
|
62
|
-
/**
|
|
63
|
-
* Generate a random string
|
|
64
|
-
* @category String
|
|
65
|
-
*/
|
|
66
|
-
declare function randomStr(size?: number, dict?: string): string;
|
|
67
|
-
/**
|
|
68
|
-
* Slugify a string
|
|
69
|
-
* @category string
|
|
70
|
-
* @example
|
|
71
|
-
* ```
|
|
72
|
-
* slug('Hello World') => 'hello-world'
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
declare function slug(str: string, options?: SlugOptions): string;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* First letter uppercase, other lowercase
|
|
79
|
-
* @category string
|
|
80
|
-
* @example
|
|
81
|
-
* ```
|
|
82
|
-
* capitalize('hello world') => 'Hello world'
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
declare function capitalize(str: string): string;
|
|
86
|
-
|
|
87
|
-
declare const plural: typeof pluralize.plural;
|
|
88
|
-
declare const singular: typeof pluralize.singular;
|
|
89
|
-
declare const isPlural: typeof pluralize.isPlural;
|
|
90
|
-
declare const isSingular: typeof pluralize.isSingular;
|
|
91
|
-
declare const addPluralRule: typeof pluralize.addPluralRule;
|
|
92
|
-
declare const addSingularRule: typeof pluralize.addSingularRule;
|
|
93
|
-
declare const addIrregularRule: typeof pluralize.addIrregularRule;
|
|
94
|
-
declare const addUncountableRule: typeof pluralize.addUncountableRule;
|
|
95
|
-
|
|
96
|
-
declare class Str extends Macroable {
|
|
97
|
-
slash(str: string): string;
|
|
98
|
-
ensurePrefix(prefix: string, str: string): string;
|
|
99
|
-
ensureSuffix(suffix: string, str: string): string;
|
|
100
|
-
template(str: string, ...args: any[]): string;
|
|
101
|
-
/**
|
|
102
|
-
* Truncate a string
|
|
103
|
-
*/
|
|
104
|
-
truncate(str: string, length: number, end?: string): string;
|
|
105
|
-
random(length?: number): string;
|
|
106
|
-
capitalize(str: string): string;
|
|
107
|
-
slug(str: string): string;
|
|
108
|
-
detectIndent(str: string): detect_indent.Indent;
|
|
109
|
-
detectNewline(str: string): "\r\n" | "\n" | undefined;
|
|
110
|
-
camelCase(str: string): string;
|
|
111
|
-
capitalCase(str: string): string;
|
|
112
|
-
constantCase(str: string): string;
|
|
113
|
-
dotCase(str: string): string;
|
|
114
|
-
headerCase(str: string): string;
|
|
115
|
-
noCase(str: string): string;
|
|
116
|
-
paramCase(str: string): string;
|
|
117
|
-
pascalCase(str: string): string;
|
|
118
|
-
pathCase(str: string): string;
|
|
119
|
-
sentenceCase(str: string): string;
|
|
120
|
-
snakeCase(str: string): string;
|
|
121
|
-
titleCase(str: string): string;
|
|
122
|
-
kebabCase(str: string): string;
|
|
123
|
-
plural(str: string): string;
|
|
124
|
-
singular(str: string): string;
|
|
125
|
-
isPlural(str: string): boolean;
|
|
126
|
-
isSingular(str: string): boolean;
|
|
127
|
-
addPluralRule(rule: string | RegExp, repl: string): void;
|
|
128
|
-
addSingularRule(rule: string | RegExp, repl: string): void;
|
|
129
|
-
addIrregularRule(single: string, plural: string): void;
|
|
130
|
-
addUncountableRule(word: string | RegExp): void;
|
|
131
|
-
static macros: {};
|
|
132
|
-
static getters: {};
|
|
133
|
-
}
|
|
134
|
-
declare const str: Str;
|
|
135
|
-
|
|
136
|
-
export { Str, addIrregularRule, addPluralRule, addSingularRule, addUncountableRule, capitalize, ensurePrefix, ensureSuffix, isPlural, isSingular, plural, randomStr, singular, slash, slug, str, template, truncate };
|
|
1
|
+
export * from './utils';
|
|
2
|
+
export * from './case';
|
|
3
|
+
export * from './pluralize';
|
|
4
|
+
export * from './macro';
|
package/dist/index.mjs
CHANGED
|
@@ -1,165 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
export { detectNewline } from 'detect-newline';
|
|
6
|
-
import { camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase } from 'change-case';
|
|
7
|
-
export { camelCase, capitalCase, constantCase, dotCase, headerCase, paramCase as kebabCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase } from 'change-case';
|
|
8
|
-
import { titleCase } from 'title-case';
|
|
9
|
-
export { titleCase } from 'title-case';
|
|
10
|
-
import pluralize from 'pluralize';
|
|
11
|
-
import { Macroable } from 'macroable';
|
|
12
|
-
|
|
13
|
-
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
14
|
-
function slash(str) {
|
|
15
|
-
return str.replace(/\\/g, "/");
|
|
16
|
-
}
|
|
17
|
-
function ensurePrefix(prefix, str) {
|
|
18
|
-
if (!str.startsWith(prefix))
|
|
19
|
-
return prefix + str;
|
|
20
|
-
return str;
|
|
21
|
-
}
|
|
22
|
-
function ensureSuffix(suffix, str) {
|
|
23
|
-
if (!str.endsWith(suffix))
|
|
24
|
-
return str + suffix;
|
|
25
|
-
return str;
|
|
26
|
-
}
|
|
27
|
-
function template(str, ...args) {
|
|
28
|
-
return str.replace(/{(\d+)}/g, (match, key) => {
|
|
29
|
-
const index = Number(key);
|
|
30
|
-
if (Number.isNaN(index))
|
|
31
|
-
return match;
|
|
32
|
-
return args[index];
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function truncate(str, length, end = "...") {
|
|
36
|
-
if (str.length <= length)
|
|
37
|
-
return str;
|
|
38
|
-
return str.slice(0, length - end.length) + end;
|
|
39
|
-
}
|
|
40
|
-
function randomStr(size = 16, dict = urlAlphabet) {
|
|
41
|
-
let id = "";
|
|
42
|
-
let i = size;
|
|
43
|
-
const len = dict.length;
|
|
44
|
-
while (i--)
|
|
45
|
-
id += dict[Math.random() * len | 0];
|
|
46
|
-
return id;
|
|
47
|
-
}
|
|
48
|
-
function slug(str, options) {
|
|
49
|
-
if (options)
|
|
50
|
-
return slugify(str, options);
|
|
51
|
-
return slugify(str, {
|
|
52
|
-
lower: true,
|
|
53
|
-
strict: true
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function capitalize(str) {
|
|
58
|
-
return str[0].toUpperCase() + str.slice(1).toLowerCase();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const { plural, singular, isPlural, isSingular, addPluralRule, addSingularRule, addIrregularRule, addUncountableRule } = pluralize;
|
|
62
|
-
|
|
63
|
-
class Str extends Macroable {
|
|
64
|
-
slash(str2) {
|
|
65
|
-
return slash(str2);
|
|
66
|
-
}
|
|
67
|
-
ensurePrefix(prefix, str2) {
|
|
68
|
-
return ensurePrefix(prefix, str2);
|
|
69
|
-
}
|
|
70
|
-
ensureSuffix(suffix, str2) {
|
|
71
|
-
return ensureSuffix(suffix, str2);
|
|
72
|
-
}
|
|
73
|
-
template(str2, ...args) {
|
|
74
|
-
return template(str2, ...args);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Truncate a string
|
|
78
|
-
*/
|
|
79
|
-
truncate(str2, length, end = "...") {
|
|
80
|
-
return truncate(str2, length, end);
|
|
81
|
-
}
|
|
82
|
-
random(length = 16) {
|
|
83
|
-
return randomStr(length);
|
|
84
|
-
}
|
|
85
|
-
capitalize(str2) {
|
|
86
|
-
return capitalize(str2);
|
|
87
|
-
}
|
|
88
|
-
slug(str2) {
|
|
89
|
-
return slug(str2);
|
|
90
|
-
}
|
|
91
|
-
detectIndent(str2) {
|
|
92
|
-
return detectIndent(str2);
|
|
93
|
-
}
|
|
94
|
-
detectNewline(str2) {
|
|
95
|
-
return detectNewline(str2);
|
|
96
|
-
}
|
|
97
|
-
camelCase(str2) {
|
|
98
|
-
return camelCase(str2);
|
|
99
|
-
}
|
|
100
|
-
capitalCase(str2) {
|
|
101
|
-
return capitalCase(str2);
|
|
102
|
-
}
|
|
103
|
-
constantCase(str2) {
|
|
104
|
-
return constantCase(str2);
|
|
105
|
-
}
|
|
106
|
-
dotCase(str2) {
|
|
107
|
-
return dotCase(str2);
|
|
108
|
-
}
|
|
109
|
-
headerCase(str2) {
|
|
110
|
-
return headerCase(str2);
|
|
111
|
-
}
|
|
112
|
-
noCase(str2) {
|
|
113
|
-
return noCase(str2);
|
|
114
|
-
}
|
|
115
|
-
paramCase(str2) {
|
|
116
|
-
return paramCase(str2);
|
|
117
|
-
}
|
|
118
|
-
pascalCase(str2) {
|
|
119
|
-
return pascalCase(str2);
|
|
120
|
-
}
|
|
121
|
-
pathCase(str2) {
|
|
122
|
-
return pathCase(str2);
|
|
123
|
-
}
|
|
124
|
-
sentenceCase(str2) {
|
|
125
|
-
return sentenceCase(str2);
|
|
126
|
-
}
|
|
127
|
-
snakeCase(str2) {
|
|
128
|
-
return snakeCase(str2);
|
|
129
|
-
}
|
|
130
|
-
titleCase(str2) {
|
|
131
|
-
return titleCase(str2);
|
|
132
|
-
}
|
|
133
|
-
kebabCase(str2) {
|
|
134
|
-
return paramCase(str2);
|
|
135
|
-
}
|
|
136
|
-
plural(str2) {
|
|
137
|
-
return plural(str2);
|
|
138
|
-
}
|
|
139
|
-
singular(str2) {
|
|
140
|
-
return singular(str2);
|
|
141
|
-
}
|
|
142
|
-
isPlural(str2) {
|
|
143
|
-
return isPlural(str2);
|
|
144
|
-
}
|
|
145
|
-
isSingular(str2) {
|
|
146
|
-
return isSingular(str2);
|
|
147
|
-
}
|
|
148
|
-
addPluralRule(rule, repl) {
|
|
149
|
-
return addPluralRule(rule, repl);
|
|
150
|
-
}
|
|
151
|
-
addSingularRule(rule, repl) {
|
|
152
|
-
return addSingularRule(rule, repl);
|
|
153
|
-
}
|
|
154
|
-
addIrregularRule(single, plural) {
|
|
155
|
-
return addIrregularRule(single, plural);
|
|
156
|
-
}
|
|
157
|
-
addUncountableRule(word) {
|
|
158
|
-
return addUncountableRule(word);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
Str.macros = {};
|
|
162
|
-
Str.getters = {};
|
|
163
|
-
const str = new Str();
|
|
164
|
-
|
|
165
|
-
export { Str, addIrregularRule, addPluralRule, addSingularRule, addUncountableRule, capitalize, ensurePrefix, ensureSuffix, isPlural, isSingular, plural, randomStr, singular, slash, slug, str, template, truncate };
|
|
1
|
+
export * from "./utils.mjs";
|
|
2
|
+
export * from "./case.mjs";
|
|
3
|
+
export * from "./pluralize.mjs";
|
|
4
|
+
export * from "./macro.mjs";
|
package/dist/is.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { HashAlgorithm } from '@stacksjs/types';
|
|
2
|
+
export declare function isEmail(email: string): boolean;
|
|
3
|
+
export declare function isStrongPassword(password: string): boolean;
|
|
4
|
+
export declare function isAlphanumeric(username: string): boolean;
|
|
5
|
+
export declare function validateUsername(username: string): boolean;
|
|
6
|
+
export declare function isURL(url: string): boolean;
|
|
7
|
+
export declare function isMobilePhone(phoneNumber: string): boolean;
|
|
8
|
+
export declare function isAlpha(name: string): boolean;
|
|
9
|
+
export declare function isPostalCode(zipCode: string): boolean;
|
|
10
|
+
export declare function isNumeric(number: string): boolean;
|
|
11
|
+
export declare function isHexColor(color: string): boolean;
|
|
12
|
+
export declare function isHexadecimal(hex: string): boolean;
|
|
13
|
+
export declare function isBase64(base64: string): boolean;
|
|
14
|
+
export declare function isUUID(uuid: string): boolean;
|
|
15
|
+
export declare function isJSON(json: string): boolean;
|
|
16
|
+
export declare function isCreditCard(creditCard: string): boolean;
|
|
17
|
+
export declare function isISBN(isbn: string): boolean;
|
|
18
|
+
export declare function isIP(ip: string): boolean;
|
|
19
|
+
export declare function isIPRange(ip: string): boolean;
|
|
20
|
+
export declare function isMACAddress(macAddress: string): boolean;
|
|
21
|
+
export declare function isLatLong(latitude: string): boolean;
|
|
22
|
+
export declare function isLatitude(longitude: string): boolean;
|
|
23
|
+
export declare function isLongitude(longitude: string): boolean;
|
|
24
|
+
export declare function isCurrency(currency: string): boolean;
|
|
25
|
+
export declare function isDataURI(dataURI: string): boolean;
|
|
26
|
+
export declare function isMimeType(mimeType: string): boolean;
|
|
27
|
+
export declare function isJWT(jwt: string): boolean;
|
|
28
|
+
export declare function isAscii(ascii: string): boolean;
|
|
29
|
+
export declare function isBase32(base32: string): boolean;
|
|
30
|
+
export declare function isByteLength(byteLength: string): boolean;
|
|
31
|
+
export declare function isFQDN(fqdn: string): boolean;
|
|
32
|
+
export declare function isFullWidth(fullWidth: string): boolean;
|
|
33
|
+
export declare function isHalfWidth(halfWidth: string): boolean;
|
|
34
|
+
export declare function isHash(hash: string, algorithm: HashAlgorithm): boolean;
|
|
35
|
+
export declare function isHSL(hsl: string): boolean;
|
|
36
|
+
export declare function isIBAN(iban: string): boolean;
|
|
37
|
+
export declare function isIdentityCard(identityCard: string): boolean;
|
|
38
|
+
export declare function isISIN(isin: string): boolean;
|
|
39
|
+
export declare function isISO8601(iso8601: string): boolean;
|
|
40
|
+
export declare function isISRC(isrc: string): boolean;
|
|
41
|
+
export declare function isISSN(issn: string): boolean;
|
|
42
|
+
export declare function isISO31661Alpha2(iso31661Alpha2: string): boolean;
|
|
43
|
+
export declare function isISO31661Alpha3(iso31661Alpha3: string): boolean;
|
package/dist/is.mjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import v from "validator";
|
|
2
|
+
export function isEmail(email) {
|
|
3
|
+
return v.isEmail(email);
|
|
4
|
+
}
|
|
5
|
+
export function isStrongPassword(password) {
|
|
6
|
+
return v.isStrongPassword(password);
|
|
7
|
+
}
|
|
8
|
+
export function isAlphanumeric(username) {
|
|
9
|
+
return v.isAlphanumeric(username);
|
|
10
|
+
}
|
|
11
|
+
export function validateUsername(username) {
|
|
12
|
+
return isAlphanumeric(username);
|
|
13
|
+
}
|
|
14
|
+
export function isURL(url) {
|
|
15
|
+
return v.isURL(url);
|
|
16
|
+
}
|
|
17
|
+
export function isMobilePhone(phoneNumber) {
|
|
18
|
+
return v.isMobilePhone(phoneNumber);
|
|
19
|
+
}
|
|
20
|
+
export function isAlpha(name) {
|
|
21
|
+
return v.isAlpha(name);
|
|
22
|
+
}
|
|
23
|
+
export function isPostalCode(zipCode) {
|
|
24
|
+
return v.isPostalCode(zipCode, "any");
|
|
25
|
+
}
|
|
26
|
+
export function isNumeric(number) {
|
|
27
|
+
return v.isNumeric(number);
|
|
28
|
+
}
|
|
29
|
+
export function isHexColor(color) {
|
|
30
|
+
return v.isHexColor(color);
|
|
31
|
+
}
|
|
32
|
+
export function isHexadecimal(hex) {
|
|
33
|
+
return v.isHexadecimal(hex);
|
|
34
|
+
}
|
|
35
|
+
export function isBase64(base64) {
|
|
36
|
+
return v.isBase64(base64);
|
|
37
|
+
}
|
|
38
|
+
export function isUUID(uuid) {
|
|
39
|
+
return v.isUUID(uuid);
|
|
40
|
+
}
|
|
41
|
+
export function isJSON(json) {
|
|
42
|
+
return v.isJSON(json);
|
|
43
|
+
}
|
|
44
|
+
export function isCreditCard(creditCard) {
|
|
45
|
+
return v.isCreditCard(creditCard);
|
|
46
|
+
}
|
|
47
|
+
export function isISBN(isbn) {
|
|
48
|
+
return v.isISBN(isbn);
|
|
49
|
+
}
|
|
50
|
+
export function isIP(ip) {
|
|
51
|
+
return v.isIP(ip);
|
|
52
|
+
}
|
|
53
|
+
export function isIPRange(ip) {
|
|
54
|
+
return v.isIPRange(ip);
|
|
55
|
+
}
|
|
56
|
+
export function isMACAddress(macAddress) {
|
|
57
|
+
return v.isMACAddress(macAddress);
|
|
58
|
+
}
|
|
59
|
+
export function isLatLong(latitude) {
|
|
60
|
+
return v.isLatLong(latitude);
|
|
61
|
+
}
|
|
62
|
+
export function isLatitude(longitude) {
|
|
63
|
+
return v.isLatLong(longitude);
|
|
64
|
+
}
|
|
65
|
+
export function isLongitude(longitude) {
|
|
66
|
+
return v.isLatLong(longitude);
|
|
67
|
+
}
|
|
68
|
+
export function isCurrency(currency) {
|
|
69
|
+
return v.isCurrency(currency);
|
|
70
|
+
}
|
|
71
|
+
export function isDataURI(dataURI) {
|
|
72
|
+
return v.isDataURI(dataURI);
|
|
73
|
+
}
|
|
74
|
+
export function isMimeType(mimeType) {
|
|
75
|
+
return v.isMimeType(mimeType);
|
|
76
|
+
}
|
|
77
|
+
export function isJWT(jwt) {
|
|
78
|
+
return v.isJWT(jwt);
|
|
79
|
+
}
|
|
80
|
+
export function isAscii(ascii) {
|
|
81
|
+
return v.isAscii(ascii);
|
|
82
|
+
}
|
|
83
|
+
export function isBase32(base32) {
|
|
84
|
+
return v.isBase32(base32);
|
|
85
|
+
}
|
|
86
|
+
export function isByteLength(byteLength) {
|
|
87
|
+
return v.isByteLength(byteLength);
|
|
88
|
+
}
|
|
89
|
+
export function isFQDN(fqdn) {
|
|
90
|
+
return v.isFQDN(fqdn);
|
|
91
|
+
}
|
|
92
|
+
export function isFullWidth(fullWidth) {
|
|
93
|
+
return v.isFullWidth(fullWidth);
|
|
94
|
+
}
|
|
95
|
+
export function isHalfWidth(halfWidth) {
|
|
96
|
+
return v.isHalfWidth(halfWidth);
|
|
97
|
+
}
|
|
98
|
+
export function isHash(hash, algorithm) {
|
|
99
|
+
return v.isHash(hash, algorithm);
|
|
100
|
+
}
|
|
101
|
+
export function isHSL(hsl) {
|
|
102
|
+
return v.isHSL(hsl);
|
|
103
|
+
}
|
|
104
|
+
export function isIBAN(iban) {
|
|
105
|
+
return v.isIBAN(iban);
|
|
106
|
+
}
|
|
107
|
+
export function isIdentityCard(identityCard) {
|
|
108
|
+
return v.isIdentityCard(identityCard);
|
|
109
|
+
}
|
|
110
|
+
export function isISIN(isin) {
|
|
111
|
+
return v.isISIN(isin);
|
|
112
|
+
}
|
|
113
|
+
export function isISO8601(iso8601) {
|
|
114
|
+
return v.isISO8601(iso8601);
|
|
115
|
+
}
|
|
116
|
+
export function isISRC(isrc) {
|
|
117
|
+
return v.isISRC(isrc);
|
|
118
|
+
}
|
|
119
|
+
export function isISSN(issn) {
|
|
120
|
+
return v.isISSN(issn);
|
|
121
|
+
}
|
|
122
|
+
export function isISO31661Alpha2(iso31661Alpha2) {
|
|
123
|
+
return v.isISO31661Alpha2(iso31661Alpha2);
|
|
124
|
+
}
|
|
125
|
+
export function isISO31661Alpha3(iso31661Alpha3) {
|
|
126
|
+
return v.isISO31661Alpha3(iso31661Alpha3);
|
|
127
|
+
}
|
package/dist/macro.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Macroable } from 'macroable';
|
|
2
|
+
export declare class Str extends Macroable {
|
|
3
|
+
slash(str: string): string;
|
|
4
|
+
ensurePrefix(prefix: string, str: string): string;
|
|
5
|
+
ensureSuffix(suffix: string, str: string): string;
|
|
6
|
+
template(str: string, ...args: any[]): string;
|
|
7
|
+
/**
|
|
8
|
+
* Truncate a string
|
|
9
|
+
*/
|
|
10
|
+
truncate(str: string, length: number, end?: string): string;
|
|
11
|
+
random(length?: number): string;
|
|
12
|
+
capitalize(str: string): string;
|
|
13
|
+
slug(str: string): string;
|
|
14
|
+
detectIndent(str: string): import("detect-indent").Indent;
|
|
15
|
+
detectNewline(str: string): "\r\n" | "\n" | undefined;
|
|
16
|
+
camelCase(str: string): string;
|
|
17
|
+
capitalCase(str: string): string;
|
|
18
|
+
constantCase(str: string): string;
|
|
19
|
+
dotCase(str: string): string;
|
|
20
|
+
headerCase(str: string): string;
|
|
21
|
+
noCase(str: string): string;
|
|
22
|
+
paramCase(str: string): string;
|
|
23
|
+
pascalCase(str: string): string;
|
|
24
|
+
pathCase(str: string): string;
|
|
25
|
+
sentenceCase(str: string): string;
|
|
26
|
+
snakeCase(str: string): string;
|
|
27
|
+
titleCase(str: string): string;
|
|
28
|
+
kebabCase(str: string): string;
|
|
29
|
+
plural(str: string): any;
|
|
30
|
+
singular(str: string): any;
|
|
31
|
+
isPlural(str: string): any;
|
|
32
|
+
isSingular(str: string): any;
|
|
33
|
+
addPluralRule(rule: string | RegExp, repl: string): any;
|
|
34
|
+
addSingularRule(rule: string | RegExp, repl: string): any;
|
|
35
|
+
addIrregularRule(single: string, plural: string): any;
|
|
36
|
+
addUncountableRule(word: string | RegExp): any;
|
|
37
|
+
static macros: {};
|
|
38
|
+
static getters: {};
|
|
39
|
+
}
|
|
40
|
+
export declare const str: Str;
|
package/dist/macro.mjs
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Macroable } from "macroable";
|
|
2
|
+
import * as c from "./case.mjs";
|
|
3
|
+
import * as p from "./pluralize.mjs";
|
|
4
|
+
import * as u from "./utils.mjs";
|
|
5
|
+
export class Str extends Macroable {
|
|
6
|
+
slash(str2) {
|
|
7
|
+
return u.slash(str2);
|
|
8
|
+
}
|
|
9
|
+
ensurePrefix(prefix, str2) {
|
|
10
|
+
return u.ensurePrefix(prefix, str2);
|
|
11
|
+
}
|
|
12
|
+
ensureSuffix(suffix, str2) {
|
|
13
|
+
return u.ensureSuffix(suffix, str2);
|
|
14
|
+
}
|
|
15
|
+
template(str2, ...args) {
|
|
16
|
+
return u.template(str2, ...args);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Truncate a string
|
|
20
|
+
*/
|
|
21
|
+
truncate(str2, length, end = "...") {
|
|
22
|
+
return u.truncate(str2, length, end);
|
|
23
|
+
}
|
|
24
|
+
random(length = 16) {
|
|
25
|
+
return u.randomStr(length);
|
|
26
|
+
}
|
|
27
|
+
capitalize(str2) {
|
|
28
|
+
return c.capitalize(str2);
|
|
29
|
+
}
|
|
30
|
+
slug(str2) {
|
|
31
|
+
return u.slug(str2);
|
|
32
|
+
}
|
|
33
|
+
detectIndent(str2) {
|
|
34
|
+
return u.detectIndent(str2);
|
|
35
|
+
}
|
|
36
|
+
detectNewline(str2) {
|
|
37
|
+
return u.detectNewline(str2);
|
|
38
|
+
}
|
|
39
|
+
camelCase(str2) {
|
|
40
|
+
return c.camelCase(str2);
|
|
41
|
+
}
|
|
42
|
+
capitalCase(str2) {
|
|
43
|
+
return c.capitalCase(str2);
|
|
44
|
+
}
|
|
45
|
+
constantCase(str2) {
|
|
46
|
+
return c.constantCase(str2);
|
|
47
|
+
}
|
|
48
|
+
dotCase(str2) {
|
|
49
|
+
return c.dotCase(str2);
|
|
50
|
+
}
|
|
51
|
+
headerCase(str2) {
|
|
52
|
+
return c.headerCase(str2);
|
|
53
|
+
}
|
|
54
|
+
noCase(str2) {
|
|
55
|
+
return c.noCase(str2);
|
|
56
|
+
}
|
|
57
|
+
paramCase(str2) {
|
|
58
|
+
return c.paramCase(str2);
|
|
59
|
+
}
|
|
60
|
+
pascalCase(str2) {
|
|
61
|
+
return c.pascalCase(str2);
|
|
62
|
+
}
|
|
63
|
+
pathCase(str2) {
|
|
64
|
+
return c.pathCase(str2);
|
|
65
|
+
}
|
|
66
|
+
sentenceCase(str2) {
|
|
67
|
+
return c.sentenceCase(str2);
|
|
68
|
+
}
|
|
69
|
+
snakeCase(str2) {
|
|
70
|
+
return c.snakeCase(str2);
|
|
71
|
+
}
|
|
72
|
+
titleCase(str2) {
|
|
73
|
+
return c.titleCase(str2);
|
|
74
|
+
}
|
|
75
|
+
kebabCase(str2) {
|
|
76
|
+
return c.kebabCase(str2);
|
|
77
|
+
}
|
|
78
|
+
plural(str2) {
|
|
79
|
+
return p.plural(str2);
|
|
80
|
+
}
|
|
81
|
+
singular(str2) {
|
|
82
|
+
return p.singular(str2);
|
|
83
|
+
}
|
|
84
|
+
isPlural(str2) {
|
|
85
|
+
return p.isPlural(str2);
|
|
86
|
+
}
|
|
87
|
+
isSingular(str2) {
|
|
88
|
+
return p.isSingular(str2);
|
|
89
|
+
}
|
|
90
|
+
addPluralRule(rule, repl) {
|
|
91
|
+
return p.addPluralRule(rule, repl);
|
|
92
|
+
}
|
|
93
|
+
addSingularRule(rule, repl) {
|
|
94
|
+
return p.addSingularRule(rule, repl);
|
|
95
|
+
}
|
|
96
|
+
addIrregularRule(single, plural) {
|
|
97
|
+
return p.addIrregularRule(single, plural);
|
|
98
|
+
}
|
|
99
|
+
addUncountableRule(word) {
|
|
100
|
+
return p.addUncountableRule(word);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
Str.macros = {};
|
|
104
|
+
Str.getters = {};
|
|
105
|
+
export const str = new Str();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const plural: any, singular: any, isPlural: any, isSingular: any, addPluralRule: any, addSingularRule: any, addIrregularRule: any, addUncountableRule: any;
|
|
2
|
+
export { plural, singular, isPlural, isSingular, addPluralRule, addSingularRule, addIrregularRule, addUncountableRule };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import pluralize from "pluralize";
|
|
2
|
+
const { plural, singular, isPlural, isSingular, addPluralRule, addSingularRule, addIrregularRule, addUncountableRule } = pluralize;
|
|
3
|
+
export { plural, singular, isPlural, isSingular, addPluralRule, addSingularRule, addIrregularRule, addUncountableRule };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
interface SlugOptions {
|
|
2
|
+
replacement?: string;
|
|
3
|
+
remove?: RegExp;
|
|
4
|
+
lower?: boolean;
|
|
5
|
+
strict?: boolean;
|
|
6
|
+
locale?: string;
|
|
7
|
+
trim?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Replace backslash to slash
|
|
11
|
+
*
|
|
12
|
+
* @category String
|
|
13
|
+
* @example
|
|
14
|
+
* ```
|
|
15
|
+
* slash('C:\\Users\\Chris') => 'C:/Users/Chris'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function slash(str: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Ensure prefix of a string
|
|
21
|
+
*
|
|
22
|
+
* @category String
|
|
23
|
+
* @example
|
|
24
|
+
* ```
|
|
25
|
+
* ensurePrefix('https://', 'google.com') => 'https://google.com'
|
|
26
|
+
* ensurePrefix('https://', 'http://google.com') => 'https://google.com'
|
|
27
|
+
*/
|
|
28
|
+
export declare function ensurePrefix(prefix: string, str: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Ensure suffix of a string
|
|
31
|
+
*
|
|
32
|
+
* @category String
|
|
33
|
+
* @example
|
|
34
|
+
* ```
|
|
35
|
+
* ensureSuffix('.js', 'index') => 'index.js'
|
|
36
|
+
* ensureSuffix('.js', 'index.js') => 'index.js'
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function ensureSuffix(suffix: string, str: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Dead simple template engine, just like Python's `.format()`
|
|
42
|
+
*
|
|
43
|
+
* @category String
|
|
44
|
+
* @example
|
|
45
|
+
* ```
|
|
46
|
+
* const result = template('Hello {0}! My name is {1}.',
|
|
47
|
+
* 'Buddy',
|
|
48
|
+
* 'Chris'
|
|
49
|
+
* ) // Hello Buddy! My name is Chris.
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function template(str: string, ...args: any[]): string;
|
|
53
|
+
export declare function truncate(str: string, length: number, end?: string): string;
|
|
54
|
+
/**
|
|
55
|
+
* Generate a random string
|
|
56
|
+
* @category String
|
|
57
|
+
*/
|
|
58
|
+
export declare function randomStr(size?: number, dict?: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* Slugify a string
|
|
61
|
+
* @category string
|
|
62
|
+
* @example
|
|
63
|
+
* ```
|
|
64
|
+
* slug('Hello World') => 'hello-world'
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function slug(str: string, options?: SlugOptions): string;
|
|
68
|
+
export { default as detectIndent } from 'detect-indent';
|
|
69
|
+
export { detectNewline } from 'detect-newline';
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import slugify from "slugify";
|
|
2
|
+
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
3
|
+
export function slash(str) {
|
|
4
|
+
return str.replace(/\\/g, "/");
|
|
5
|
+
}
|
|
6
|
+
export function ensurePrefix(prefix, str) {
|
|
7
|
+
if (!str.startsWith(prefix))
|
|
8
|
+
return prefix + str;
|
|
9
|
+
return str;
|
|
10
|
+
}
|
|
11
|
+
export function ensureSuffix(suffix, str) {
|
|
12
|
+
if (!str.endsWith(suffix))
|
|
13
|
+
return str + suffix;
|
|
14
|
+
return str;
|
|
15
|
+
}
|
|
16
|
+
export function template(str, ...args) {
|
|
17
|
+
return str.replace(/{(\d+)}/g, (match, key) => {
|
|
18
|
+
const index = Number(key);
|
|
19
|
+
if (Number.isNaN(index))
|
|
20
|
+
return match;
|
|
21
|
+
return args[index];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function truncate(str, length, end = "...") {
|
|
25
|
+
if (str.length <= length)
|
|
26
|
+
return str;
|
|
27
|
+
return str.slice(0, length - end.length) + end;
|
|
28
|
+
}
|
|
29
|
+
export function randomStr(size = 16, dict = urlAlphabet) {
|
|
30
|
+
let id = "";
|
|
31
|
+
let i = size;
|
|
32
|
+
const len = dict.length;
|
|
33
|
+
while (i--)
|
|
34
|
+
id += dict[Math.random() * len | 0];
|
|
35
|
+
return id;
|
|
36
|
+
}
|
|
37
|
+
export function slug(str, options) {
|
|
38
|
+
if (options)
|
|
39
|
+
return slugify(str, options);
|
|
40
|
+
return slugify(str, {
|
|
41
|
+
lower: true,
|
|
42
|
+
strict: true
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
export { default as detectIndent } from "detect-indent";
|
|
46
|
+
export { detectNewline } from "detect-newline";
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/strings",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"packageManager": "pnpm@8.6.
|
|
4
|
+
"version": "0.57.3",
|
|
5
|
+
"packageManager": "pnpm@8.6.6",
|
|
6
6
|
"description": "The Stacks string utilities.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"license": "MIT",
|
|
@@ -60,14 +60,14 @@
|
|
|
60
60
|
"slugify": "^1.6.6",
|
|
61
61
|
"title-case": "^3.0.3",
|
|
62
62
|
"validator": "^13.9.0",
|
|
63
|
-
"@stacksjs/alias": "0.
|
|
64
|
-
"@stacksjs/types": "0.
|
|
63
|
+
"@stacksjs/alias": "0.57.3",
|
|
64
|
+
"@stacksjs/types": "0.57.3"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"macroable": "^7.0.2"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@stacksjs/development": "0.
|
|
70
|
+
"@stacksjs/development": "0.57.3"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "unbuild",
|