@stacksjs/strings 0.64.6 → 0.65.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 +44 -44
- package/dist/case.d.ts +12 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +176 -2
- package/dist/index.js.map +170 -11
- package/dist/is.d.ts +43 -0
- package/dist/macro.d.ts +37 -0
- package/dist/pluralize.d.ts +23 -0
- package/dist/string.d.ts +6 -0
- package/dist/types.d.ts +1 -0
- package/dist/utils.d.ts +70 -0
- package/package.json +11 -16
- package/src/case.ts +1 -1
- package/src/helpers.ts +1 -1
- package/src/is.ts +42 -42
- package/src/macro.ts +39 -35
- package/src/pluralize.ts +6 -5
- package/src/string.ts +5 -3
- package/src/utils.ts +13 -10
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/macro.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const Str: {
|
|
2
|
+
slash(str: string): string;
|
|
3
|
+
ensurePrefix(prefix: string, str: string): string;
|
|
4
|
+
ensureSuffix(suffix: string, str: string): string;
|
|
5
|
+
template(str: string, ...args: any[]): string;
|
|
6
|
+
truncate(str: string, length: number, end?: string): string;
|
|
7
|
+
random(length?: number, dict?: string): string;
|
|
8
|
+
capitalize(str: string): string;
|
|
9
|
+
slug(str: string): string;
|
|
10
|
+
detectIndent(str: string): {
|
|
11
|
+
amount: number;
|
|
12
|
+
type: string | undefined;
|
|
13
|
+
indent: string;
|
|
14
|
+
};
|
|
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
|
+
noCase(str: string): string;
|
|
21
|
+
paramCase(str: string): string;
|
|
22
|
+
pascalCase(str: string): string;
|
|
23
|
+
pathCase(str: string): string;
|
|
24
|
+
sentenceCase(str: string): string;
|
|
25
|
+
snakeCase(str: string): string;
|
|
26
|
+
titleCase(str: string): string;
|
|
27
|
+
kebabCase(str: string): string;
|
|
28
|
+
plural(str: string): string;
|
|
29
|
+
singular(str: string): string;
|
|
30
|
+
isPlural(str: string): boolean;
|
|
31
|
+
isSingular(str: string): boolean;
|
|
32
|
+
addPluralRule(rule: string | RegExp, repl: string): void;
|
|
33
|
+
addSingularRule(rule: string | RegExp, repl: string): void;
|
|
34
|
+
addIrregularRule(single: string, plural: string): void;
|
|
35
|
+
addUncountableRule(word: string | RegExp): void;
|
|
36
|
+
};
|
|
37
|
+
export declare const str: typeof Str;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type Rule = string | RegExp;
|
|
2
|
+
type Replacement = string;
|
|
3
|
+
type Word = string;
|
|
4
|
+
export type PluralizeTest = (word: Word) => boolean;
|
|
5
|
+
export interface Pluralize {
|
|
6
|
+
plural: (word: Word, count?: number, inclusive?: boolean) => Word;
|
|
7
|
+
singular: (word: Word) => Word;
|
|
8
|
+
isPlural: (word: Word) => boolean;
|
|
9
|
+
isSingular: (word: Word) => boolean;
|
|
10
|
+
addPluralRule: (rule: Rule, replacement: Replacement) => void;
|
|
11
|
+
addSingularRule: (rule: Rule, replacement: Replacement) => void;
|
|
12
|
+
addIrregularRule: (single: Word, plural: Word) => void;
|
|
13
|
+
addUncountableRule: (word: Word | RegExp) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare const plural: Pluralize["plural"];
|
|
16
|
+
export declare const singular: Pluralize["singular"];
|
|
17
|
+
export declare const isPlural: Pluralize["isPlural"];
|
|
18
|
+
export declare const isSingular: Pluralize["isSingular"];
|
|
19
|
+
export declare const addPluralRule: Pluralize["addPluralRule"];
|
|
20
|
+
export declare const addSingularRule: Pluralize["addSingularRule"];
|
|
21
|
+
export declare const addIrregularRule: Pluralize["addIrregularRule"];
|
|
22
|
+
export declare const addUncountableRule: Pluralize["addUncountableRule"];
|
|
23
|
+
export {};
|
package/dist/string.d.ts
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { pluralize };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
interface SlugOptions {
|
|
2
|
+
replacement?: string;
|
|
3
|
+
remove?: RegExp;
|
|
4
|
+
lower?: boolean;
|
|
5
|
+
strict?: boolean;
|
|
6
|
+
locale?: string;
|
|
7
|
+
trim?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
10
|
+
/**
|
|
11
|
+
* Replace backslash to slash
|
|
12
|
+
*
|
|
13
|
+
* @category String
|
|
14
|
+
* @example
|
|
15
|
+
* ```
|
|
16
|
+
* slash('C:\\Users\\Chris') => 'C:/Users/Chris'
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function slash(str: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Ensure prefix of a string
|
|
22
|
+
*
|
|
23
|
+
* @category String
|
|
24
|
+
* @example
|
|
25
|
+
* ```
|
|
26
|
+
* ensurePrefix('https://', 'google.com') => 'https://google.com'
|
|
27
|
+
* ensurePrefix('https://', 'http://google.com') => 'https://google.com'
|
|
28
|
+
*/
|
|
29
|
+
export declare function ensurePrefix(prefix: string, str: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Ensure suffix of a string
|
|
32
|
+
*
|
|
33
|
+
* @category String
|
|
34
|
+
* @example
|
|
35
|
+
* ```
|
|
36
|
+
* ensureSuffix('.js', 'index') => 'index.js'
|
|
37
|
+
* ensureSuffix('.js', 'index.js') => 'index.js'
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare function ensureSuffix(suffix: string, str: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Dead simple template engine, just like Python's `.format()`
|
|
43
|
+
*
|
|
44
|
+
* @category String
|
|
45
|
+
* @example
|
|
46
|
+
* ```
|
|
47
|
+
* const result = template('Hello {0}! My name is {1}.',
|
|
48
|
+
* 'Buddy',
|
|
49
|
+
* 'Chris'
|
|
50
|
+
* ) // Hello Buddy! My name is Chris.
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function template(str: string, ...args: any[]): string;
|
|
54
|
+
export declare function truncate(str: string, length: number, end?: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* Generate a random string
|
|
57
|
+
* @category String
|
|
58
|
+
*/
|
|
59
|
+
export declare function random(size?: number, dict?: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Slugify a string
|
|
62
|
+
* @category string
|
|
63
|
+
* @example
|
|
64
|
+
* ```
|
|
65
|
+
* slug('Hello World') => 'hello-world'
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function slug(str: string, options?: SlugOptions): string;
|
|
69
|
+
export { default as detectIndent } from "detect-indent";
|
|
70
|
+
export { detectNewline } from "detect-newline";
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/strings",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.65.0",
|
|
5
5
|
"description": "The Stacks string utilities.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
|
+
"contributors": ["Chris Breuer <chris@stacksjs.org>"],
|
|
7
8
|
"license": "MIT",
|
|
8
9
|
"funding": "https://github.com/sponsors/chrisbbreuer",
|
|
9
10
|
"homepage": "https://github.com/stacksjs/stacks/tree/main/storage/framework/core/strings#readme",
|
|
@@ -45,22 +46,16 @@
|
|
|
45
46
|
},
|
|
46
47
|
"module": "dist/index.js",
|
|
47
48
|
"types": "dist/index.d.ts",
|
|
48
|
-
"
|
|
49
|
-
"Chris Breuer <chris@stacksjs.org>"
|
|
50
|
-
],
|
|
51
|
-
"files": [
|
|
52
|
-
"README.md",
|
|
53
|
-
"dist",
|
|
54
|
-
"src"
|
|
55
|
-
],
|
|
49
|
+
"files": ["README.md", "dist", "src"],
|
|
56
50
|
"scripts": {
|
|
57
|
-
"build": "bun
|
|
58
|
-
"typecheck": "bun
|
|
51
|
+
"build": "bun build.ts",
|
|
52
|
+
"typecheck": "bun tsc --noEmit",
|
|
53
|
+
"test": "bun test",
|
|
59
54
|
"prepublishOnly": "bun run build"
|
|
60
55
|
},
|
|
61
56
|
"dependencies": {
|
|
62
|
-
"@stacksjs/alias": "
|
|
63
|
-
"@stacksjs/types": "
|
|
57
|
+
"@stacksjs/alias": "0.64.6",
|
|
58
|
+
"@stacksjs/types": "0.64.6",
|
|
64
59
|
"change-case": "^5.4.4",
|
|
65
60
|
"detect-indent": "^7.0.1",
|
|
66
61
|
"detect-newline": "^4.0.1",
|
|
@@ -68,12 +63,12 @@
|
|
|
68
63
|
"pluralize": "^8.0.0",
|
|
69
64
|
"slugify": "^1.6.6",
|
|
70
65
|
"string-ts": "^2.2.0",
|
|
71
|
-
"title-case": "^4.3.
|
|
66
|
+
"title-case": "^4.3.2",
|
|
72
67
|
"validator": "^13.12.0"
|
|
73
68
|
},
|
|
74
69
|
"devDependencies": {
|
|
75
|
-
"@stacksjs/development": "
|
|
70
|
+
"@stacksjs/development": "0.64.6",
|
|
76
71
|
"@types/pluralize": "^0.0.33",
|
|
77
|
-
"@types/validator": "^13.12.
|
|
72
|
+
"@types/validator": "^13.12.2"
|
|
78
73
|
}
|
|
79
74
|
}
|
package/src/case.ts
CHANGED
package/src/helpers.ts
CHANGED
package/src/is.ts
CHANGED
|
@@ -1,170 +1,170 @@
|
|
|
1
1
|
import type { HashAlgorithm } from '@stacksjs/types'
|
|
2
2
|
import validator from 'validator'
|
|
3
3
|
|
|
4
|
-
export function isEmail(email: string) {
|
|
4
|
+
export function isEmail(email: string): boolean {
|
|
5
5
|
return validator.isEmail(email)
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export function isStrongPassword(password: string) {
|
|
8
|
+
export function isStrongPassword(password: string): boolean {
|
|
9
9
|
return validator.isStrongPassword(password)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export function isAlphanumeric(username: string) {
|
|
12
|
+
export function isAlphanumeric(username: string): boolean {
|
|
13
13
|
return validator.isAlphanumeric(username)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export function validateUsername(username: string) {
|
|
16
|
+
export function validateUsername(username: string): boolean {
|
|
17
17
|
return isAlphanumeric(username)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export function isURL(url: string) {
|
|
20
|
+
export function isURL(url: string): boolean {
|
|
21
21
|
return validator.isURL(url)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function isMobilePhone(phoneNumber: string) {
|
|
24
|
+
export function isMobilePhone(phoneNumber: string): boolean {
|
|
25
25
|
return validator.isMobilePhone(phoneNumber)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export function isAlpha(name: string) {
|
|
28
|
+
export function isAlpha(name: string): boolean {
|
|
29
29
|
return validator.isAlpha(name)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export function isPostalCode(zipCode: string) {
|
|
32
|
+
export function isPostalCode(zipCode: string): boolean {
|
|
33
33
|
return validator.isPostalCode(zipCode, 'any')
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export function isNumeric(number: string) {
|
|
36
|
+
export function isNumeric(number: string): boolean {
|
|
37
37
|
return validator.isNumeric(number)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export function isHexColor(color: string) {
|
|
40
|
+
export function isHexColor(color: string): boolean {
|
|
41
41
|
return validator.isHexColor(color)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export function isHexadecimal(hex: string) {
|
|
44
|
+
export function isHexadecimal(hex: string): boolean {
|
|
45
45
|
return validator.isHexadecimal(hex)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export function isBase64(base64: string) {
|
|
48
|
+
export function isBase64(base64: string): boolean {
|
|
49
49
|
return validator.isBase64(base64)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export function isUUID(uuid: string) {
|
|
52
|
+
export function isUUID(uuid: string): boolean {
|
|
53
53
|
return validator.isUUID(uuid)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
export function isJSON(json: string) {
|
|
56
|
+
export function isJSON(json: string): boolean {
|
|
57
57
|
return validator.isJSON(json)
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export function isCreditCard(creditCard: string) {
|
|
60
|
+
export function isCreditCard(creditCard: string): boolean {
|
|
61
61
|
return validator.isCreditCard(creditCard)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export function isISBN(isbn: string) {
|
|
64
|
+
export function isISBN(isbn: string): boolean {
|
|
65
65
|
return validator.isISBN(isbn)
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
export function isIP(ip: string) {
|
|
68
|
+
export function isIP(ip: string): boolean {
|
|
69
69
|
return validator.isIP(ip)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
export function isIPRange(ip: string) {
|
|
72
|
+
export function isIPRange(ip: string): boolean {
|
|
73
73
|
return validator.isIPRange(ip)
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
export function isMACAddress(macAddress: string) {
|
|
76
|
+
export function isMACAddress(macAddress: string): boolean {
|
|
77
77
|
return validator.isMACAddress(macAddress)
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
export function isLatLong(latitude: string) {
|
|
80
|
+
export function isLatLong(latitude: string): boolean {
|
|
81
81
|
return validator.isLatLong(latitude)
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
export function isLatitude(longitude: string) {
|
|
84
|
+
export function isLatitude(longitude: string): boolean {
|
|
85
85
|
return validator.isLatLong(longitude)
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
export function isLongitude(longitude: string) {
|
|
88
|
+
export function isLongitude(longitude: string): boolean {
|
|
89
89
|
return validator.isLatLong(longitude)
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
export function isCurrency(currency: string) {
|
|
92
|
+
export function isCurrency(currency: string): boolean {
|
|
93
93
|
return validator.isCurrency(currency)
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
export function isDataURI(dataURI: string) {
|
|
96
|
+
export function isDataURI(dataURI: string): boolean {
|
|
97
97
|
return validator.isDataURI(dataURI)
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
export function isMimeType(mimeType: string) {
|
|
100
|
+
export function isMimeType(mimeType: string): boolean {
|
|
101
101
|
return validator.isMimeType(mimeType)
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
export function isJWT(jwt: string) {
|
|
104
|
+
export function isJWT(jwt: string): boolean {
|
|
105
105
|
return validator.isJWT(jwt)
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
export function isAscii(ascii: string) {
|
|
108
|
+
export function isAscii(ascii: string): boolean {
|
|
109
109
|
return validator.isAscii(ascii)
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
export function isBase32(base32: string) {
|
|
112
|
+
export function isBase32(base32: string): boolean {
|
|
113
113
|
return validator.isBase32(base32)
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
export function isByteLength(byteLength: string) {
|
|
116
|
+
export function isByteLength(byteLength: string): boolean {
|
|
117
117
|
return validator.isByteLength(byteLength)
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
export function isFQDN(fqdn: string) {
|
|
120
|
+
export function isFQDN(fqdn: string): boolean {
|
|
121
121
|
return validator.isFQDN(fqdn)
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
export function isFullWidth(fullWidth: string) {
|
|
124
|
+
export function isFullWidth(fullWidth: string): boolean {
|
|
125
125
|
return validator.isFullWidth(fullWidth)
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
export function isHalfWidth(halfWidth: string) {
|
|
128
|
+
export function isHalfWidth(halfWidth: string): boolean {
|
|
129
129
|
return validator.isHalfWidth(halfWidth)
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
export function isHash(hash: string, algorithm: HashAlgorithm) {
|
|
132
|
+
export function isHash(hash: string, algorithm: HashAlgorithm): boolean {
|
|
133
133
|
return validator.isHash(hash, algorithm)
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
export function isHSL(hsl: string) {
|
|
136
|
+
export function isHSL(hsl: string): boolean {
|
|
137
137
|
return validator.isHSL(hsl)
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
export function isIBAN(iban: string) {
|
|
140
|
+
export function isIBAN(iban: string): boolean {
|
|
141
141
|
return validator.isIBAN(iban)
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
export function isIdentityCard(identityCard: string) {
|
|
144
|
+
export function isIdentityCard(identityCard: string): boolean {
|
|
145
145
|
return validator.isIdentityCard(identityCard)
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
export function isISIN(isin: string) {
|
|
148
|
+
export function isISIN(isin: string): boolean {
|
|
149
149
|
return validator.isISIN(isin)
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
export function isISO8601(iso8601: string) {
|
|
152
|
+
export function isISO8601(iso8601: string): boolean {
|
|
153
153
|
return validator.isISO8601(iso8601)
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
export function isISRC(isrc: string) {
|
|
156
|
+
export function isISRC(isrc: string): boolean {
|
|
157
157
|
return validator.isISRC(isrc)
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
export function isISSN(issn: string) {
|
|
160
|
+
export function isISSN(issn: string): boolean {
|
|
161
161
|
return validator.isISSN(issn)
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
export function isISO31661Alpha2(iso31661Alpha2: string) {
|
|
164
|
+
export function isISO31661Alpha2(iso31661Alpha2: string): boolean {
|
|
165
165
|
return validator.isISO31661Alpha2(iso31661Alpha2)
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
export function isISO31661Alpha3(iso31661Alpha3: string) {
|
|
168
|
+
export function isISO31661Alpha3(iso31661Alpha3: string): boolean {
|
|
169
169
|
return validator.isISO31661Alpha3(iso31661Alpha3)
|
|
170
170
|
}
|
package/src/macro.ts
CHANGED
|
@@ -3,15 +3,15 @@ import * as p from './pluralize'
|
|
|
3
3
|
import * as u from './utils'
|
|
4
4
|
|
|
5
5
|
export const Str = {
|
|
6
|
-
slash(str: string) {
|
|
6
|
+
slash(str: string): string {
|
|
7
7
|
return u.slash(str)
|
|
8
8
|
},
|
|
9
9
|
|
|
10
|
-
ensurePrefix(prefix: string, str: string) {
|
|
10
|
+
ensurePrefix(prefix: string, str: string): string {
|
|
11
11
|
return u.ensurePrefix(prefix, str)
|
|
12
12
|
},
|
|
13
13
|
|
|
14
|
-
ensureSuffix(suffix: string, str: string) {
|
|
14
|
+
ensureSuffix(suffix: string, str: string): string {
|
|
15
15
|
return u.ensureSuffix(suffix, str)
|
|
16
16
|
},
|
|
17
17
|
|
|
@@ -22,110 +22,114 @@ export const Str = {
|
|
|
22
22
|
/**
|
|
23
23
|
* Truncate a string
|
|
24
24
|
*/
|
|
25
|
-
truncate(str: string, length: number, end = '...') {
|
|
25
|
+
truncate(str: string, length: number, end = '...'): string {
|
|
26
26
|
return u.truncate(str, length, end)
|
|
27
27
|
},
|
|
28
28
|
|
|
29
|
-
random(length = 16) {
|
|
30
|
-
return u.random(length)
|
|
29
|
+
random(length = 16, dict?: string): string {
|
|
30
|
+
return u.random(length, dict)
|
|
31
31
|
},
|
|
32
32
|
|
|
33
|
-
capitalize(str: string) {
|
|
33
|
+
capitalize(str: string): string {
|
|
34
34
|
return c.capitalize(str)
|
|
35
35
|
},
|
|
36
36
|
|
|
37
|
-
slug(str: string) {
|
|
37
|
+
slug(str: string): string {
|
|
38
38
|
return u.slug(str)
|
|
39
39
|
},
|
|
40
40
|
|
|
41
|
-
detectIndent(str: string) {
|
|
41
|
+
detectIndent(str: string): {
|
|
42
|
+
amount: number
|
|
43
|
+
type: string | undefined
|
|
44
|
+
indent: string
|
|
45
|
+
} {
|
|
42
46
|
return u.detectIndent(str)
|
|
43
47
|
},
|
|
44
48
|
|
|
45
|
-
detectNewline(str: string) {
|
|
49
|
+
detectNewline(str: string): '\r\n' | '\n' | undefined {
|
|
46
50
|
return u.detectNewline(str)
|
|
47
51
|
},
|
|
48
52
|
|
|
49
|
-
camelCase(str: string) {
|
|
53
|
+
camelCase(str: string): string {
|
|
50
54
|
return c.camelCase(str)
|
|
51
55
|
},
|
|
52
56
|
|
|
53
|
-
capitalCase(str: string) {
|
|
57
|
+
capitalCase(str: string): string {
|
|
54
58
|
return c.capitalCase(str)
|
|
55
59
|
},
|
|
56
60
|
|
|
57
|
-
constantCase(str: string) {
|
|
61
|
+
constantCase(str: string): string {
|
|
58
62
|
return c.constantCase(str)
|
|
59
63
|
},
|
|
60
64
|
|
|
61
|
-
dotCase(str: string) {
|
|
65
|
+
dotCase(str: string): string {
|
|
62
66
|
return c.dotCase(str)
|
|
63
67
|
},
|
|
64
68
|
|
|
65
|
-
noCase(str: string) {
|
|
69
|
+
noCase(str: string): string {
|
|
66
70
|
return c.noCase(str)
|
|
67
71
|
},
|
|
68
72
|
|
|
69
|
-
paramCase(str: string) {
|
|
73
|
+
paramCase(str: string): string {
|
|
70
74
|
return c.paramCase(str)
|
|
71
75
|
},
|
|
72
76
|
|
|
73
|
-
pascalCase(str: string) {
|
|
77
|
+
pascalCase(str: string): string {
|
|
74
78
|
return c.pascalCase(str)
|
|
75
79
|
},
|
|
76
80
|
|
|
77
|
-
pathCase(str: string) {
|
|
81
|
+
pathCase(str: string): string {
|
|
78
82
|
return c.pathCase(str)
|
|
79
83
|
},
|
|
80
84
|
|
|
81
|
-
sentenceCase(str: string) {
|
|
85
|
+
sentenceCase(str: string): string {
|
|
82
86
|
return c.sentenceCase(str)
|
|
83
87
|
},
|
|
84
88
|
|
|
85
|
-
snakeCase(str: string) {
|
|
89
|
+
snakeCase(str: string): string {
|
|
86
90
|
return c.snakeCase(str)
|
|
87
91
|
},
|
|
88
92
|
|
|
89
|
-
titleCase(str: string) {
|
|
93
|
+
titleCase(str: string): string {
|
|
90
94
|
return c.titleCase(str)
|
|
91
95
|
},
|
|
92
96
|
|
|
93
|
-
kebabCase(str: string) {
|
|
97
|
+
kebabCase(str: string): string {
|
|
94
98
|
return c.kebabCase(str)
|
|
95
99
|
},
|
|
96
100
|
|
|
97
|
-
plural(str: string) {
|
|
101
|
+
plural(str: string): string {
|
|
98
102
|
// plural, singular, isPlural, isSingular, addPluralRule, addSingularRule, addIrregularRule, addUncountableRule
|
|
99
103
|
return p.plural(str)
|
|
100
104
|
},
|
|
101
105
|
|
|
102
|
-
singular(str: string) {
|
|
106
|
+
singular(str: string): string {
|
|
103
107
|
return p.singular(str)
|
|
104
108
|
},
|
|
105
109
|
|
|
106
|
-
isPlural(str: string) {
|
|
110
|
+
isPlural(str: string): boolean {
|
|
107
111
|
return p.isPlural(str)
|
|
108
112
|
},
|
|
109
113
|
|
|
110
|
-
isSingular(str: string) {
|
|
114
|
+
isSingular(str: string): boolean {
|
|
111
115
|
return p.isSingular(str)
|
|
112
116
|
},
|
|
113
117
|
|
|
114
|
-
addPluralRule(rule: string | RegExp, repl: string) {
|
|
115
|
-
|
|
118
|
+
addPluralRule(rule: string | RegExp, repl: string): void {
|
|
119
|
+
p.addPluralRule(rule, repl)
|
|
116
120
|
},
|
|
117
121
|
|
|
118
|
-
addSingularRule(rule: string | RegExp, repl: string) {
|
|
119
|
-
|
|
122
|
+
addSingularRule(rule: string | RegExp, repl: string): void {
|
|
123
|
+
p.addSingularRule(rule, repl)
|
|
120
124
|
},
|
|
121
125
|
|
|
122
|
-
addIrregularRule(single: string, plural: string) {
|
|
123
|
-
|
|
126
|
+
addIrregularRule(single: string, plural: string): void {
|
|
127
|
+
p.addIrregularRule(single, plural)
|
|
124
128
|
},
|
|
125
129
|
|
|
126
|
-
addUncountableRule(word: string | RegExp) {
|
|
127
|
-
|
|
130
|
+
addUncountableRule(word: string | RegExp): void {
|
|
131
|
+
p.addUncountableRule(word)
|
|
128
132
|
},
|
|
129
133
|
}
|
|
130
134
|
|
|
131
|
-
export const str = Str
|
|
135
|
+
export const str: typeof Str = Str
|
package/src/pluralize.ts
CHANGED
|
@@ -17,18 +17,19 @@ export interface Pluralize {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export const plural: Pluralize['plural'] = (word, count, inclusive) => {
|
|
20
|
-
if (count !== undefined && inclusive)
|
|
20
|
+
if (count !== undefined && inclusive)
|
|
21
|
+
return `${count} ${pluralize.plural(word)}`
|
|
21
22
|
|
|
22
23
|
return pluralize.plural(word)
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
export const singular: Pluralize['singular'] =
|
|
26
|
-
export const isPlural: Pluralize['isPlural'] =
|
|
27
|
-
export const isSingular: Pluralize['isSingular'] =
|
|
26
|
+
export const singular: Pluralize['singular'] = word => pluralize.singular(word)
|
|
27
|
+
export const isPlural: Pluralize['isPlural'] = word => pluralize.isPlural(word)
|
|
28
|
+
export const isSingular: Pluralize['isSingular'] = word => pluralize.isSingular(word)
|
|
28
29
|
export const addPluralRule: Pluralize['addPluralRule'] = (rule, replacement) =>
|
|
29
30
|
pluralize.addPluralRule(rule, replacement)
|
|
30
31
|
export const addSingularRule: Pluralize['addSingularRule'] = (rule, replacement) =>
|
|
31
32
|
pluralize.addSingularRule(rule, replacement)
|
|
32
33
|
export const addIrregularRule: Pluralize['addIrregularRule'] = (single, plural) =>
|
|
33
34
|
pluralize.addIrregularRule(single, plural)
|
|
34
|
-
export const addUncountableRule: Pluralize['addUncountableRule'] =
|
|
35
|
+
export const addUncountableRule: Pluralize['addUncountableRule'] = word => pluralize.addUncountableRule(word)
|
package/src/string.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export * from './utils'
|
|
2
1
|
export * from './case'
|
|
3
|
-
export * from './pluralize'
|
|
4
|
-
export * from './macro'
|
|
5
2
|
export * from './helpers'
|
|
3
|
+
export * from './macro'
|
|
4
|
+
export * from './pluralize'
|
|
5
|
+
export * from './utils'
|
|
6
|
+
|
|
7
|
+
export { isString } from '@stacksjs/validation'
|