@stacksjs/strings 0.39.1 → 0.41.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/index.d.ts +46 -0
- package/dist/index.mjs +33 -0
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,48 @@
|
|
|
1
1
|
export { plural, singular, isPlural, isSingular, addPluralRule, addSingularRule, addIrregularRule, addUncountableRule } from 'pluralize';
|
|
2
2
|
export { camelCase, capitalCase, constantCase, dotCase, headerCase, noCase, paramCase, paramCase as kebabCase, pascalCase, pathCase, sentenceCase, snakeCase, } from 'change-case';
|
|
3
|
+
/**
|
|
4
|
+
* Replace backslash to slash
|
|
5
|
+
*
|
|
6
|
+
* @category String
|
|
7
|
+
*/
|
|
8
|
+
export declare function slash(str: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Ensure prefix of a string
|
|
11
|
+
*
|
|
12
|
+
* @category String
|
|
13
|
+
*/
|
|
14
|
+
export declare function ensurePrefix(prefix: string, str: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Ensure suffix of a string
|
|
17
|
+
*
|
|
18
|
+
* @category String
|
|
19
|
+
*/
|
|
20
|
+
export declare function ensureSuffix(suffix: string, str: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Dead simple template engine, just like Python's `.format()`
|
|
23
|
+
*
|
|
24
|
+
* @category String
|
|
25
|
+
* @example
|
|
26
|
+
* ```
|
|
27
|
+
* const result = template(
|
|
28
|
+
* 'Hello {0}! My name is {1}.',
|
|
29
|
+
* 'Inès',
|
|
30
|
+
* 'Anthony'
|
|
31
|
+
* ) // Hello Inès! My name is Anthony.
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function template(str: string, ...args: any[]): string;
|
|
35
|
+
/**
|
|
36
|
+
* Generate a random string
|
|
37
|
+
* @category String
|
|
38
|
+
*/
|
|
39
|
+
export declare function randomStr(size?: number, dict?: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* First letter uppercase, other lowercase
|
|
42
|
+
* @category string
|
|
43
|
+
* @example
|
|
44
|
+
* ```
|
|
45
|
+
* capitalize('hello') => 'Hello'
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function capitalize(str: string): string;
|
package/dist/index.mjs
CHANGED
|
@@ -13,3 +13,36 @@ export {
|
|
|
13
13
|
sentenceCase,
|
|
14
14
|
snakeCase
|
|
15
15
|
} from "change-case";
|
|
16
|
+
export function slash(str) {
|
|
17
|
+
return str.replace(/\\/g, "/");
|
|
18
|
+
}
|
|
19
|
+
export function ensurePrefix(prefix, str) {
|
|
20
|
+
if (!str.startsWith(prefix))
|
|
21
|
+
return prefix + str;
|
|
22
|
+
return str;
|
|
23
|
+
}
|
|
24
|
+
export function ensureSuffix(suffix, str) {
|
|
25
|
+
if (!str.endsWith(suffix))
|
|
26
|
+
return str + suffix;
|
|
27
|
+
return str;
|
|
28
|
+
}
|
|
29
|
+
export function template(str, ...args) {
|
|
30
|
+
return str.replace(/{(\d+)}/g, (match, key) => {
|
|
31
|
+
const index = Number(key);
|
|
32
|
+
if (Number.isNaN(index))
|
|
33
|
+
return match;
|
|
34
|
+
return args[index];
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
38
|
+
export function randomStr(size = 16, dict = urlAlphabet) {
|
|
39
|
+
let id = "";
|
|
40
|
+
let i = size;
|
|
41
|
+
const len = dict.length;
|
|
42
|
+
while (i--)
|
|
43
|
+
id += dict[Math.random() * len | 0];
|
|
44
|
+
return id;
|
|
45
|
+
}
|
|
46
|
+
export function capitalize(str) {
|
|
47
|
+
return str[0].toUpperCase() + str.slice(1).toLowerCase();
|
|
48
|
+
}
|
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@7.
|
|
4
|
+
"version": "0.41.0",
|
|
5
|
+
"packageManager": "pnpm@7.16.0",
|
|
6
6
|
"description": "The Stacks string utilities.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"license": "MIT",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
],
|
|
47
47
|
"engines": {
|
|
48
48
|
"node": ">=v18.12.1",
|
|
49
|
-
"pnpm": ">=7.
|
|
49
|
+
"pnpm": ">=7.16.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@types/pluralize": "^0.0.29",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"pluralize": "^8.0.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"mkdist": "^0.
|
|
57
|
+
"mkdist": "^1.0.0",
|
|
58
58
|
"typescript": "^4.8.4"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|