@teamkeel/functions-runtime 0.381.1 → 0.382.1
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/package.json +1 -1
- package/src/casing.js +26 -2
- package/src/casing.test.js +33 -2
package/package.json
CHANGED
package/src/casing.js
CHANGED
|
@@ -3,7 +3,16 @@ const { snakeCase, camelCase } = require("change-case");
|
|
|
3
3
|
function camelCaseObject(obj = {}) {
|
|
4
4
|
const r = {};
|
|
5
5
|
for (const key of Object.keys(obj)) {
|
|
6
|
-
r[
|
|
6
|
+
r[
|
|
7
|
+
camelCase(key, {
|
|
8
|
+
transform: camelCaseTransform,
|
|
9
|
+
splitRegexp: [
|
|
10
|
+
/([a-z0-9])([A-Z])/g,
|
|
11
|
+
/([A-Z])([A-Z][a-z])/g,
|
|
12
|
+
/([a-zA-Z])([0-9])/g,
|
|
13
|
+
],
|
|
14
|
+
})
|
|
15
|
+
] = obj[key];
|
|
7
16
|
}
|
|
8
17
|
return r;
|
|
9
18
|
}
|
|
@@ -11,7 +20,15 @@ function camelCaseObject(obj = {}) {
|
|
|
11
20
|
function snakeCaseObject(obj) {
|
|
12
21
|
const r = {};
|
|
13
22
|
for (const key of Object.keys(obj)) {
|
|
14
|
-
r[
|
|
23
|
+
r[
|
|
24
|
+
snakeCase(key, {
|
|
25
|
+
splitRegexp: [
|
|
26
|
+
/([a-z0-9])([A-Z])/g,
|
|
27
|
+
/([A-Z])([A-Z][a-z])/g,
|
|
28
|
+
/([a-zA-Z])([0-9])/g,
|
|
29
|
+
],
|
|
30
|
+
})
|
|
31
|
+
] = obj[key];
|
|
15
32
|
}
|
|
16
33
|
return r;
|
|
17
34
|
}
|
|
@@ -21,6 +38,13 @@ function upperCamelCase(s) {
|
|
|
21
38
|
return s[0].toUpperCase() + s.substring(1);
|
|
22
39
|
}
|
|
23
40
|
|
|
41
|
+
function camelCaseTransform(input, index) {
|
|
42
|
+
if (index === 0) return input.toLowerCase();
|
|
43
|
+
const firstChar = input.charAt(0);
|
|
44
|
+
const lowerChars = input.substr(1).toLowerCase();
|
|
45
|
+
return `${firstChar.toUpperCase()}${lowerChars}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
24
48
|
module.exports = {
|
|
25
49
|
camelCaseObject,
|
|
26
50
|
snakeCaseObject,
|
package/src/casing.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { test, expect } from "vitest";
|
|
2
|
-
import { camelCaseObject } from "./casing";
|
|
2
|
+
import { camelCaseObject, snakeCaseObject } from "./casing";
|
|
3
3
|
|
|
4
4
|
const cases = {
|
|
5
5
|
FROM_SNAKE: {
|
|
@@ -7,18 +7,49 @@ const cases = {
|
|
|
7
7
|
id: "123",
|
|
8
8
|
slack_id: "xxx_2929",
|
|
9
9
|
api_key: "1234",
|
|
10
|
+
test_11: "1234",
|
|
11
|
+
test_1_test: "1234",
|
|
12
|
+
test12: "1234",
|
|
13
|
+
abc123_test: "1234",
|
|
10
14
|
},
|
|
11
15
|
expected: {
|
|
12
16
|
id: "123",
|
|
13
17
|
slackId: "xxx_2929",
|
|
14
18
|
apiKey: "1234",
|
|
19
|
+
test11: "1234",
|
|
20
|
+
test1Test: "1234",
|
|
21
|
+
test12: "1234",
|
|
22
|
+
abc123Test: "1234",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
FROM_CAMEL: {
|
|
26
|
+
input: {
|
|
27
|
+
id: "123",
|
|
28
|
+
slackId: "xxx_2929",
|
|
29
|
+
apiKey: "1234",
|
|
30
|
+
test1: "test",
|
|
31
|
+
testA1: "test",
|
|
32
|
+
test1Test: "test",
|
|
33
|
+
test20: "test",
|
|
34
|
+
testURL: "test",
|
|
35
|
+
},
|
|
36
|
+
expected: {
|
|
37
|
+
id: "123",
|
|
38
|
+
slack_id: "xxx_2929",
|
|
39
|
+
api_key: "1234",
|
|
40
|
+
test_1: "test",
|
|
41
|
+
test_a_1: "test",
|
|
42
|
+
test_1_test: "test",
|
|
43
|
+
test_20: "test",
|
|
44
|
+
test_url: "test",
|
|
15
45
|
},
|
|
16
46
|
},
|
|
17
47
|
};
|
|
18
48
|
|
|
19
49
|
Object.entries(cases).map(([key, { input, expected }]) => {
|
|
20
50
|
test(key, () => {
|
|
21
|
-
const result =
|
|
51
|
+
const result =
|
|
52
|
+
key === "FROM_SNAKE" ? camelCaseObject(input) : snakeCaseObject(input);
|
|
22
53
|
|
|
23
54
|
expect(result).toEqual(expected);
|
|
24
55
|
});
|