@stacksjs/strings 0.65.0 → 0.68.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/dist/case.d.ts +34 -10
- package/dist/detect-indent.d.ts +9 -0
- package/dist/detect-newline.d.ts +2 -0
- package/dist/helpers.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +963 -161
- package/dist/is.d.ts +3 -2
- package/dist/macro.d.ts +33 -35
- package/dist/pluralize.d.ts +31 -22
- package/dist/slug.d.ts +13 -0
- package/dist/sponge-case.d.ts +1 -0
- package/dist/string.d.ts +6 -6
- package/dist/swap-case.d.ts +1 -0
- package/dist/title-case.d.ts +14 -0
- package/dist/utils.d.ts +12 -64
- package/package.json +5 -15
- package/dist/index.js.map +0 -179
- package/dist/types.d.ts +0 -1
- package/src/case.ts +0 -31
- package/src/helpers.ts +0 -3
- package/src/index.ts +0 -2
- package/src/is.ts +0 -170
- package/src/macro.ts +0 -135
- package/src/pluralize.ts +0 -35
- package/src/string.ts +0 -7
- package/src/types.ts +0 -4
- package/src/utils.ts +0 -116
package/dist/is.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { HashAlgorithm } from
|
|
1
|
+
import type { HashAlgorithm } from '@stacksjs/types';
|
|
2
|
+
|
|
2
3
|
export declare function isEmail(email: string): boolean;
|
|
3
4
|
export declare function isStrongPassword(password: string): boolean;
|
|
4
5
|
export declare function isAlphanumeric(username: string): boolean;
|
|
@@ -40,4 +41,4 @@ export declare function isISO8601(iso8601: string): boolean;
|
|
|
40
41
|
export declare function isISRC(isrc: string): boolean;
|
|
41
42
|
export declare function isISSN(issn: string): boolean;
|
|
42
43
|
export declare function isISO31661Alpha2(iso31661Alpha2: string): boolean;
|
|
43
|
-
export declare function isISO31661Alpha3(iso31661Alpha3: string): boolean;
|
|
44
|
+
export declare function isISO31661Alpha3(iso31661Alpha3: string): boolean;
|
package/dist/macro.d.ts
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
1
|
export declare const Str: {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
addIrregularRule(single: string, plural: string): void;
|
|
35
|
-
addUncountableRule(word: string | RegExp): void;
|
|
2
|
+
slash: (str: string) => void;
|
|
3
|
+
ensurePrefix: (prefix: string, str: string) => void;
|
|
4
|
+
ensureSuffix: (suffix: string, str: string) => void;
|
|
5
|
+
template: (str: string, ...args: any[]) => void;
|
|
6
|
+
* Truncate a string
|
|
7
|
+
*/
|
|
8
|
+
truncate: () => unknown;
|
|
9
|
+
random: (length: number, dict?: string) => void;
|
|
10
|
+
capitalize: (str: string) => void;
|
|
11
|
+
slug: (str: string) => void;
|
|
12
|
+
detectIndent: (str: string) => void;
|
|
13
|
+
detectNewline: (str: string) => void;
|
|
14
|
+
camelCase: (str: string) => void;
|
|
15
|
+
capitalCase: (str: string) => void;
|
|
16
|
+
constantCase: (str: string) => void;
|
|
17
|
+
dotCase: (str: string) => void;
|
|
18
|
+
noCase: (str: string) => void;
|
|
19
|
+
paramCase: (str: string) => void;
|
|
20
|
+
pascalCase: (str: string) => void;
|
|
21
|
+
pathCase: (str: string) => void;
|
|
22
|
+
sentenceCase: (str: string) => void;
|
|
23
|
+
snakeCase: (str: string) => void;
|
|
24
|
+
titleCase: (str: string) => void;
|
|
25
|
+
kebabCase: (str: string) => void;
|
|
26
|
+
plural: (str: string) => void;
|
|
27
|
+
singular: (str: string) => void;
|
|
28
|
+
isPlural: (str: string) => void;
|
|
29
|
+
isSingular: (str: string) => void;
|
|
30
|
+
addPluralRule: (rule: string | RegExp, repl: string) => void;
|
|
31
|
+
addSingularRule: (rule: string | RegExp, repl: string) => void;
|
|
32
|
+
addIrregularRule: (single: string, plural: string) => void;
|
|
33
|
+
addUncountableRule: (word: string | RegExp) => void
|
|
36
34
|
};
|
|
37
|
-
export declare const str: typeof Str;
|
|
35
|
+
export declare const str: typeof Str;
|
package/dist/pluralize.d.ts
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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;
|
|
1
|
+
export declare interface PluralizeOptions {
|
|
2
|
+
count?: number
|
|
3
|
+
inclusive?: boolean
|
|
14
4
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
declare type Rule = [RegExp, string]
|
|
6
|
+
type StringOrRegExp = string | RegExp
|
|
7
|
+
declare interface PluralizeFunction {
|
|
8
|
+
(word: string, options?: PluralizeOptions): string
|
|
9
|
+
plural: (word: string) => string
|
|
10
|
+
isPlural: (word: string) => boolean
|
|
11
|
+
singular: (word: string) => string
|
|
12
|
+
isSingular: (word: string) => boolean
|
|
13
|
+
addPluralRule: (rule: StringOrRegExp, replacement: string) => void
|
|
14
|
+
addSingularRule: (rule: StringOrRegExp, replacement: string) => void
|
|
15
|
+
addUncountableRule: (word: string | RegExp) => void
|
|
16
|
+
addIrregularRule: (single: string, plural: string) => void
|
|
17
|
+
}
|
|
18
|
+
declare const pluralRules: Rule[];
|
|
19
|
+
declare const irregularPlurals: Record<string, string>;
|
|
20
|
+
declare function sanitizeRule(rule: string | RegExp): RegExp;
|
|
21
|
+
declare function restoreCase(word: string, token: string): string;
|
|
22
|
+
declare function interpolate(str: string, ...args: any[]): string;
|
|
23
|
+
declare function replace(word: string, rule: Rule): string;
|
|
24
|
+
declare function sanitizeWord(token: string, word: string, rules: Rule[]): string;
|
|
25
|
+
declare function replaceWord(replaceMap: Record<string, string>, keepMap: Record<string, string>, rules: Rule[]): (word: string) => string { return (word: string) => { const token = word.toLowerCase() if (keepMap[token]) return restoreCase(word, token) if (replaceMap[token]) return restoreCase(word, replaceMap[token]) return sanitizeWord(token, word, rules) } };
|
|
26
|
+
declare function checkWord(replaceMap: Record<string, string>, keepMap: Record<string, string>, rules: Rule[]): (word: string) => boolean { return (word: string) => { const token = word.toLowerCase() if (keepMap[token]) return true if (replaceMap[token]) return false return sanitizeWord(token, token, rules) === token } };
|
|
27
|
+
export declare const pluralize: PluralizeFunction;
|
|
28
|
+
export declare const singular: PluralizeFunction;
|
|
29
|
+
export declare const plural: PluralizeFunction;
|
|
30
|
+
declare const lowerPlural: unknown;
|
|
31
|
+
|
|
32
|
+
export default pluralize;
|
package/dist/slug.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare interface SlugifyOptions {
|
|
2
|
+
replacement?: string
|
|
3
|
+
remove?: RegExp
|
|
4
|
+
lower?: boolean
|
|
5
|
+
strict?: boolean
|
|
6
|
+
locale?: string
|
|
7
|
+
trim?: boolean
|
|
8
|
+
}
|
|
9
|
+
declare type CharMap = Record<string, string>
|
|
10
|
+
type LocaleMap = Record<string, CharMap>
|
|
11
|
+
declare const locales: LocaleMap;
|
|
12
|
+
export declare function slugify(string: string, options: SlugifyOptions = {}): string;
|
|
13
|
+
export declare function extendCharMap(customMap: CharMap): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function spongeCase(input: string, locale?: string[] | string): string;
|
package/dist/string.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export
|
|
1
|
+
export * from './case'
|
|
2
|
+
export * from './helpers'
|
|
3
|
+
export * from './macro'
|
|
4
|
+
export * from './pluralize'
|
|
5
|
+
export * from './slug'
|
|
6
|
+
export * from './utils'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function swapCase(input: string, locale?: string[] | string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const WORD_SEPARATORS: Set<string>;
|
|
2
|
+
export declare const SENTENCE_TERMINATORS: Set<string>;
|
|
3
|
+
export declare const TITLE_TERMINATORS: Set<string>;
|
|
4
|
+
export declare const SMALL_WORDS: Set<string>;
|
|
5
|
+
export declare interface TitleCaseOptions {
|
|
6
|
+
locale?: string | string[]
|
|
7
|
+
sentenceCase?: boolean
|
|
8
|
+
sentenceTerminators?: Set<string>
|
|
9
|
+
smallWords?: Set<string>
|
|
10
|
+
titleTerminators?: Set<string>
|
|
11
|
+
wordSeparators?: Set<string>
|
|
12
|
+
}
|
|
13
|
+
export declare function titleCase(input: string, options: TitleCaseOptions | string[] | string = {}): string;
|
|
14
|
+
declare function upperAt(input: string, index: number, locale: string | string[] | undefined,): void;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,70 +1,18 @@
|
|
|
1
|
-
interface SlugOptions {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
declare interface SlugOptions {
|
|
2
|
+
replacement?: string
|
|
3
|
+
remove?: RegExp
|
|
4
|
+
lower?: boolean
|
|
5
|
+
strict?: boolean
|
|
6
|
+
locale?: string
|
|
7
|
+
trim?: boolean
|
|
8
8
|
}
|
|
9
|
-
export declare const urlAlphabet
|
|
10
|
-
/**
|
|
11
|
-
* Replace backslash to slash
|
|
12
|
-
*
|
|
13
|
-
* @category String
|
|
14
|
-
* @example
|
|
15
|
-
* ```
|
|
16
|
-
* slash('C:\\Users\\Chris') => 'C:/Users/Chris'
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
9
|
+
export declare const urlAlphabet: (...args: any[]) => unknown;
|
|
19
10
|
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
11
|
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
12
|
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
13
|
export declare function template(str: string, ...args: any[]): string;
|
|
54
|
-
export declare function truncate(str: string, length: number, end
|
|
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
|
-
*/
|
|
14
|
+
export declare function truncate(str: string, length: number, end = '...'): string;
|
|
15
|
+
export declare function random(size = 16, dict: string = urlAlphabet): string;
|
|
68
16
|
export declare function slug(str: string, options?: SlugOptions): string;
|
|
69
|
-
export
|
|
70
|
-
export
|
|
17
|
+
export * from './detect-indent'
|
|
18
|
+
export * from './detect-newline'
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/strings",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.68.0",
|
|
5
5
|
"description": "The Stacks string utilities.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": ["Chris Breuer <chris@stacksjs.org>"],
|
|
@@ -36,17 +36,15 @@
|
|
|
36
36
|
],
|
|
37
37
|
"exports": {
|
|
38
38
|
".": {
|
|
39
|
-
"bun": "./src/index.ts",
|
|
40
39
|
"import": "./dist/index.js"
|
|
41
40
|
},
|
|
42
41
|
"./*": {
|
|
43
|
-
"bun": "./src/*",
|
|
44
42
|
"import": "./dist/*"
|
|
45
43
|
}
|
|
46
44
|
},
|
|
47
45
|
"module": "dist/index.js",
|
|
48
46
|
"types": "dist/index.d.ts",
|
|
49
|
-
"files": ["README.md", "dist"
|
|
47
|
+
"files": ["README.md", "dist"],
|
|
50
48
|
"scripts": {
|
|
51
49
|
"build": "bun build.ts",
|
|
52
50
|
"typecheck": "bun tsc --noEmit",
|
|
@@ -54,21 +52,13 @@
|
|
|
54
52
|
"prepublishOnly": "bun run build"
|
|
55
53
|
},
|
|
56
54
|
"dependencies": {
|
|
57
|
-
"@stacksjs/alias": "0.64.6",
|
|
58
|
-
"@stacksjs/types": "0.64.6",
|
|
59
|
-
"change-case": "^5.4.4",
|
|
60
|
-
"detect-indent": "^7.0.1",
|
|
61
|
-
"detect-newline": "^4.0.1",
|
|
62
55
|
"macroable": "^7.0.2",
|
|
63
|
-
"pluralize": "^8.0.0",
|
|
64
|
-
"slugify": "^1.6.6",
|
|
65
|
-
"string-ts": "^2.2.0",
|
|
66
|
-
"title-case": "^4.3.2",
|
|
67
56
|
"validator": "^13.12.0"
|
|
68
57
|
},
|
|
69
58
|
"devDependencies": {
|
|
70
|
-
"@stacksjs/
|
|
71
|
-
"@
|
|
59
|
+
"@stacksjs/alias": "0.67.0",
|
|
60
|
+
"@stacksjs/development": "0.67.0",
|
|
61
|
+
"@stacksjs/types": "0.67.0",
|
|
72
62
|
"@types/validator": "^13.12.2"
|
|
73
63
|
}
|
|
74
64
|
}
|