@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/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,23 +1,32 @@
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;
1
+ export declare interface PluralizeOptions {
2
+ count?: number
3
+ inclusive?: boolean
14
4
  }
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 {};
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 "./case";
2
- export * from "./helpers";
3
- export * from "./macro";
4
- export * from "./pluralize";
5
- export * from "./utils";
6
- export { isString } from "@stacksjs/validation";
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
- 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 { default as detectIndent } from "detect-indent";
70
- export { detectNewline } from "detect-newline";
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.65.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", "src"],
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/development": "0.64.6",
71
- "@types/pluralize": "^0.0.33",
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
  }