@yangsaiyam/helper 1.5.3 → 1.6.0
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 +6 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/routes/index.test.ts +114 -0
- package/src/routes/index.ts +148 -0
- package/src/track/index.test.ts +9 -0
- package/src/track/index.ts +14 -14
package/README.md
CHANGED
|
@@ -69,6 +69,12 @@ src/
|
|
|
69
69
|
- `CAREER_CATEGORY`
|
|
70
70
|
- `CAREER_MODE`
|
|
71
71
|
- `CAREER_LOCATION`
|
|
72
|
+
- `ROUTES`
|
|
73
|
+
- `ROUTE`
|
|
74
|
+
- `buildLocalizedRoute`
|
|
75
|
+
- `buildRoutePathName`
|
|
76
|
+
- `routeLabelKey`
|
|
77
|
+
- `routePathKey`
|
|
72
78
|
- `CONTACT_FORM_ENQUIRY_TYPE`
|
|
73
79
|
- `FILE_STATUS`
|
|
74
80
|
- `FILE_ORIGIN`
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ROUTE,
|
|
5
|
+
ROUTES,
|
|
6
|
+
buildRoutePathName,
|
|
7
|
+
buildLocalizedRoute,
|
|
8
|
+
routeLabelKey,
|
|
9
|
+
routePathKey,
|
|
10
|
+
} from "./index";
|
|
11
|
+
|
|
12
|
+
assert.deepEqual(ROUTES, [
|
|
13
|
+
{
|
|
14
|
+
key: "home",
|
|
15
|
+
path: "/[locale]",
|
|
16
|
+
path_name: "/",
|
|
17
|
+
path_key: "/",
|
|
18
|
+
i18nKey: "routes.home",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
key: "about",
|
|
22
|
+
path: "/[locale]/about",
|
|
23
|
+
path_name: "/about",
|
|
24
|
+
path_key: "/about",
|
|
25
|
+
i18nKey: "routes.about",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
key: "career",
|
|
29
|
+
path: "/[locale]/career",
|
|
30
|
+
path_name: "/career",
|
|
31
|
+
path_key: "/career",
|
|
32
|
+
i18nKey: "routes.career",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
key: "careerDetail",
|
|
36
|
+
path: "/[locale]/career/[id]",
|
|
37
|
+
path_name: "/career/[id]",
|
|
38
|
+
path_key: "/career/[id]",
|
|
39
|
+
i18nKey: "routes.careerDetail",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
key: "careerApply",
|
|
43
|
+
path: "/[locale]/career/[id]/apply",
|
|
44
|
+
path_name: "/career/[id]/apply",
|
|
45
|
+
path_key: "/career/[id]/apply",
|
|
46
|
+
i18nKey: "routes.careerApply",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
key: "careerAssessment",
|
|
50
|
+
path: "/[locale]/career/[id]/apply/assessment",
|
|
51
|
+
path_name: "/career/[id]/apply/assessment",
|
|
52
|
+
path_key: "/career/[id]/apply/assessment",
|
|
53
|
+
i18nKey: "routes.careerAssessment",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
key: "contact",
|
|
57
|
+
path: "/[locale]/contact",
|
|
58
|
+
path_name: "/contact",
|
|
59
|
+
path_key: "/contact",
|
|
60
|
+
i18nKey: "routes.contact",
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
key: "services",
|
|
64
|
+
path: "/[locale]/services",
|
|
65
|
+
path_name: "/services",
|
|
66
|
+
path_key: "/services",
|
|
67
|
+
i18nKey: "routes.services",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
key: "servicesAdvertisingPlatform",
|
|
71
|
+
path: "/[locale]/services/advertising-platform",
|
|
72
|
+
path_name: "/services/advertising-platform",
|
|
73
|
+
path_key: "/services/advertising-platform",
|
|
74
|
+
i18nKey: "routes.servicesAdvertisingPlatform",
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: "servicesMcnBusiness",
|
|
78
|
+
path: "/[locale]/services/mcn-business",
|
|
79
|
+
path_name: "/services/mcn-business",
|
|
80
|
+
path_key: "/services/mcn-business",
|
|
81
|
+
i18nKey: "routes.servicesMcnBusiness",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
key: "servicesSoftwareDevelopment",
|
|
85
|
+
path: "/[locale]/services/software-development",
|
|
86
|
+
path_name: "/services/software-development",
|
|
87
|
+
path_key: "/services/software-development",
|
|
88
|
+
i18nKey: "routes.servicesSoftwareDevelopment",
|
|
89
|
+
},
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
assert.equal(ROUTE.home, "/[locale]");
|
|
93
|
+
assert.equal(ROUTE.careerAssessment, "/[locale]/career/[id]/apply/assessment");
|
|
94
|
+
assert.equal(
|
|
95
|
+
buildLocalizedRoute("careerApply", "en", { id: "frontend-engineer" }),
|
|
96
|
+
"/en/career/frontend-engineer/apply",
|
|
97
|
+
);
|
|
98
|
+
assert.equal(
|
|
99
|
+
buildLocalizedRoute("servicesMcnBusiness", "zh"),
|
|
100
|
+
"/zh/services/mcn-business",
|
|
101
|
+
);
|
|
102
|
+
assert.equal(
|
|
103
|
+
buildRoutePathName("careerApply", { id: "frontend-engineer" }),
|
|
104
|
+
"/career/frontend-engineer/apply",
|
|
105
|
+
);
|
|
106
|
+
assert.equal(routePathKey("home"), "/");
|
|
107
|
+
assert.equal(routePathKey("careerApply"), "/career/[id]/apply");
|
|
108
|
+
assert.throws(() => buildLocalizedRoute("careerDetail", "en"), {
|
|
109
|
+
message: 'Route "careerDetail" requires an id parameter.',
|
|
110
|
+
});
|
|
111
|
+
assert.equal(
|
|
112
|
+
routeLabelKey("servicesSoftwareDevelopment"),
|
|
113
|
+
"routes.servicesSoftwareDevelopment",
|
|
114
|
+
);
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
export type RouteKey =
|
|
2
|
+
| "home"
|
|
3
|
+
| "about"
|
|
4
|
+
| "career"
|
|
5
|
+
| "careerDetail"
|
|
6
|
+
| "careerApply"
|
|
7
|
+
| "careerAssessment"
|
|
8
|
+
| "contact"
|
|
9
|
+
| "services"
|
|
10
|
+
| "servicesAdvertisingPlatform"
|
|
11
|
+
| "servicesMcnBusiness"
|
|
12
|
+
| "servicesSoftwareDevelopment";
|
|
13
|
+
|
|
14
|
+
export type RouteMapping = {
|
|
15
|
+
key: RouteKey;
|
|
16
|
+
path: string;
|
|
17
|
+
path_name: string;
|
|
18
|
+
path_key: string;
|
|
19
|
+
i18nKey: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const ROUTES = [
|
|
23
|
+
{
|
|
24
|
+
key: "home",
|
|
25
|
+
path: "/[locale]",
|
|
26
|
+
path_name: "/",
|
|
27
|
+
path_key: "/",
|
|
28
|
+
i18nKey: "routes.home",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
key: "about",
|
|
32
|
+
path: "/[locale]/about",
|
|
33
|
+
path_name: "/about",
|
|
34
|
+
path_key: "/about",
|
|
35
|
+
i18nKey: "routes.about",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "career",
|
|
39
|
+
path: "/[locale]/career",
|
|
40
|
+
path_name: "/career",
|
|
41
|
+
path_key: "/career",
|
|
42
|
+
i18nKey: "routes.career",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "careerDetail",
|
|
46
|
+
path: "/[locale]/career/[id]",
|
|
47
|
+
path_name: "/career/[id]",
|
|
48
|
+
path_key: "/career/[id]",
|
|
49
|
+
i18nKey: "routes.careerDetail",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
key: "careerApply",
|
|
53
|
+
path: "/[locale]/career/[id]/apply",
|
|
54
|
+
path_name: "/career/[id]/apply",
|
|
55
|
+
path_key: "/career/[id]/apply",
|
|
56
|
+
i18nKey: "routes.careerApply",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
key: "careerAssessment",
|
|
60
|
+
path: "/[locale]/career/[id]/apply/assessment",
|
|
61
|
+
path_name: "/career/[id]/apply/assessment",
|
|
62
|
+
path_key: "/career/[id]/apply/assessment",
|
|
63
|
+
i18nKey: "routes.careerAssessment",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
key: "contact",
|
|
67
|
+
path: "/[locale]/contact",
|
|
68
|
+
path_name: "/contact",
|
|
69
|
+
path_key: "/contact",
|
|
70
|
+
i18nKey: "routes.contact",
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
key: "services",
|
|
74
|
+
path: "/[locale]/services",
|
|
75
|
+
path_name: "/services",
|
|
76
|
+
path_key: "/services",
|
|
77
|
+
i18nKey: "routes.services",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
key: "servicesAdvertisingPlatform",
|
|
81
|
+
path: "/[locale]/services/advertising-platform",
|
|
82
|
+
path_name: "/services/advertising-platform",
|
|
83
|
+
path_key: "/services/advertising-platform",
|
|
84
|
+
i18nKey: "routes.servicesAdvertisingPlatform",
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
key: "servicesMcnBusiness",
|
|
88
|
+
path: "/[locale]/services/mcn-business",
|
|
89
|
+
path_name: "/services/mcn-business",
|
|
90
|
+
path_key: "/services/mcn-business",
|
|
91
|
+
i18nKey: "routes.servicesMcnBusiness",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
key: "servicesSoftwareDevelopment",
|
|
95
|
+
path: "/[locale]/services/software-development",
|
|
96
|
+
path_name: "/services/software-development",
|
|
97
|
+
path_key: "/services/software-development",
|
|
98
|
+
i18nKey: "routes.servicesSoftwareDevelopment",
|
|
99
|
+
},
|
|
100
|
+
] as const satisfies readonly RouteMapping[];
|
|
101
|
+
|
|
102
|
+
export const ROUTE = Object.fromEntries(
|
|
103
|
+
ROUTES.map((route) => [route.key, route.path]),
|
|
104
|
+
) as Record<RouteKey, string>;
|
|
105
|
+
|
|
106
|
+
export function routeLabelKey(route: RouteKey): string {
|
|
107
|
+
return ROUTES.find((item) => item.key === route)?.i18nKey ?? "routes.home";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function routePathKey(route: RouteKey): string {
|
|
111
|
+
return ROUTES.find((item) => item.key === route)?.path_key ?? "/";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function buildRoutePathName(
|
|
115
|
+
route: RouteKey,
|
|
116
|
+
params: Partial<Record<"id", string | number>> = {},
|
|
117
|
+
): string {
|
|
118
|
+
let pathName: string =
|
|
119
|
+
ROUTES.find((item) => item.key === route)?.path_name ?? "/";
|
|
120
|
+
|
|
121
|
+
if (pathName.includes("[id]")) {
|
|
122
|
+
if (params.id === undefined || params.id === null) {
|
|
123
|
+
throw new Error(`Route "${route}" requires an id parameter.`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
pathName = pathName.replace("[id]", encodeURIComponent(String(params.id)));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return pathName;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function buildLocalizedRoute(
|
|
133
|
+
route: RouteKey,
|
|
134
|
+
locale: string,
|
|
135
|
+
params: Partial<Record<"id", string | number>> = {},
|
|
136
|
+
): string {
|
|
137
|
+
let path = ROUTE[route].replace("[locale]", encodeURIComponent(locale));
|
|
138
|
+
|
|
139
|
+
if (path.includes("[id]")) {
|
|
140
|
+
if (params.id === undefined || params.id === null) {
|
|
141
|
+
throw new Error(`Route "${route}" requires an id parameter.`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
path = path.replace("[id]", encodeURIComponent(String(params.id)));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return path;
|
|
148
|
+
}
|
package/src/track/index.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { MappingOption } from "../shared/types";
|
|
2
2
|
|
|
3
|
-
export const ORIGIN = [
|
|
4
|
-
{
|
|
5
|
-
key:
|
|
6
|
-
value: "Website",
|
|
7
|
-
i18nKey: "track.origin.
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
key:
|
|
11
|
-
value: "Linkedin",
|
|
12
|
-
i18nKey: "track.origin.
|
|
13
|
-
},
|
|
14
|
-
{ key:
|
|
15
|
-
{ key:
|
|
16
|
-
] as const satisfies readonly MappingOption[];
|
|
3
|
+
export const ORIGIN = [
|
|
4
|
+
{
|
|
5
|
+
key: 0,
|
|
6
|
+
value: "Website",
|
|
7
|
+
i18nKey: "track.origin.0",
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
key: 1,
|
|
11
|
+
value: "Linkedin",
|
|
12
|
+
i18nKey: "track.origin.1",
|
|
13
|
+
},
|
|
14
|
+
{ key: 2, value: "Jobstreet", i18nKey: "track.origin.2" },
|
|
15
|
+
{ key: 3, value: "Maukerja", i18nKey: "track.origin.3" },
|
|
16
|
+
] as const satisfies readonly MappingOption[];
|