@flareone/common 0.1.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/LICENSE +21 -0
- package/README.md +36 -0
- package/dist/chunk-4TE4W4RZ.js +231 -0
- package/dist/chunk-4TE4W4RZ.js.map +1 -0
- package/dist/chunk-JAMM5H7G.js +577 -0
- package/dist/chunk-JAMM5H7G.js.map +1 -0
- package/dist/chunk-TLAV6QIM.js +327 -0
- package/dist/chunk-TLAV6QIM.js.map +1 -0
- package/dist/chunk-VDUV5SQH.js +281 -0
- package/dist/chunk-VDUV5SQH.js.map +1 -0
- package/dist/chunk-XUS63JTZ.js +16 -0
- package/dist/chunk-XUS63JTZ.js.map +1 -0
- package/dist/guards/index.d.ts +230 -0
- package/dist/guards/index.js +4 -0
- package/dist/guards/index.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/interceptors/index.d.ts +151 -0
- package/dist/interceptors/index.js +4 -0
- package/dist/interceptors/index.js.map +1 -0
- package/dist/pipes/index.d.ts +120 -0
- package/dist/pipes/index.js +4 -0
- package/dist/pipes/index.js.map +1 -0
- package/dist/utils/index.d.ts +155 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utils
|
|
3
|
+
* mostly stuff i didn't want to re-implement for the 100th time.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Generate a random UUID v4
|
|
7
|
+
*/
|
|
8
|
+
declare function uuid(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Generate a random string
|
|
11
|
+
*/
|
|
12
|
+
declare function randomString(length: number, charset?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Hash a string using SHA-256
|
|
15
|
+
*/
|
|
16
|
+
declare function sha256(data: string): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Hash a string using SHA-512
|
|
19
|
+
*/
|
|
20
|
+
declare function sha512(data: string): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Create HMAC signature
|
|
23
|
+
*/
|
|
24
|
+
declare function hmac(data: string, secret: string, algorithm?: 'SHA-256' | 'SHA-384' | 'SHA-512'): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Constant-time string comparison
|
|
27
|
+
*/
|
|
28
|
+
declare function constantTimeEqual(a: string, b: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Base64 encode
|
|
31
|
+
*/
|
|
32
|
+
declare function base64Encode(data: string | ArrayBuffer): string;
|
|
33
|
+
/**
|
|
34
|
+
* Base64 decode
|
|
35
|
+
*/
|
|
36
|
+
declare function base64Decode(data: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Base64 URL-safe encode
|
|
39
|
+
*/
|
|
40
|
+
declare function base64UrlEncode(data: string | ArrayBuffer): string;
|
|
41
|
+
/**
|
|
42
|
+
* Base64 URL-safe decode
|
|
43
|
+
*/
|
|
44
|
+
declare function base64UrlDecode(data: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Hex encode
|
|
47
|
+
*/
|
|
48
|
+
declare function hexEncode(data: ArrayBuffer | Uint8Array): string;
|
|
49
|
+
/**
|
|
50
|
+
* Hex decode
|
|
51
|
+
*/
|
|
52
|
+
declare function hexDecode(hex: string): Uint8Array;
|
|
53
|
+
/**
|
|
54
|
+
* Convert string to camelCase
|
|
55
|
+
*/
|
|
56
|
+
declare function camelCase(str: string): string;
|
|
57
|
+
/**
|
|
58
|
+
* Convert string to PascalCase
|
|
59
|
+
*/
|
|
60
|
+
declare function pascalCase(str: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Convert string to snake_case
|
|
63
|
+
*/
|
|
64
|
+
declare function snakeCase(str: string): string;
|
|
65
|
+
/**
|
|
66
|
+
* Convert string to kebab-case
|
|
67
|
+
*/
|
|
68
|
+
declare function kebabCase(str: string): string;
|
|
69
|
+
/**
|
|
70
|
+
* Generate URL-friendly slug
|
|
71
|
+
*/
|
|
72
|
+
declare function slugify(str: string): string;
|
|
73
|
+
/**
|
|
74
|
+
* Truncate string with ellipsis
|
|
75
|
+
*/
|
|
76
|
+
declare function truncate(str: string, length: number, suffix?: string): string;
|
|
77
|
+
/**
|
|
78
|
+
* Deep clone an object
|
|
79
|
+
*/
|
|
80
|
+
declare function deepClone<T>(obj: T): T;
|
|
81
|
+
/**
|
|
82
|
+
* Deep merge objects
|
|
83
|
+
*/
|
|
84
|
+
declare function deepMerge<T extends Record<string, unknown>>(target: T, ...sources: Partial<T>[]): T;
|
|
85
|
+
/**
|
|
86
|
+
* Pick specific keys from an object
|
|
87
|
+
*/
|
|
88
|
+
declare function pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
89
|
+
/**
|
|
90
|
+
* Omit specific keys from an object
|
|
91
|
+
*/
|
|
92
|
+
declare function omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
93
|
+
/**
|
|
94
|
+
* Get nested property value
|
|
95
|
+
*/
|
|
96
|
+
declare function get<T>(obj: unknown, path: string, defaultValue?: T): T | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Set nested property value
|
|
99
|
+
*/
|
|
100
|
+
declare function set<T extends Record<string, unknown>>(obj: T, path: string, value: unknown): T;
|
|
101
|
+
/**
|
|
102
|
+
* Split array into chunks
|
|
103
|
+
*/
|
|
104
|
+
declare function chunk<T>(arr: T[], size: number): T[][];
|
|
105
|
+
/**
|
|
106
|
+
* Get unique values from array
|
|
107
|
+
*/
|
|
108
|
+
declare function unique<T>(arr: T[]): T[];
|
|
109
|
+
/**
|
|
110
|
+
* Group array elements by key
|
|
111
|
+
*/
|
|
112
|
+
declare function groupBy<T, K extends string | number | symbol>(arr: T[], keyFn: (item: T) => K): Record<K, T[]>;
|
|
113
|
+
/**
|
|
114
|
+
* Shuffle array (Fisher-Yates)
|
|
115
|
+
*/
|
|
116
|
+
declare function shuffle<T>(arr: T[]): T[];
|
|
117
|
+
/**
|
|
118
|
+
* Sleep for specified milliseconds
|
|
119
|
+
*/
|
|
120
|
+
declare function sleep(ms: number): Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Retry a function with exponential backoff
|
|
123
|
+
*/
|
|
124
|
+
declare function retry<T>(fn: () => Promise<T>, options?: {
|
|
125
|
+
maxAttempts?: number;
|
|
126
|
+
initialDelay?: number;
|
|
127
|
+
maxDelay?: number;
|
|
128
|
+
factor?: number;
|
|
129
|
+
}): Promise<T>;
|
|
130
|
+
/**
|
|
131
|
+
* Execute promises with concurrency limit
|
|
132
|
+
*/
|
|
133
|
+
declare function parallel<T>(tasks: (() => Promise<T>)[], concurrency: number): Promise<T[]>;
|
|
134
|
+
/**
|
|
135
|
+
* Validate email format
|
|
136
|
+
*/
|
|
137
|
+
declare function isEmail(value: string): boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Validate URL format
|
|
140
|
+
*/
|
|
141
|
+
declare function isUrl(value: string): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Validate UUID format
|
|
144
|
+
*/
|
|
145
|
+
declare function isUuid(value: string): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Validate IPv4 address
|
|
148
|
+
*/
|
|
149
|
+
declare function isIpv4(value: string): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Check if value is empty
|
|
152
|
+
*/
|
|
153
|
+
declare function isEmpty(value: unknown): boolean;
|
|
154
|
+
|
|
155
|
+
export { base64Decode, base64Encode, base64UrlDecode, base64UrlEncode, camelCase, chunk, constantTimeEqual, deepClone, deepMerge, get, groupBy, hexDecode, hexEncode, hmac, isEmail, isEmpty, isIpv4, isUrl, isUuid, kebabCase, omit, parallel, pascalCase, pick, randomString, retry, set, sha256, sha512, shuffle, sleep, slugify, snakeCase, truncate, unique, uuid };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { base64Decode, base64Encode, base64UrlDecode, base64UrlEncode, camelCase, chunk, constantTimeEqual, deepClone, deepMerge, get, groupBy, hexDecode, hexEncode, hmac, isEmail, isEmpty, isIpv4, isUrl, isUuid, kebabCase, omit, parallel, pascalCase, pick, randomString, retry, set, sha256, sha512, shuffle, sleep, slugify, snakeCase, truncate, unique, uuid } from '../chunk-VDUV5SQH.js';
|
|
2
|
+
import '../chunk-XUS63JTZ.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flareone/common",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Common utilities for Flareone framework",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cloudflare",
|
|
7
|
+
"workers",
|
|
8
|
+
"flareon",
|
|
9
|
+
"utilities",
|
|
10
|
+
"validation",
|
|
11
|
+
"pipes"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://flareone.dev",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "Flareone Contributors",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./pipes": {
|
|
23
|
+
"types": "./dist/pipes/index.d.ts",
|
|
24
|
+
"import": "./dist/pipes/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./guards": {
|
|
27
|
+
"types": "./dist/guards/index.d.ts",
|
|
28
|
+
"import": "./dist/guards/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./interceptors": {
|
|
31
|
+
"types": "./dist/interceptors/index.d.ts",
|
|
32
|
+
"import": "./dist/interceptors/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./utils": {
|
|
35
|
+
"types": "./dist/utils/index.d.ts",
|
|
36
|
+
"import": "./dist/utils/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"main": "./dist/index.js",
|
|
40
|
+
"types": "./dist/index.d.ts",
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"README.md"
|
|
44
|
+
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@flareone/core": "0.1.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@cloudflare/workers-types": "^4.20250109.0",
|
|
50
|
+
"rimraf": "^6.0.0",
|
|
51
|
+
"tsup": "^8.3.0",
|
|
52
|
+
"typescript": "^5.7.0"
|
|
53
|
+
},
|
|
54
|
+
"sideEffects": false,
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup",
|
|
57
|
+
"clean": "rimraf dist",
|
|
58
|
+
"dev": "tsup --watch",
|
|
59
|
+
"typecheck": "tsc --noEmit"
|
|
60
|
+
}
|
|
61
|
+
}
|