@isikk/core 0.4.0 → 0.7.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/configError-BtEWY-oE.d.ts +79 -0
- package/dist/drf/index.cjs +55 -0
- package/dist/drf/index.cjs.map +1 -0
- package/dist/drf/index.d.cts +27 -0
- package/dist/drf/index.d.ts +27 -0
- package/dist/drf/index.js +28 -0
- package/dist/drf/index.js.map +1 -0
- package/dist/hooks/index.cjs +18 -10
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.js +18 -10
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +7 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/next/config/browser.d.ts +6 -4
- package/dist/next/config/browser.js +62 -12
- package/dist/next/config/browser.js.map +1 -1
- package/dist/next/config/index.d.ts +7 -13
- package/dist/next/config/index.js +65 -15
- package/dist/next/config/index.js.map +1 -1
- package/dist/next/middleware/index.cjs.map +1 -1
- package/dist/next/middleware/index.js.map +1 -1
- package/dist/next/request/index.cjs.map +1 -1
- package/dist/next/request/index.d.cts +2 -4
- package/dist/next/request/index.d.ts +2 -4
- package/dist/next/request/index.js.map +1 -1
- package/dist/node/index.cjs +4 -3
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.js +4 -3
- package/dist/node/index.js.map +1 -1
- package/package.json +11 -2
- package/dist/shared-NQ6Ct9hr.d.ts +0 -37
package/dist/index.cjs.map
CHANGED
|
@@ -1 +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","../src/colors/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'\nexport * from './colors'\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\nexport interface SetCookieOptions {\n /** Days until the cookie expires. Omit for a session cookie (cleared when the browser closes). */\n days?: number\n path?: string\n}\n\nexport function setCookie(name: string, value: string, options: SetCookieOptions = {}): void {\n const { days, path = '/' } = options\n const expires = days === undefined ? '' : `; expires=${new Date(Date.now() + days * 86_400_000).toUTCString()}`\n document.cookie = `${name}=${value}${expires}; path=${path}`\n}\n\nexport function removeCookie(name: string, path: string = '/'): void {\n document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}`\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","export type TailwindShade = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950\n\nexport type TailwindColorScale = Record<TailwindShade, string>\n\ninterface Rgb {\n r: number\n g: number\n b: number\n}\n\nconst HEX_PATTERN = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i\n\nfunction hexToRgb(hex: string): Rgb {\n const match = HEX_PATTERN.exec(hex.trim())\n if (!match) {\n throw new Error(`Invalid hex color: \"${hex}\"`)\n }\n\n const digits = match[1]\n const normalized =\n digits.length === 3\n ? digits\n .split('')\n .map((char) => char + char)\n .join('')\n : digits\n\n return {\n r: parseInt(normalized.slice(0, 2), 16),\n g: parseInt(normalized.slice(2, 4), 16),\n b: parseInt(normalized.slice(4, 6), 16),\n }\n}\n\nfunction rgbToHex({ r, g, b }: Rgb): string {\n return `#${[r, g, b].map((channel) => Math.round(channel).toString(16).padStart(2, '0')).join('')}`\n}\n\nfunction mixRgb(base: Rgb, target: Rgb, weight: number): Rgb {\n return {\n r: base.r + (target.r - base.r) * weight,\n g: base.g + (target.g - base.g) * weight,\n b: base.b + (target.b - base.b) * weight,\n }\n}\n\nconst WHITE: Rgb = { r: 255, g: 255, b: 255 }\nconst BLACK: Rgb = { r: 0, g: 0, b: 0 }\n\n// Weight of white/black mixed into the base color at each shade, tuned so 500 is the input\n// color unchanged and the rest approximate the spread of Tailwind's own default palettes.\nconst TINT_WEIGHTS: Record<50 | 100 | 200 | 300 | 400, number> = { 50: 0.95, 100: 0.9, 200: 0.75, 300: 0.6, 400: 0.3 }\nconst SHADE_WEIGHTS: Record<600 | 700 | 800 | 900 | 950, number> = {\n 600: 0.15,\n 700: 0.3,\n 800: 0.45,\n 900: 0.6,\n 950: 0.8,\n}\n\n/**\n * Generates a Tailwind-style 50-950 color scale from a single base hex color, treated as the 500 shade.\n */\nexport function generateTailwindColorScale(baseColor: string): TailwindColorScale {\n const base = hexToRgb(baseColor)\n\n return {\n 50: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[50])),\n 100: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[100])),\n 200: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[200])),\n 300: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[300])),\n 400: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[400])),\n 500: rgbToHex(base),\n 600: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[600])),\n 700: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[700])),\n 800: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[800])),\n 900: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[900])),\n 950: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[950])),\n }\n}\n\n/**\n * Like {@link generateTailwindColorScale}, but prefixes each shade with `name` (e.g. `primary500`)\n * so multiple scales can be spread into one flat palette object.\n */\nexport function generateNamedTailwindColorScale<T extends string>(\n baseColor: string,\n name: T\n): Record<`${T}${TailwindShade}`, string> {\n const scale = generateTailwindColorScale(baseColor)\n\n return Object.fromEntries(Object.entries(scale).map(([shade, hex]) => [`${name}${shade}`, hex])) as Record<\n `${T}${TailwindShade}`,\n string\n >\n}\n\nfunction rgbToHsl({ r, g, b }: Rgb): { h: number; s: number; l: number } {\n const rN = r / 255\n const gN = g / 255\n const bN = b / 255\n\n const max = Math.max(rN, gN, bN)\n const min = Math.min(rN, gN, bN)\n const l = (max + min) / 2\n\n if (max === min) {\n return { h: 0, s: 0, l: l * 100 }\n }\n\n const delta = max - min\n const s = l > 0.5 ? delta / (2 - max - min) : delta / (max + min)\n\n let h: number\n if (max === rN) {\n h = ((gN - bN) / delta + (gN < bN ? 6 : 0)) * 60\n } else if (max === gN) {\n h = ((bN - rN) / delta + 2) * 60\n } else {\n h = ((rN - gN) / delta + 4) * 60\n }\n\n return { h, s: s * 100, l: l * 100 }\n}\n\n/**\n * Formats a hex color as the \"H S% L%\" triplet shadcn/Tailwind CSS variable themes expect,\n * e.g. for `--primary: 240 5.9% 10%;` consumed as `hsl(var(--primary))`.\n */\nexport function hexToHslTriplet(hex: string, precision: number = 1): string {\n const { h, s, l } = rgbToHsl(hexToRgb(hex))\n const round = (value: number) => Number(value.toFixed(precision))\n\n return `${round(h)} ${round(s)}% ${round(l)}%`\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;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,UAAU,OAA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,EAAE;AAC/B,QAAM,KAAK,MAAM,OAAO;AAExB,MAAI,QAAQ,KAAK;AACf,WAAO,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,IAAI;AAAA,EAClC;AAEA,QAAM,QAAQ,MAAM;AACpB,QAAM,IAAI,IAAI,MAAM,SAAS,IAAI,MAAM,OAAO,SAAS,MAAM;AAE7D,MAAI;AACJ,MAAI,QAAQ,IAAI;AACd,UAAM,KAAK,MAAM,SAAS,KAAK,KAAK,IAAI,MAAM;AAAA,EAChD,WAAW,QAAQ,IAAI;AACrB,UAAM,KAAK,MAAM,QAAQ,KAAK;AAAA,EAChC,OAAO;AACL,UAAM,KAAK,MAAM,QAAQ,KAAK;AAAA,EAChC;AAEA,SAAO,EAAE,GAAG,GAAG,IAAI,KAAK,GAAG,IAAI,IAAI;AACrC;AAMO,SAAS,gBAAgB,KAAa,YAAoB,GAAW;AAC1E,QAAM,EAAE,GAAG,GAAG,EAAE,IAAI,SAAS,SAAS,GAAG,CAAC;AAC1C,QAAM,QAAQ,CAAC,UAAkB,OAAO,MAAM,QAAQ,SAAS,CAAC;AAEhE,SAAO,GAAG,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;AAC7C;","names":[]}
|
|
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","../src/colors/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'\nexport * from './colors'\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 // Stryker disable next-line ConditionalExpression,BlockStatement: equivalent mutant. An async\n // function auto-adopts a returned thenable through the same resolution algorithm `await`\n // uses, so `return result` here resolves to the same value as `return await result` - the\n // only difference is an extra microtask tick, which isn't part of this function's contract.\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.normalize('NFKD')\n // eslint-disable-next-line no-control-regex\n value = value.replace(/[^\\x00-\\x7F]/g, '')\n // Stryker disable next-line Regex: equivalent mutant. The `+` quantifier is redundant with\n // the `[-\\s]+` -> '-' collapse below, which flattens a run of replaced newlines to a single\n // dash regardless of how many spaces this leaves - kept for clarity/intent, not correctness.\n value = value.replace(/[\\r\\n]+/g, ' ')\n // Stryker disable next-line MethodExpression: equivalent mutant. Redundant with the collapse\n // + trim below, which strips any whitespace this would have removed once it's converted to\n // leading/trailing dashes - kept for clarity/intent, not correctness.\n value = value.trim()\n value = value.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 // Stryker disable next-line OptionalChaining: equivalent mutant. String#split always returns at\n // least one element for any input (including ''), so .pop() here can never actually be\n // undefined - the `?.` exists only to satisfy Array#pop()'s TypeScript signature.\n const extension = withoutQueryOrHash.split('.').pop()?.toLowerCase()\n switch (extension) {\n // Stryker disable next-line StringLiteral: equivalent mutant. This case and `default` below\n // both return 'image/png', so no input can distinguish which of the two branches ran it.\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 // Stryker disable next-line MethodExpression: equivalent mutant. This branch only runs when\n // filename.length > maxLength, and escapeName preserves length, so\n // maxLength - extension.length < maxLength - (filename.length - dotIndex) = dotIndex always\n // holds. The slice below therefore never reads past index dotIndex, which is exactly where\n // filename and filename.slice(0, dotIndex) still agree - dropping the slice can't change it.\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\nexport interface SetCookieOptions {\n /** Days until the cookie expires. Omit for a session cookie (cleared when the browser closes). */\n days?: number\n path?: string\n}\n\nexport function setCookie(name: string, value: string, options: SetCookieOptions = {}): void {\n const { days, path = '/' } = options\n const expires = days === undefined ? '' : `; expires=${new Date(Date.now() + days * 86_400_000).toUTCString()}`\n document.cookie = `${name}=${value}${expires}; path=${path}`\n}\n\nexport function removeCookie(name: string, path: string = '/'): void {\n document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}`\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","export type TailwindShade = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950\n\nexport type TailwindColorScale = Record<TailwindShade, string>\n\ninterface Rgb {\n r: number\n g: number\n b: number\n}\n\nconst HEX_PATTERN = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i\n\nfunction hexToRgb(hex: string): Rgb {\n const match = HEX_PATTERN.exec(hex.trim())\n if (!match) {\n throw new Error(`Invalid hex color: \"${hex}\"`)\n }\n\n const digits = match[1]\n const normalized =\n digits.length === 3\n ? digits\n .split('')\n .map((char) => char + char)\n .join('')\n : digits\n\n return {\n r: parseInt(normalized.slice(0, 2), 16),\n g: parseInt(normalized.slice(2, 4), 16),\n b: parseInt(normalized.slice(4, 6), 16),\n }\n}\n\nfunction rgbToHex({ r, g, b }: Rgb): string {\n return `#${[r, g, b].map((channel) => Math.round(channel).toString(16).padStart(2, '0')).join('')}`\n}\n\nfunction mixRgb(base: Rgb, target: Rgb, weight: number): Rgb {\n return {\n r: base.r + (target.r - base.r) * weight,\n g: base.g + (target.g - base.g) * weight,\n b: base.b + (target.b - base.b) * weight,\n }\n}\n\nconst WHITE: Rgb = { r: 255, g: 255, b: 255 }\nconst BLACK: Rgb = { r: 0, g: 0, b: 0 }\n\n// Weight of white/black mixed into the base color at each shade, tuned so 500 is the input\n// color unchanged and the rest approximate the spread of Tailwind's own default palettes.\nconst TINT_WEIGHTS: Record<50 | 100 | 200 | 300 | 400, number> = { 50: 0.95, 100: 0.9, 200: 0.75, 300: 0.6, 400: 0.3 }\nconst SHADE_WEIGHTS: Record<600 | 700 | 800 | 900 | 950, number> = {\n 600: 0.15,\n 700: 0.3,\n 800: 0.45,\n 900: 0.6,\n 950: 0.8,\n}\n\n/**\n * Generates a Tailwind-style 50-950 color scale from a single base hex color, treated as the 500 shade.\n */\nexport function generateTailwindColorScale(baseColor: string): TailwindColorScale {\n const base = hexToRgb(baseColor)\n\n return {\n 50: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[50])),\n 100: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[100])),\n 200: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[200])),\n 300: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[300])),\n 400: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[400])),\n 500: rgbToHex(base),\n 600: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[600])),\n 700: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[700])),\n 800: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[800])),\n 900: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[900])),\n 950: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[950])),\n }\n}\n\n/**\n * Like {@link generateTailwindColorScale}, but prefixes each shade with `name` (e.g. `primary500`)\n * so multiple scales can be spread into one flat palette object.\n */\nexport function generateNamedTailwindColorScale<T extends string>(\n baseColor: string,\n name: T\n): Record<`${T}${TailwindShade}`, string> {\n const scale = generateTailwindColorScale(baseColor)\n\n return Object.fromEntries(Object.entries(scale).map(([shade, hex]) => [`${name}${shade}`, hex])) as Record<\n `${T}${TailwindShade}`,\n string\n >\n}\n\nfunction rgbToHsl({ r, g, b }: Rgb): { h: number; s: number; l: number } {\n const rN = r / 255\n const gN = g / 255\n const bN = b / 255\n\n const max = Math.max(rN, gN, bN)\n const min = Math.min(rN, gN, bN)\n const l = (max + min) / 2\n\n if (max === min) {\n return { h: 0, s: 0, l: l * 100 }\n }\n\n const delta = max - min\n // Stryker disable next-line EqualityOperator: equivalent mutant. l === 0.5 iff max + min === 1,\n // in which case 2 - max - min === max + min too, so both branches compute the same value and\n // no test can ever distinguish `>` from `>=` here.\n const s = l > 0.5 ? delta / (2 - max - min) : delta / (max + min)\n\n let h: number\n if (max === rN) {\n h = ((gN - bN) / delta + (gN < bN ? 6 : 0)) * 60\n } else if (max === gN) {\n h = ((bN - rN) / delta + 2) * 60\n } else {\n h = ((rN - gN) / delta + 4) * 60\n }\n\n return { h, s: s * 100, l: l * 100 }\n}\n\n/**\n * Formats a hex color as the \"H S% L%\" triplet shadcn/Tailwind CSS variable themes expect,\n * e.g. for `--primary: 240 5.9% 10%;` consumed as `hsl(var(--primary))`.\n */\nexport function hexToHslTriplet(hex: string, precision: number = 1): string {\n const { h, s, l } = rgbToHsl(hexToRgb(hex))\n const round = (value: number) => Number(value.toFixed(precision))\n\n return `${round(h)} ${round(s)}% ${round(l)}%`\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;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,gB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AAAA,EAChC;AAEA,SAAO,EAAE,GAAG,GAAG,IAAI,KAAK,GAAG,IAAI,IAAI;AACrC;AAMO,SAAS,gBAAgB,KAAa,YAAoB,GAAW;AAC1E,QAAM,EAAE,GAAG,GAAG,EAAE,IAAI,SAAS,SAAS,GAAG,CAAC;AAC1C,QAAM,QAAQ,CAAC,UAAkB,OAAO,MAAM,QAAQ,SAAS,CAAC;AAEhE,SAAO,GAAG,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;AAC7C;","names":[]}
|
package/dist/index.js
CHANGED
|
@@ -164,7 +164,11 @@ function slugify(value, allowUnicode = false) {
|
|
|
164
164
|
if (allowUnicode) {
|
|
165
165
|
value = value.normalize("NFKC").replace(/[^\p{L}\p{N}_\s-]/gu, "");
|
|
166
166
|
} else {
|
|
167
|
-
value = value.normalize("NFKD")
|
|
167
|
+
value = value.normalize("NFKD");
|
|
168
|
+
value = value.replace(/[^\x00-\x7F]/g, "");
|
|
169
|
+
value = value.replace(/[\r\n]+/g, " ");
|
|
170
|
+
value = value.trim();
|
|
171
|
+
value = value.replace(/[^\w\s-]/g, "");
|
|
168
172
|
}
|
|
169
173
|
value = value.toLowerCase();
|
|
170
174
|
return value.replace(/[-\s]+/g, "-").replace(/^[-_]+|[-_]+$/g, "");
|
|
@@ -201,6 +205,8 @@ function guessImageMimeType(filename) {
|
|
|
201
205
|
const withoutQueryOrHash = filename.split(/[?#]/)[0];
|
|
202
206
|
const extension = withoutQueryOrHash.split(".").pop()?.toLowerCase();
|
|
203
207
|
switch (extension) {
|
|
208
|
+
// Stryker disable next-line StringLiteral: equivalent mutant. This case and `default` below
|
|
209
|
+
// both return 'image/png', so no input can distinguish which of the two branches ran it.
|
|
204
210
|
case "png":
|
|
205
211
|
return "image/png";
|
|
206
212
|
case "jfif":
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../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","../src/colors/index.ts"],"sourcesContent":["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\nexport interface SetCookieOptions {\n /** Days until the cookie expires. Omit for a session cookie (cleared when the browser closes). */\n days?: number\n path?: string\n}\n\nexport function setCookie(name: string, value: string, options: SetCookieOptions = {}): void {\n const { days, path = '/' } = options\n const expires = days === undefined ? '' : `; expires=${new Date(Date.now() + days * 86_400_000).toUTCString()}`\n document.cookie = `${name}=${value}${expires}; path=${path}`\n}\n\nexport function removeCookie(name: string, path: string = '/'): void {\n document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}`\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","export type TailwindShade = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950\n\nexport type TailwindColorScale = Record<TailwindShade, string>\n\ninterface Rgb {\n r: number\n g: number\n b: number\n}\n\nconst HEX_PATTERN = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i\n\nfunction hexToRgb(hex: string): Rgb {\n const match = HEX_PATTERN.exec(hex.trim())\n if (!match) {\n throw new Error(`Invalid hex color: \"${hex}\"`)\n }\n\n const digits = match[1]\n const normalized =\n digits.length === 3\n ? digits\n .split('')\n .map((char) => char + char)\n .join('')\n : digits\n\n return {\n r: parseInt(normalized.slice(0, 2), 16),\n g: parseInt(normalized.slice(2, 4), 16),\n b: parseInt(normalized.slice(4, 6), 16),\n }\n}\n\nfunction rgbToHex({ r, g, b }: Rgb): string {\n return `#${[r, g, b].map((channel) => Math.round(channel).toString(16).padStart(2, '0')).join('')}`\n}\n\nfunction mixRgb(base: Rgb, target: Rgb, weight: number): Rgb {\n return {\n r: base.r + (target.r - base.r) * weight,\n g: base.g + (target.g - base.g) * weight,\n b: base.b + (target.b - base.b) * weight,\n }\n}\n\nconst WHITE: Rgb = { r: 255, g: 255, b: 255 }\nconst BLACK: Rgb = { r: 0, g: 0, b: 0 }\n\n// Weight of white/black mixed into the base color at each shade, tuned so 500 is the input\n// color unchanged and the rest approximate the spread of Tailwind's own default palettes.\nconst TINT_WEIGHTS: Record<50 | 100 | 200 | 300 | 400, number> = { 50: 0.95, 100: 0.9, 200: 0.75, 300: 0.6, 400: 0.3 }\nconst SHADE_WEIGHTS: Record<600 | 700 | 800 | 900 | 950, number> = {\n 600: 0.15,\n 700: 0.3,\n 800: 0.45,\n 900: 0.6,\n 950: 0.8,\n}\n\n/**\n * Generates a Tailwind-style 50-950 color scale from a single base hex color, treated as the 500 shade.\n */\nexport function generateTailwindColorScale(baseColor: string): TailwindColorScale {\n const base = hexToRgb(baseColor)\n\n return {\n 50: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[50])),\n 100: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[100])),\n 200: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[200])),\n 300: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[300])),\n 400: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[400])),\n 500: rgbToHex(base),\n 600: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[600])),\n 700: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[700])),\n 800: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[800])),\n 900: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[900])),\n 950: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[950])),\n }\n}\n\n/**\n * Like {@link generateTailwindColorScale}, but prefixes each shade with `name` (e.g. `primary500`)\n * so multiple scales can be spread into one flat palette object.\n */\nexport function generateNamedTailwindColorScale<T extends string>(\n baseColor: string,\n name: T\n): Record<`${T}${TailwindShade}`, string> {\n const scale = generateTailwindColorScale(baseColor)\n\n return Object.fromEntries(Object.entries(scale).map(([shade, hex]) => [`${name}${shade}`, hex])) as Record<\n `${T}${TailwindShade}`,\n string\n >\n}\n\nfunction rgbToHsl({ r, g, b }: Rgb): { h: number; s: number; l: number } {\n const rN = r / 255\n const gN = g / 255\n const bN = b / 255\n\n const max = Math.max(rN, gN, bN)\n const min = Math.min(rN, gN, bN)\n const l = (max + min) / 2\n\n if (max === min) {\n return { h: 0, s: 0, l: l * 100 }\n }\n\n const delta = max - min\n const s = l > 0.5 ? delta / (2 - max - min) : delta / (max + min)\n\n let h: number\n if (max === rN) {\n h = ((gN - bN) / delta + (gN < bN ? 6 : 0)) * 60\n } else if (max === gN) {\n h = ((bN - rN) / delta + 2) * 60\n } else {\n h = ((rN - gN) / delta + 4) * 60\n }\n\n return { h, s: s * 100, l: l * 100 }\n}\n\n/**\n * Formats a hex color as the \"H S% L%\" triplet shadcn/Tailwind CSS variable themes expect,\n * e.g. for `--primary: 240 5.9% 10%;` consumed as `hsl(var(--primary))`.\n */\nexport function hexToHslTriplet(hex: string, precision: number = 1): string {\n const { h, s, l } = rgbToHsl(hexToRgb(hex))\n const round = (value: number) => Number(value.toFixed(precision))\n\n return `${round(h)} ${round(s)}% ${round(l)}%`\n}\n"],"mappings":";AAAO,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;A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AO,SAAS,MAAM;AAE7D,MAAI;AACJ,MAAI,QAAQ,IAAI;AACd,UAAM,KAAK,MAAM,SAAS,KAAK,KAAK,IAAI,MAAM;AAAA,EAChD,WAAW,QAAQ,IAAI;AACrB,UAAM,KAAK,MAAM,QAAQ,KAAK;AAAA,EAChC,OAAO;AACL,UAAM,KAAK,MAAM,QAAQ,KAAK;AAAA,EAChC;AAEA,SAAO,EAAE,GAAG,GAAG,IAAI,KAAK,GAAG,IAAI,IAAI;AACrC;AAMO,SAAS,gBAAgB,KAAa,YAAoB,GAAW;AAC1E,QAAM,EAAE,GAAG,GAAG,EAAE,IAAI,SAAS,SAAS,GAAG,CAAC;AAC1C,QAAM,QAAQ,CAAC,UAAkB,OAAO,MAAM,QAAQ,SAAS,CAAC;AAEhE,SAAO,GAAG,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;AAC7C;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../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","../src/colors/index.ts"],"sourcesContent":["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 // Stryker disable next-line ConditionalExpression,BlockStatement: equivalent mutant. An async\n // function auto-adopts a returned thenable through the same resolution algorithm `await`\n // uses, so `return result` here resolves to the same value as `return await result` - the\n // only difference is an extra microtask tick, which isn't part of this function's contract.\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.normalize('NFKD')\n // eslint-disable-next-line no-control-regex\n value = value.replace(/[^\\x00-\\x7F]/g, '')\n // Stryker disable next-line Regex: equivalent mutant. The `+` quantifier is redundant with\n // the `[-\\s]+` -> '-' collapse below, which flattens a run of replaced newlines to a single\n // dash regardless of how many spaces this leaves - kept for clarity/intent, not correctness.\n value = value.replace(/[\\r\\n]+/g, ' ')\n // Stryker disable next-line MethodExpression: equivalent mutant. Redundant with the collapse\n // + trim below, which strips any whitespace this would have removed once it's converted to\n // leading/trailing dashes - kept for clarity/intent, not correctness.\n value = value.trim()\n value = value.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 // Stryker disable next-line OptionalChaining: equivalent mutant. String#split always returns at\n // least one element for any input (including ''), so .pop() here can never actually be\n // undefined - the `?.` exists only to satisfy Array#pop()'s TypeScript signature.\n const extension = withoutQueryOrHash.split('.').pop()?.toLowerCase()\n switch (extension) {\n // Stryker disable next-line StringLiteral: equivalent mutant. This case and `default` below\n // both return 'image/png', so no input can distinguish which of the two branches ran it.\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 // Stryker disable next-line MethodExpression: equivalent mutant. This branch only runs when\n // filename.length > maxLength, and escapeName preserves length, so\n // maxLength - extension.length < maxLength - (filename.length - dotIndex) = dotIndex always\n // holds. The slice below therefore never reads past index dotIndex, which is exactly where\n // filename and filename.slice(0, dotIndex) still agree - dropping the slice can't change it.\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\nexport interface SetCookieOptions {\n /** Days until the cookie expires. Omit for a session cookie (cleared when the browser closes). */\n days?: number\n path?: string\n}\n\nexport function setCookie(name: string, value: string, options: SetCookieOptions = {}): void {\n const { days, path = '/' } = options\n const expires = days === undefined ? '' : `; expires=${new Date(Date.now() + days * 86_400_000).toUTCString()}`\n document.cookie = `${name}=${value}${expires}; path=${path}`\n}\n\nexport function removeCookie(name: string, path: string = '/'): void {\n document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}`\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","export type TailwindShade = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950\n\nexport type TailwindColorScale = Record<TailwindShade, string>\n\ninterface Rgb {\n r: number\n g: number\n b: number\n}\n\nconst HEX_PATTERN = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i\n\nfunction hexToRgb(hex: string): Rgb {\n const match = HEX_PATTERN.exec(hex.trim())\n if (!match) {\n throw new Error(`Invalid hex color: \"${hex}\"`)\n }\n\n const digits = match[1]\n const normalized =\n digits.length === 3\n ? digits\n .split('')\n .map((char) => char + char)\n .join('')\n : digits\n\n return {\n r: parseInt(normalized.slice(0, 2), 16),\n g: parseInt(normalized.slice(2, 4), 16),\n b: parseInt(normalized.slice(4, 6), 16),\n }\n}\n\nfunction rgbToHex({ r, g, b }: Rgb): string {\n return `#${[r, g, b].map((channel) => Math.round(channel).toString(16).padStart(2, '0')).join('')}`\n}\n\nfunction mixRgb(base: Rgb, target: Rgb, weight: number): Rgb {\n return {\n r: base.r + (target.r - base.r) * weight,\n g: base.g + (target.g - base.g) * weight,\n b: base.b + (target.b - base.b) * weight,\n }\n}\n\nconst WHITE: Rgb = { r: 255, g: 255, b: 255 }\nconst BLACK: Rgb = { r: 0, g: 0, b: 0 }\n\n// Weight of white/black mixed into the base color at each shade, tuned so 500 is the input\n// color unchanged and the rest approximate the spread of Tailwind's own default palettes.\nconst TINT_WEIGHTS: Record<50 | 100 | 200 | 300 | 400, number> = { 50: 0.95, 100: 0.9, 200: 0.75, 300: 0.6, 400: 0.3 }\nconst SHADE_WEIGHTS: Record<600 | 700 | 800 | 900 | 950, number> = {\n 600: 0.15,\n 700: 0.3,\n 800: 0.45,\n 900: 0.6,\n 950: 0.8,\n}\n\n/**\n * Generates a Tailwind-style 50-950 color scale from a single base hex color, treated as the 500 shade.\n */\nexport function generateTailwindColorScale(baseColor: string): TailwindColorScale {\n const base = hexToRgb(baseColor)\n\n return {\n 50: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[50])),\n 100: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[100])),\n 200: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[200])),\n 300: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[300])),\n 400: rgbToHex(mixRgb(base, WHITE, TINT_WEIGHTS[400])),\n 500: rgbToHex(base),\n 600: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[600])),\n 700: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[700])),\n 800: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[800])),\n 900: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[900])),\n 950: rgbToHex(mixRgb(base, BLACK, SHADE_WEIGHTS[950])),\n }\n}\n\n/**\n * Like {@link generateTailwindColorScale}, but prefixes each shade with `name` (e.g. `primary500`)\n * so multiple scales can be spread into one flat palette object.\n */\nexport function generateNamedTailwindColorScale<T extends string>(\n baseColor: string,\n name: T\n): Record<`${T}${TailwindShade}`, string> {\n const scale = generateTailwindColorScale(baseColor)\n\n return Object.fromEntries(Object.entries(scale).map(([shade, hex]) => [`${name}${shade}`, hex])) as Record<\n `${T}${TailwindShade}`,\n string\n >\n}\n\nfunction rgbToHsl({ r, g, b }: Rgb): { h: number; s: number; l: number } {\n const rN = r / 255\n const gN = g / 255\n const bN = b / 255\n\n const max = Math.max(rN, gN, bN)\n const min = Math.min(rN, gN, bN)\n const l = (max + min) / 2\n\n if (max === min) {\n return { h: 0, s: 0, l: l * 100 }\n }\n\n const delta = max - min\n // Stryker disable next-line EqualityOperator: equivalent mutant. l === 0.5 iff max + min === 1,\n // in which case 2 - max - min === max + min too, so both branches compute the same value and\n // no test can ever distinguish `>` from `>=` here.\n const s = l > 0.5 ? delta / (2 - max - min) : delta / (max + min)\n\n let h: number\n if (max === rN) {\n h = ((gN - bN) / delta + (gN < bN ? 6 : 0)) * 60\n } else if (max === gN) {\n h = ((bN - rN) / delta + 2) * 60\n } else {\n h = ((rN - gN) / delta + 4) * 60\n }\n\n return { h, s: s * 100, l: l * 100 }\n}\n\n/**\n * Formats a hex color as the \"H S% L%\" triplet shadcn/Tailwind CSS variable themes expect,\n * e.g. for `--primary: 240 5.9% 10%;` consumed as `hsl(var(--primary))`.\n */\nexport function hexToHslTriplet(hex: string, precision: number = 1): string {\n const { h, s, l } = rgbToHsl(hexToRgb(hex))\n const round = (value: number) => Number(value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vE,QAAM,KAAK,IAAI;AACf,QAAM,KAAK,IAAI;AACf,QAAM,KAAK,IAAI;AAEf,QAAM,MAAM,KAAK,IAAI,IAAI,IAAI,EAAE;AAC/B,QAAM,MAAM,KAAK,IAAI,IAAI,IAAI,EAAE;AAC/B,QAAM,KAAK,MAAM,OAAO;AAExB,MAAI,QAAQ,KAAK;AACf,WAAO,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,IAAI;AAAA,EAClC;AAEA,QAAM,QAAQ,MAAM;AAIpB,QAAM,IAAI,IAAI,MAAM,SAAS,IAAI,MAAM,OAAO,SAAS,MAAM;AAE7D,MAAI;AACJ,MAAI,QAAQ,IAAI;AACd,UAAM,KAAK,MAAM,SAAS,KAAK,KAAK,IAAI,MAAM;AAAA,EAChD,WAAW,QAAQ,IAAI;AACrB,UAAM,KAAK,MAAM,QAAQ,KAAK;AAAA,EAChC,OAAO;AACL,UAAM,KAAK,MAAM,QAAQ,KAAK;AAAA,EAChC;AAEA,SAAO,EAAE,GAAG,GAAG,IAAI,KAAK,GAAG,IAAI,IAAI;AACrC;AAMO,SAAS,gBAAgB,KAAa,YAAoB,GAAW;AAC1E,QAAM,EAAE,GAAG,GAAG,EAAE,IAAI,SAAS,SAAS,GAAG,CAAC;AAC1C,QAAM,QAAQ,CAAC,UAAkB,OAAO,MAAM,QAAQ,SAAS,CAAC;AAEhE,SAAO,GAAG,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;AAC7C;","names":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { C as ConfigSchema, P as PublicConfigOptions, a as PublicConfig } from '../../
|
|
1
|
+
import { C as ConfigSchema, P as PublicConfigOptions, a as PublicConfig } from '../../configError-BtEWY-oE.js';
|
|
2
|
+
export { b as Caster, c as ConfigError, I as InferConfig, d as PublicConfigScriptComponent, e as PublicConfigScriptProps, f as boolean, g as caster, h as commaSeparatedFloatList, i as commaSeparatedIntList, j as commaSeparatedList, k as float, l as integer, s as string } from '../../configError-BtEWY-oE.js';
|
|
2
3
|
import 'react';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -11,8 +12,9 @@ import 'react';
|
|
|
11
12
|
* The schema argument is accepted and ignored - values arrive already cast, through the injected
|
|
12
13
|
* global. It stays in the signature so `InferConfig<S>` produces the identical type on both
|
|
13
14
|
* sides, which is what lets one `app/config.ts` be imported by server and client components
|
|
14
|
-
* alike.
|
|
15
|
+
* alike. `options.globalKey` is not ignored: it is the only thing this half needs, and it is read
|
|
16
|
+
* from the same options object the server half was given.
|
|
15
17
|
*/
|
|
16
|
-
declare function publicConfig<S extends ConfigSchema>(_schema: S, options
|
|
18
|
+
declare function publicConfig<S extends ConfigSchema>(_schema: S, options: PublicConfigOptions): PublicConfig<S>;
|
|
17
19
|
|
|
18
|
-
export { publicConfig };
|
|
20
|
+
export { ConfigSchema, PublicConfig, PublicConfigOptions, publicConfig };
|
|
@@ -3,16 +3,14 @@ var ConfigError = class extends Error {
|
|
|
3
3
|
};
|
|
4
4
|
|
|
5
5
|
// src/next/config/shared.ts
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return options.globalKey;
|
|
6
|
+
function requireGlobalKey(options) {
|
|
7
|
+
const { globalKey } = options;
|
|
8
|
+
if (typeof globalKey !== "string" || globalKey === "") {
|
|
9
|
+
throw new ConfigError(
|
|
10
|
+
'publicConfig: globalKey is required and must be a non-empty string - it names the window property the config is injected under, e.g. { globalKey: "__MY_APP_CONFIG__" }. There is no default, so the name is yours and two configs cannot collide on one neither of them chose.'
|
|
11
|
+
);
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
return prefix === "" ? GLOBAL_KEY_BASE : `${GLOBAL_KEY_BASE}${prefix}__`;
|
|
13
|
+
return globalKey;
|
|
16
14
|
}
|
|
17
15
|
function memoize(resolve) {
|
|
18
16
|
let value;
|
|
@@ -37,9 +35,52 @@ function lazyConfigProxy(resolve) {
|
|
|
37
35
|
});
|
|
38
36
|
}
|
|
39
37
|
|
|
38
|
+
// src/node/casters.ts
|
|
39
|
+
function caster(fn) {
|
|
40
|
+
return function(options = {}) {
|
|
41
|
+
const clone = ((value) => fn(value));
|
|
42
|
+
if ("missingDefault" in options) {
|
|
43
|
+
clone.missingDefault = options.missingDefault;
|
|
44
|
+
}
|
|
45
|
+
if ("errorDefault" in options) {
|
|
46
|
+
clone.errorDefault = options.errorDefault;
|
|
47
|
+
}
|
|
48
|
+
return clone;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function parseStrictInteger(value) {
|
|
52
|
+
if (value.trim() === "" || !Number.isInteger(Number(value))) {
|
|
53
|
+
throw new Error(`Value ${JSON.stringify(value)} can not be parsed into an integer.`);
|
|
54
|
+
}
|
|
55
|
+
return Number(value);
|
|
56
|
+
}
|
|
57
|
+
function parseStrictFloat(value) {
|
|
58
|
+
if (value.trim() === "" || Number.isNaN(Number(value))) {
|
|
59
|
+
throw new Error(`Value ${JSON.stringify(value)} can not be parsed into a float.`);
|
|
60
|
+
}
|
|
61
|
+
return Number(value);
|
|
62
|
+
}
|
|
63
|
+
var string = caster((value) => value);
|
|
64
|
+
var integer = caster(parseStrictInteger);
|
|
65
|
+
var float = caster(parseStrictFloat);
|
|
66
|
+
var boolean = caster((value) => {
|
|
67
|
+
const truthy = ["true", "True", "1"];
|
|
68
|
+
const falsy = ["false", "False", "0"];
|
|
69
|
+
if (truthy.includes(value)) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
if (falsy.includes(value)) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
throw new Error(`Value ${JSON.stringify(value)} can not be parsed into a boolean.`);
|
|
76
|
+
});
|
|
77
|
+
var commaSeparatedList = caster((value) => value.split(","));
|
|
78
|
+
var commaSeparatedIntList = caster((value) => value.split(",").map(parseStrictInteger));
|
|
79
|
+
var commaSeparatedFloatList = caster((value) => value.split(",").map(parseStrictFloat));
|
|
80
|
+
|
|
40
81
|
// src/next/config/browser.ts
|
|
41
|
-
function publicConfig(_schema, options
|
|
42
|
-
const globalKey =
|
|
82
|
+
function publicConfig(_schema, options) {
|
|
83
|
+
const globalKey = requireGlobalKey(options);
|
|
43
84
|
return {
|
|
44
85
|
CONFIG: lazyConfigProxy(memoize(() => readInjectedConfig(globalKey))),
|
|
45
86
|
// Injection is a server-render concern; there is nothing to emit once the document exists.
|
|
@@ -56,6 +97,15 @@ function readInjectedConfig(globalKey) {
|
|
|
56
97
|
return injected;
|
|
57
98
|
}
|
|
58
99
|
export {
|
|
59
|
-
|
|
100
|
+
ConfigError,
|
|
101
|
+
boolean,
|
|
102
|
+
caster,
|
|
103
|
+
commaSeparatedFloatList,
|
|
104
|
+
commaSeparatedIntList,
|
|
105
|
+
commaSeparatedList,
|
|
106
|
+
float,
|
|
107
|
+
integer,
|
|
108
|
+
publicConfig,
|
|
109
|
+
string
|
|
60
110
|
};
|
|
61
111
|
//# sourceMappingURL=browser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/node/configError.ts","../../../src/next/config/shared.ts","../../../src/next/config/browser.ts"],"sourcesContent":["/**\n * Isolated in its own module - with no `process.env` access anywhere in it - so that the browser\n * half of `@isikk/core/next/config` can throw the same error type without importing\n * anything that reads the environment. Keeping the split structural means the guarantee holds\n * because of what the file contains, not because a bundler happened to tree-shake it away.\n */\nexport class ConfigError extends Error {}\n","import type { ReactNode } from 'react'\n\nimport type { ConfigSchema, InferConfig } from '../../node/configCore'\nimport { ConfigError } from '../../node/configError'\n\nexport interface PublicConfigOptions {\n /** Prepended to every environment variable name this call reads, joined with `sep`. */\n prefix?: string\n /** Joins the prefix and the nested key path into a variable name. Defaults to `\"__\"`. */\n sep?: string\n /**\n * The property the payload is injected under on `window`. Defaults to a name derived from\n * `prefix`. Set it to run two public configs off one prefix, to keep two copies of the package\n * in one page from reading each other's payload, or just to own the name yourself.\n */\n globalKey?: string\n}\n\nexport interface PublicConfigScriptProps {\n /** Forwarded to the injected `<script>` so a CSP with a per-request nonce keeps working. */\n nonce?: string\n}\n\nexport type PublicConfigScriptComponent = (props: PublicConfigScriptProps) => ReactNode | Promise<ReactNode>\n\nexport interface PublicConfig<S extends ConfigSchema> {\n CONFIG: InferConfig<S>\n PublicConfigScript: PublicConfigScriptComponent\n}\n\nexport const GLOBAL_KEY_BASE = '__ISIK_PUBLIC_CONFIG__'\n\n/**\n * Decides the property the payload is injected under, from an explicit `globalKey` or else from\n * `prefix` - which namespaces the default, so two `publicConfig()` calls on different prefixes\n * land on different properties instead of the second one silently declining to overwrite the\n * first.\n *\n * Both halves of the module resolve the key through this one function, from the same options\n * object: the schema and options live at a single call site in the consuming app, and only the\n * library import flips between builds. That is what makes the two sides agree by construction -\n * a server that wrote one key and a browser that read another would fail with nothing to point\n * at.\n *\n * No character restrictions: the key is emitted as an escaped string literal and read back with\n * bracket notation, so anything goes. An empty string is rejected only because it is far more\n * likely to be an accident than an intent.\n */\nexport function resolveGlobalKey(options: PublicConfigOptions): string {\n if (options.globalKey !== undefined) {\n if (options.globalKey === '') {\n throw new ConfigError('publicConfig: globalKey cannot be an empty string. Omit it to derive one from prefix.')\n }\n return options.globalKey\n }\n\n const prefix = options.prefix ?? ''\n return prefix === '' ? GLOBAL_KEY_BASE : `${GLOBAL_KEY_BASE}${prefix}__`\n}\n\n/**\n * Encodes a string as a JavaScript string literal that is safe to interpolate into a `<script>`\n * body. `JSON.stringify` alone is not: `</script>` inside a value closes the tag early and drops\n * the rest of the payload into the document as markup, and U+2028/U+2029 are literal line\n * terminators in JavaScript source, so a value containing one produces a syntax error. Escaping\n * `<` covers the first (the sequence can no longer be written) and the two explicit replacements\n * cover the second. `>` and `&` need no handling - a script element is raw text, so nothing in it\n * is parsed as markup or entities once `<` can't start a closing tag.\n */\nexport function jsStringLiteral(value: string): string {\n return JSON.stringify(value)\n .replace(/</g, '\\\\u003c')\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029')\n}\n\n/**\n * The script that hands the resolved config to the browser. Values travel as a JSON string parsed\n * at runtime rather than as an object literal: it parses faster than equivalent JS source, and it\n * narrows everything that needs escaping down to the single quoted string handled above.\n *\n * The definition is deep-frozen and non-writable, so nothing can reshape config after hydration,\n * and re-entrant if the script somehow runs twice - redefining a non-configurable property would\n * throw, so an existing key means there is nothing left to do.\n */\nexport function serializePublicConfigScript(key: string, value: unknown): string {\n return (\n '(function(w,k,v){if(k in w)return;' +\n 'var f=function(o){if(o&&typeof o==\"object\"){for(var p in o)f(o[p]);Object.freeze(o)}};' +\n 'f(v);Object.defineProperty(w,k,{value:v,enumerable:true})})' +\n `(window,${jsStringLiteral(key)},JSON.parse(${jsStringLiteral(JSON.stringify(value))}))`\n )\n}\n\nexport function memoize<T>(resolve: () => T): () => T {\n let value: T\n let resolved = false\n return () => {\n if (!resolved) {\n value = resolve()\n resolved = true\n }\n return value\n }\n}\n\n/**\n * Presents `resolve()`'s result as a plain object without calling it until something is actually\n * read. That deferral is load-bearing on both sides of the package. On the server it keeps\n * `next build` from resolving anything while collecting page data, so a missing variable no\n * longer fails the build - \"can this build\" stops depending on \"is this configured\". In the\n * browser it means the injected global is read at access time rather than at chunk-evaluation\n * time, so an async chunk that happens to run before the inline script still sees the config.\n */\nexport function lazyConfigProxy<T>(resolve: () => T): T {\n return new Proxy({} as object, {\n get: (_target, property) => Reflect.get(resolve() as object, property),\n has: (_target, property) => Reflect.has(resolve() as object, property),\n ownKeys: () => Reflect.ownKeys(resolve() as object),\n getOwnPropertyDescriptor: (_target, property) => {\n const descriptor = Reflect.getOwnPropertyDescriptor(resolve() as object, property)\n // The proxy target is an empty object, and a proxy may not report a non-configurable\n // property that its target doesn't have - so re-mark descriptors as configurable, or\n // Object.keys()/JSON.stringify() over the config throw a TypeError.\n return descriptor === undefined ? undefined : { ...descriptor, configurable: true }\n },\n }) as T\n}\n","import type { ConfigSchema, InferConfig } from '../../node/configCore'\nimport { ConfigError } from '../../node/configError'\nimport { type PublicConfig, type PublicConfigOptions, lazyConfigProxy, memoize, resolveGlobalKey } from './shared'\n\n/**\n * The browser half of `publicConfig()`, substituted for the server module by the `browser`\n * export condition in package.json rather than branched to at runtime. That substitution is what\n * makes the split safe: this file contains no reference to `process.env` at all, so bundling the\n * config module for the client cannot ship a server value no matter what the schema says. It is a\n * property of what the file contains, not a discipline anyone has to maintain.\n *\n * The schema argument is accepted and ignored - values arrive already cast, through the injected\n * global. It stays in the signature so `InferConfig<S>` produces the identical type on both\n * sides, which is what lets one `app/config.ts` be imported by server and client components\n * alike.\n */\nexport function publicConfig<S extends ConfigSchema>(_schema: S, options: PublicConfigOptions = {}): PublicConfig<S> {\n const globalKey = resolveGlobalKey(options)\n\n return {\n CONFIG: lazyConfigProxy<InferConfig<S>>(memoize(() => readInjectedConfig<S>(globalKey))),\n // Injection is a server-render concern; there is nothing to emit once the document exists.\n PublicConfigScript: () => null,\n }\n}\n\nfunction readInjectedConfig<S extends ConfigSchema>(globalKey: string): InferConfig<S> {\n const injected = (globalThis as unknown as Record<string, unknown>)[globalKey]\n\n if (injected === undefined) {\n throw new ConfigError(\n `window.${globalKey} is not set, so there is no public config to read. Render <PublicConfigScript /> ` +\n 'once in your root layout (inside a <Suspense> boundary if Cache Components is enabled). If this is a ' +\n 'test or a non-Next renderer, assign the object yourself before anything reads the config.'\n )\n }\n\n return injected as InferConfig<S>\n}\n"],"mappings":";AAMO,IAAM,cAAN,cAA0B,MAAM;AAAC;;;ACwBjC,IAAM,kBAAkB;AAkBxB,SAAS,iBAAiB,SAAsC;AACrE,MAAI,QAAQ,cAAc,QAAW;AACnC,QAAI,QAAQ,cAAc,IAAI;AAC5B,YAAM,IAAI,YAAY,uFAAuF;AAAA,IAC/G;AACA,WAAO,QAAQ;AAAA,EACjB;AAEA,QAAM,SAAS,QAAQ,UAAU;AACjC,SAAO,WAAW,KAAK,kBAAkB,GAAG,eAAe,GAAG,MAAM;AACtE;AAoCO,SAAS,QAAW,SAA2B;AACpD,MAAI;AACJ,MAAI,WAAW;AACf,SAAO,MAAM;AACX,QAAI,CAAC,UAAU;AACb,cAAQ,QAAQ;AAChB,iBAAW;AAAA,IACb;AACA,WAAO;AAAA,EACT;AACF;AAUO,SAAS,gBAAmB,SAAqB;AACtD,SAAO,IAAI,MAAM,CAAC,GAAa;AAAA,IAC7B,KAAK,CAAC,SAAS,aAAa,QAAQ,IAAI,QAAQ,GAAa,QAAQ;AAAA,IACrE,KAAK,CAAC,SAAS,aAAa,QAAQ,IAAI,QAAQ,GAAa,QAAQ;AAAA,IACrE,SAAS,MAAM,QAAQ,QAAQ,QAAQ,CAAW;AAAA,IAClD,0BAA0B,CAAC,SAAS,aAAa;AAC/C,YAAM,aAAa,QAAQ,yBAAyB,QAAQ,GAAa,QAAQ;AAIjF,aAAO,eAAe,SAAY,SAAY,EAAE,GAAG,YAAY,cAAc,KAAK;AAAA,IACpF;AAAA,EACF,CAAC;AACH;;;AC/GO,SAAS,aAAqC,SAAY,UAA+B,CAAC,GAAoB;AACnH,QAAM,YAAY,iBAAiB,OAAO;AAE1C,SAAO;AAAA,IACL,QAAQ,gBAAgC,QAAQ,MAAM,mBAAsB,SAAS,CAAC,CAAC;AAAA;AAAA,IAEvF,oBAAoB,MAAM;AAAA,EAC5B;AACF;AAEA,SAAS,mBAA2C,WAAmC;AACrF,QAAM,WAAY,WAAkD,SAAS;AAE7E,MAAI,aAAa,QAAW;AAC1B,UAAM,IAAI;AAAA,MACR,UAAU,SAAS;AAAA,IAGrB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/node/configError.ts","../../../src/next/config/shared.ts","../../../src/node/casters.ts","../../../src/next/config/browser.ts"],"sourcesContent":["/**\n * Isolated in its own module - with no `process.env` access anywhere in it - so that the browser\n * half of `@isikk/core/next/config` can throw the same error type without importing\n * anything that reads the environment. Keeping the split structural means the guarantee holds\n * because of what the file contains, not because a bundler happened to tree-shake it away.\n */\nexport class ConfigError extends Error {}\n","import type { ReactNode } from 'react'\n\nimport type { ConfigSchema, InferConfig } from '../../node/configCore'\nimport { ConfigError } from '../../node/configError'\n\nexport interface PublicConfigOptions {\n /**\n * The property the payload is injected under on `window`. Required, with no default and no\n * derived fallback: the name belongs in your application's namespace, not this package's, and\n * naming it at the call site is what stops two configs from silently landing on a name neither\n * of them chose.\n */\n globalKey: string\n /** Prepended to every environment variable name this call reads, joined with `sep`. */\n prefix?: string\n /** Joins the prefix and the nested key path into a variable name. Defaults to `\"__\"`. */\n sep?: string\n}\n\nexport interface PublicConfigScriptProps {\n /** Forwarded to the injected `<script>` so a CSP with a per-request nonce keeps working. */\n nonce?: string\n}\n\nexport type PublicConfigScriptComponent = (props: PublicConfigScriptProps) => ReactNode | Promise<ReactNode>\n\nexport interface PublicConfig<S extends ConfigSchema> {\n CONFIG: InferConfig<S>\n PublicConfigScript: PublicConfigScriptComponent\n}\n\n/**\n * Validates the caller-supplied global key. There is deliberately no default and nothing derived\n * from `prefix` to fall back to: a package-chosen name would put this package's identity into\n * every consuming app's `window`, and - worse - two `publicConfig()` calls could quietly agree on\n * a name neither of them wrote down. Since the payload is injected non-writable, that agreement\n * loses the second config silently in the browser while both still resolve on the server. Making\n * the name mandatory turns that from an invisible default into a line you can read at the call\n * site.\n *\n * Both halves of the module go through this one function, from the same options object: the\n * schema and options live at a single call site in the consuming app, and only the library import\n * flips between builds. That is what makes the two sides agree by construction - a server that\n * wrote one key and a browser that read another would fail with nothing to point at.\n *\n * No character restrictions, since the key is emitted as an escaped string literal and read back\n * with bracket notation. The runtime check covers callers without types, for whom a missing key\n * would otherwise mean reading `window[undefined]`.\n */\nexport function requireGlobalKey(options: PublicConfigOptions): string {\n const { globalKey } = options\n\n if (typeof globalKey !== 'string' || globalKey === '') {\n throw new ConfigError(\n 'publicConfig: globalKey is required and must be a non-empty string - it names the window ' +\n 'property the config is injected under, e.g. { globalKey: \"__MY_APP_CONFIG__\" }. There is no ' +\n 'default, so the name is yours and two configs cannot collide on one neither of them chose.'\n )\n }\n\n return globalKey\n}\n\n/**\n * Encodes a string as a JavaScript string literal that is safe to interpolate into a `<script>`\n * body. `JSON.stringify` alone is not: `</script>` inside a value closes the tag early and drops\n * the rest of the payload into the document as markup, and U+2028/U+2029 are literal line\n * terminators in JavaScript source, so a value containing one produces a syntax error. Escaping\n * `<` covers the first (the sequence can no longer be written) and the two explicit replacements\n * cover the second. `>` and `&` need no handling - a script element is raw text, so nothing in it\n * is parsed as markup or entities once `<` can't start a closing tag.\n */\nexport function jsStringLiteral(value: string): string {\n return JSON.stringify(value)\n .replace(/</g, '\\\\u003c')\n .replace(/\\u2028/g, '\\\\u2028')\n .replace(/\\u2029/g, '\\\\u2029')\n}\n\n/**\n * The script that hands the resolved config to the browser. Values travel as a JSON string parsed\n * at runtime rather than as an object literal: it parses faster than equivalent JS source, and it\n * narrows everything that needs escaping down to the single quoted string handled above.\n *\n * The definition is deep-frozen and non-writable, so nothing can reshape config after hydration,\n * and re-entrant if the script somehow runs twice - redefining a non-configurable property would\n * throw, so an existing key means there is nothing left to do.\n */\nexport function serializePublicConfigScript(key: string, value: unknown): string {\n return (\n '(function(w,k,v){if(k in w)return;' +\n 'var f=function(o){if(o&&typeof o==\"object\"){for(var p in o)f(o[p]);Object.freeze(o)}};' +\n 'f(v);Object.defineProperty(w,k,{value:v,enumerable:true})})' +\n `(window,${jsStringLiteral(key)},JSON.parse(${jsStringLiteral(JSON.stringify(value))}))`\n )\n}\n\nexport function memoize<T>(resolve: () => T): () => T {\n let value: T\n let resolved = false\n return () => {\n if (!resolved) {\n value = resolve()\n resolved = true\n }\n return value\n }\n}\n\n/**\n * Presents `resolve()`'s result as a plain object without calling it until something is actually\n * read. That deferral is load-bearing on both sides of the package. On the server it keeps\n * `next build` from resolving anything while collecting page data, so a missing variable no\n * longer fails the build - \"can this build\" stops depending on \"is this configured\". In the\n * browser it means the injected global is read at access time rather than at chunk-evaluation\n * time, so an async chunk that happens to run before the inline script still sees the config.\n */\nexport function lazyConfigProxy<T>(resolve: () => T): T {\n return new Proxy({} as object, {\n get: (_target, property) => Reflect.get(resolve() as object, property),\n has: (_target, property) => Reflect.has(resolve() as object, property),\n ownKeys: () => Reflect.ownKeys(resolve() as object),\n getOwnPropertyDescriptor: (_target, property) => {\n const descriptor = Reflect.getOwnPropertyDescriptor(resolve() as object, property)\n // The proxy target is an empty object, and a proxy may not report a non-configurable\n // property that its target doesn't have - so re-mark descriptors as configurable, or\n // Object.keys()/JSON.stringify() over the config throw a TypeError.\n return descriptor === undefined ? undefined : { ...descriptor, configurable: true }\n },\n }) as T\n}\n","export type Caster<T> = ((value: string) => T) & { missingDefault?: T; errorDefault?: T }\n\nexport function caster<T>(fn: (value: string) => T) {\n return function (options: { missingDefault?: T; errorDefault?: T } = {}): Caster<T> {\n const clone = ((value: string) => fn(value)) as Caster<T>\n if ('missingDefault' in options) {\n clone.missingDefault = options.missingDefault\n }\n if ('errorDefault' in options) {\n clone.errorDefault = options.errorDefault\n }\n return clone\n }\n}\n\n// JS's Number()/parseInt()/parseFloat() don't throw on unparseable input the way Python's int()/\n// float() do (parseInt('123abc') silently returns 123, Number('') silently returns 0) - these\n// helpers add back the \"either it's a clean, fully-parsed number or it throws\" contract the\n// missingDefault/errorDefault fallback system above depends on.\nfunction parseStrictInteger(value: string): number {\n if (value.trim() === '' || !Number.isInteger(Number(value))) {\n throw new Error(`Value ${JSON.stringify(value)} can not be parsed into an integer.`)\n }\n return Number(value)\n}\n\nfunction parseStrictFloat(value: string): number {\n if (value.trim() === '' || Number.isNaN(Number(value))) {\n throw new Error(`Value ${JSON.stringify(value)} can not be parsed into a float.`)\n }\n return Number(value)\n}\n\nexport const string = caster((value: string) => value)\n\nexport const integer = caster(parseStrictInteger)\n\nexport const float = caster(parseStrictFloat)\n\nexport const boolean = caster((value: string) => {\n const truthy = ['true', 'True', '1']\n const falsy = ['false', 'False', '0']\n if (truthy.includes(value)) {\n return true\n }\n if (falsy.includes(value)) {\n return false\n }\n throw new Error(`Value ${JSON.stringify(value)} can not be parsed into a boolean.`)\n})\n\nexport const commaSeparatedList = caster((value: string) => value.split(','))\n\nexport const commaSeparatedIntList = caster((value: string) => value.split(',').map(parseStrictInteger))\n\nexport const commaSeparatedFloatList = caster((value: string) => value.split(',').map(parseStrictFloat))\n","import type { ConfigSchema, InferConfig } from '../../node/configCore'\nimport { ConfigError } from '../../node/configError'\nimport { type PublicConfig, type PublicConfigOptions, lazyConfigProxy, memoize, requireGlobalKey } from './shared'\n\n// Mirrors the server half's re-export, so the shared schema call site resolves the same caster\n// names in the browser bundle. Pure functions, no environment access - see index.tsx for why they\n// cannot be imported from `@isikk/core/node` here.\nexport * from '../../node/casters'\nexport { ConfigError } from '../../node/configError'\nexport type { ConfigSchema, InferConfig } from '../../node/configCore'\nexport type { PublicConfig, PublicConfigOptions, PublicConfigScriptComponent, PublicConfigScriptProps } from './shared'\n\n/**\n * The browser half of `publicConfig()`, substituted for the server module by the `browser`\n * export condition in package.json rather than branched to at runtime. That substitution is what\n * makes the split safe: this file contains no reference to `process.env` at all, so bundling the\n * config module for the client cannot ship a server value no matter what the schema says. It is a\n * property of what the file contains, not a discipline anyone has to maintain.\n *\n * The schema argument is accepted and ignored - values arrive already cast, through the injected\n * global. It stays in the signature so `InferConfig<S>` produces the identical type on both\n * sides, which is what lets one `app/config.ts` be imported by server and client components\n * alike. `options.globalKey` is not ignored: it is the only thing this half needs, and it is read\n * from the same options object the server half was given.\n */\nexport function publicConfig<S extends ConfigSchema>(_schema: S, options: PublicConfigOptions): PublicConfig<S> {\n const globalKey = requireGlobalKey(options)\n\n return {\n CONFIG: lazyConfigProxy<InferConfig<S>>(memoize(() => readInjectedConfig<S>(globalKey))),\n // Injection is a server-render concern; there is nothing to emit once the document exists.\n PublicConfigScript: () => null,\n }\n}\n\nfunction readInjectedConfig<S extends ConfigSchema>(globalKey: string): InferConfig<S> {\n const injected = (globalThis as unknown as Record<string, unknown>)[globalKey]\n\n if (injected === undefined) {\n throw new ConfigError(\n `window.${globalKey} is not set, so there is no public config to read. Render <PublicConfigScript /> ` +\n 'once in your root layout (inside a <Suspense> boundary if Cache Components is enabled). If this is a ' +\n 'test or a non-Next renderer, assign the object yourself before anything reads the config.'\n )\n }\n\n return injected as InferConfig<S>\n}\n"],"mappings":";AAMO,IAAM,cAAN,cAA0B,MAAM;AAAC;;;AC2CjC,SAAS,iBAAiB,SAAsC;AACrE,QAAM,EAAE,UAAU,IAAI;AAEtB,MAAI,OAAO,cAAc,YAAY,cAAc,IAAI;AACrD,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AAEA,SAAO;AACT;AAoCO,SAAS,QAAW,SAA2B;AACpD,MAAI;AACJ,MAAI,WAAW;AACf,SAAO,MAAM;AACX,QAAI,CAAC,UAAU;AACb,cAAQ,QAAQ;AAChB,iBAAW;AAAA,IACb;AACA,WAAO;AAAA,EACT;AACF;AAUO,SAAS,gBAAmB,SAAqB;AACtD,SAAO,IAAI,MAAM,CAAC,GAAa;AAAA,IAC7B,KAAK,CAAC,SAAS,aAAa,QAAQ,IAAI,QAAQ,GAAa,QAAQ;AAAA,IACrE,KAAK,CAAC,SAAS,aAAa,QAAQ,IAAI,QAAQ,GAAa,QAAQ;AAAA,IACrE,SAAS,MAAM,QAAQ,QAAQ,QAAQ,CAAW;AAAA,IAClD,0BAA0B,CAAC,SAAS,aAAa;AAC/C,YAAM,aAAa,QAAQ,yBAAyB,QAAQ,GAAa,QAAQ;AAIjF,aAAO,eAAe,SAAY,SAAY,EAAE,GAAG,YAAY,cAAc,KAAK;AAAA,IACpF;AAAA,EACF,CAAC;AACH;;;AChIO,SAAS,OAAU,IAA0B;AAClD,SAAO,SAAU,UAAoD,CAAC,GAAc;AAClF,UAAM,SAAS,CAAC,UAAkB,GAAG,KAAK;AAC1C,QAAI,oBAAoB,SAAS;AAC/B,YAAM,iBAAiB,QAAQ;AAAA,IACjC;AACA,QAAI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AE1C,SAAO;AAAA,IACL,QAAQ,gBAAgC,QAAQ,MAAM,mBAAsB,SAAS,CAAC,CAAC;AAAA;AAAA,IAEvF,oBAAoB,MAAM;AAAA,EAC5B;AACF;AAEA,SAAS,mBAA2C,WAAmC;AACrF,QAAM,WAAY,WAAkD,SAAS;AAE7E,MAAI,aAAa,QAAW;AAC1B,UAAM,IAAI;AAAA,MACR,UAAU,SAAS;AAAA,IAGrB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import { C as ConfigSchema, P as PublicConfigOptions, a as PublicConfig } from '../../
|
|
2
|
-
export { I as InferConfig,
|
|
1
|
+
import { C as ConfigSchema, P as PublicConfigOptions, a as PublicConfig } from '../../configError-BtEWY-oE.js';
|
|
2
|
+
export { b as Caster, c as ConfigError, I as InferConfig, d as PublicConfigScriptComponent, e as PublicConfigScriptProps, f as boolean, g as caster, h as commaSeparatedFloatList, i as commaSeparatedIntList, j as commaSeparatedList, k as float, l as integer, s as string } from '../../configError-BtEWY-oE.js';
|
|
3
3
|
import 'react';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Isolated in its own module - with no `process.env` access anywhere in it - so that the browser
|
|
7
|
-
* half of `@isikk/core/next/config` can throw the same error type without importing
|
|
8
|
-
* anything that reads the environment. Keeping the split structural means the guarantee holds
|
|
9
|
-
* because of what the file contains, not because a bundler happened to tree-shake it away.
|
|
10
|
-
*/
|
|
11
|
-
declare class ConfigError extends Error {
|
|
12
|
-
}
|
|
13
|
-
|
|
14
5
|
/**
|
|
15
6
|
* The browser-visible sibling of `config()`: same schema, same casters, same variable naming, but
|
|
16
7
|
* the resolved values are serialized into the document so client components can read them at
|
|
@@ -21,10 +12,13 @@ declare class ConfigError extends Error {
|
|
|
21
12
|
* must not overlap one already claimed by `config()`, so a server-only key pasted into this
|
|
22
13
|
* schema by mistake resolves to nothing and throws rather than getting published.
|
|
23
14
|
*
|
|
15
|
+
* `options.globalKey` is required - it names the `window` property the payload is injected under,
|
|
16
|
+
* and there is no default to fall back to.
|
|
17
|
+
*
|
|
24
18
|
* Values are read per request, not baked in at build - which is the entire point next to
|
|
25
19
|
* `NEXT_PUBLIC_*`, and what lets one image run in staging and production. Nothing resolves until
|
|
26
20
|
* something reads it, so `next build` needs none of these variables set.
|
|
27
21
|
*/
|
|
28
|
-
declare function publicConfig<S extends ConfigSchema>(schema: S, options
|
|
22
|
+
declare function publicConfig<S extends ConfigSchema>(schema: S, options: PublicConfigOptions): PublicConfig<S>;
|
|
29
23
|
|
|
30
|
-
export {
|
|
24
|
+
export { ConfigSchema, PublicConfig, PublicConfigOptions, publicConfig };
|