@jitsu/functions-lib 1.10.4 → 2.14.0-beta.101

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.
@@ -1,168 +0,0 @@
1
- export const classicEvents = [
2
- {
3
- _timestamp: "2024-12-25T14:23:48.606561Z",
4
- api_key: "js.123.123",
5
- click_id: {},
6
- doc_encoding: "UTF-8",
7
- doc_host: "events.example.com",
8
- doc_path: "/a-v/123",
9
- doc_search: "",
10
- event_type: "user_identify",
11
- eventn_ctx_event_id: "1d199165-fdf3-4051-82fc-08a8c5502f33",
12
- ids: {
13
- ga: "GA1.1.123.123",
14
- },
15
- local_tz_offset: 420,
16
- page_title: "aa.aa.24",
17
- referer: "",
18
- screen_resolution: "1680x1050",
19
- source_ip: "127.0.13.36",
20
- src: "jitsu",
21
- url: "https://events.example.com/a-v/123",
22
- user: {
23
- anonymous_id: "5adv25gea6",
24
- email: "user@example.com",
25
- hashed_anonymous_id: "41217f4f06dba2b145dbd7d0879a871e",
26
- name: "John Doe",
27
- uid: "123",
28
- },
29
- user_agent:
30
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36",
31
- user_language: "en-US",
32
- utc_time: "2024-12-25T14:23:46.483000Z",
33
- utm: {},
34
- vp_size: "1384x775",
35
- },
36
- {
37
- _timestamp: "2024-12-25T14:31:48.875505Z",
38
- api_key: "s2s.123.123",
39
- common_properties: {
40
- c_version: "1.1.11",
41
- client: {
42
- creation_timestamp: "2024-12-25T14:31:48.794613+00:00",
43
- id: "123",
44
- },
45
- in_v: false,
46
- a_version: null,
47
- },
48
- event_type: "serve_init",
49
- eventn_ctx_event_id: "99406a96-3bc3-4939-a3cc-6f5eeb458078",
50
- session_id: "abc",
51
- source_ip: "127.0.41.132",
52
- src: "api",
53
- },
54
- {
55
- _timestamp: "2024-12-25T14:26:22.484904Z",
56
- api_key: "js.123.123",
57
- chromeVersion: "131",
58
- click_id: {},
59
- companyId: 123,
60
- email: "john.doe@example.com",
61
- event_type: "workflow-complete",
62
- eventn_ctx_event_id: "62615da7-a605-420f-9b73-d88ca488fa6d",
63
- ids: {},
64
- info: {
65
- billing: {
66
- nodeTypeCounts: {
67
- "click-element": 13,
68
- },
69
- ticketDurationsMs: [],
70
- },
71
- callCount: 1,
72
- metrics: {
73
- actual: {},
74
- },
75
- results: [
76
- {
77
- callCount: 1,
78
- },
79
- ],
80
- status: "complete",
81
- },
82
- jobId: "f3b97b73-15e5-4d5b-af73-43bbbf237b24",
83
- local_tz_offset: 0,
84
- manifestVersion: "1.0.0",
85
- runtimeEnvironment: "production",
86
- source_ip: "127.0.32.11",
87
- src: "jitsu",
88
- teamId: 1,
89
- timestamp: 1735136772062,
90
- type: "workflow-complete",
91
- user: {
92
- anonymous_id: "",
93
- hashed_anonymous_id: "bef91c4d78dbf5b10b791d1f483faa9a",
94
- },
95
- user_agent:
96
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
97
- utc_time: "2024-12-25T14:26:12.097000Z",
98
- utm: {},
99
- },
100
- {
101
- _timestamp: "2024-12-25T00:26:56.305721Z",
102
- api_key: "js.123.123",
103
- click_id: {
104
- gclid: "123",
105
- dclid: "1233",
106
- },
107
- doc_encoding: "UTF-8",
108
- doc_host: "app.example.com",
109
- doc_path: "/login",
110
- doc_search: "?next=%2F",
111
- event_type: "pageview",
112
- eventn_ctx_event_id: "15fea8d7-14af-4488-92a9-0ae52eba5499",
113
- ids: {},
114
- local_tz_offset: 300,
115
- page_title: "Login - Litnerd",
116
- referer: "",
117
- screen_resolution: "1920x1080",
118
- source_ip: "127.0.56.1",
119
- src: "jitsu",
120
- url: "https://app.example.com/login?next=%2F",
121
- user: {
122
- anonymous_id: "123",
123
- hashed_anonymous_id: "49a8381a0fe28827b68a48416dd69a23",
124
- id: "student:123",
125
- name: "JOHN DOE",
126
- role: "student",
127
- school_id: 123,
128
- },
129
- user_agent:
130
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
131
- user_language: "en-US",
132
- utc_time: "2024-12-25T00:26:56.481000Z",
133
- utm: {},
134
- vp_size: "1920x911",
135
- },
136
- {
137
- _timestamp: "2024-12-25T15:33:08.369746Z",
138
- api_key: "s2s.123.123",
139
- click_id: {
140
- gclid: "123",
141
- dclid: "1233",
142
- },
143
- doc_host: "localhost:3000",
144
- doc_path: "/auth/login",
145
- doc_search: "",
146
- event_type: "page_view",
147
- eventn_ctx_event_id: "98373e80-6228-4163-957e-90703182e9de",
148
- ids: {
149
- ga: "GA1.1.123.123",
150
- },
151
- isAuthorized: false,
152
- nextPrefetch: false,
153
- onVercel: false,
154
- page_title: "",
155
- page_url: "http://localhost:3000/auth/login",
156
- referer: "",
157
- source_ip: "",
158
- src: "api",
159
- url: "http://localhost:3000/auth/login",
160
- user: {
161
- anonymous_id: "123",
162
- hashed_anonymous_id: "ee3cd46ca7a46adb9fa1c9599e64249f",
163
- },
164
- user_agent: "Wget/1.21.3",
165
- utc_time: "2024-12-25T15:33:07.992Z",
166
- utm: {},
167
- },
168
- ];
package/jest.config.js DELETED
@@ -1,8 +0,0 @@
1
- /** @type {import("ts-jest").JestConfigWithTsJest} */
2
- module.exports = {
3
- preset: "ts-jest",
4
- testMatch: ["**/__tests__/**/*.test.ts"],
5
- testEnvironment: "node",
6
- runner: "jest-runner",
7
- "setupFiles": ["./jest.setup.js"]
8
- };
package/jest.setup.js DELETED
@@ -1,8 +0,0 @@
1
-
2
- global.console = {
3
- log: message => process.stdout.write(message + '\n'),
4
- error: console.error,
5
- warn: console.warn,
6
- info: console.info,
7
- debug: console.debug,
8
- };
package/rollup.config.js DELETED
@@ -1,14 +0,0 @@
1
- const typescript = require("@rollup/plugin-typescript");
2
- const resolve = require("@rollup/plugin-node-resolve");
3
- const commonjs = require("@rollup/plugin-commonjs");
4
-
5
- module.exports = [
6
- {
7
- plugins: [typescript(), resolve({ preferBuiltins: false }), commonjs()],
8
- input: ["./src/index.ts"],
9
- output: [
10
- { file: "dist/index.es.js", format: "es" },
11
- { file: "dist/index.cjs.js", format: "cjs" },
12
- ],
13
- },
14
- ];
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./lib/functions";
2
- export * from "./lib/objects";
3
- export * from "./lib/strings";
@@ -1,341 +0,0 @@
1
- import { AnyEvent, FullContext, UserAgent } from "@jitsu/protocols/functions";
2
- import { AnalyticsServerEvent } from "@jitsu/protocols/analytics";
3
- import { removeUndefined, transferAsSnakeCase, transfer, transferAsClassic } from "./objects";
4
-
5
- export const TableNameParameter = "JITSU_TABLE_NAME";
6
-
7
- export const DropRetryErrorName = "Drop & RetryError";
8
- export const RetryErrorName = "RetryError";
9
-
10
- export class RetryError extends Error {
11
- status: number;
12
- response: string;
13
- message: string;
14
- constructor(message?: any, options?: { drop: boolean }) {
15
- if (typeof message === "object") {
16
- super(message.message);
17
- this.message = message.message;
18
- this.status = message.status;
19
- this.response = message.response;
20
- } else {
21
- super(message);
22
- this.message = message;
23
- }
24
- this.name = options?.drop ? `${DropRetryErrorName}` : `${RetryErrorName}`;
25
- }
26
- toJSON() {
27
- return {
28
- name: this.name,
29
- message: this.message,
30
- status: this.status,
31
- response: this.response,
32
- };
33
- }
34
- }
35
-
36
- export class HTTPError extends Error {
37
- status: number;
38
- response: string;
39
- message: string;
40
- constructor(message: string, status: number, response: string) {
41
- super(message);
42
- this.message = message;
43
- this.name = "HTTPError";
44
- this.status = status;
45
- this.response = response.length > 1000 ? response.slice(0, 1000) + "..." : response;
46
- }
47
-
48
- toJSON() {
49
- return {
50
- name: this.name,
51
- message: this.message,
52
- status: this.status,
53
- response: this.response,
54
- };
55
- }
56
- }
57
-
58
- function anonymizeIp(ip: string | undefined) {
59
- if (!ip) {
60
- return;
61
- }
62
- const parts = ip.split(".");
63
- if (parts.length === 4) {
64
- return `${parts[0]}.${parts[1]}.${parts[2]}.0`;
65
- }
66
- }
67
-
68
- export function toJitsuClassic(event: AnalyticsServerEvent, ctx: FullContext): AnyEvent {
69
- const keepOriginalNames = !!ctx.props.keepOriginalNames;
70
- const fileStorage = ctx.destination.type === "s3" || ctx.destination.type === "gcs";
71
- let transferFunc = transferAsSnakeCase;
72
- if (keepOriginalNames) {
73
- if (fileStorage) {
74
- transferFunc = transfer;
75
- } else {
76
- transferFunc = transferAsClassic;
77
- }
78
- }
79
- let url: URL | undefined = undefined;
80
- const analyticsContext = event.context || {};
81
- const urlStr = analyticsContext.page?.url || event.properties?.url;
82
- try {
83
- if (urlStr) {
84
- url = new URL(urlStr as string);
85
- }
86
- } catch (e) {}
87
- const click_id = {};
88
- transferFunc(click_id, analyticsContext.clientIds, ["ga4", "fbp", "fbc"]);
89
- let ids: any = {};
90
- if (Object.keys(analyticsContext.clientIds || {}).length > 0) {
91
- ids = removeUndefined({
92
- ga: analyticsContext.clientIds.ga4?.clientId,
93
- fbp: analyticsContext.clientIds.fbp,
94
- fbc: analyticsContext.clientIds.fbc,
95
- });
96
- }
97
- const geo = analyticsContext.geo || {};
98
- const ua: UserAgent = ctx?.ua || ({} as UserAgent);
99
- const user = removeUndefined({
100
- id: event.userId,
101
- anonymous_id: event.anonymousId,
102
- email: (analyticsContext.traits?.email || event.traits?.email || undefined) as string | undefined,
103
- name: (analyticsContext.traits?.name || event.traits?.name || undefined) as string | undefined,
104
- });
105
- transferFunc(user, analyticsContext.traits, ["email", "name"]);
106
- transferFunc(user, event.traits, ["email", "name"]);
107
- const classic = {
108
- [TableNameParameter]: event[TableNameParameter],
109
- anon_ip: analyticsContext.ip ? anonymizeIp(analyticsContext.ip) : undefined,
110
- api_key: event.writeKey || "",
111
- click_id: Object.keys(click_id).length > 0 ? click_id : undefined,
112
- doc_encoding: analyticsContext.page?.encoding ?? event.properties?.encoding,
113
- doc_host: (analyticsContext.page?.host ?? event.properties?.host) || url?.host,
114
- doc_path: (analyticsContext.page?.path ?? event.properties?.path) || url?.pathname,
115
- doc_search: (analyticsContext.page?.search ?? event.properties?.search) || url?.search,
116
- eventn_ctx_event_id: event.messageId,
117
- event_type: event.event || event.type,
118
- local_tz_offset: analyticsContext.page?.timezoneOffset ?? event.properties?.timezoneOffset,
119
- page_title: analyticsContext.page?.title,
120
- referer: analyticsContext.page?.referrer,
121
- screen_resolution:
122
- Object.keys(analyticsContext.screen || {}).length > 0
123
- ? Math.max(analyticsContext.screen.width || 0) + "x" + Math.max(analyticsContext.screen.height || 0)
124
- : undefined,
125
- source_ip: analyticsContext.ip,
126
- src: event.properties?.src || "jitsu",
127
- url: urlStr as string,
128
- user: Object.keys(user).length > 0 ? user : undefined,
129
- location:
130
- Object.keys(geo).length > 0
131
- ? {
132
- city: geo.city?.name,
133
- continent: geo.continent?.name,
134
- country: geo.country?.code,
135
- country_name: geo.country?.name,
136
- latitude: geo.location?.latitude,
137
- longitude: geo.location?.longitude,
138
- region: geo.region?.code,
139
- zip: geo.postalCode?.code,
140
- timezone: geo.location?.timezone,
141
- autonomous_system_number: geo.provider?.as?.num,
142
- autonomous_system_organization: geo.provider?.as?.name,
143
- isp: geo.provider?.isp,
144
- domain: geo.provider?.domain,
145
- }
146
- : undefined,
147
- ids: Object.keys(ids).length > 0 ? ids : undefined,
148
- parsed_ua:
149
- event.parsed_ua ||
150
- (Object.keys(ua).length > 0
151
- ? {
152
- os_family: ua.os?.name,
153
- os_version: ua.os?.version,
154
- ua_family: ua.browser?.name,
155
- ua_version: ua.browser?.version,
156
- device_brand: ua.device?.vendor,
157
- device_type: ua.device?.type,
158
- device_model: ua.device?.model,
159
- bot: ua.bot,
160
- }
161
- : undefined),
162
- user_agent: analyticsContext.userAgent,
163
- user_language: analyticsContext.locale,
164
- utc_time: event.timestamp,
165
- _timestamp: event.receivedAt,
166
- utm: analyticsContext.campaign,
167
- vp_size:
168
- Object.keys(analyticsContext.screen || {}).length > 0
169
- ? Math.max(analyticsContext.screen.innerWidth || 0) + "x" + Math.max(analyticsContext.screen.innerHeight || 0)
170
- : undefined,
171
- };
172
- if (event.type === "track") {
173
- transferFunc(classic, event.properties);
174
- } else {
175
- transferFunc(classic, event.properties, ["url", "title", "referrer", "search", "host", "path", "width", "height"]);
176
- }
177
-
178
- return removeUndefined(classic);
179
- }
180
-
181
- export function fromJitsuClassic(event: AnyEvent): AnyEvent {
182
- let type = "track";
183
- let eventName: string | undefined = undefined;
184
- switch ((event.event_type ?? "").toLowerCase()) {
185
- case "pageview":
186
- case "page_view":
187
- case "page":
188
- type = "page";
189
- eventName = event.event_type;
190
- break;
191
- case "identify":
192
- type = "identify";
193
- break;
194
- case "screen":
195
- type = "screen";
196
- break;
197
- case "group":
198
- type = "group";
199
- break;
200
- case "alias":
201
- type = "alias";
202
- break;
203
- default:
204
- type = "track";
205
- eventName = event.event_type;
206
- break;
207
- }
208
- const clientIds =
209
- Object.keys(event.ids || event.click_id || {}).length > 0
210
- ? {
211
- ga4: event.ids?.ga
212
- ? {
213
- clientId: event.ids.ga,
214
- }
215
- : undefined,
216
- fbp: event.ids?.fbp,
217
- fbc: event.ids?.fbc,
218
- ...event.click_id,
219
- }
220
- : undefined;
221
- const loc = event.location || {};
222
- const geo =
223
- Object.keys(loc).length > 0
224
- ? {
225
- city: {
226
- name: loc.city,
227
- },
228
- continent: {
229
- code: loc.continent,
230
- },
231
- country: {
232
- code: loc.country,
233
- name: loc.country_name,
234
- },
235
- location: {
236
- latitude: loc.latitude,
237
- longitude: loc.longitude,
238
- timezone: loc.timezone,
239
- },
240
- region: {
241
- code: loc.region,
242
- },
243
- postalCode: {
244
- code: loc.zip,
245
- },
246
- provider: {
247
- as: {
248
- num: loc.autonomous_system_number,
249
- name: loc.autonomous_system_organization,
250
- },
251
- isp: loc.isp,
252
- domain: loc.domain,
253
- },
254
- }
255
- : undefined;
256
- const traits = {};
257
- transfer(traits, event.user, ["id", "anonymous_id"]);
258
- const properties: any = {};
259
- transfer(properties, event, [
260
- TableNameParameter,
261
- "anon_ip",
262
- "api_key",
263
- "click_id",
264
- "doc_encoding",
265
- "doc_host",
266
- "doc_path",
267
- "doc_search",
268
- "eventn_ctx_event_id",
269
- "event_type",
270
- "local_tz_offset",
271
- "page_title",
272
- "referer",
273
- "screen_resolution",
274
- "source_ip",
275
- "url",
276
- "user",
277
- "location",
278
- "parsed_ua",
279
- "user_agent",
280
- "user_language",
281
- "utc_time",
282
- "_timestamp",
283
- "utm",
284
- "vp_size",
285
- ]);
286
- if (type === "page") {
287
- properties.url = event.url;
288
- properties.title = event.page_title;
289
- properties.referrer = event.referer;
290
- properties.search = event.doc_search;
291
- properties.host = event.doc_host;
292
- properties.path = event.doc_path;
293
- properties.width = parseInt(event.vp_size?.split("x")[0]);
294
- properties.height = parseInt(event.vp_size?.split("x")[1]);
295
- }
296
- const screen: any = {};
297
- const sr = event.screen_resolution?.split("x");
298
- if (sr?.length === 2) {
299
- screen.width = parseInt(sr[0]);
300
- screen.height = parseInt(sr[1]);
301
- }
302
- const vs = event.vp_size?.split("x");
303
- if (vs?.length === 2) {
304
- screen.innerWidth = parseInt(vs[0]);
305
- screen.innerHeight = parseInt(vs[1]);
306
- }
307
-
308
- return removeUndefined({
309
- [TableNameParameter]: event[TableNameParameter],
310
- messageId: event.eventn_ctx_event_id,
311
- userId: event.user?.id,
312
- anonymousId: event.user?.anonymous_id,
313
- timestamp: event.utc_time,
314
- receivedAt: event._timestamp,
315
- writeKey: event.api_key,
316
- type,
317
- event: eventName,
318
- context: {
319
- ip: event.source_ip,
320
- locale: event.user_language,
321
- userAgent: event.user_agent,
322
- page: {
323
- url: event.url,
324
- title: event.page_title,
325
- referrer: event.referer,
326
- search: event.doc_search,
327
- host: event.doc_host,
328
- path: event.doc_path,
329
- encoding: event.doc_encoding,
330
- timezoneOffset: event.local_tz_offset,
331
- },
332
- screen: Object.keys(screen).length > 0 ? screen : undefined,
333
- clientIds,
334
- campaign: event.utm,
335
- traits,
336
- geo,
337
- },
338
- properties,
339
- traits: type === "identify" || type === "group" ? traits : undefined,
340
- });
341
- }
@@ -1,96 +0,0 @@
1
- import { idToClassic, idToSnakeCaseFast } from "./strings";
2
-
3
- export function toSnakeCase(param: any): any {
4
- if (Array.isArray(param)) {
5
- return param.map(toSnakeCase);
6
- } else if (typeof param === "object" && param !== null) {
7
- const r = {};
8
- for (const [key, value] of Object.entries(param)) {
9
- r[idToSnakeCaseFast(key)] = toSnakeCase(value);
10
- }
11
- return r;
12
- } else {
13
- return param;
14
- }
15
- }
16
-
17
- export function toClassic(param: any): any {
18
- if (Array.isArray(param)) {
19
- return param.map(toClassic);
20
- } else if (typeof param === "object" && param !== null) {
21
- const r = {};
22
- for (const [key, value] of Object.entries(param)) {
23
- r[idToClassic(key)] = toClassic(value);
24
- }
25
- return r;
26
- } else {
27
- return param;
28
- }
29
- }
30
-
31
- export function removeUndefined(param: any): any {
32
- if (Array.isArray(param)) {
33
- return param.map(removeUndefined);
34
- } else if (typeof param === "object" && param !== null) {
35
- for (const [key, value] of Object.entries(param)) {
36
- switch (typeof value) {
37
- case "undefined":
38
- delete param[key];
39
- break;
40
- case "object":
41
- if (value !== null) {
42
- removeUndefined(value);
43
- }
44
- break;
45
- }
46
- }
47
- }
48
- return param;
49
- }
50
-
51
- export function transferAsSnakeCase(target: Record<string, any>, source: any, omit?: string[]) {
52
- if (typeof source !== "object") {
53
- return;
54
- }
55
- for (const [k, v] of Object.entries(source)) {
56
- if (!omit || !omit.includes(k)) {
57
- target[idToSnakeCaseFast(k)] = toSnakeCase(v);
58
- }
59
- }
60
- }
61
-
62
- export function transferAsClassic(target: Record<string, any>, source: any, omit?: string[]) {
63
- if (typeof source !== "object") {
64
- return;
65
- }
66
- for (const [k, v] of Object.entries(source)) {
67
- if (!omit || !omit.includes(k)) {
68
- target[idToClassic(k)] = toClassic(v);
69
- }
70
- }
71
- }
72
-
73
- export function transferValueAsSnakeCase(target: Record<string, any>, property: string, source: any) {
74
- if (typeof source === "undefined") {
75
- return;
76
- }
77
- target[property] = toSnakeCase(source);
78
- }
79
-
80
- export function transfer(target: Record<string, any>, source: any, omit?: string[]) {
81
- if (typeof source !== "object") {
82
- return;
83
- }
84
- for (const [k, v] of Object.entries(source)) {
85
- if (!omit || !omit.includes(k)) {
86
- target[k] = v;
87
- }
88
- }
89
- }
90
-
91
- export function transferValue(target: Record<string, any>, property: string, source: any) {
92
- if (typeof source === "undefined") {
93
- return;
94
- }
95
- target[property] = source;
96
- }
@@ -1,60 +0,0 @@
1
- const ACode = "A".charCodeAt(0);
2
- const ZCode = "Z".charCodeAt(0);
3
- const aCode = "a".charCodeAt(0);
4
- const zCode = "z".charCodeAt(0);
5
- const zeroCode = "0".charCodeAt(0);
6
- const nineCode = "9".charCodeAt(0);
7
- const spaceCode = " ".charCodeAt(0);
8
- const underscodeCode = "_".charCodeAt(0);
9
-
10
- export function idToSnakeCaseFast(id: string) {
11
- let res = "";
12
- let concatIndex = 0;
13
- let i = 0;
14
- let needUnderscore = false;
15
- for (; i < id.length; i++) {
16
- const c = id.charCodeAt(i);
17
- if (c >= ACode && c <= ZCode) {
18
- res += id.substring(concatIndex, i) + (needUnderscore ? "_" : "") + id.charAt(i).toLowerCase();
19
- concatIndex = i + 1;
20
- } else if (c == spaceCode) {
21
- res += id.substring(concatIndex, i) + "_";
22
- concatIndex = i + 1;
23
- }
24
- // needUnderscore is used in case next char is a capital latin letter
25
- // we add underscore only between latin letters
26
- needUnderscore = (c >= aCode && c <= zCode) || (c >= ACode && c <= ZCode);
27
- }
28
- if (concatIndex == 0) {
29
- return id;
30
- } else if (concatIndex < i) {
31
- res += id.substring(concatIndex, i);
32
- }
33
- return res;
34
- }
35
-
36
- export function idToClassic(id: string) {
37
- let needConvert = false;
38
- for (let i = 0; i < id.length; i++) {
39
- const c = id.charCodeAt(i);
40
- if (!((c >= aCode && c <= zCode) || (c >= zeroCode && c <= nineCode) || c == underscodeCode)) {
41
- needConvert = true;
42
- break;
43
- }
44
- }
45
- if (!needConvert) {
46
- return id;
47
- }
48
- let res = "";
49
- for (let i = 0; i < id.length; i++) {
50
- const c = id.charCodeAt(i);
51
- if (c >= ACode && c <= ZCode) {
52
- res += id.charAt(i).toLowerCase();
53
- } else if ((c >= aCode && c <= zCode) || (c >= zeroCode && c <= nineCode)) {
54
- res += id.charAt(i);
55
- } else {
56
- res += "_";
57
- }
58
- }
59
- return res;
60
- }