@stacksjs/strings 0.67.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 CHANGED
@@ -1,90 +1,36 @@
1
- /**
2
- * First letter uppercase, other lowercase
3
- * @category string
4
- * @example
5
- * ```
6
- * capitalize('hello world') => 'Hello world'
7
- * ```
8
- */
9
1
  export declare function capitalize(str: string): string;
10
2
  export declare function lowercase(str: string): string;
11
- /**
12
- * Supported locale values. Use `false` to ignore locale.
13
- * Defaults to `undefined`, which uses the host environment.
14
- */
15
- export type Locale = string[] | string | false | undefined;
16
- /**
17
- * Options used for converting strings to pascal/camel case.
18
- */
19
- export interface PascalCaseOptions extends CaseOptions {
20
- mergeAmbiguousCharacters?: boolean;
3
+ declare const DEFAULT_PREFIX_SUFFIX_CHARACTERS: unknown;
4
+ export declare type Locale = string[] | string | false | undefined
5
+ export declare interface PascalCaseOptions extends CaseOptions {
6
+ mergeAmbiguousCharacters?: boolean
21
7
  }
22
- /**
23
- * Options used for converting strings to any case.
24
- */
25
- export interface CaseOptions {
26
- locale?: Locale;
27
- split?: (value: string) => string[];
28
- delimiter?: string;
29
- prefixCharacters?: string;
30
- suffixCharacters?: string;
8
+ export declare interface CaseOptions {
9
+ locale?: Locale
10
+ split?: (value: string) => string[]
11
+ delimiter?: string
12
+ prefixCharacters?: string
13
+ suffixCharacters?: string
31
14
  }
32
- /**
33
- * Split any cased input strings into an array of words.
34
- */
35
15
  export declare function split(value: string): string[];
36
- /**
37
- * Split the input string into an array of words, separating numbers.
38
- */
39
16
  export declare function splitSeparateNumbers(value: string): string[];
40
- /**
41
- * Convert a string to space separated lower case (`foo bar`).
42
- */
43
17
  export declare function noCase(input: string, options?: CaseOptions): string;
44
- /**
45
- * Convert a string to camel case (`fooBar`).
46
- */
47
18
  export declare function camelCase(input: string, options?: PascalCaseOptions): string;
48
- /**
49
- * Convert a string to pascal case (`FooBar`).
50
- */
51
19
  export declare function pascalCase(input: string, options?: PascalCaseOptions): string;
52
- /**
53
- * Convert a string to pascal snake case (`Foo_Bar`).
54
- */
55
20
  export declare function pascalSnakeCase(input: string, options?: CaseOptions): string;
56
- /**
57
- * Convert a string to capital case (`Foo Bar`).
58
- */
59
21
  export declare function capitalCase(input: string, options?: CaseOptions): string;
60
- /**
61
- * Convert a string to constant case (`FOO_BAR`).
62
- */
63
22
  export declare function constantCase(input: string, options?: CaseOptions): string;
64
- /**
65
- * Convert a string to dot case (`foo.bar`).
66
- */
67
23
  export declare function dotCase(input: string, options?: CaseOptions): string;
68
- /**
69
- * Convert a string to kebab case (`foo-bar`).
70
- */
71
24
  export declare function kebabCase(input: string, options?: CaseOptions): string;
72
- /**
73
- * Convert a string to path case (`foo/bar`).
74
- */
75
25
  export declare function pathCase(input: string, options?: CaseOptions): string;
76
- /**
77
- * Convert a string to path case (`Foo bar`).
78
- */
79
26
  export declare function sentenceCase(input: string, options?: CaseOptions): string;
80
- /**
81
- * Convert a string to snake case (`foo_bar`).
82
- */
83
27
  export declare function snakeCase(input: string, options?: CaseOptions): string;
84
- /**
85
- * Convert a string to header case (`Foo-Bar`).
86
- */
87
28
  export declare function trainCase(input: string, options?: CaseOptions): string;
88
- export * from "./sponge-case";
89
- export * from "./swap-case";
90
- export * from "./title-case";
29
+ declare function lowerFactory(locale: Locale): (input: string) => string { return locale === false ? (input: string) => input.toLowerCase() : (input: string) => input.toLocaleLowerCase(locale) };
30
+ declare function upperFactory(locale: Locale): (input: string) => string { return locale === false ? (input: string) => input.toUpperCase() : (input: string) => input.toLocaleUpperCase(locale) };
31
+ declare function capitalCaseTransformFactory(lower: (input: string) => string, upper: (input: string) => string,): void;
32
+ declare function pascalCaseTransformFactory(lower: (input: string) => string, upper: (input: string) => string,): void;
33
+ declare function splitPrefixSuffix(input: string, options: CaseOptions = {},): [string, string[], string];
34
+ export * from './sponge-case'
35
+ export * from './swap-case'
36
+ export * from './title-case'
@@ -1,6 +1,9 @@
1
- export declare function detectIndent(string: string): {
2
- amount: number;
3
- type?: string;
4
- indent: string;
5
- };
6
- export default detectIndent;
1
+ declare const INDENT_TYPE_SPACE: 'space' const INDENT_TYPE_TAB = 'tab';
2
+ declare function makeIndentsMap(string: string, ignoreSingleSpaces: boolean = true): void;
3
+ declare function encodeIndentsKey(indentType: any, indentAmount: any): void;
4
+ declare function decodeIndentsKey(indentsKey: any): void;
5
+ declare function getMostUsedKey(indents: any): void;
6
+ declare function makeIndentString(type: any, amount: any): void;
7
+ export declare function detectIndent(string: string);
8
+
9
+ export default detectIndent;
@@ -1,2 +1,2 @@
1
1
  export declare function detectNewline(string: string): string | undefined;
2
- export declare function detectNewlineGraceful(string: string): string;
2
+ export declare function detectNewlineGraceful(string: string): string;
package/dist/helpers.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function toString(v: any): string;
1
+ export declare function toString(v: any): string;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./string";
2
- export * as string from "./string";
1
+ export * from './string'
2
+ export * as string from './string'
package/dist/is.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { HashAlgorithm } from "@stacksjs/types";
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
- 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;
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;
@@ -1,20 +1,32 @@
1
- export interface PluralizeOptions {
2
- count?: number;
3
- inclusive?: boolean;
1
+ export declare interface PluralizeOptions {
2
+ count?: number
3
+ inclusive?: boolean
4
4
  }
5
- type StringOrRegExp = string | RegExp;
6
- interface PluralizeFunction {
7
- (word: string, options?: PluralizeOptions): string;
8
- plural: (word: string) => string;
9
- isPlural: (word: string) => boolean;
10
- singular: (word: string) => string;
11
- isSingular: (word: string) => boolean;
12
- addPluralRule: (rule: StringOrRegExp, replacement: string) => void;
13
- addSingularRule: (rule: StringOrRegExp, replacement: string) => void;
14
- addUncountableRule: (word: string | RegExp) => void;
15
- addIrregularRule: (single: string, plural: string) => void;
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
16
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 } };
17
27
  export declare const pluralize: PluralizeFunction;
18
28
  export declare const singular: PluralizeFunction;
19
29
  export declare const plural: PluralizeFunction;
20
- export default pluralize;
30
+ declare const lowerPlural: unknown;
31
+
32
+ export default pluralize;
package/dist/slug.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- export interface SlugifyOptions {
2
- replacement?: string;
3
- remove?: RegExp;
4
- lower?: boolean;
5
- strict?: boolean;
6
- locale?: string;
7
- trim?: boolean;
1
+ export declare interface SlugifyOptions {
2
+ replacement?: string
3
+ remove?: RegExp
4
+ lower?: boolean
5
+ strict?: boolean
6
+ locale?: string
7
+ trim?: boolean
8
8
  }
9
- type CharMap = Record<string, string>;
10
- export declare function slugify(string: string, options?: SlugifyOptions): string;
11
- export declare function extendCharMap(customMap: CharMap): void;
12
- export {};
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;
@@ -1 +1 @@
1
- export declare function spongeCase(input: string, locale?: string[] | string): string;
1
+ export declare function spongeCase(input: string, locale?: string[] | string): string;
package/dist/string.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from "./case";
2
- export * from "./helpers";
3
- export * from "./macro";
4
- export * from "./pluralize";
5
- export * from "./slug";
6
- export * from "./utils";
1
+ export * from './case'
2
+ export * from './helpers'
3
+ export * from './macro'
4
+ export * from './pluralize'
5
+ export * from './slug'
6
+ export * from './utils'
@@ -1 +1 @@
1
- export declare function swapCase(input: string, locale?: string[] | string): string;
1
+ export declare function swapCase(input: string, locale?: string[] | string): string;
@@ -2,12 +2,13 @@ export declare const WORD_SEPARATORS: Set<string>;
2
2
  export declare const SENTENCE_TERMINATORS: Set<string>;
3
3
  export declare const TITLE_TERMINATORS: Set<string>;
4
4
  export declare const SMALL_WORDS: Set<string>;
5
- export 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>;
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
12
  }
13
- export declare function titleCase(input: string, options?: TitleCaseOptions | string[] | string): string;
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,71 +1,18 @@
1
- interface SlugOptions {
2
- replacement?: string;
3
- remove?: RegExp;
4
- lower?: boolean;
5
- strict?: boolean;
6
- locale?: string;
7
- trim?: boolean;
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 = "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
- */
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?: 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
- */
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 * from "./detect-indent";
70
- export * from "./detect-newline";
71
- 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.67.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>"],