@yangsaiyam/helper 1.12.3 → 1.12.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.
Files changed (50) hide show
  1. package/dist/addressess/index.d.ts +137 -0
  2. package/dist/addressess/index.js +24 -0
  3. package/dist/addressess/index.test.d.ts +1 -0
  4. package/dist/addressess/index.test.js +16 -0
  5. package/dist/assessment-question/index.d.ts +19 -0
  6. package/dist/assessment-question/index.js +22 -0
  7. package/dist/assessment-question/index.test.d.ts +1 -0
  8. package/dist/assessment-question/index.test.js +27 -0
  9. package/dist/career/index.d.ts +132 -0
  10. package/dist/career/index.js +40 -0
  11. package/dist/contact-form/index.d.ts +13 -0
  12. package/dist/contact-form/index.js +13 -0
  13. package/dist/email-history/index.d.ts +17 -0
  14. package/dist/email-history/index.js +6 -0
  15. package/dist/email-template/index.d.ts +13 -0
  16. package/dist/email-template/index.js +5 -0
  17. package/dist/files/index.d.ts +18 -0
  18. package/dist/files/index.js +8 -0
  19. package/dist/index.d.ts +17 -655
  20. package/dist/index.js +17 -703
  21. package/dist/job-applications/index.d.ts +33 -0
  22. package/dist/job-applications/index.js +10 -0
  23. package/dist/locale/index.d.ts +9 -0
  24. package/dist/locale/index.js +4 -0
  25. package/dist/roles/index.d.ts +61 -0
  26. package/dist/roles/index.js +170 -0
  27. package/dist/roles/index.test.d.ts +1 -0
  28. package/dist/roles/index.test.js +80 -0
  29. package/dist/routes/index.d.ts +80 -0
  30. package/dist/routes/index.js +106 -0
  31. package/dist/routes/index.test.d.ts +1 -0
  32. package/dist/routes/index.test.js +92 -0
  33. package/dist/shared/helpers.d.ts +5 -0
  34. package/dist/shared/helpers.js +15 -0
  35. package/dist/shared/types.d.ts +5 -0
  36. package/dist/shared/types.js +1 -0
  37. package/dist/time/index.d.ts +73 -0
  38. package/dist/time/index.js +161 -0
  39. package/dist/time/index.test.d.ts +1 -0
  40. package/dist/time/index.test.js +35 -0
  41. package/dist/track/index.d.ts +17 -0
  42. package/dist/track/index.js +14 -0
  43. package/dist/track/index.test.d.ts +1 -0
  44. package/dist/track/index.test.js +7 -0
  45. package/dist/url-prefix/index.d.ts +8 -0
  46. package/dist/url-prefix/index.js +9 -0
  47. package/dist/website/index.d.ts +16 -0
  48. package/dist/website/index.js +17 -0
  49. package/package.json +1 -1
  50. package/src/email-history/index.ts +1 -0
@@ -0,0 +1,33 @@
1
+ export declare const JOB_APPLICATION_STATUS: readonly [{
2
+ readonly key: 0;
3
+ readonly value: "Pending Review";
4
+ readonly i18nKey: "jobApplication.status.0";
5
+ }, {
6
+ readonly key: 1;
7
+ readonly value: "Shortlisted";
8
+ readonly i18nKey: "jobApplication.status.1";
9
+ }, {
10
+ readonly key: 2;
11
+ readonly value: "Interview";
12
+ readonly i18nKey: "jobApplication.status.2";
13
+ }, {
14
+ readonly key: 3;
15
+ readonly value: "Offered";
16
+ readonly i18nKey: "jobApplication.status.3";
17
+ }, {
18
+ readonly key: 4;
19
+ readonly value: "Hired";
20
+ readonly i18nKey: "jobApplication.status.4";
21
+ }, {
22
+ readonly key: 5;
23
+ readonly value: "Rejected";
24
+ readonly i18nKey: "jobApplication.status.5";
25
+ }, {
26
+ readonly key: 6;
27
+ readonly value: "Withdrawn";
28
+ readonly i18nKey: "jobApplication.status.6";
29
+ }, {
30
+ readonly key: 7;
31
+ readonly value: "Ghosted";
32
+ readonly i18nKey: "jobApplication.status.7";
33
+ }];
@@ -0,0 +1,10 @@
1
+ export const JOB_APPLICATION_STATUS = [
2
+ { key: 0, value: "Pending Review", i18nKey: "jobApplication.status.0" },
3
+ { key: 1, value: "Shortlisted", i18nKey: "jobApplication.status.1" },
4
+ { key: 2, value: "Interview", i18nKey: "jobApplication.status.2" },
5
+ { key: 3, value: "Offered", i18nKey: "jobApplication.status.3" },
6
+ { key: 4, value: "Hired", i18nKey: "jobApplication.status.4" },
7
+ { key: 5, value: "Rejected", i18nKey: "jobApplication.status.5" },
8
+ { key: 6, value: "Withdrawn", i18nKey: "jobApplication.status.6" },
9
+ { key: 7, value: "Ghosted", i18nKey: "jobApplication.status.7" },
10
+ ];
@@ -0,0 +1,9 @@
1
+ export declare const LOCALE: readonly [{
2
+ readonly key: 1;
3
+ readonly value: "en";
4
+ readonly i18nKey: "locale.en";
5
+ }, {
6
+ readonly key: 2;
7
+ readonly value: "zh";
8
+ readonly i18nKey: "locale.zh";
9
+ }];
@@ -0,0 +1,4 @@
1
+ export const LOCALE = [
2
+ { key: 1, value: "en", i18nKey: "locale.en" },
3
+ { key: 2, value: "zh", i18nKey: "locale.zh" },
4
+ ];
@@ -0,0 +1,61 @@
1
+ export type CanonicalRole = "super-admin" | "admin" | "staff" | "hr" | "visitor" | "none";
2
+ export type RoleValue = CanonicalRole | number;
3
+ export type RoleInput = RoleValue | string;
4
+ export declare const ROLE_MAP: Record<number, CanonicalRole>;
5
+ export declare const ROLE: readonly [{
6
+ readonly key: 0;
7
+ readonly value: "super-admin";
8
+ readonly i18nKey: "users.roleSuperAdmin";
9
+ }, {
10
+ readonly key: 1;
11
+ readonly value: "admin";
12
+ readonly i18nKey: "users.roleAdmin";
13
+ }, {
14
+ readonly key: 2;
15
+ readonly value: "staff";
16
+ readonly i18nKey: "users.roleStaff";
17
+ }, {
18
+ readonly key: 3;
19
+ readonly value: "hr";
20
+ readonly i18nKey: "users.roleHr";
21
+ }, {
22
+ readonly key: 32766;
23
+ readonly value: "visitor";
24
+ readonly i18nKey: "users.roleVisitor";
25
+ }, {
26
+ readonly key: 32767;
27
+ readonly value: "none";
28
+ readonly i18nKey: "users.roleNone";
29
+ }];
30
+ export declare function normalizeRole(role: RoleInput | undefined): CanonicalRole | undefined;
31
+ export declare function roleLabelKey(role: RoleInput | undefined): string;
32
+ export declare function roleToId(role: RoleInput | undefined): number | undefined;
33
+ export declare const Permission: {
34
+ readonly ALLOWED_EMAILS_READ: "allowed-emails:read";
35
+ readonly ALLOWED_EMAILS_WRITE: "allowed-emails:write";
36
+ readonly USERS_READ: "users:read";
37
+ readonly USERS_WRITE: "users:write";
38
+ readonly USERS_DELETE: "users:delete";
39
+ readonly CAREERS_READ: "careers:read";
40
+ readonly CAREERS_WRITE: "careers:write";
41
+ readonly CAREERS_DELETE: "careers:delete";
42
+ readonly CONTACT_FORM_READ: "contact-form:read";
43
+ readonly CONTACT_FORM_DELETE: "contact-form:delete";
44
+ readonly JOB_APPLICATIONS_READ: "job-applications:read";
45
+ readonly OTP_ATTEMPTS_READ: "otp-attempts:read";
46
+ readonly OTP_ATTEMPTS_WRITE: "otp-attempts:write";
47
+ readonly TWO_FACTOR_AUTH_READ: "two-factor-auth:read";
48
+ readonly TWO_FACTOR_AUTH_WRITE: "two-factor-auth:write";
49
+ readonly VIEWS_READ: "views:read";
50
+ readonly LOGS_READ: "logs:read";
51
+ readonly UTM_RECORDS_READ: "utm-records:read";
52
+ readonly UTM_RECORDS_WRITE: "utm-records:write";
53
+ readonly ORIGIN_READ: "origin:read";
54
+ readonly ORIGIN_WRITE: "origin:write";
55
+ readonly ORIGIN_DELETE: "origin:delete";
56
+ };
57
+ export type Permission = (typeof Permission)[keyof typeof Permission];
58
+ export declare const PERMISSION_I18N_KEY: Record<Permission, string>;
59
+ export declare const ROLE_PERMISSIONS: Record<CanonicalRole, Permission[]>;
60
+ export declare function hasPermission(role: RoleInput | undefined, permission: Permission): boolean;
61
+ export declare function permissionLabelKey(permission: Permission): string;
@@ -0,0 +1,170 @@
1
+ export const ROLE_MAP = {
2
+ 0: "super-admin",
3
+ 1: "admin",
4
+ 2: "staff",
5
+ 3: "hr",
6
+ 32766: "visitor",
7
+ 32767: "none",
8
+ };
9
+ export const ROLE = [
10
+ { key: 0, value: "super-admin", i18nKey: "users.roleSuperAdmin" },
11
+ { key: 1, value: "admin", i18nKey: "users.roleAdmin" },
12
+ { key: 2, value: "staff", i18nKey: "users.roleStaff" },
13
+ { key: 3, value: "hr", i18nKey: "users.roleHr" },
14
+ { key: 32766, value: "visitor", i18nKey: "users.roleVisitor" },
15
+ { key: 32767, value: "none", i18nKey: "users.roleNone" },
16
+ ];
17
+ export function normalizeRole(role) {
18
+ if (typeof role === "number") {
19
+ return ROLE_MAP[role];
20
+ }
21
+ switch (role) {
22
+ case "super-admin":
23
+ return "super-admin";
24
+ case "admin":
25
+ return "admin";
26
+ case "staff":
27
+ return "staff";
28
+ case "hr":
29
+ return "hr";
30
+ case "visitor":
31
+ return "visitor";
32
+ case "none":
33
+ return "none";
34
+ default:
35
+ return undefined;
36
+ }
37
+ }
38
+ export function roleLabelKey(role) {
39
+ switch (normalizeRole(role)) {
40
+ case "super-admin":
41
+ return "users.roleSuperAdmin";
42
+ case "admin":
43
+ return "users.roleAdmin";
44
+ case "hr":
45
+ return "users.roleHr";
46
+ case "staff":
47
+ return "users.roleStaff";
48
+ case "visitor":
49
+ return "users.roleVisitor";
50
+ case "none":
51
+ return "users.roleNone";
52
+ default:
53
+ return "users.roleStaff";
54
+ }
55
+ }
56
+ export function roleToId(role) {
57
+ const normalizedRole = normalizeRole(role);
58
+ return ROLE.find((option) => option.value === normalizedRole)?.key;
59
+ }
60
+ export const Permission = {
61
+ ALLOWED_EMAILS_READ: "allowed-emails:read",
62
+ ALLOWED_EMAILS_WRITE: "allowed-emails:write",
63
+ USERS_READ: "users:read",
64
+ USERS_WRITE: "users:write",
65
+ USERS_DELETE: "users:delete",
66
+ CAREERS_READ: "careers:read",
67
+ CAREERS_WRITE: "careers:write",
68
+ CAREERS_DELETE: "careers:delete",
69
+ CONTACT_FORM_READ: "contact-form:read",
70
+ CONTACT_FORM_DELETE: "contact-form:delete",
71
+ JOB_APPLICATIONS_READ: "job-applications:read",
72
+ OTP_ATTEMPTS_READ: "otp-attempts:read",
73
+ OTP_ATTEMPTS_WRITE: "otp-attempts:write",
74
+ TWO_FACTOR_AUTH_READ: "two-factor-auth:read",
75
+ TWO_FACTOR_AUTH_WRITE: "two-factor-auth:write",
76
+ VIEWS_READ: "views:read",
77
+ LOGS_READ: "logs:read",
78
+ UTM_RECORDS_READ: "utm-records:read",
79
+ UTM_RECORDS_WRITE: "utm-records:write",
80
+ ORIGIN_READ: "origin:read",
81
+ ORIGIN_WRITE: "origin:write",
82
+ ORIGIN_DELETE: "origin:delete",
83
+ };
84
+ export const PERMISSION_I18N_KEY = {
85
+ [Permission.ALLOWED_EMAILS_READ]: "permissions.allowedEmailsRead",
86
+ [Permission.ALLOWED_EMAILS_WRITE]: "permissions.allowedEmailsWrite",
87
+ [Permission.USERS_READ]: "permissions.usersRead",
88
+ [Permission.USERS_WRITE]: "permissions.usersWrite",
89
+ [Permission.USERS_DELETE]: "permissions.usersDelete",
90
+ [Permission.CAREERS_READ]: "permissions.careersRead",
91
+ [Permission.CAREERS_WRITE]: "permissions.careersWrite",
92
+ [Permission.CAREERS_DELETE]: "permissions.careersDelete",
93
+ [Permission.CONTACT_FORM_READ]: "permissions.contactFormRead",
94
+ [Permission.CONTACT_FORM_DELETE]: "permissions.contactFormDelete",
95
+ [Permission.JOB_APPLICATIONS_READ]: "permissions.jobApplicationsRead",
96
+ [Permission.OTP_ATTEMPTS_READ]: "permissions.otpAttemptsRead",
97
+ [Permission.OTP_ATTEMPTS_WRITE]: "permissions.otpAttemptsWrite",
98
+ [Permission.TWO_FACTOR_AUTH_READ]: "permissions.twoFactorAuthRead",
99
+ [Permission.TWO_FACTOR_AUTH_WRITE]: "permissions.twoFactorAuthWrite",
100
+ [Permission.VIEWS_READ]: "permissions.viewsRead",
101
+ [Permission.LOGS_READ]: "permissions.logsRead",
102
+ [Permission.UTM_RECORDS_READ]: "permissions.utmRecordsRead",
103
+ [Permission.UTM_RECORDS_WRITE]: "permissions.utmRecordsWrite",
104
+ [Permission.ORIGIN_READ]: "permissions.originRead",
105
+ [Permission.ORIGIN_WRITE]: "permissions.originWrite",
106
+ [Permission.ORIGIN_DELETE]: "permissions.originDelete",
107
+ };
108
+ export const ROLE_PERMISSIONS = {
109
+ "super-admin": [
110
+ Permission.ALLOWED_EMAILS_READ,
111
+ Permission.ALLOWED_EMAILS_WRITE,
112
+ Permission.USERS_READ,
113
+ Permission.USERS_WRITE,
114
+ Permission.USERS_DELETE,
115
+ Permission.CAREERS_READ,
116
+ Permission.CAREERS_WRITE,
117
+ Permission.CAREERS_DELETE,
118
+ Permission.CONTACT_FORM_READ,
119
+ Permission.CONTACT_FORM_DELETE,
120
+ Permission.JOB_APPLICATIONS_READ,
121
+ Permission.OTP_ATTEMPTS_READ,
122
+ Permission.OTP_ATTEMPTS_WRITE,
123
+ Permission.TWO_FACTOR_AUTH_READ,
124
+ Permission.TWO_FACTOR_AUTH_WRITE,
125
+ Permission.VIEWS_READ,
126
+ Permission.LOGS_READ,
127
+ Permission.UTM_RECORDS_READ,
128
+ Permission.UTM_RECORDS_WRITE,
129
+ Permission.ORIGIN_READ,
130
+ Permission.ORIGIN_WRITE,
131
+ Permission.ORIGIN_DELETE,
132
+ ],
133
+ admin: [
134
+ Permission.ALLOWED_EMAILS_READ,
135
+ Permission.ALLOWED_EMAILS_WRITE,
136
+ Permission.USERS_READ,
137
+ Permission.CAREERS_READ,
138
+ Permission.CAREERS_WRITE,
139
+ Permission.CAREERS_DELETE,
140
+ Permission.CONTACT_FORM_READ,
141
+ Permission.CONTACT_FORM_DELETE,
142
+ Permission.JOB_APPLICATIONS_READ,
143
+ Permission.VIEWS_READ,
144
+ Permission.LOGS_READ,
145
+ Permission.UTM_RECORDS_READ,
146
+ Permission.UTM_RECORDS_WRITE,
147
+ Permission.ORIGIN_READ,
148
+ Permission.ORIGIN_WRITE,
149
+ Permission.ORIGIN_DELETE,
150
+ ],
151
+ hr: [
152
+ Permission.CAREERS_READ,
153
+ Permission.CAREERS_WRITE,
154
+ Permission.CAREERS_DELETE,
155
+ Permission.JOB_APPLICATIONS_READ,
156
+ ],
157
+ staff: [Permission.CONTACT_FORM_READ],
158
+ visitor: [],
159
+ none: [],
160
+ };
161
+ export function hasPermission(role, permission) {
162
+ const normalizedRole = normalizeRole(role);
163
+ if (!normalizedRole) {
164
+ return false;
165
+ }
166
+ return ROLE_PERMISSIONS[normalizedRole].includes(permission);
167
+ }
168
+ export function permissionLabelKey(permission) {
169
+ return PERMISSION_I18N_KEY[permission];
170
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,80 @@
1
+ import assert from "node:assert/strict";
2
+ import { PERMISSION_I18N_KEY, Permission, ROLE, ROLE_PERMISSIONS, hasPermission, normalizeRole, permissionLabelKey, roleLabelKey, roleToId, } from "./index.js";
3
+ assert.equal(normalizeRole(0), "super-admin");
4
+ assert.equal(normalizeRole("admin"), "admin");
5
+ assert.equal(normalizeRole(2), "staff");
6
+ assert.equal(normalizeRole("hr"), "hr");
7
+ assert.equal(normalizeRole(32766), "visitor");
8
+ assert.equal(normalizeRole("none"), "none");
9
+ assert.equal(normalizeRole("unknown"), undefined);
10
+ assert.equal(normalizeRole(undefined), undefined);
11
+ assert.equal(roleToId("super-admin"), 0);
12
+ assert.equal(roleToId("admin"), 1);
13
+ assert.equal(roleToId("staff"), 2);
14
+ assert.equal(roleToId("hr"), 3);
15
+ assert.equal(roleToId("visitor"), 32766);
16
+ assert.equal(roleToId("none"), 32767);
17
+ assert.equal(roleToId("unknown"), undefined);
18
+ assert.equal(roleLabelKey(0), "users.roleSuperAdmin");
19
+ assert.equal(roleLabelKey("admin"), "users.roleAdmin");
20
+ assert.equal(roleLabelKey(2), "users.roleStaff");
21
+ assert.equal(roleLabelKey("hr"), "users.roleHr");
22
+ assert.equal(roleLabelKey("visitor"), "users.roleVisitor");
23
+ assert.equal(roleLabelKey("none"), "users.roleNone");
24
+ assert.equal(roleLabelKey(undefined), "users.roleStaff");
25
+ assert.deepEqual(ROLE[0], {
26
+ key: 0,
27
+ value: "super-admin",
28
+ i18nKey: "users.roleSuperAdmin",
29
+ });
30
+ assert.equal(ROLE[3]?.i18nKey, "users.roleHr");
31
+ assert.deepEqual(ROLE[4], {
32
+ key: 32766,
33
+ value: "visitor",
34
+ i18nKey: "users.roleVisitor",
35
+ });
36
+ assert.deepEqual(ROLE[5], {
37
+ key: 32767,
38
+ value: "none",
39
+ i18nKey: "users.roleNone",
40
+ });
41
+ assert.equal(PERMISSION_I18N_KEY[Permission.ALLOWED_EMAILS_READ], "permissions.allowedEmailsRead");
42
+ assert.equal(permissionLabelKey(Permission.CONTACT_FORM_DELETE), "permissions.contactFormDelete");
43
+ assert.equal(permissionLabelKey(Permission.OTP_ATTEMPTS_READ), "permissions.otpAttemptsRead");
44
+ assert.equal(permissionLabelKey(Permission.TWO_FACTOR_AUTH_WRITE), "permissions.twoFactorAuthWrite");
45
+ assert.equal(permissionLabelKey(Permission.VIEWS_READ), "permissions.viewsRead");
46
+ assert.equal(permissionLabelKey(Permission.LOGS_READ), "permissions.logsRead");
47
+ assert.equal(permissionLabelKey(Permission.UTM_RECORDS_READ), "permissions.utmRecordsRead");
48
+ assert.equal(permissionLabelKey(Permission.UTM_RECORDS_WRITE), "permissions.utmRecordsWrite");
49
+ assert.equal(permissionLabelKey(Permission.ORIGIN_READ), "permissions.originRead");
50
+ assert.equal(permissionLabelKey(Permission.ORIGIN_WRITE), "permissions.originWrite");
51
+ assert.equal(permissionLabelKey(Permission.ORIGIN_DELETE), "permissions.originDelete");
52
+ assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.USERS_DELETE));
53
+ assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.OTP_ATTEMPTS_READ));
54
+ assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.TWO_FACTOR_AUTH_WRITE));
55
+ assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.VIEWS_READ));
56
+ assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.LOGS_READ));
57
+ assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.UTM_RECORDS_WRITE));
58
+ assert.ok(ROLE_PERMISSIONS["super-admin"].includes(Permission.ORIGIN_DELETE));
59
+ assert.ok(ROLE_PERMISSIONS.admin.includes(Permission.CONTACT_FORM_DELETE));
60
+ assert.ok(ROLE_PERMISSIONS.admin.includes(Permission.VIEWS_READ));
61
+ assert.ok(ROLE_PERMISSIONS.admin.includes(Permission.LOGS_READ));
62
+ assert.ok(ROLE_PERMISSIONS.admin.includes(Permission.UTM_RECORDS_WRITE));
63
+ assert.ok(ROLE_PERMISSIONS.admin.includes(Permission.ORIGIN_DELETE));
64
+ assert.equal(ROLE_PERMISSIONS.admin.includes(Permission.USERS_WRITE), false);
65
+ assert.ok(ROLE_PERMISSIONS.hr.includes(Permission.JOB_APPLICATIONS_READ));
66
+ assert.deepEqual(ROLE_PERMISSIONS.staff, [Permission.CONTACT_FORM_READ]);
67
+ assert.deepEqual(ROLE_PERMISSIONS.visitor, []);
68
+ assert.deepEqual(ROLE_PERMISSIONS.none, []);
69
+ assert.equal(hasPermission("super-admin", Permission.USERS_WRITE), true);
70
+ assert.equal(hasPermission("super-admin", Permission.OTP_ATTEMPTS_WRITE), true);
71
+ assert.equal(hasPermission(1, Permission.USERS_WRITE), false);
72
+ assert.equal(hasPermission("hr", Permission.CAREERS_WRITE), true);
73
+ assert.equal(hasPermission("staff", Permission.CAREERS_WRITE), false);
74
+ assert.equal(hasPermission("staff", Permission.CONTACT_FORM_READ), true);
75
+ assert.equal(hasPermission("admin", Permission.VIEWS_READ), true);
76
+ assert.equal(hasPermission("admin", Permission.UTM_RECORDS_WRITE), true);
77
+ assert.equal(hasPermission("admin", Permission.ORIGIN_DELETE), true);
78
+ assert.equal(hasPermission("visitor", Permission.VIEWS_READ), false);
79
+ assert.equal(hasPermission(32767, Permission.LOGS_READ), false);
80
+ assert.equal(hasPermission(undefined, Permission.CAREERS_READ), false);
@@ -0,0 +1,80 @@
1
+ export type RouteKey = "home" | "about" | "career" | "careerDetail" | "careerApply" | "careerAssessment" | "contact" | "services" | "servicesAdvertisingPlatform" | "servicesMcnBusiness" | "servicesSoftwareDevelopment";
2
+ export type RouteMapping = {
3
+ key: RouteKey;
4
+ path: string;
5
+ path_name: string;
6
+ path_key: string;
7
+ i18nKey: string;
8
+ };
9
+ export declare const ROUTES: readonly [{
10
+ readonly key: "home";
11
+ readonly path: "/[locale]";
12
+ readonly path_name: "/";
13
+ readonly path_key: "/";
14
+ readonly i18nKey: "routes.home";
15
+ }, {
16
+ readonly key: "about";
17
+ readonly path: "/[locale]/about";
18
+ readonly path_name: "/about";
19
+ readonly path_key: "/about";
20
+ readonly i18nKey: "routes.about";
21
+ }, {
22
+ readonly key: "career";
23
+ readonly path: "/[locale]/career";
24
+ readonly path_name: "/career";
25
+ readonly path_key: "/career";
26
+ readonly i18nKey: "routes.career";
27
+ }, {
28
+ readonly key: "careerDetail";
29
+ readonly path: "/[locale]/career/[id]";
30
+ readonly path_name: "/career/[id]";
31
+ readonly path_key: "/career/[id]";
32
+ readonly i18nKey: "routes.careerDetail";
33
+ }, {
34
+ readonly key: "careerApply";
35
+ readonly path: "/[locale]/career/[id]/apply";
36
+ readonly path_name: "/career/[id]/apply";
37
+ readonly path_key: "/career/[id]/apply";
38
+ readonly i18nKey: "routes.careerApply";
39
+ }, {
40
+ readonly key: "careerAssessment";
41
+ readonly path: "/[locale]/career/[id]/apply/assessment";
42
+ readonly path_name: "/career/[id]/apply/assessment";
43
+ readonly path_key: "/career/[id]/apply/assessment";
44
+ readonly i18nKey: "routes.careerAssessment";
45
+ }, {
46
+ readonly key: "contact";
47
+ readonly path: "/[locale]/contact";
48
+ readonly path_name: "/contact";
49
+ readonly path_key: "/contact";
50
+ readonly i18nKey: "routes.contact";
51
+ }, {
52
+ readonly key: "services";
53
+ readonly path: "/[locale]/services";
54
+ readonly path_name: "/services";
55
+ readonly path_key: "/services";
56
+ readonly i18nKey: "routes.services";
57
+ }, {
58
+ readonly key: "servicesAdvertisingPlatform";
59
+ readonly path: "/[locale]/services/advertising-platform";
60
+ readonly path_name: "/services/advertising-platform";
61
+ readonly path_key: "/services/advertising-platform";
62
+ readonly i18nKey: "routes.servicesAdvertisingPlatform";
63
+ }, {
64
+ readonly key: "servicesMcnBusiness";
65
+ readonly path: "/[locale]/services/mcn-business";
66
+ readonly path_name: "/services/mcn-business";
67
+ readonly path_key: "/services/mcn-business";
68
+ readonly i18nKey: "routes.servicesMcnBusiness";
69
+ }, {
70
+ readonly key: "servicesSoftwareDevelopment";
71
+ readonly path: "/[locale]/services/software-development";
72
+ readonly path_name: "/services/software-development";
73
+ readonly path_key: "/services/software-development";
74
+ readonly i18nKey: "routes.servicesSoftwareDevelopment";
75
+ }];
76
+ export declare const ROUTE: Record<RouteKey, string>;
77
+ export declare function routeLabelKey(route: RouteKey): string;
78
+ export declare function routePathKey(route: RouteKey): string;
79
+ export declare function buildRoutePathName(route: RouteKey, params?: Partial<Record<"id", string | number>>): string;
80
+ export declare function buildLocalizedRoute(route: RouteKey, locale: string, params?: Partial<Record<"id", string | number>>): string;
@@ -0,0 +1,106 @@
1
+ export const ROUTES = [
2
+ {
3
+ key: "home",
4
+ path: "/[locale]",
5
+ path_name: "/",
6
+ path_key: "/",
7
+ i18nKey: "routes.home",
8
+ },
9
+ {
10
+ key: "about",
11
+ path: "/[locale]/about",
12
+ path_name: "/about",
13
+ path_key: "/about",
14
+ i18nKey: "routes.about",
15
+ },
16
+ {
17
+ key: "career",
18
+ path: "/[locale]/career",
19
+ path_name: "/career",
20
+ path_key: "/career",
21
+ i18nKey: "routes.career",
22
+ },
23
+ {
24
+ key: "careerDetail",
25
+ path: "/[locale]/career/[id]",
26
+ path_name: "/career/[id]",
27
+ path_key: "/career/[id]",
28
+ i18nKey: "routes.careerDetail",
29
+ },
30
+ {
31
+ key: "careerApply",
32
+ path: "/[locale]/career/[id]/apply",
33
+ path_name: "/career/[id]/apply",
34
+ path_key: "/career/[id]/apply",
35
+ i18nKey: "routes.careerApply",
36
+ },
37
+ {
38
+ key: "careerAssessment",
39
+ path: "/[locale]/career/[id]/apply/assessment",
40
+ path_name: "/career/[id]/apply/assessment",
41
+ path_key: "/career/[id]/apply/assessment",
42
+ i18nKey: "routes.careerAssessment",
43
+ },
44
+ {
45
+ key: "contact",
46
+ path: "/[locale]/contact",
47
+ path_name: "/contact",
48
+ path_key: "/contact",
49
+ i18nKey: "routes.contact",
50
+ },
51
+ {
52
+ key: "services",
53
+ path: "/[locale]/services",
54
+ path_name: "/services",
55
+ path_key: "/services",
56
+ i18nKey: "routes.services",
57
+ },
58
+ {
59
+ key: "servicesAdvertisingPlatform",
60
+ path: "/[locale]/services/advertising-platform",
61
+ path_name: "/services/advertising-platform",
62
+ path_key: "/services/advertising-platform",
63
+ i18nKey: "routes.servicesAdvertisingPlatform",
64
+ },
65
+ {
66
+ key: "servicesMcnBusiness",
67
+ path: "/[locale]/services/mcn-business",
68
+ path_name: "/services/mcn-business",
69
+ path_key: "/services/mcn-business",
70
+ i18nKey: "routes.servicesMcnBusiness",
71
+ },
72
+ {
73
+ key: "servicesSoftwareDevelopment",
74
+ path: "/[locale]/services/software-development",
75
+ path_name: "/services/software-development",
76
+ path_key: "/services/software-development",
77
+ i18nKey: "routes.servicesSoftwareDevelopment",
78
+ },
79
+ ];
80
+ export const ROUTE = Object.fromEntries(ROUTES.map((route) => [route.key, route.path]));
81
+ export function routeLabelKey(route) {
82
+ return ROUTES.find((item) => item.key === route)?.i18nKey ?? "routes.home";
83
+ }
84
+ export function routePathKey(route) {
85
+ return ROUTES.find((item) => item.key === route)?.path_key ?? "/";
86
+ }
87
+ export function buildRoutePathName(route, params = {}) {
88
+ let pathName = ROUTES.find((item) => item.key === route)?.path_name ?? "/";
89
+ if (pathName.includes("[id]")) {
90
+ if (params.id === undefined || params.id === null) {
91
+ throw new Error(`Route "${route}" requires an id parameter.`);
92
+ }
93
+ pathName = pathName.replace("[id]", encodeURIComponent(String(params.id)));
94
+ }
95
+ return pathName;
96
+ }
97
+ export function buildLocalizedRoute(route, locale, params = {}) {
98
+ let path = ROUTE[route].replace("[locale]", encodeURIComponent(locale));
99
+ if (path.includes("[id]")) {
100
+ if (params.id === undefined || params.id === null) {
101
+ throw new Error(`Route "${route}" requires an id parameter.`);
102
+ }
103
+ path = path.replace("[id]", encodeURIComponent(String(params.id)));
104
+ }
105
+ return path;
106
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,92 @@
1
+ import assert from "node:assert/strict";
2
+ import { ROUTE, ROUTES, buildRoutePathName, buildLocalizedRoute, routeLabelKey, routePathKey, } from "./index.js";
3
+ assert.deepEqual(ROUTES, [
4
+ {
5
+ key: "home",
6
+ path: "/[locale]",
7
+ path_name: "/",
8
+ path_key: "/",
9
+ i18nKey: "routes.home",
10
+ },
11
+ {
12
+ key: "about",
13
+ path: "/[locale]/about",
14
+ path_name: "/about",
15
+ path_key: "/about",
16
+ i18nKey: "routes.about",
17
+ },
18
+ {
19
+ key: "career",
20
+ path: "/[locale]/career",
21
+ path_name: "/career",
22
+ path_key: "/career",
23
+ i18nKey: "routes.career",
24
+ },
25
+ {
26
+ key: "careerDetail",
27
+ path: "/[locale]/career/[id]",
28
+ path_name: "/career/[id]",
29
+ path_key: "/career/[id]",
30
+ i18nKey: "routes.careerDetail",
31
+ },
32
+ {
33
+ key: "careerApply",
34
+ path: "/[locale]/career/[id]/apply",
35
+ path_name: "/career/[id]/apply",
36
+ path_key: "/career/[id]/apply",
37
+ i18nKey: "routes.careerApply",
38
+ },
39
+ {
40
+ key: "careerAssessment",
41
+ path: "/[locale]/career/[id]/apply/assessment",
42
+ path_name: "/career/[id]/apply/assessment",
43
+ path_key: "/career/[id]/apply/assessment",
44
+ i18nKey: "routes.careerAssessment",
45
+ },
46
+ {
47
+ key: "contact",
48
+ path: "/[locale]/contact",
49
+ path_name: "/contact",
50
+ path_key: "/contact",
51
+ i18nKey: "routes.contact",
52
+ },
53
+ {
54
+ key: "services",
55
+ path: "/[locale]/services",
56
+ path_name: "/services",
57
+ path_key: "/services",
58
+ i18nKey: "routes.services",
59
+ },
60
+ {
61
+ key: "servicesAdvertisingPlatform",
62
+ path: "/[locale]/services/advertising-platform",
63
+ path_name: "/services/advertising-platform",
64
+ path_key: "/services/advertising-platform",
65
+ i18nKey: "routes.servicesAdvertisingPlatform",
66
+ },
67
+ {
68
+ key: "servicesMcnBusiness",
69
+ path: "/[locale]/services/mcn-business",
70
+ path_name: "/services/mcn-business",
71
+ path_key: "/services/mcn-business",
72
+ i18nKey: "routes.servicesMcnBusiness",
73
+ },
74
+ {
75
+ key: "servicesSoftwareDevelopment",
76
+ path: "/[locale]/services/software-development",
77
+ path_name: "/services/software-development",
78
+ path_key: "/services/software-development",
79
+ i18nKey: "routes.servicesSoftwareDevelopment",
80
+ },
81
+ ]);
82
+ assert.equal(ROUTE.home, "/[locale]");
83
+ assert.equal(ROUTE.careerAssessment, "/[locale]/career/[id]/apply/assessment");
84
+ assert.equal(buildLocalizedRoute("careerApply", "en", { id: "frontend-engineer" }), "/en/career/frontend-engineer/apply");
85
+ assert.equal(buildLocalizedRoute("servicesMcnBusiness", "zh"), "/zh/services/mcn-business");
86
+ assert.equal(buildRoutePathName("careerApply", { id: "frontend-engineer" }), "/career/frontend-engineer/apply");
87
+ assert.equal(routePathKey("home"), "/");
88
+ assert.equal(routePathKey("careerApply"), "/career/[id]/apply");
89
+ assert.throws(() => buildLocalizedRoute("careerDetail", "en"), {
90
+ message: 'Route "careerDetail" requires an id parameter.',
91
+ });
92
+ assert.equal(routeLabelKey("servicesSoftwareDevelopment"), "routes.servicesSoftwareDevelopment");
@@ -0,0 +1,5 @@
1
+ import type { MappingOption } from "./types.js";
2
+ export declare function getOptionByKey<T extends MappingOption>(options: readonly T[], key?: number | null): T | undefined;
3
+ export declare function getLabelByKey<T extends MappingOption>(options: readonly T[], key?: number | null, fallback?: string): string;
4
+ export declare function getI18nKeyByKey<T extends MappingOption>(options: readonly T[], key?: number | null, fallback?: string): string;
5
+ export declare function toRecord<T extends MappingOption>(options: readonly T[]): Record<number, string>;