@simplysm/core-common 13.0.76 → 13.0.78
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 +64 -21
- package/dist/extensions/arr-ext.d.ts +1 -1
- package/dist/extensions/arr-ext.d.ts.map +1 -1
- package/dist/extensions/arr-ext.helpers.d.ts +8 -0
- package/dist/extensions/arr-ext.helpers.d.ts.map +1 -1
- package/dist/extensions/arr-ext.helpers.js +65 -0
- package/dist/extensions/arr-ext.helpers.js.map +2 -2
- package/dist/extensions/arr-ext.js +16 -124
- package/dist/extensions/arr-ext.js.map +2 -2
- package/dist/extensions/arr-ext.types.d.ts +40 -32
- package/dist/extensions/arr-ext.types.d.ts.map +1 -1
- package/dist/extensions/map-ext.js.map +1 -1
- package/dist/extensions/set-ext.js.map +1 -1
- package/dist/features/event-emitter.d.ts +4 -4
- package/dist/features/event-emitter.d.ts.map +1 -1
- package/dist/features/event-emitter.js.map +1 -1
- package/dist/features/serial-queue.js +2 -2
- package/dist/features/serial-queue.js.map +1 -1
- package/dist/index.d.ts +13 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -13
- package/dist/index.js.map +1 -1
- package/dist/types/date-only.js +2 -2
- package/dist/types/date-only.js.map +1 -1
- package/dist/types/date-time.js +2 -2
- package/dist/types/date-time.js.map +1 -1
- package/dist/types/time.js +2 -2
- package/dist/types/time.js.map +1 -1
- package/dist/types/uuid.d.ts +2 -2
- package/dist/types/uuid.d.ts.map +1 -1
- package/dist/types/uuid.js +1 -1
- package/dist/types/uuid.js.map +1 -1
- package/dist/utils/bytes.d.ts +10 -10
- package/dist/utils/bytes.d.ts.map +1 -1
- package/dist/utils/bytes.js +10 -10
- package/dist/utils/bytes.js.map +1 -1
- package/dist/utils/date-format.d.ts +1 -1
- package/dist/utils/date-format.d.ts.map +1 -1
- package/dist/utils/date-format.js +2 -2
- package/dist/utils/date-format.js.map +1 -1
- package/dist/utils/error.d.ts +1 -1
- package/dist/utils/error.d.ts.map +1 -1
- package/dist/utils/error.js +2 -2
- package/dist/utils/error.js.map +1 -1
- package/dist/utils/json.d.ts +4 -2
- package/dist/utils/json.d.ts.map +1 -1
- package/dist/utils/json.js +9 -9
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/num.d.ts +10 -10
- package/dist/utils/num.d.ts.map +1 -1
- package/dist/utils/num.js +11 -11
- package/dist/utils/num.js.map +1 -1
- package/dist/utils/obj.d.ts +40 -40
- package/dist/utils/obj.d.ts.map +1 -1
- package/dist/utils/obj.js +102 -99
- package/dist/utils/obj.js.map +1 -1
- package/dist/utils/path.d.ts +3 -3
- package/dist/utils/path.d.ts.map +1 -1
- package/dist/utils/path.js +6 -6
- package/dist/utils/path.js.map +1 -1
- package/dist/utils/primitive.d.ts +1 -1
- package/dist/utils/primitive.d.ts.map +1 -1
- package/dist/utils/primitive.js +2 -2
- package/dist/utils/primitive.js.map +1 -1
- package/dist/utils/str.d.ts +16 -16
- package/dist/utils/str.d.ts.map +1 -1
- package/dist/utils/str.js +16 -16
- package/dist/utils/str.js.map +1 -1
- package/dist/utils/transferable.d.ts +3 -3
- package/dist/utils/transferable.d.ts.map +1 -1
- package/dist/utils/transferable.js +10 -10
- package/dist/utils/transferable.js.map +1 -1
- package/dist/utils/wait.d.ts +2 -2
- package/dist/utils/wait.d.ts.map +1 -1
- package/dist/utils/wait.js +5 -5
- package/dist/utils/wait.js.map +1 -1
- package/dist/utils/xml.d.ts +2 -2
- package/dist/utils/xml.d.ts.map +1 -1
- package/dist/utils/xml.js +4 -4
- package/dist/utils/xml.js.map +1 -1
- package/dist/{zip/sd-zip.d.ts → utils/zip.d.ts} +1 -1
- package/dist/utils/zip.d.ts.map +1 -0
- package/dist/{zip/sd-zip.js → utils/zip.js} +1 -1
- package/dist/{zip/sd-zip.js.map → utils/zip.js.map} +1 -1
- package/package.json +1 -1
- package/src/extensions/arr-ext.helpers.ts +86 -0
- package/src/extensions/arr-ext.ts +22 -170
- package/src/extensions/arr-ext.types.ts +76 -48
- package/src/extensions/map-ext.ts +3 -3
- package/src/extensions/set-ext.ts +2 -2
- package/src/features/event-emitter.ts +6 -6
- package/src/features/serial-queue.ts +2 -2
- package/src/index.ts +16 -16
- package/src/types/date-only.ts +2 -2
- package/src/types/date-time.ts +2 -2
- package/src/types/time.ts +2 -2
- package/src/types/uuid.ts +2 -2
- package/src/utils/bytes.ts +15 -15
- package/src/utils/date-format.ts +1 -1
- package/src/utils/error.ts +1 -1
- package/src/utils/json.ts +9 -7
- package/src/utils/num.ts +15 -15
- package/src/utils/obj.ts +119 -116
- package/src/utils/path.ts +3 -3
- package/src/utils/primitive.ts +1 -1
- package/src/utils/str.ts +16 -16
- package/src/utils/transferable.ts +9 -9
- package/src/utils/wait.ts +3 -3
- package/src/utils/xml.ts +2 -2
- package/tests/extensions/array-extension.spec.ts +7 -5
- package/tests/types/uuid.spec.ts +4 -4
- package/tests/utils/bytes-utils.spec.ts +42 -49
- package/tests/utils/date-format.spec.ts +89 -88
- package/tests/utils/debounce-queue.spec.ts +3 -1
- package/tests/utils/json.spec.ts +61 -68
- package/tests/utils/number.spec.ts +41 -46
- package/tests/utils/object.spec.ts +120 -139
- package/tests/utils/path.spec.ts +19 -19
- package/tests/utils/primitive.spec.ts +12 -12
- package/tests/utils/string.spec.ts +66 -74
- package/tests/utils/transferable.spec.ts +55 -62
- package/tests/utils/wait.spec.ts +10 -10
- package/tests/utils/xml.spec.ts +25 -25
- package/dist/zip/sd-zip.d.ts.map +0 -1
- /package/src/{zip/sd-zip.ts → utils/zip.ts} +0 -0
- /package/tests/{zip/sd-zip.spec.ts → utils/zip.spec.ts} +0 -0
package/tests/utils/path.spec.ts
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import { path } from "@simplysm/core-common";
|
|
3
3
|
|
|
4
4
|
describe("path utils", () => {
|
|
5
|
-
describe("
|
|
5
|
+
describe("join()", () => {
|
|
6
6
|
it("Combines path segments", () => {
|
|
7
|
-
expect(
|
|
7
|
+
expect(path.join("a", "b", "c")).toBe("a/b/c");
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
it("Preserves leading slash", () => {
|
|
11
|
-
expect(
|
|
11
|
+
expect(path.join("/a", "b")).toBe("/a/b");
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
it("Removes duplicate slashes", () => {
|
|
15
|
-
expect(
|
|
15
|
+
expect(path.join("a/", "/b/", "/c")).toBe("a/b/c");
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
it("Ignores empty segments", () => {
|
|
19
|
-
expect(
|
|
19
|
+
expect(path.join("a", "", "b")).toBe("a/b");
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
it("Empty input returns empty string", () => {
|
|
23
|
-
expect(
|
|
23
|
+
expect(path.join()).toBe("");
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
describe("
|
|
27
|
+
describe("basename()", () => {
|
|
28
28
|
it("Extracts filename", () => {
|
|
29
|
-
expect(
|
|
29
|
+
expect(path.basename("a/b/file.txt")).toBe("file.txt");
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
it("Removes extension", () => {
|
|
33
|
-
expect(
|
|
33
|
+
expect(path.basename("a/b/file.txt", ".txt")).toBe("file");
|
|
34
34
|
});
|
|
35
35
|
|
|
36
36
|
it("Ignores non-matching extension", () => {
|
|
37
|
-
expect(
|
|
37
|
+
expect(path.basename("a/b/file.txt", ".md")).toBe("file.txt");
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
it("Handles filename without path", () => {
|
|
41
|
-
expect(
|
|
41
|
+
expect(path.basename("file.txt")).toBe("file.txt");
|
|
42
42
|
});
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
describe("
|
|
45
|
+
describe("extname()", () => {
|
|
46
46
|
it("Extracts extension", () => {
|
|
47
|
-
expect(
|
|
47
|
+
expect(path.extname("file.txt")).toBe(".txt");
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
it("Extracts only last extension", () => {
|
|
51
|
-
expect(
|
|
51
|
+
expect(path.extname("archive.tar.gz")).toBe(".gz");
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
it("File without extension returns empty string", () => {
|
|
55
|
-
expect(
|
|
55
|
+
expect(path.extname("Makefile")).toBe("");
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
it("Hidden file returns empty string", () => {
|
|
59
|
-
expect(
|
|
59
|
+
expect(path.extname(".gitignore")).toBe("");
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
it("Extracts extension from file with path", () => {
|
|
63
|
-
expect(
|
|
63
|
+
expect(path.extname("a/b/file.ts")).toBe(".ts");
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
it("Empty string returns empty string", () => {
|
|
67
|
-
expect(
|
|
67
|
+
expect(path.extname("")).toBe("");
|
|
68
68
|
});
|
|
69
69
|
});
|
|
70
70
|
});
|
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
2
|
+
import { primitive, DateTime, DateOnly, Time, Uuid } from "@simplysm/core-common";
|
|
3
3
|
|
|
4
4
|
describe("primitive utils", () => {
|
|
5
|
-
describe("
|
|
5
|
+
describe("typeStr()", () => {
|
|
6
6
|
it("Returns string", () => {
|
|
7
|
-
expect(
|
|
7
|
+
expect(primitive.typeStr("hello")).toBe("string");
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
it("Returns number", () => {
|
|
11
|
-
expect(
|
|
11
|
+
expect(primitive.typeStr(42)).toBe("number");
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
it("Returns boolean", () => {
|
|
15
|
-
expect(
|
|
16
|
-
expect(
|
|
15
|
+
expect(primitive.typeStr(true)).toBe("boolean");
|
|
16
|
+
expect(primitive.typeStr(false)).toBe("boolean");
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
it("Returns DateTime", () => {
|
|
20
|
-
expect(
|
|
20
|
+
expect(primitive.typeStr(new DateTime())).toBe("DateTime");
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
it("Returns DateOnly", () => {
|
|
24
|
-
expect(
|
|
24
|
+
expect(primitive.typeStr(new DateOnly())).toBe("DateOnly");
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
it("Returns Time", () => {
|
|
28
|
-
expect(
|
|
28
|
+
expect(primitive.typeStr(new Time())).toBe("Time");
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
it("Returns Uuid", () => {
|
|
32
|
-
expect(
|
|
32
|
+
expect(primitive.typeStr(Uuid.generate())).toBe("Uuid");
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
it("Uint8Array returns Bytes", () => {
|
|
36
|
-
expect(
|
|
36
|
+
expect(primitive.typeStr(new Uint8Array([1, 2]))).toBe("Bytes");
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
it("Unsupported type throws error", () => {
|
|
40
|
-
expect(() =>
|
|
40
|
+
expect(() => primitive.typeStr({} as never)).toThrow();
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
43
|
});
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
koreanGetSuffix,
|
|
4
|
-
strReplaceFullWidth,
|
|
5
|
-
strToPascalCase,
|
|
6
|
-
strToCamelCase,
|
|
7
|
-
strToKebabCase,
|
|
8
|
-
strToSnakeCase,
|
|
9
|
-
strInsert,
|
|
10
|
-
} from "@simplysm/core-common";
|
|
2
|
+
import { str } from "@simplysm/core-common";
|
|
11
3
|
|
|
12
4
|
describe("string utils", () => {
|
|
13
5
|
//#region koreanGetSuffix - Korean postposition handling
|
|
@@ -15,104 +7,104 @@ describe("string utils", () => {
|
|
|
15
7
|
describe("koreanGetSuffix()", () => {
|
|
16
8
|
describe("with final consonant", () => {
|
|
17
9
|
it("'을' type returns '을'", () => {
|
|
18
|
-
expect(
|
|
10
|
+
expect(str.getKoreanSuffix("책", "을")).toBe("을");
|
|
19
11
|
});
|
|
20
12
|
|
|
21
13
|
it("'은' type returns '은'", () => {
|
|
22
|
-
expect(
|
|
14
|
+
expect(str.getKoreanSuffix("책", "은")).toBe("은");
|
|
23
15
|
});
|
|
24
16
|
|
|
25
17
|
it("'이' type returns '이'", () => {
|
|
26
|
-
expect(
|
|
18
|
+
expect(str.getKoreanSuffix("책", "이")).toBe("이");
|
|
27
19
|
});
|
|
28
20
|
|
|
29
21
|
it("'와' type returns '과'", () => {
|
|
30
|
-
expect(
|
|
22
|
+
expect(str.getKoreanSuffix("책", "와")).toBe("과");
|
|
31
23
|
});
|
|
32
24
|
|
|
33
25
|
it("'랑' type returns '이랑'", () => {
|
|
34
|
-
expect(
|
|
26
|
+
expect(str.getKoreanSuffix("책", "랑")).toBe("이랑");
|
|
35
27
|
});
|
|
36
28
|
|
|
37
29
|
it("'로' type returns '으로'", () => {
|
|
38
|
-
expect(
|
|
30
|
+
expect(str.getKoreanSuffix("책", "로")).toBe("으로");
|
|
39
31
|
});
|
|
40
32
|
|
|
41
33
|
it("'라' type returns '이라'", () => {
|
|
42
|
-
expect(
|
|
34
|
+
expect(str.getKoreanSuffix("책", "라")).toBe("이라");
|
|
43
35
|
});
|
|
44
36
|
});
|
|
45
37
|
|
|
46
38
|
describe("non-Korean character cases", () => {
|
|
47
39
|
it("treats words ending with English letter as no final consonant", () => {
|
|
48
|
-
expect(
|
|
49
|
-
expect(
|
|
40
|
+
expect(str.getKoreanSuffix("ABC", "을")).toBe("를");
|
|
41
|
+
expect(str.getKoreanSuffix("test", "은")).toBe("는");
|
|
50
42
|
});
|
|
51
43
|
|
|
52
44
|
it("treats words ending with number as no final consonant", () => {
|
|
53
|
-
expect(
|
|
54
|
-
expect(
|
|
45
|
+
expect(str.getKoreanSuffix("123", "을")).toBe("를");
|
|
46
|
+
expect(str.getKoreanSuffix("456", "은")).toBe("는");
|
|
55
47
|
});
|
|
56
48
|
|
|
57
49
|
it("empty string treated as no final consonant", () => {
|
|
58
|
-
expect(
|
|
59
|
-
expect(
|
|
50
|
+
expect(str.getKoreanSuffix("", "을")).toBe("를");
|
|
51
|
+
expect(str.getKoreanSuffix("", "은")).toBe("는");
|
|
60
52
|
});
|
|
61
53
|
});
|
|
62
54
|
|
|
63
55
|
describe("without final consonant", () => {
|
|
64
56
|
it("'을' type returns '를'", () => {
|
|
65
|
-
expect(
|
|
57
|
+
expect(str.getKoreanSuffix("나무", "을")).toBe("를");
|
|
66
58
|
});
|
|
67
59
|
|
|
68
60
|
it("'은' type returns '는'", () => {
|
|
69
|
-
expect(
|
|
61
|
+
expect(str.getKoreanSuffix("나무", "은")).toBe("는");
|
|
70
62
|
});
|
|
71
63
|
|
|
72
64
|
it("'이' type returns '가'", () => {
|
|
73
|
-
expect(
|
|
65
|
+
expect(str.getKoreanSuffix("나무", "이")).toBe("가");
|
|
74
66
|
});
|
|
75
67
|
|
|
76
68
|
it("'와' type returns '와'", () => {
|
|
77
|
-
expect(
|
|
69
|
+
expect(str.getKoreanSuffix("나무", "와")).toBe("와");
|
|
78
70
|
});
|
|
79
71
|
|
|
80
72
|
it("'랑' type returns '랑'", () => {
|
|
81
|
-
expect(
|
|
73
|
+
expect(str.getKoreanSuffix("나무", "랑")).toBe("랑");
|
|
82
74
|
});
|
|
83
75
|
|
|
84
76
|
it("'로' type returns '로'", () => {
|
|
85
|
-
expect(
|
|
77
|
+
expect(str.getKoreanSuffix("나무", "로")).toBe("로");
|
|
86
78
|
});
|
|
87
79
|
|
|
88
80
|
it("'라' type returns '라'", () => {
|
|
89
|
-
expect(
|
|
81
|
+
expect(str.getKoreanSuffix("나무", "라")).toBe("라");
|
|
90
82
|
});
|
|
91
83
|
});
|
|
92
84
|
|
|
93
85
|
describe("final consonant ㄹ (special '로' handling)", () => {
|
|
94
86
|
it("'로' type returns '로' for final ㄹ (Seoul)", () => {
|
|
95
|
-
expect(
|
|
87
|
+
expect(str.getKoreanSuffix("서울", "로")).toBe("로");
|
|
96
88
|
});
|
|
97
89
|
|
|
98
90
|
it("'로' type returns '로' for final ㄹ (road)", () => {
|
|
99
|
-
expect(
|
|
91
|
+
expect(str.getKoreanSuffix("길", "로")).toBe("로");
|
|
100
92
|
});
|
|
101
93
|
|
|
102
94
|
it("'로' type returns '로' for final ㄹ (foot)", () => {
|
|
103
|
-
expect(
|
|
95
|
+
expect(str.getKoreanSuffix("발", "로")).toBe("로");
|
|
104
96
|
});
|
|
105
97
|
|
|
106
98
|
it("'로' type returns '로' for final ㄹ (alcohol)", () => {
|
|
107
|
-
expect(
|
|
99
|
+
expect(str.getKoreanSuffix("술", "로")).toBe("로");
|
|
108
100
|
});
|
|
109
101
|
|
|
110
102
|
it("'을' type returns '을' for final ㄹ by general rule", () => {
|
|
111
|
-
expect(
|
|
103
|
+
expect(str.getKoreanSuffix("서울", "을")).toBe("을");
|
|
112
104
|
});
|
|
113
105
|
|
|
114
106
|
it("'은' type returns '은' for final ㄹ by general rule", () => {
|
|
115
|
-
expect(
|
|
107
|
+
expect(str.getKoreanSuffix("서울", "은")).toBe("은");
|
|
116
108
|
});
|
|
117
109
|
});
|
|
118
110
|
});
|
|
@@ -123,32 +115,32 @@ describe("string utils", () => {
|
|
|
123
115
|
|
|
124
116
|
//#region strReplaceFullWidth - Full-width to half-width conversion
|
|
125
117
|
|
|
126
|
-
describe("
|
|
118
|
+
describe("replaceFullWidth()", () => {
|
|
127
119
|
it("converts full-width alphabet to half-width", () => {
|
|
128
|
-
expect(
|
|
129
|
-
expect(
|
|
130
|
-
expect(
|
|
131
|
-
expect(
|
|
120
|
+
expect(str.replaceFullWidth("ABCDEFG")).toBe("ABCDEFG");
|
|
121
|
+
expect(str.replaceFullWidth("HIJKLMN")).toBe("HIJKLMN");
|
|
122
|
+
expect(str.replaceFullWidth("OPQRSTU")).toBe("OPQRSTU");
|
|
123
|
+
expect(str.replaceFullWidth("VWXYZ")).toBe("VWXYZ");
|
|
132
124
|
});
|
|
133
125
|
|
|
134
126
|
it("converts full-width number to half-width", () => {
|
|
135
|
-
expect(
|
|
127
|
+
expect(str.replaceFullWidth("0123456789")).toBe("0123456789");
|
|
136
128
|
});
|
|
137
129
|
|
|
138
130
|
it("converts full-width parenthesis to half-width", () => {
|
|
139
|
-
expect(
|
|
131
|
+
expect(str.replaceFullWidth("(ABC)")).toBe("(ABC)");
|
|
140
132
|
});
|
|
141
133
|
|
|
142
134
|
it("converts full-width space to half-width space", () => {
|
|
143
|
-
expect(
|
|
135
|
+
expect(str.replaceFullWidth("A B C")).toBe("A B C");
|
|
144
136
|
});
|
|
145
137
|
|
|
146
138
|
it("converts mixed full-width/half-width string", () => {
|
|
147
|
-
expect(
|
|
139
|
+
expect(str.replaceFullWidth("ABC123")).toBe("ABC123");
|
|
148
140
|
});
|
|
149
141
|
|
|
150
142
|
it("returns original if no full-width characters", () => {
|
|
151
|
-
expect(
|
|
143
|
+
expect(str.replaceFullWidth("ABC123")).toBe("ABC123");
|
|
152
144
|
});
|
|
153
145
|
});
|
|
154
146
|
|
|
@@ -158,98 +150,98 @@ describe("string utils", () => {
|
|
|
158
150
|
|
|
159
151
|
//#region Case conversion
|
|
160
152
|
|
|
161
|
-
describe("
|
|
153
|
+
describe("toPascalCase()", () => {
|
|
162
154
|
it("converts kebab-case to PascalCase", () => {
|
|
163
|
-
expect(
|
|
155
|
+
expect(str.toPascalCase("hello-world")).toBe("HelloWorld");
|
|
164
156
|
});
|
|
165
157
|
|
|
166
158
|
it("converts dot.case to PascalCase", () => {
|
|
167
|
-
expect(
|
|
159
|
+
expect(str.toPascalCase("hello.world")).toBe("HelloWorld");
|
|
168
160
|
});
|
|
169
161
|
|
|
170
162
|
it("converts snake_case to PascalCase", () => {
|
|
171
|
-
expect(
|
|
163
|
+
expect(str.toPascalCase("hello_world")).toBe("HelloWorld");
|
|
172
164
|
});
|
|
173
165
|
|
|
174
166
|
it("capitalizes first letter of lowercase string", () => {
|
|
175
|
-
expect(
|
|
167
|
+
expect(str.toPascalCase("hello")).toBe("Hello");
|
|
176
168
|
});
|
|
177
169
|
|
|
178
170
|
it("returns as-is if already PascalCase", () => {
|
|
179
|
-
expect(
|
|
171
|
+
expect(str.toPascalCase("HelloWorld")).toBe("HelloWorld");
|
|
180
172
|
});
|
|
181
173
|
|
|
182
174
|
it("handles consecutive hyphens", () => {
|
|
183
|
-
expect(
|
|
175
|
+
expect(str.toPascalCase("hello-world-test")).toBe("HelloWorldTest");
|
|
184
176
|
});
|
|
185
177
|
});
|
|
186
178
|
|
|
187
|
-
describe("
|
|
179
|
+
describe("toCamelCase()", () => {
|
|
188
180
|
it("converts kebab-case to camelCase", () => {
|
|
189
|
-
expect(
|
|
181
|
+
expect(str.toCamelCase("hello-world")).toBe("helloWorld");
|
|
190
182
|
});
|
|
191
183
|
|
|
192
184
|
it("converts PascalCase to camelCase", () => {
|
|
193
|
-
expect(
|
|
185
|
+
expect(str.toCamelCase("HelloWorld")).toBe("helloWorld");
|
|
194
186
|
});
|
|
195
187
|
|
|
196
188
|
it("converts dot.case to camelCase", () => {
|
|
197
|
-
expect(
|
|
189
|
+
expect(str.toCamelCase("hello.world")).toBe("helloWorld");
|
|
198
190
|
});
|
|
199
191
|
|
|
200
192
|
it("converts snake_case to camelCase", () => {
|
|
201
|
-
expect(
|
|
193
|
+
expect(str.toCamelCase("hello_world")).toBe("helloWorld");
|
|
202
194
|
});
|
|
203
195
|
|
|
204
196
|
it("returns as-is if already camelCase", () => {
|
|
205
|
-
expect(
|
|
197
|
+
expect(str.toCamelCase("helloWorld")).toBe("helloWorld");
|
|
206
198
|
});
|
|
207
199
|
});
|
|
208
200
|
|
|
209
|
-
describe("
|
|
201
|
+
describe("toKebabCase()", () => {
|
|
210
202
|
it("converts PascalCase to kebab-case", () => {
|
|
211
|
-
expect(
|
|
203
|
+
expect(str.toKebabCase("HelloWorld")).toBe("hello-world");
|
|
212
204
|
});
|
|
213
205
|
|
|
214
206
|
it("converts camelCase to kebab-case", () => {
|
|
215
|
-
expect(
|
|
207
|
+
expect(str.toKebabCase("helloWorld")).toBe("hello-world");
|
|
216
208
|
});
|
|
217
209
|
|
|
218
210
|
it("adds hyphen before underscore when present", () => {
|
|
219
211
|
// toKebabCase converts [-_]?[A-Z] to -lowercase, so _W → -_w
|
|
220
|
-
expect(
|
|
212
|
+
expect(str.toKebabCase("Hello_World")).toBe("hello-_world");
|
|
221
213
|
});
|
|
222
214
|
|
|
223
215
|
it("returns as-is if already kebab-case", () => {
|
|
224
|
-
expect(
|
|
216
|
+
expect(str.toKebabCase("hello-world")).toBe("hello-world");
|
|
225
217
|
});
|
|
226
218
|
|
|
227
219
|
it("handles consecutive uppercase letters", () => {
|
|
228
|
-
expect(
|
|
220
|
+
expect(str.toKebabCase("HelloWorldTest")).toBe("hello-world-test");
|
|
229
221
|
});
|
|
230
222
|
|
|
231
223
|
it("handles consecutive uppercase followed by lowercase", () => {
|
|
232
224
|
// each uppercase letter treated as separate word
|
|
233
|
-
expect(
|
|
234
|
-
expect(
|
|
225
|
+
expect(str.toKebabCase("XMLParser")).toBe("x-m-l-parser");
|
|
226
|
+
expect(str.toKebabCase("HTTPSConnection")).toBe("h-t-t-p-s-connection");
|
|
235
227
|
});
|
|
236
228
|
});
|
|
237
229
|
|
|
238
|
-
describe("
|
|
230
|
+
describe("toSnakeCase()", () => {
|
|
239
231
|
it("converts PascalCase to snake_case", () => {
|
|
240
|
-
expect(
|
|
232
|
+
expect(str.toSnakeCase("HelloWorld")).toBe("hello_world");
|
|
241
233
|
});
|
|
242
234
|
|
|
243
235
|
it("converts camelCase to snake_case", () => {
|
|
244
|
-
expect(
|
|
236
|
+
expect(str.toSnakeCase("helloWorld")).toBe("hello_world");
|
|
245
237
|
});
|
|
246
238
|
|
|
247
239
|
it("returns as-is if already snake_case", () => {
|
|
248
|
-
expect(
|
|
240
|
+
expect(str.toSnakeCase("hello_world")).toBe("hello_world");
|
|
249
241
|
});
|
|
250
242
|
|
|
251
243
|
it("handles consecutive uppercase letters", () => {
|
|
252
|
-
expect(
|
|
244
|
+
expect(str.toSnakeCase("HelloWorldTest")).toBe("hello_world_test");
|
|
253
245
|
});
|
|
254
246
|
});
|
|
255
247
|
|
|
@@ -259,13 +251,13 @@ describe("string utils", () => {
|
|
|
259
251
|
|
|
260
252
|
//#region Other
|
|
261
253
|
|
|
262
|
-
describe("
|
|
254
|
+
describe("insert()", () => {
|
|
263
255
|
it("inserts at start of string", () => {
|
|
264
|
-
expect(
|
|
256
|
+
expect(str.insert("world", 0, "hello ")).toBe("hello world");
|
|
265
257
|
});
|
|
266
258
|
|
|
267
259
|
it("inserts at end of string", () => {
|
|
268
|
-
expect(
|
|
260
|
+
expect(str.insert("hello", 5, " world")).toBe("hello world");
|
|
269
261
|
});
|
|
270
262
|
});
|
|
271
263
|
|