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