dff-util 1.4.0 → 1.4.4
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/README.md +17 -8
- package/dist/main/case-mapper.d.ts +1 -0
- package/dist/main/case-mapper.js +25 -18
- package/dist/main/const-type.d.ts +9 -2
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -9,9 +9,9 @@ Select a topic below to view its reference and examples.
|
|
|
9
9
|
| | | | | | | |
|
|
10
10
|
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
|
|
11
11
|
| [AppRandomString](#general-utilities) | [AppUniqueCode](#general-utilities) | [AppCodeByType](#general-utilities) | [AppCode](#general-utilities) | [AppDaysBack](#general-utilities) | [AppAddDays](#general-utilities) | [AppUUID4](#general-utilities) |
|
|
12
|
-
| [TruncateText](#text-and-date-formatting) | [DateTime24HrFormat](#text-and-date-formatting) | [DateTime12HrFormat](#text-and-date-formatting) | [DateAndTime](#text-and-date-formatting) | [TimeAgo](#text-and-date-formatting) | [toCamelCase](#case-conversion-and-object-mapping) | [toSnakeCase](#case-conversion-and-object-mapping) |
|
|
12
|
+
| [TruncateText](#text-and-date-formatting) | [DateTime24HrFormat](#text-and-date-formatting) | [DateTime12HrFormat](#text-and-date-formatting) | [DateAndTime](#text-and-date-formatting) | [TimeAgo](#text-and-date-formatting) | [toCamelCase](#case-conversion-and-object-mapping) | [toSnakeCase](#case-conversion-and-object-mapping) | [toKebabCase](#case-conversion-and-object-mapping) |
|
|
13
13
|
| [toLowerCase](#case-conversion-and-object-mapping) | [toUpperCase](#case-conversion-and-object-mapping) | [toPascalCase](#case-conversion-and-object-mapping) | [toViewMapper](#case-conversion-and-object-mapping) | [toEntityMapper](#case-conversion-and-object-mapping) | [toSchemaMapper](#case-conversion-and-object-mapping) | [QueryCond](#query-conditions-querycond) |
|
|
14
|
-
| [CsvToJson](#csv-and-json-conversion) | [JsonToCsv](#csv-and-json-conversion) | | | | | |
|
|
14
|
+
| [CsvToJson](#csv-and-json-conversion) | [JsonToCsv](#csv-and-json-conversion) | [toKebabCase](#case-conversion-and-object-mapping) | | | | |
|
|
15
15
|
|
|
16
16
|
**[Http](#http)**
|
|
17
17
|
|
|
@@ -45,7 +45,7 @@ Select a topic below to view its reference and examples.
|
|
|
45
45
|
| :--- | :--- | :--- | :--- | :--- |
|
|
46
46
|
| [LangDirType](#common-types) | [OrderType](#common-types) | [ThemeType](#common-types) | [UnixTimestampType](#common-types) | [OptionType](#common-types) |
|
|
47
47
|
| [FileType](#common-types) | [ResponseType](#request-and-response-types) | [SearchType](#request-and-response-types) | [KeyValueType](#request-and-response-types) | [JsonValueType](#request-and-response-types) |
|
|
48
|
-
| [RequestBodyType](#request-and-response-types) | [
|
|
48
|
+
| [RequestBodyType](#request-and-response-types) | [RequestParamType](#request-and-response-types) | [RequestByIdType](#request-and-response-types) | [SessionUser](#session-user-sessionuser) | [SessionInfo](#session-information-sessioninfo) |
|
|
49
49
|
|
|
50
50
|
**[Constants and validation](#constants-and-validation)**
|
|
51
51
|
|
|
@@ -95,11 +95,12 @@ Available helpers:
|
|
|
95
95
|
| :--- | :--- | :--- |
|
|
96
96
|
| `toCamelCase` | Join words in camel case | `user_name` → `userName`; `user-name` → `userName`; `User Name` → `userName`; `USER_NAME` → `uSERNAME` |
|
|
97
97
|
| `toSnakeCase` | Separate words with underscores and lowercase | `userName` → `user_name`; `UserName` → `user_name`; `user name` → `user_name`; `user-name` → `user_name` |
|
|
98
|
-
| `
|
|
99
|
-
| `
|
|
98
|
+
| `toKebabCase` | Separate words with hyphens and lowercase | `userName` → `user-name`; `UserName` → `user-name`; `user name` → `user-name`; `user_name` → `user-name` |
|
|
99
|
+
| `toLowerCase` | Convert word separators to underscores and lowercase | `user-name` → `user_name`; `userName` → `user_name`; `UserName` → `user_name` |
|
|
100
|
+
| `toUpperCase` | Convert word separators to underscores and uppercase | `user-name` → `USER_NAME`; `user name` → `USER_NAME`; `userName` → `USER_NAME`; `UserName` → `USER_NAME` |
|
|
100
101
|
| `toPascalCase` | Capitalize each separated word and join | `user_name` → `UserName`; `user name` → `UserName`; `user-name` → `UserName`; `USER_NAME` → `UserName` |
|
|
101
102
|
|
|
102
|
-
These examples reflect the current implementation. `toCamelCase` preserves internal uppercase letters
|
|
103
|
+
These examples reflect the current implementation. `toCamelCase` preserves internal uppercase letters.
|
|
103
104
|
|
|
104
105
|
#### Object mapping
|
|
105
106
|
|
|
@@ -1212,9 +1213,15 @@ export type KeyValueType = {
|
|
|
1212
1213
|
|
|
1213
1214
|
export type JsonValueType = string | number | boolean | null | JsonValueType[] | { [key: string]: JsonValueType };
|
|
1214
1215
|
export type RequestBodyType = Record<string, JsonValueType>;
|
|
1215
|
-
export type
|
|
1216
|
+
export type RequestParamType = Record<string, string | number | boolean | null>;
|
|
1216
1217
|
export type RequestByIdType = {
|
|
1217
|
-
id: string
|
|
1218
|
+
id: string;
|
|
1219
|
+
};
|
|
1220
|
+
|
|
1221
|
+
export type PubSubEventType = {
|
|
1222
|
+
id: string;
|
|
1223
|
+
name?: string;
|
|
1224
|
+
raw?: string;
|
|
1218
1225
|
};
|
|
1219
1226
|
|
|
1220
1227
|
```
|
|
@@ -1227,6 +1234,7 @@ export type SessionUser = {
|
|
|
1227
1234
|
email?: string;
|
|
1228
1235
|
mobile?: string;
|
|
1229
1236
|
name?: string;
|
|
1237
|
+
tenant?: string;
|
|
1230
1238
|
roles: string[];
|
|
1231
1239
|
type?: string;
|
|
1232
1240
|
};
|
|
@@ -1240,6 +1248,7 @@ export type SessionInfo = {
|
|
|
1240
1248
|
email?: string;
|
|
1241
1249
|
mobile?: string;
|
|
1242
1250
|
name?: string;
|
|
1251
|
+
tenant?: string;
|
|
1243
1252
|
roles: string[];
|
|
1244
1253
|
type?: string;
|
|
1245
1254
|
requestId?: string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare function toCamelCase(str: string): string;
|
|
2
2
|
export declare function toSnakeCase(str: string): string;
|
|
3
|
+
export declare function toKebabCase(str: string): string;
|
|
3
4
|
export declare function toPascalCase(str: string): string;
|
|
4
5
|
export declare function toUpperCase(str: string): string;
|
|
5
6
|
export declare function toLowerCase(str: string): string;
|
package/dist/main/case-mapper.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toCamelCase = toCamelCase;
|
|
4
4
|
exports.toSnakeCase = toSnakeCase;
|
|
5
|
+
exports.toKebabCase = toKebabCase;
|
|
5
6
|
exports.toPascalCase = toPascalCase;
|
|
6
7
|
exports.toUpperCase = toUpperCase;
|
|
7
8
|
exports.toLowerCase = toLowerCase;
|
|
@@ -11,37 +12,43 @@ exports.toSchemaMapper = toSchemaMapper;
|
|
|
11
12
|
const const_value_1 = require("./const-value");
|
|
12
13
|
function toCamelCase(str) {
|
|
13
14
|
return str
|
|
14
|
-
.replace(/[_\s-]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : ''))
|
|
15
|
-
.replace(/^[A-Z]/, (chr) => chr.toLowerCase());
|
|
15
|
+
.replace(/[_\s-]+(.)?/g, (_, chr) => (chr ? chr.toUpperCase() : '')) // snake/kebab/space → camel
|
|
16
|
+
.replace(/^[A-Z]/, (chr) => chr.toLowerCase()); // PascalCase → camelCase
|
|
16
17
|
}
|
|
17
18
|
function toSnakeCase(str) {
|
|
18
19
|
return str
|
|
19
20
|
.replace(/([a-z0-9])([A-Z])/g, '$1_$2') // camelCase → camel_Case
|
|
20
|
-
.replace(/[\s-]+/g, '_') // space/
|
|
21
|
+
.replace(/[\s-]+/g, '_') // space/kebab → underscore
|
|
21
22
|
.replace(/__+/g, '_') // collapse multiple underscores
|
|
22
23
|
.toLowerCase();
|
|
23
24
|
}
|
|
25
|
+
function toKebabCase(str) {
|
|
26
|
+
return str
|
|
27
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2') // camelCase → camel-Case
|
|
28
|
+
.replace(/[_\s]+/g, '-') // snake/space → hyphen
|
|
29
|
+
.replace(/--+/g, '-') // collapse multiple hyphens
|
|
30
|
+
.toLowerCase();
|
|
31
|
+
}
|
|
24
32
|
function toPascalCase(str) {
|
|
25
33
|
return str
|
|
26
|
-
.replace(/[_\s-]+/g, ' ')
|
|
27
|
-
.replace(/\w+/g, (word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()
|
|
28
|
-
|
|
34
|
+
.replace(/[_\s-]+/g, ' ') // snake/kebab/space → words
|
|
35
|
+
.replace(/\w+/g, (word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() // capitalize each word
|
|
36
|
+
)
|
|
37
|
+
.replace(/\s+/g, ''); // join words
|
|
29
38
|
}
|
|
30
|
-
function
|
|
39
|
+
function toUnderscoreSeparated(str) {
|
|
31
40
|
return str
|
|
32
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1_$2') // camelCase
|
|
33
|
-
.replace(/[
|
|
34
|
-
.replace(/
|
|
35
|
-
.replace(
|
|
36
|
-
.
|
|
41
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2') // camelCase → camel_Case
|
|
42
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') // XMLHttp → XML_Http
|
|
43
|
+
.replace(/[\s-]+/g, '_') // space/kebab → underscore
|
|
44
|
+
.replace(/__+/g, '_') // collapse multiple underscores
|
|
45
|
+
.replace(/^_+|_+$/g, ''); // trim leading/trailing _
|
|
46
|
+
}
|
|
47
|
+
function toUpperCase(str) {
|
|
48
|
+
return toUnderscoreSeparated(str).toUpperCase();
|
|
37
49
|
}
|
|
38
50
|
function toLowerCase(str) {
|
|
39
|
-
return str
|
|
40
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
41
|
-
.replace(/[\s-]+/g, '_')
|
|
42
|
-
.replace(/([A-Z]+)/g, '_$1')
|
|
43
|
-
.replace(/^_+|_+$/g, '')
|
|
44
|
-
.toLowerCase();
|
|
51
|
+
return toUnderscoreSeparated(str).toLowerCase();
|
|
45
52
|
}
|
|
46
53
|
function isPlainObject(obj) {
|
|
47
54
|
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
@@ -3,6 +3,7 @@ export type SessionInfo = {
|
|
|
3
3
|
email?: string;
|
|
4
4
|
mobile?: string;
|
|
5
5
|
name?: string;
|
|
6
|
+
tenant?: string;
|
|
6
7
|
roles: string[];
|
|
7
8
|
requestId?: string;
|
|
8
9
|
type?: string;
|
|
@@ -16,6 +17,7 @@ export type SessionUser = {
|
|
|
16
17
|
email?: string;
|
|
17
18
|
mobile?: string;
|
|
18
19
|
name?: string;
|
|
20
|
+
tenant?: string;
|
|
19
21
|
roles: string[];
|
|
20
22
|
type?: string;
|
|
21
23
|
};
|
|
@@ -48,9 +50,14 @@ export type JsonValueType = string | number | boolean | null | JsonValueType[] |
|
|
|
48
50
|
[key: string]: JsonValueType;
|
|
49
51
|
};
|
|
50
52
|
export type RequestBodyType = Record<string, JsonValueType>;
|
|
51
|
-
export type
|
|
53
|
+
export type RequestParamType = Record<string, string | number | boolean | null>;
|
|
52
54
|
export type RequestByIdType = {
|
|
53
|
-
id: string
|
|
55
|
+
id: string;
|
|
56
|
+
};
|
|
57
|
+
export type PubSubEventType = {
|
|
58
|
+
id: string;
|
|
59
|
+
name?: string;
|
|
60
|
+
raw?: string;
|
|
54
61
|
};
|
|
55
62
|
export type CountryType = {
|
|
56
63
|
code: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dff-util",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
"pp": "npm run build"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [
|
|
12
|
+
"dff-util",
|
|
13
|
+
"dff-utils",
|
|
12
14
|
"npm",
|
|
13
15
|
"dff",
|
|
14
16
|
"util"
|