@isik-kaplan/core 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/dist/index.cjs ADDED
@@ -0,0 +1,466 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ LONG_DATE_FORMAT: () => LONG_DATE_FORMAT,
24
+ SHORT_DATETIME_FORMAT: () => SHORT_DATETIME_FORMAT,
25
+ SHORT_DATE_FORMAT: () => SHORT_DATE_FORMAT,
26
+ allCombinations: () => allCombinations,
27
+ checkRequiredKeys: () => checkRequiredKeys,
28
+ cloned: () => cloned,
29
+ createConsoleDebugSwitch: () => createConsoleDebugSwitch,
30
+ downloadAndFormatImage: () => downloadAndFormatImage,
31
+ enabledIf: () => enabledIf,
32
+ escapeName: () => escapeName,
33
+ fileToBase64: () => fileToBase64,
34
+ fileToBase64Native: () => fileToBase64Native,
35
+ forcedType: () => forcedType,
36
+ formattedDate: () => formattedDate,
37
+ getCookie: () => getCookie,
38
+ getKeys: () => getKeys,
39
+ getLazyValue: () => getLazyValue,
40
+ getLazyValueAsync: () => getLazyValueAsync,
41
+ guessImageMimeType: () => guessImageMimeType,
42
+ isImageMimeType: () => isImageMimeType,
43
+ isPathMatched: () => isPathMatched,
44
+ longFormattedDate: () => longFormattedDate,
45
+ makeCallable: () => makeCallable,
46
+ notNone: () => notNone,
47
+ optionalDate: () => optionalDate,
48
+ preventDefault: () => preventDefault,
49
+ raises: () => raises,
50
+ requireExclusiveKeys: () => requireExclusiveKeys,
51
+ safeFileName: () => safeFileName,
52
+ setKeyValueToObjectIfValue: () => setKeyValueToObjectIfValue,
53
+ shortFormattedDate: () => shortFormattedDate,
54
+ shortFormattedDateTime: () => shortFormattedDateTime,
55
+ slugify: () => slugify,
56
+ suppress: () => suppress,
57
+ transformExceptions: () => transformExceptions,
58
+ withAttributes: () => withAttributes
59
+ });
60
+ module.exports = __toCommonJS(src_exports);
61
+
62
+ // src/types/index.ts
63
+ var getKeys = Object.keys;
64
+ function forcedType(obj) {
65
+ return obj;
66
+ }
67
+
68
+ // src/arrays/index.ts
69
+ function notNone(value) {
70
+ return value !== null && value !== void 0;
71
+ }
72
+ function combinationsOfSize(items, size) {
73
+ if (size === 0) {
74
+ return [[]];
75
+ }
76
+ if (size > items.length) {
77
+ return [];
78
+ }
79
+ const [first, ...rest] = items;
80
+ const withFirst = combinationsOfSize(rest, size - 1).map((combination) => [first, ...combination]);
81
+ const withoutFirst = combinationsOfSize(rest, size);
82
+ return [...withFirst, ...withoutFirst];
83
+ }
84
+ function allCombinations(options) {
85
+ const result = [];
86
+ for (let size = 1; size <= options.length; size++) {
87
+ result.push(...combinationsOfSize(options, size));
88
+ }
89
+ return result;
90
+ }
91
+
92
+ // src/functions/index.ts
93
+ function withAttributes(fn, attributes) {
94
+ for (const key of Object.keys(attributes)) {
95
+ Object.defineProperty(fn, key, {
96
+ value: attributes[key],
97
+ writable: true,
98
+ configurable: true,
99
+ enumerable: true
100
+ });
101
+ }
102
+ return fn;
103
+ }
104
+ function makeCallable(originalCallable) {
105
+ return (data) => () => originalCallable(data);
106
+ }
107
+ function getLazyValue(input) {
108
+ if (typeof input === "function") {
109
+ return input();
110
+ }
111
+ return input;
112
+ }
113
+ async function getLazyValueAsync(input) {
114
+ if (typeof input === "function") {
115
+ const result = input();
116
+ if (result instanceof Promise) {
117
+ return await result;
118
+ }
119
+ return result;
120
+ }
121
+ return input;
122
+ }
123
+ function suppress(exceptions, fn, onError) {
124
+ try {
125
+ return fn();
126
+ } catch (error) {
127
+ if (exceptions.some((exception) => error instanceof exception)) {
128
+ return onError ? onError(error) : void 0;
129
+ }
130
+ throw error;
131
+ }
132
+ }
133
+ function preventDefault(callable) {
134
+ return async function(event) {
135
+ event.preventDefault();
136
+ return await callable(event);
137
+ };
138
+ }
139
+ function isPathMatched(pathname, pattern, exemptPatterns = []) {
140
+ if (exemptPatterns.some((exempt) => exempt.test(pathname))) {
141
+ return false;
142
+ }
143
+ return pattern.test(pathname);
144
+ }
145
+ function raises(error) {
146
+ return () => {
147
+ throw error;
148
+ };
149
+ }
150
+ function cloned(fn) {
151
+ return ((...args) => fn(...args));
152
+ }
153
+ function enabledIf(condition, options) {
154
+ const enabled = typeof condition === "function" ? condition() : condition;
155
+ return function(fn) {
156
+ if (!enabled) {
157
+ return cloned((() => options.ifNotEnabledReturnValue));
158
+ }
159
+ return cloned(fn);
160
+ };
161
+ }
162
+ function transformExceptions(exceptionTypes, transform, options = {}) {
163
+ const { keepOriginal = true } = options;
164
+ return function(fn) {
165
+ return ((...args) => {
166
+ try {
167
+ return fn(...args);
168
+ } catch (error) {
169
+ if (!exceptionTypes.some((ExceptionType) => error instanceof ExceptionType)) {
170
+ throw error;
171
+ }
172
+ const newError = transform(error);
173
+ if (keepOriginal) {
174
+ newError.cause = error;
175
+ }
176
+ throw newError;
177
+ }
178
+ });
179
+ };
180
+ }
181
+
182
+ // src/objects/index.ts
183
+ function checkRequiredKeys(obj, conditions) {
184
+ const matchingConditions = Object.entries(conditions).filter(
185
+ ([, keys]) => keys.every((key) => obj[key] !== void 0) && Object.keys(obj).every((key) => keys.includes(key) || obj[key] === void 0)
186
+ );
187
+ if (matchingConditions.length !== 1) {
188
+ throw new Error(`Object keys do not match exactly one required condition. ${JSON.stringify(conditions)}`);
189
+ }
190
+ return matchingConditions[0][0];
191
+ }
192
+ function requireExclusiveKeys(conditions, options = {}) {
193
+ const conditionEntries = Object.entries(conditions);
194
+ if (conditionEntries.length === 0) {
195
+ throw new Error("At least one condition must be provided.");
196
+ }
197
+ const { allowEmpty = false } = options;
198
+ const governedKeys = new Set(conditionEntries.flatMap(([, keys]) => keys));
199
+ return function(fn) {
200
+ return ((arg) => {
201
+ const provided = new Set(
202
+ Object.keys(arg).filter((key) => governedKeys.has(key) && arg[key] !== void 0)
203
+ );
204
+ if (allowEmpty && provided.size === 0) {
205
+ return fn(arg);
206
+ }
207
+ const matches = conditionEntries.filter(
208
+ ([, keys]) => keys.length === provided.size && keys.every((key) => provided.has(key))
209
+ );
210
+ if (matches.length !== 1) {
211
+ throw new Error(`Object keys do not match exactly one required condition. ${JSON.stringify(conditions)}`);
212
+ }
213
+ return fn(arg);
214
+ });
215
+ };
216
+ }
217
+ function setKeyValueToObjectIfValue(key, value, object) {
218
+ if (value) {
219
+ Object.defineProperty(object, key, { value, writable: true, configurable: true, enumerable: true });
220
+ }
221
+ }
222
+
223
+ // src/strings/index.ts
224
+ function slugify(value, allowUnicode = false) {
225
+ if (allowUnicode) {
226
+ value = value.normalize("NFKC").replace(/[^\p{L}\p{N}_\s-]/gu, "");
227
+ } else {
228
+ value = value.normalize("NFKD").replace(/[^\x00-\x7F]/g, "").replace(/[\r\n]+/g, " ").trim().replace(/[^\w\s-]/g, "");
229
+ }
230
+ value = value.toLowerCase();
231
+ return value.replace(/[-\s]+/g, "-").replace(/^[-_]+|[-_]+$/g, "");
232
+ }
233
+
234
+ // src/dates/_format.ts
235
+ var import_date_fns = require("date-fns");
236
+ function formatDate(date, pattern) {
237
+ return (0, import_date_fns.format)(date, pattern);
238
+ }
239
+
240
+ // src/dates/index.ts
241
+ var LONG_DATE_FORMAT = "EEEE, MMMM dd, yyyy 'at' hh:mm a";
242
+ var SHORT_DATE_FORMAT = "dd.MM.yyyy";
243
+ var SHORT_DATETIME_FORMAT = "dd.MM.yyyy HH:mm a";
244
+ function formattedDate(pattern, date = /* @__PURE__ */ new Date()) {
245
+ return formatDate(date, pattern);
246
+ }
247
+ function longFormattedDate(date = /* @__PURE__ */ new Date()) {
248
+ return formattedDate(LONG_DATE_FORMAT, date);
249
+ }
250
+ function shortFormattedDate(date = /* @__PURE__ */ new Date()) {
251
+ return formattedDate(SHORT_DATE_FORMAT, date);
252
+ }
253
+ function shortFormattedDateTime(date = /* @__PURE__ */ new Date()) {
254
+ return formattedDate(SHORT_DATETIME_FORMAT, date);
255
+ }
256
+ function optionalDate(date) {
257
+ return date ? new Date(date) : void 0;
258
+ }
259
+
260
+ // src/files/index.ts
261
+ function guessImageMimeType(filename) {
262
+ const withoutQueryOrHash = filename.split(/[?#]/)[0];
263
+ const extension = withoutQueryOrHash.split(".").pop()?.toLowerCase();
264
+ switch (extension) {
265
+ case "png":
266
+ return "image/png";
267
+ case "jfif":
268
+ case "jpg":
269
+ case "jpeg":
270
+ return "image/jpeg";
271
+ case "webp":
272
+ return "image/webp";
273
+ default:
274
+ return "image/png";
275
+ }
276
+ }
277
+ function isImageMimeType(mimeType) {
278
+ return mimeType === "image/png" || mimeType === "image/jpeg" || mimeType === "image/webp";
279
+ }
280
+ function escapeName(name) {
281
+ return name.replace(/[^a-zA-Z0-9-_.]/g, "_");
282
+ }
283
+ function safeFileName(filename, maxLength = 255) {
284
+ if (filename.length <= maxLength) return filename;
285
+ const dotIndex = filename.lastIndexOf(".");
286
+ const hasExtension = dotIndex > 0;
287
+ const extension = escapeName(hasExtension ? filename.slice(dotIndex) : "");
288
+ const name = escapeName(hasExtension ? filename.slice(0, dotIndex) : filename);
289
+ return name.slice(0, Math.max(0, maxLength - extension.length)) + extension;
290
+ }
291
+ async function downloadAndFormatImage(src, name = "image.png", mimeType = guessImageMimeType(name), quality = 1) {
292
+ name = safeFileName(name);
293
+ try {
294
+ const img = new Image();
295
+ img.crossOrigin = "anonymous";
296
+ await new Promise((resolve, reject) => {
297
+ img.onload = resolve;
298
+ img.onerror = reject;
299
+ img.src = src;
300
+ });
301
+ const canvas = document.createElement("canvas");
302
+ canvas.width = img.width;
303
+ canvas.height = img.height;
304
+ const ctx = canvas.getContext("2d");
305
+ if (!ctx) {
306
+ throw new Error("Could not get canvas context");
307
+ }
308
+ ctx.drawImage(img, 0, 0);
309
+ const blob = await new Promise((resolve) => {
310
+ canvas.toBlob(resolve, mimeType, quality);
311
+ });
312
+ if (!blob) {
313
+ throw new Error("Could not generate blob");
314
+ }
315
+ const link = document.createElement("a");
316
+ const downloadUrl = URL.createObjectURL(blob);
317
+ try {
318
+ link.href = downloadUrl;
319
+ link.download = name;
320
+ document.body.appendChild(link);
321
+ link.click();
322
+ } finally {
323
+ document.body.removeChild(link);
324
+ URL.revokeObjectURL(downloadUrl);
325
+ }
326
+ } catch (error) {
327
+ console.error("Failed to download image:", error);
328
+ }
329
+ }
330
+ async function fileToBase64Native(file) {
331
+ const result = await new Promise((resolve, reject) => {
332
+ const reader = new FileReader();
333
+ reader.readAsDataURL(file);
334
+ reader.onload = () => resolve(reader.result);
335
+ reader.onerror = (error) => reject(error);
336
+ });
337
+ if (typeof result === "string") {
338
+ return result;
339
+ } else {
340
+ throw new Error("Failed to read file as Data URL");
341
+ }
342
+ }
343
+ async function fileToBase64(file, quality = 1) {
344
+ if (isImageMimeType(file.type)) {
345
+ const img = new Image();
346
+ const url = URL.createObjectURL(file);
347
+ try {
348
+ await new Promise((resolve, reject) => {
349
+ img.onload = () => resolve();
350
+ img.onerror = () => reject(new Error("Failed to load image for metadata removal"));
351
+ img.src = url;
352
+ });
353
+ const canvas = document.createElement("canvas");
354
+ canvas.width = img.width;
355
+ canvas.height = img.height;
356
+ const ctx = canvas.getContext("2d");
357
+ if (!ctx) {
358
+ throw new Error("Failed to get canvas context");
359
+ }
360
+ ctx.drawImage(img, 0, 0);
361
+ const cleanDataUrl = canvas.toDataURL(file.type, quality);
362
+ if (cleanDataUrl === "data:,") {
363
+ return await fileToBase64Native(file);
364
+ }
365
+ return cleanDataUrl;
366
+ } finally {
367
+ URL.revokeObjectURL(url);
368
+ }
369
+ } else {
370
+ return await fileToBase64Native(file);
371
+ }
372
+ }
373
+
374
+ // src/cookies/index.ts
375
+ function getCookie(name) {
376
+ for (const pair of document.cookie.split("; ")) {
377
+ const separatorIndex = pair.indexOf("=");
378
+ if (separatorIndex === -1) {
379
+ continue;
380
+ }
381
+ if (pair.slice(0, separatorIndex) === name) {
382
+ return pair.slice(separatorIndex + 1);
383
+ }
384
+ }
385
+ return void 0;
386
+ }
387
+
388
+ // src/console/index.ts
389
+ var patchedWindows = /* @__PURE__ */ new WeakMap();
390
+ function createConsoleDebugSwitch(targetWindow, options) {
391
+ if (!targetWindow) {
392
+ return;
393
+ }
394
+ const { namespace } = options;
395
+ let enabledNamespaces = patchedWindows.get(targetWindow);
396
+ if (!enabledNamespaces) {
397
+ enabledNamespaces = /* @__PURE__ */ new Set();
398
+ patchedWindows.set(targetWindow, enabledNamespaces);
399
+ const original = {
400
+ log: targetWindow.console.log.bind(targetWindow.console),
401
+ info: targetWindow.console.info.bind(targetWindow.console),
402
+ warn: targetWindow.console.warn.bind(targetWindow.console),
403
+ error: targetWindow.console.error.bind(targetWindow.console)
404
+ };
405
+ const conditional = (method) => (...args) => {
406
+ if (enabledNamespaces.size > 0) {
407
+ method(...args);
408
+ }
409
+ };
410
+ targetWindow.console.log = conditional(original.log);
411
+ targetWindow.console.info = conditional(original.info);
412
+ targetWindow.console.warn = conditional(original.warn);
413
+ targetWindow.console.error = conditional(original.error);
414
+ }
415
+ const globals = targetWindow;
416
+ const existing = Object.prototype.hasOwnProperty.call(globals, namespace) ? Object.getOwnPropertyDescriptor(globals, namespace)?.value : void 0;
417
+ const target = existing ?? {};
418
+ target.debug = (flag) => {
419
+ if (flag) {
420
+ enabledNamespaces.add(namespace);
421
+ } else {
422
+ enabledNamespaces.delete(namespace);
423
+ }
424
+ };
425
+ Object.defineProperty(globals, namespace, { value: target, writable: true, configurable: true, enumerable: true });
426
+ }
427
+ // Annotate the CommonJS export names for ESM import in node:
428
+ 0 && (module.exports = {
429
+ LONG_DATE_FORMAT,
430
+ SHORT_DATETIME_FORMAT,
431
+ SHORT_DATE_FORMAT,
432
+ allCombinations,
433
+ checkRequiredKeys,
434
+ cloned,
435
+ createConsoleDebugSwitch,
436
+ downloadAndFormatImage,
437
+ enabledIf,
438
+ escapeName,
439
+ fileToBase64,
440
+ fileToBase64Native,
441
+ forcedType,
442
+ formattedDate,
443
+ getCookie,
444
+ getKeys,
445
+ getLazyValue,
446
+ getLazyValueAsync,
447
+ guessImageMimeType,
448
+ isImageMimeType,
449
+ isPathMatched,
450
+ longFormattedDate,
451
+ makeCallable,
452
+ notNone,
453
+ optionalDate,
454
+ preventDefault,
455
+ raises,
456
+ requireExclusiveKeys,
457
+ safeFileName,
458
+ setKeyValueToObjectIfValue,
459
+ shortFormattedDate,
460
+ shortFormattedDateTime,
461
+ slugify,
462
+ suppress,
463
+ transformExceptions,
464
+ withAttributes
465
+ });
466
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/types/index.ts","../src/arrays/index.ts","../src/functions/index.ts","../src/objects/index.ts","../src/strings/index.ts","../src/dates/_format.ts","../src/dates/index.ts","../src/files/index.ts","../src/cookies/index.ts","../src/console/index.ts"],"sourcesContent":["export * from './types'\nexport * from './arrays'\nexport * from './functions'\nexport * from './objects'\nexport * from './strings'\nexport * from './dates'\nexport * from './files'\nexport * from './cookies'\nexport * from './console'\n","export const getKeys = Object.keys as <T extends object>(obj: T) => Array<keyof T>\n\nexport type RecursivePartial<T> = { [P in keyof T]?: RecursivePartial<T[P]> }\n\nexport type RecursiveRecord = {\n [key: string]: string | number | boolean | RecursiveRecord | Array<RecursiveRecord>\n}\n\nexport function forcedType<T>(obj: unknown): T {\n return obj as unknown as T\n}\n","export function notNone<T>(value: T | null | undefined): value is T {\n return value !== null && value !== undefined\n}\n\nfunction combinationsOfSize<T>(items: T[], size: number): T[][] {\n if (size === 0) {\n return [[]]\n }\n if (size > items.length) {\n return []\n }\n const [first, ...rest] = items\n const withFirst = combinationsOfSize(rest, size - 1).map((combination) => [first, ...combination])\n const withoutFirst = combinationsOfSize(rest, size)\n return [...withFirst, ...withoutFirst]\n}\n\nexport function allCombinations<T>(options: T[]): T[][] {\n const result: T[][] = []\n for (let size = 1; size <= options.length; size++) {\n result.push(...combinationsOfSize(options, size))\n }\n return result\n}\n","export function withAttributes<Fn extends (...args: never[]) => unknown, Attrs extends Record<string, unknown>>(\n fn: Fn,\n attributes: Attrs\n): Fn & Attrs {\n for (const key of Object.keys(attributes)) {\n // Object.defineProperty (unlike a plain `fn[key] = value` assignment) always creates/\n // overwrites an own property, even when key is \"__proto__\" - a plain assignment would instead\n // be intercepted by Object.prototype's special __proto__ accessor and reassign fn's own\n // prototype instead of setting a property on it.\n Object.defineProperty(fn, key, {\n value: attributes[key],\n writable: true,\n configurable: true,\n enumerable: true,\n })\n }\n return fn as Fn & Attrs\n}\n\nexport function makeCallable<T, R>(originalCallable: (arg: T) => R) {\n return (data: T) => () => originalCallable(data)\n}\n\nexport function getLazyValue<T>(input: T | (() => T)): T {\n if (typeof input === 'function') {\n return (input as () => T)()\n }\n return input\n}\n\nexport async function getLazyValueAsync<T>(input: T | (() => Promise<T>) | (() => T)): Promise<T> {\n if (typeof input === 'function') {\n const result = (input as () => Promise<T>)()\n if (result instanceof Promise) {\n return await result\n }\n return result as unknown as T\n }\n return input\n}\n\nexport function suppress<T, ERT>(\n exceptions: Array<new (message?: string) => Error>,\n fn: () => T,\n onError?: (error: unknown) => ERT\n): T | ERT | undefined {\n try {\n return fn()\n } catch (error) {\n if (exceptions.some((exception) => error instanceof exception)) {\n return onError ? onError(error) : undefined\n }\n throw error\n }\n}\n\nexport function preventDefault<E extends Event, R>(callable: (event: E) => R): (event: E) => Promise<Awaited<R>> {\n return async function (event: E): Promise<Awaited<R>> {\n event.preventDefault()\n return await callable(event)\n }\n}\n\nexport function isPathMatched(pathname: string, pattern: RegExp, exemptPatterns: RegExp[] = []): boolean {\n if (exemptPatterns.some((exempt) => exempt.test(pathname))) {\n return false\n }\n return pattern.test(pathname)\n}\n\nexport function raises(error: Error): (...args: unknown[]) => never {\n return () => {\n throw error\n }\n}\n\nexport function cloned<Fn extends (...args: never[]) => unknown>(fn: Fn): Fn {\n return ((...args: Parameters<Fn>) => fn(...args)) as Fn\n}\n\nexport function enabledIf<R>(condition: boolean | (() => boolean), options: { ifNotEnabledReturnValue: R }) {\n const enabled = typeof condition === 'function' ? condition() : condition\n\n return function <Fn extends (...args: never[]) => R>(fn: Fn): Fn {\n if (!enabled) {\n return cloned((() => options.ifNotEnabledReturnValue) as Fn)\n }\n return cloned(fn)\n }\n}\n\nexport function transformExceptions<E extends Error>(\n exceptionTypes: Array<new (...args: never[]) => E>,\n transform: (error: E) => Error,\n options: { keepOriginal?: boolean } = {}\n) {\n const { keepOriginal = true } = options\n\n return function <Fn extends (...args: never[]) => unknown>(fn: Fn): Fn {\n return ((...args: Parameters<Fn>) => {\n try {\n return fn(...args)\n } catch (error) {\n if (!exceptionTypes.some((ExceptionType) => error instanceof ExceptionType)) {\n throw error\n }\n const newError = transform(error as E)\n if (keepOriginal) {\n newError.cause = error\n }\n throw newError\n }\n }) as Fn\n }\n}\n","export function checkRequiredKeys<T extends Record<string, unknown>, C extends Record<string, Array<keyof T>>>(\n obj: T,\n conditions: C\n): keyof C {\n const matchingConditions = Object.entries(conditions).filter(\n ([, keys]) =>\n keys.every((key) => obj[key] !== undefined) &&\n Object.keys(obj).every((key) => keys.includes(key as keyof T) || obj[key] === undefined)\n )\n\n if (matchingConditions.length !== 1) {\n throw new Error(`Object keys do not match exactly one required condition. ${JSON.stringify(conditions)}`)\n }\n\n return matchingConditions[0][0] as keyof C\n}\n\nexport function requireExclusiveKeys<T extends Record<string, unknown>, C extends Record<string, Array<keyof T>>>(\n conditions: C,\n options: { allowEmpty?: boolean } = {}\n) {\n const conditionEntries = Object.entries(conditions) as Array<[string, Array<keyof T>]>\n if (conditionEntries.length === 0) {\n throw new Error('At least one condition must be provided.')\n }\n const { allowEmpty = false } = options\n const governedKeys = new Set(conditionEntries.flatMap(([, keys]) => keys))\n\n return function <Fn extends (arg: T) => unknown>(fn: Fn): Fn {\n return ((arg: T) => {\n // Only keys that are actually governed by a condition are considered - unlike\n // checkRequiredKeys, any other key on `arg` is fully unconstrained and ignored here\n // regardless of its value, since this is meant to validate one options object that may\n // legitimately carry other, unrelated fields alongside the mutually-exclusive ones.\n const provided = new Set(\n Object.keys(arg).filter((key) => governedKeys.has(key as keyof T) && arg[key] !== undefined)\n )\n\n if (allowEmpty && provided.size === 0) {\n return fn(arg)\n }\n\n const matches = conditionEntries.filter(\n ([, keys]) => keys.length === provided.size && keys.every((key) => provided.has(key as string))\n )\n if (matches.length !== 1) {\n throw new Error(`Object keys do not match exactly one required condition. ${JSON.stringify(conditions)}`)\n }\n return fn(arg)\n }) as Fn\n }\n}\n\nexport function setKeyValueToObjectIfValue(key: string, value: unknown, object: Record<string, unknown>) {\n if (value) {\n // Object.defineProperty (unlike a plain `object[key] = value` assignment) always creates/\n // overwrites an own property, even when key is \"__proto__\" - a plain assignment would instead\n // be intercepted by Object.prototype's special __proto__ accessor and reassign this object's\n // prototype instead of setting a property on it.\n Object.defineProperty(object, key, { value, writable: true, configurable: true, enumerable: true })\n }\n}\n","export function slugify(value: string, allowUnicode: boolean = false): string {\n if (allowUnicode) {\n value = value.normalize('NFKC').replace(/[^\\p{L}\\p{N}_\\s-]/gu, '')\n } else {\n value = value\n .normalize('NFKD')\n // eslint-disable-next-line no-control-regex\n .replace(/[^\\x00-\\x7F]/g, '')\n .replace(/[\\r\\n]+/g, ' ')\n .trim()\n .replace(/[^\\w\\s-]/g, '')\n }\n\n value = value.toLowerCase()\n\n return value.replace(/[-\\s]+/g, '-').replace(/^[-_]+|[-_]+$/g, '')\n}\n","import { format } from 'date-fns'\n\nexport function formatDate(date: Date, pattern: string): string {\n return format(date, pattern)\n}\n","import { formatDate } from './_format'\n\nexport const LONG_DATE_FORMAT = \"EEEE, MMMM dd, yyyy 'at' hh:mm a\"\nexport const SHORT_DATE_FORMAT = 'dd.MM.yyyy'\nexport const SHORT_DATETIME_FORMAT = 'dd.MM.yyyy HH:mm a'\n\nexport function formattedDate(pattern: string, date: Date = new Date()): string {\n return formatDate(date, pattern)\n}\n\nexport function longFormattedDate(date: Date = new Date()): string {\n return formattedDate(LONG_DATE_FORMAT, date)\n}\n\nexport function shortFormattedDate(date: Date = new Date()): string {\n return formattedDate(SHORT_DATE_FORMAT, date)\n}\n\nexport function shortFormattedDateTime(date: Date = new Date()): string {\n return formattedDate(SHORT_DATETIME_FORMAT, date)\n}\n\nexport function optionalDate(date?: string): Date | undefined {\n return date ? new Date(date) : undefined\n}\n","type MimeType = 'image/png' | 'image/jpeg' | 'image/webp'\n\nexport function guessImageMimeType(filename: string): MimeType {\n const withoutQueryOrHash = filename.split(/[?#]/)[0]\n const extension = withoutQueryOrHash.split('.').pop()?.toLowerCase()\n switch (extension) {\n case 'png':\n return 'image/png'\n case 'jfif':\n case 'jpg':\n case 'jpeg':\n return 'image/jpeg'\n case 'webp':\n return 'image/webp'\n default:\n return 'image/png'\n }\n}\n\nexport function isImageMimeType(mimeType: string): mimeType is MimeType {\n return mimeType === 'image/png' || mimeType === 'image/jpeg' || mimeType === 'image/webp'\n}\n\nexport function escapeName(name: string): string {\n return name.replace(/[^a-zA-Z0-9-_.]/g, '_')\n}\n\nexport function safeFileName(filename: string, maxLength: number = 255): string {\n if (filename.length <= maxLength) return filename\n\n const dotIndex = filename.lastIndexOf('.')\n const hasExtension = dotIndex > 0\n const extension = escapeName(hasExtension ? filename.slice(dotIndex) : '')\n const name = escapeName(hasExtension ? filename.slice(0, dotIndex) : filename)\n\n return name.slice(0, Math.max(0, maxLength - extension.length)) + extension\n}\n\nexport async function downloadAndFormatImage(\n src: string,\n name: string = 'image.png',\n mimeType: MimeType = guessImageMimeType(name),\n quality: number = 1\n): Promise<void> {\n name = safeFileName(name)\n try {\n const img = new Image()\n img.crossOrigin = 'anonymous'\n\n await new Promise((resolve, reject) => {\n img.onload = resolve\n img.onerror = reject\n img.src = src\n })\n\n const canvas = document.createElement('canvas')\n canvas.width = img.width\n canvas.height = img.height\n const ctx = canvas.getContext('2d')\n\n if (!ctx) {\n throw new Error('Could not get canvas context')\n }\n\n ctx.drawImage(img, 0, 0)\n\n const blob = await new Promise<Blob | null>((resolve) => {\n canvas.toBlob(resolve, mimeType, quality)\n })\n\n if (!blob) {\n throw new Error('Could not generate blob')\n }\n\n const link = document.createElement('a')\n const downloadUrl = URL.createObjectURL(blob)\n try {\n link.href = downloadUrl\n link.download = name\n document.body.appendChild(link)\n link.click()\n } finally {\n document.body.removeChild(link)\n URL.revokeObjectURL(downloadUrl)\n }\n } catch (error) {\n console.error('Failed to download image:', error)\n }\n}\n\nexport async function fileToBase64Native(file: File): Promise<string> {\n const result = await new Promise<string | ArrayBuffer | null>((resolve, reject) => {\n const reader = new FileReader()\n reader.readAsDataURL(file)\n reader.onload = () => resolve(reader.result)\n reader.onerror = (error) => reject(error)\n })\n\n if (typeof result === 'string') {\n return result\n } else {\n throw new Error('Failed to read file as Data URL')\n }\n}\n\nexport async function fileToBase64(file: File, quality: number = 1): Promise<string> {\n if (isImageMimeType(file.type)) {\n const img = new Image()\n const url = URL.createObjectURL(file)\n try {\n await new Promise<void>((resolve, reject) => {\n img.onload = () => resolve()\n img.onerror = () => reject(new Error('Failed to load image for metadata removal'))\n img.src = url\n })\n\n const canvas = document.createElement('canvas')\n canvas.width = img.width\n canvas.height = img.height\n\n const ctx = canvas.getContext('2d')\n if (!ctx) {\n throw new Error('Failed to get canvas context')\n }\n ctx.drawImage(img, 0, 0)\n\n const cleanDataUrl = canvas.toDataURL(file.type, quality)\n if (cleanDataUrl === 'data:,') {\n return await fileToBase64Native(file)\n }\n\n return cleanDataUrl\n } finally {\n URL.revokeObjectURL(url)\n }\n } else {\n return await fileToBase64Native(file)\n }\n}\n","export function getCookie(name: string): string | undefined {\n for (const pair of document.cookie.split('; ')) {\n const separatorIndex = pair.indexOf('=')\n if (separatorIndex === -1) {\n continue\n }\n if (pair.slice(0, separatorIndex) === name) {\n return pair.slice(separatorIndex + 1)\n }\n }\n return undefined\n}\n","type ConsoleMethod = (...args: unknown[]) => void\ntype WindowLike = Window & typeof globalThis\n\nconst patchedWindows = new WeakMap<WindowLike, Set<string>>()\n\nexport function createConsoleDebugSwitch(targetWindow: WindowLike, options: { namespace: string }): void {\n if (!targetWindow) {\n return\n }\n\n const { namespace } = options\n\n let enabledNamespaces = patchedWindows.get(targetWindow)\n if (!enabledNamespaces) {\n enabledNamespaces = new Set<string>()\n patchedWindows.set(targetWindow, enabledNamespaces)\n\n const original = {\n log: targetWindow.console.log.bind(targetWindow.console),\n info: targetWindow.console.info.bind(targetWindow.console),\n warn: targetWindow.console.warn.bind(targetWindow.console),\n error: targetWindow.console.error.bind(targetWindow.console),\n }\n\n const conditional =\n (method: ConsoleMethod): ConsoleMethod =>\n (...args) => {\n if (enabledNamespaces!.size > 0) {\n method(...args)\n }\n }\n\n targetWindow.console.log = conditional(original.log)\n targetWindow.console.info = conditional(original.info)\n targetWindow.console.warn = conditional(original.warn)\n targetWindow.console.error = conditional(original.error)\n }\n\n type Namespace = { debug: (enabled: boolean) => void }\n const globals = targetWindow as unknown as Record<string, Namespace | undefined>\n const existing = Object.prototype.hasOwnProperty.call(globals, namespace)\n ? (Object.getOwnPropertyDescriptor(globals, namespace)?.value as Namespace | undefined)\n : undefined\n const target = existing ?? ({} as Namespace)\n target.debug = (flag: boolean) => {\n if (flag) {\n enabledNamespaces!.add(namespace)\n } else {\n enabledNamespaces!.delete(namespace)\n }\n }\n // Object.defineProperty (unlike a plain `globals[namespace] = target` assignment) always\n // creates/overwrites an own property, even when namespace is a name like \"__proto__\" that\n // would otherwise be intercepted by Object.prototype's special __proto__ accessor and\n // pollute the shared prototype instead of setting a property on this specific object.\n Object.defineProperty(globals, namespace, { value: target, writable: true, configurable: true, enumerable: true })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,UAAU,OAAO;AAQvB,SAAS,WAAc,KAAiB;AAC7C,SAAO;AACT;;;ACVO,SAAS,QAAW,OAAyC;AAClE,SAAO,UAAU,QAAQ,UAAU;AACrC;AAEA,SAAS,mBAAsB,OAAY,MAAqB;AAC9D,MAAI,SAAS,GAAG;AACd,WAAO,CAAC,CAAC,CAAC;AAAA,EACZ;AACA,MAAI,OAAO,MAAM,QAAQ;AACvB,WAAO,CAAC;AAAA,EACV;AACA,QAAM,CAAC,OAAO,GAAG,IAAI,IAAI;AACzB,QAAM,YAAY,mBAAmB,MAAM,OAAO,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,OAAO,GAAG,WAAW,CAAC;AACjG,QAAM,eAAe,mBAAmB,MAAM,IAAI;AAClD,SAAO,CAAC,GAAG,WAAW,GAAG,YAAY;AACvC;AAEO,SAAS,gBAAmB,SAAqB;AACtD,QAAM,SAAgB,CAAC;AACvB,WAAS,OAAO,GAAG,QAAQ,QAAQ,QAAQ,QAAQ;AACjD,WAAO,KAAK,GAAG,mBAAmB,SAAS,IAAI,CAAC;AAAA,EAClD;AACA,SAAO;AACT;;;ACvBO,SAAS,eACd,IACA,YACY;AACZ,aAAW,OAAO,OAAO,KAAK,UAAU,GAAG;AAKzC,WAAO,eAAe,IAAI,KAAK;A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EAAE,OAAO,QAAQ,UAAU,MAAM,cAAc,MAAM,YAAY,KAAK,CAAC;AACnH;","names":[]}
@@ -0,0 +1,62 @@
1
+ declare const getKeys: <T extends object>(obj: T) => Array<keyof T>;
2
+ type RecursivePartial<T> = {
3
+ [P in keyof T]?: RecursivePartial<T[P]>;
4
+ };
5
+ type RecursiveRecord = {
6
+ [key: string]: string | number | boolean | RecursiveRecord | Array<RecursiveRecord>;
7
+ };
8
+ declare function forcedType<T>(obj: unknown): T;
9
+
10
+ declare function notNone<T>(value: T | null | undefined): value is T;
11
+ declare function allCombinations<T>(options: T[]): T[][];
12
+
13
+ declare function withAttributes<Fn extends (...args: never[]) => unknown, Attrs extends Record<string, unknown>>(fn: Fn, attributes: Attrs): Fn & Attrs;
14
+ declare function makeCallable<T, R>(originalCallable: (arg: T) => R): (data: T) => () => R;
15
+ declare function getLazyValue<T>(input: T | (() => T)): T;
16
+ declare function getLazyValueAsync<T>(input: T | (() => Promise<T>) | (() => T)): Promise<T>;
17
+ declare function suppress<T, ERT>(exceptions: Array<new (message?: string) => Error>, fn: () => T, onError?: (error: unknown) => ERT): T | ERT | undefined;
18
+ declare function preventDefault<E extends Event, R>(callable: (event: E) => R): (event: E) => Promise<Awaited<R>>;
19
+ declare function isPathMatched(pathname: string, pattern: RegExp, exemptPatterns?: RegExp[]): boolean;
20
+ declare function raises(error: Error): (...args: unknown[]) => never;
21
+ declare function cloned<Fn extends (...args: never[]) => unknown>(fn: Fn): Fn;
22
+ declare function enabledIf<R>(condition: boolean | (() => boolean), options: {
23
+ ifNotEnabledReturnValue: R;
24
+ }): <Fn extends (...args: never[]) => R>(fn: Fn) => Fn;
25
+ declare function transformExceptions<E extends Error>(exceptionTypes: Array<new (...args: never[]) => E>, transform: (error: E) => Error, options?: {
26
+ keepOriginal?: boolean;
27
+ }): <Fn extends (...args: never[]) => unknown>(fn: Fn) => Fn;
28
+
29
+ declare function checkRequiredKeys<T extends Record<string, unknown>, C extends Record<string, Array<keyof T>>>(obj: T, conditions: C): keyof C;
30
+ declare function requireExclusiveKeys<T extends Record<string, unknown>, C extends Record<string, Array<keyof T>>>(conditions: C, options?: {
31
+ allowEmpty?: boolean;
32
+ }): <Fn extends (arg: T) => unknown>(fn: Fn) => Fn;
33
+ declare function setKeyValueToObjectIfValue(key: string, value: unknown, object: Record<string, unknown>): void;
34
+
35
+ declare function slugify(value: string, allowUnicode?: boolean): string;
36
+
37
+ declare const LONG_DATE_FORMAT = "EEEE, MMMM dd, yyyy 'at' hh:mm a";
38
+ declare const SHORT_DATE_FORMAT = "dd.MM.yyyy";
39
+ declare const SHORT_DATETIME_FORMAT = "dd.MM.yyyy HH:mm a";
40
+ declare function formattedDate(pattern: string, date?: Date): string;
41
+ declare function longFormattedDate(date?: Date): string;
42
+ declare function shortFormattedDate(date?: Date): string;
43
+ declare function shortFormattedDateTime(date?: Date): string;
44
+ declare function optionalDate(date?: string): Date | undefined;
45
+
46
+ type MimeType = 'image/png' | 'image/jpeg' | 'image/webp';
47
+ declare function guessImageMimeType(filename: string): MimeType;
48
+ declare function isImageMimeType(mimeType: string): mimeType is MimeType;
49
+ declare function escapeName(name: string): string;
50
+ declare function safeFileName(filename: string, maxLength?: number): string;
51
+ declare function downloadAndFormatImage(src: string, name?: string, mimeType?: MimeType, quality?: number): Promise<void>;
52
+ declare function fileToBase64Native(file: File): Promise<string>;
53
+ declare function fileToBase64(file: File, quality?: number): Promise<string>;
54
+
55
+ declare function getCookie(name: string): string | undefined;
56
+
57
+ type WindowLike = Window & typeof globalThis;
58
+ declare function createConsoleDebugSwitch(targetWindow: WindowLike, options: {
59
+ namespace: string;
60
+ }): void;
61
+
62
+ export { LONG_DATE_FORMAT, type RecursivePartial, type RecursiveRecord, SHORT_DATETIME_FORMAT, SHORT_DATE_FORMAT, allCombinations, checkRequiredKeys, cloned, createConsoleDebugSwitch, downloadAndFormatImage, enabledIf, escapeName, fileToBase64, fileToBase64Native, forcedType, formattedDate, getCookie, getKeys, getLazyValue, getLazyValueAsync, guessImageMimeType, isImageMimeType, isPathMatched, longFormattedDate, makeCallable, notNone, optionalDate, preventDefault, raises, requireExclusiveKeys, safeFileName, setKeyValueToObjectIfValue, shortFormattedDate, shortFormattedDateTime, slugify, suppress, transformExceptions, withAttributes };
@@ -0,0 +1,62 @@
1
+ declare const getKeys: <T extends object>(obj: T) => Array<keyof T>;
2
+ type RecursivePartial<T> = {
3
+ [P in keyof T]?: RecursivePartial<T[P]>;
4
+ };
5
+ type RecursiveRecord = {
6
+ [key: string]: string | number | boolean | RecursiveRecord | Array<RecursiveRecord>;
7
+ };
8
+ declare function forcedType<T>(obj: unknown): T;
9
+
10
+ declare function notNone<T>(value: T | null | undefined): value is T;
11
+ declare function allCombinations<T>(options: T[]): T[][];
12
+
13
+ declare function withAttributes<Fn extends (...args: never[]) => unknown, Attrs extends Record<string, unknown>>(fn: Fn, attributes: Attrs): Fn & Attrs;
14
+ declare function makeCallable<T, R>(originalCallable: (arg: T) => R): (data: T) => () => R;
15
+ declare function getLazyValue<T>(input: T | (() => T)): T;
16
+ declare function getLazyValueAsync<T>(input: T | (() => Promise<T>) | (() => T)): Promise<T>;
17
+ declare function suppress<T, ERT>(exceptions: Array<new (message?: string) => Error>, fn: () => T, onError?: (error: unknown) => ERT): T | ERT | undefined;
18
+ declare function preventDefault<E extends Event, R>(callable: (event: E) => R): (event: E) => Promise<Awaited<R>>;
19
+ declare function isPathMatched(pathname: string, pattern: RegExp, exemptPatterns?: RegExp[]): boolean;
20
+ declare function raises(error: Error): (...args: unknown[]) => never;
21
+ declare function cloned<Fn extends (...args: never[]) => unknown>(fn: Fn): Fn;
22
+ declare function enabledIf<R>(condition: boolean | (() => boolean), options: {
23
+ ifNotEnabledReturnValue: R;
24
+ }): <Fn extends (...args: never[]) => R>(fn: Fn) => Fn;
25
+ declare function transformExceptions<E extends Error>(exceptionTypes: Array<new (...args: never[]) => E>, transform: (error: E) => Error, options?: {
26
+ keepOriginal?: boolean;
27
+ }): <Fn extends (...args: never[]) => unknown>(fn: Fn) => Fn;
28
+
29
+ declare function checkRequiredKeys<T extends Record<string, unknown>, C extends Record<string, Array<keyof T>>>(obj: T, conditions: C): keyof C;
30
+ declare function requireExclusiveKeys<T extends Record<string, unknown>, C extends Record<string, Array<keyof T>>>(conditions: C, options?: {
31
+ allowEmpty?: boolean;
32
+ }): <Fn extends (arg: T) => unknown>(fn: Fn) => Fn;
33
+ declare function setKeyValueToObjectIfValue(key: string, value: unknown, object: Record<string, unknown>): void;
34
+
35
+ declare function slugify(value: string, allowUnicode?: boolean): string;
36
+
37
+ declare const LONG_DATE_FORMAT = "EEEE, MMMM dd, yyyy 'at' hh:mm a";
38
+ declare const SHORT_DATE_FORMAT = "dd.MM.yyyy";
39
+ declare const SHORT_DATETIME_FORMAT = "dd.MM.yyyy HH:mm a";
40
+ declare function formattedDate(pattern: string, date?: Date): string;
41
+ declare function longFormattedDate(date?: Date): string;
42
+ declare function shortFormattedDate(date?: Date): string;
43
+ declare function shortFormattedDateTime(date?: Date): string;
44
+ declare function optionalDate(date?: string): Date | undefined;
45
+
46
+ type MimeType = 'image/png' | 'image/jpeg' | 'image/webp';
47
+ declare function guessImageMimeType(filename: string): MimeType;
48
+ declare function isImageMimeType(mimeType: string): mimeType is MimeType;
49
+ declare function escapeName(name: string): string;
50
+ declare function safeFileName(filename: string, maxLength?: number): string;
51
+ declare function downloadAndFormatImage(src: string, name?: string, mimeType?: MimeType, quality?: number): Promise<void>;
52
+ declare function fileToBase64Native(file: File): Promise<string>;
53
+ declare function fileToBase64(file: File, quality?: number): Promise<string>;
54
+
55
+ declare function getCookie(name: string): string | undefined;
56
+
57
+ type WindowLike = Window & typeof globalThis;
58
+ declare function createConsoleDebugSwitch(targetWindow: WindowLike, options: {
59
+ namespace: string;
60
+ }): void;
61
+
62
+ export { LONG_DATE_FORMAT, type RecursivePartial, type RecursiveRecord, SHORT_DATETIME_FORMAT, SHORT_DATE_FORMAT, allCombinations, checkRequiredKeys, cloned, createConsoleDebugSwitch, downloadAndFormatImage, enabledIf, escapeName, fileToBase64, fileToBase64Native, forcedType, formattedDate, getCookie, getKeys, getLazyValue, getLazyValueAsync, guessImageMimeType, isImageMimeType, isPathMatched, longFormattedDate, makeCallable, notNone, optionalDate, preventDefault, raises, requireExclusiveKeys, safeFileName, setKeyValueToObjectIfValue, shortFormattedDate, shortFormattedDateTime, slugify, suppress, transformExceptions, withAttributes };