@cabloy/utils 1.0.12 → 1.0.13
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/vona.d.ts +6 -0
- package/dist/vona.js +78 -0
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/vona.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type * as ModuleInfo from '@cabloy/module-info';
|
|
2
|
+
export declare function combineResourceNameParts(resourceName: string | undefined, moduleName: ModuleInfo.IModuleInfo | string, simplify?: boolean, simplifyProviderId?: boolean): string[];
|
|
3
|
+
export declare function combineResourceName(resourceName: string | undefined, moduleName: ModuleInfo.IModuleInfo | string, simplify?: boolean, simplifyProviderId?: boolean): string;
|
|
4
|
+
export declare function combineApiPath(path: string | undefined, moduleName?: ModuleInfo.IModuleInfo | string, prefix?: string | boolean, simplify?: boolean, globalPrefixConfig?: string): string;
|
|
5
|
+
export declare function combineApiPathControllerAndAction(moduleName: ModuleInfo.IModuleInfo | string, controllerPath: string | undefined, actionPath: RegExp | string | undefined, prefix?: string | boolean, simplify?: boolean, globalPrefixConfig?: string): string;
|
|
6
|
+
export declare function combineApiPathControllerAndActionRaw(moduleName: ModuleInfo.IModuleInfo | string, controllerPath: string | undefined, actionPath: RegExp | string | undefined, simplify?: boolean): string;
|
package/dist/vona.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { stringToCapitalize, toLowerCaseFirstChar } from '@cabloy/word-utils';
|
|
2
|
+
export function combineResourceNameParts(resourceName, moduleName, simplify, simplifyProviderId) {
|
|
3
|
+
simplify = simplify ?? true;
|
|
4
|
+
simplifyProviderId = simplifyProviderId ?? true;
|
|
5
|
+
if (!resourceName)
|
|
6
|
+
resourceName = '';
|
|
7
|
+
// module path + arg
|
|
8
|
+
if (typeof moduleName !== 'string')
|
|
9
|
+
moduleName = moduleName.relativeName;
|
|
10
|
+
const parts = moduleName.split('-');
|
|
11
|
+
// path
|
|
12
|
+
const res = [];
|
|
13
|
+
if (!simplifyProviderId || parts[0] !== 'a')
|
|
14
|
+
res.push(parts[0]);
|
|
15
|
+
if (!simplify || !resourceName.startsWith(parts[1]))
|
|
16
|
+
res.push(parts[1]);
|
|
17
|
+
if (resourceName)
|
|
18
|
+
res.push(resourceName);
|
|
19
|
+
return res;
|
|
20
|
+
}
|
|
21
|
+
export function combineResourceName(resourceName, moduleName, simplify, simplifyProviderId) {
|
|
22
|
+
const parts = combineResourceNameParts(resourceName, moduleName, simplify, simplifyProviderId);
|
|
23
|
+
return toLowerCaseFirstChar(stringToCapitalize(parts));
|
|
24
|
+
}
|
|
25
|
+
export function combineApiPath(path, moduleName, prefix, simplify, globalPrefixConfig) {
|
|
26
|
+
const globalPrefix = typeof prefix === 'string' ? prefix : prefix === false ? '' : globalPrefixConfig;
|
|
27
|
+
simplify = simplify ?? true;
|
|
28
|
+
if (!path)
|
|
29
|
+
path = '';
|
|
30
|
+
// ignore globalPrefix
|
|
31
|
+
if (path.startsWith('//'))
|
|
32
|
+
return path.substring(1);
|
|
33
|
+
// ignore module path
|
|
34
|
+
if (path.startsWith('/'))
|
|
35
|
+
return `${globalPrefix}${path}`;
|
|
36
|
+
// globalPrefix + module path + arg
|
|
37
|
+
const parts = combineResourceNameParts(path, moduleName ?? '', simplify, true);
|
|
38
|
+
return `${globalPrefix}/${parts.join('/')}`;
|
|
39
|
+
}
|
|
40
|
+
export function combineApiPathControllerAndAction(moduleName, controllerPath, actionPath, prefix, simplify, globalPrefixConfig) {
|
|
41
|
+
if (actionPath === undefined)
|
|
42
|
+
actionPath = '';
|
|
43
|
+
// routePath
|
|
44
|
+
let routePath;
|
|
45
|
+
if (typeof actionPath !== 'string') {
|
|
46
|
+
// regexp
|
|
47
|
+
throw new TypeError('regexp not supported');
|
|
48
|
+
}
|
|
49
|
+
else if (actionPath.startsWith('/')) {
|
|
50
|
+
// absolute
|
|
51
|
+
routePath = combineApiPath(actionPath, moduleName, prefix, simplify, globalPrefixConfig);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
// relative
|
|
55
|
+
if (!controllerPath) {
|
|
56
|
+
routePath = combineApiPath(actionPath, moduleName, prefix, simplify, globalPrefixConfig);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
routePath = combineApiPath(controllerPath, moduleName, prefix, simplify, globalPrefixConfig);
|
|
60
|
+
if (actionPath) {
|
|
61
|
+
routePath = `${routePath}/${actionPath}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return routePath;
|
|
66
|
+
}
|
|
67
|
+
export function combineApiPathControllerAndActionRaw(moduleName, controllerPath, actionPath, simplify) {
|
|
68
|
+
let apiPath = combineApiPathControllerAndAction(moduleName, controllerPath, actionPath, '/_api_', simplify);
|
|
69
|
+
if (typeof apiPath !== 'string')
|
|
70
|
+
return apiPath;
|
|
71
|
+
if (apiPath.startsWith('/_api_')) {
|
|
72
|
+
apiPath = apiPath.substring('/_api_'.length);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
apiPath = `/${apiPath}`;
|
|
76
|
+
}
|
|
77
|
+
return apiPath;
|
|
78
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cabloy/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.13",
|
|
5
5
|
"description": "cabloy utils",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"
|
|
28
|
+
"@cabloy/word-utils": "^2.0.0",
|
|
29
|
+
"cel-js": "^0.3.1",
|
|
30
|
+
"@cabloy/module-info": "^1.3.6"
|
|
29
31
|
}
|
|
30
32
|
}
|