@md-oss/common 0.1.6 → 0.1.7
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/arrays-6DA6GfsQ.mjs +2 -0
- package/dist/arrays-6DA6GfsQ.mjs.map +1 -0
- package/dist/arrays-DvPJ1GeR.d.cts +163 -0
- package/dist/arrays-DvPJ1GeR.d.mts +163 -0
- package/dist/arrays-bgbansWs.cjs +2 -0
- package/dist/arrays-bgbansWs.cjs.map +1 -0
- package/dist/constants/bytes.cjs +1 -1
- package/dist/constants/bytes.cjs.map +1 -1
- package/dist/constants/bytes.d.cts +31 -1
- package/dist/constants/bytes.d.mts +31 -1
- package/dist/constants/bytes.mjs +1 -1
- package/dist/constants/bytes.mjs.map +1 -1
- package/dist/files-DzKYei0a.mjs +2 -0
- package/dist/files-DzKYei0a.mjs.map +1 -0
- package/dist/files-m1nnj5gT.cjs +2 -0
- package/dist/files-m1nnj5gT.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +10 -8
- package/dist/index.d.mts +10 -8
- package/dist/index.mjs +1 -1
- package/dist/mime-types-BmvBrrZ7.cjs.map +1 -1
- package/dist/mime-types-D_K53zgk.mjs.map +1 -1
- package/dist/{mime-types-Bjt4NvnE.d.cts → mime-types-Dajfhq2c.d.cts} +58 -1
- package/dist/{mime-types-Bjt4NvnE.d.mts → mime-types-Dajfhq2c.d.mts} +58 -1
- package/dist/numbers-B_mptknO.cjs +2 -0
- package/dist/numbers-B_mptknO.cjs.map +1 -0
- package/dist/numbers-C2680fmA.d.cts +184 -0
- package/dist/numbers-C2680fmA.d.mts +184 -0
- package/dist/numbers-lJ6gwIpk.mjs +2 -0
- package/dist/numbers-lJ6gwIpk.mjs.map +1 -0
- package/dist/objects-VXf3mqE5.mjs +2 -0
- package/dist/objects-VXf3mqE5.mjs.map +1 -0
- package/dist/objects-fiFExjsf.d.cts +116 -0
- package/dist/objects-fiFExjsf.d.mts +116 -0
- package/dist/objects-wcO6hNA8.cjs +2 -0
- package/dist/objects-wcO6hNA8.cjs.map +1 -0
- package/dist/random-668tofPV.cjs +2 -0
- package/dist/random-668tofPV.cjs.map +1 -0
- package/dist/random-BqJDZAPb.d.cts +131 -0
- package/dist/random-BqJDZAPb.d.mts +131 -0
- package/dist/random-ihslkInn.mjs +2 -0
- package/dist/random-ihslkInn.mjs.map +1 -0
- package/dist/runtime-7fkN5_oL.d.cts +206 -0
- package/dist/runtime-7fkN5_oL.d.mts +206 -0
- package/dist/runtime-Bfs-yn_-.cjs +2 -0
- package/dist/runtime-Bfs-yn_-.cjs.map +1 -0
- package/dist/runtime-CE36Va0l.mjs +2 -0
- package/dist/runtime-CE36Va0l.mjs.map +1 -0
- package/dist/strings-CrzGdnZH.mjs +3 -0
- package/dist/strings-CrzGdnZH.mjs.map +1 -0
- package/dist/strings-_1vAPvzS.cjs +3 -0
- package/dist/strings-_1vAPvzS.cjs.map +1 -0
- package/dist/strings-jE1j-qqa.d.cts +213 -0
- package/dist/strings-jE1j-qqa.d.mts +213 -0
- package/dist/time-BrLHgSth.d.mts +68 -0
- package/dist/time-DmJNWZeL.mjs.map +1 -1
- package/dist/time-ufhllID1.d.cts +68 -0
- package/dist/time-yNkQSJnQ.cjs.map +1 -1
- package/dist/utils/arrays.cjs +1 -1
- package/dist/utils/arrays.d.cts +1 -1
- package/dist/utils/arrays.d.mts +1 -1
- package/dist/utils/arrays.mjs +1 -1
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.cts +187 -8
- package/dist/utils/index.d.mts +187 -8
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/mime-types.d.cts +1 -1
- package/dist/utils/mime-types.d.mts +1 -1
- package/dist/utils/numbers.cjs +1 -1
- package/dist/utils/numbers.d.cts +1 -1
- package/dist/utils/numbers.d.mts +1 -1
- package/dist/utils/numbers.mjs +1 -1
- package/dist/utils/objects.cjs +1 -1
- package/dist/utils/objects.d.cts +1 -1
- package/dist/utils/objects.d.mts +1 -1
- package/dist/utils/objects.mjs +1 -1
- package/dist/utils/random.cjs +1 -1
- package/dist/utils/random.d.cts +1 -1
- package/dist/utils/random.d.mts +1 -1
- package/dist/utils/random.mjs +1 -1
- package/dist/utils/runtime.cjs +1 -1
- package/dist/utils/runtime.d.cts +1 -1
- package/dist/utils/runtime.d.mts +1 -1
- package/dist/utils/runtime.mjs +1 -1
- package/dist/utils/strings.cjs +1 -1
- package/dist/utils/strings.d.cts +1 -1
- package/dist/utils/strings.d.mts +1 -1
- package/dist/utils/strings.mjs +1 -1
- package/dist/utils/time.d.cts +1 -1
- package/dist/utils/time.d.mts +1 -1
- package/package.json +2 -2
- package/dist/arrays-BkHBzTDO.mjs +0 -2
- package/dist/arrays-BkHBzTDO.mjs.map +0 -1
- package/dist/arrays-CElcW69H.d.cts +0 -43
- package/dist/arrays-CElcW69H.d.mts +0 -43
- package/dist/arrays-DaB1Xn47.cjs +0 -2
- package/dist/arrays-DaB1Xn47.cjs.map +0 -1
- package/dist/numbers-CtAqd3eH.d.cts +0 -49
- package/dist/numbers-CtAqd3eH.d.mts +0 -49
- package/dist/numbers-D2K-8sJL.mjs +0 -2
- package/dist/numbers-D2K-8sJL.mjs.map +0 -1
- package/dist/numbers-Du__2-8Y.cjs +0 -2
- package/dist/numbers-Du__2-8Y.cjs.map +0 -1
- package/dist/objects--cO_X3EV.mjs +0 -2
- package/dist/objects--cO_X3EV.mjs.map +0 -1
- package/dist/objects-CnGoVkh6.cjs +0 -2
- package/dist/objects-CnGoVkh6.cjs.map +0 -1
- package/dist/objects-cf8j7rS8.d.cts +0 -26
- package/dist/objects-cf8j7rS8.d.mts +0 -26
- package/dist/random-D1e1NTOt.cjs +0 -2
- package/dist/random-D1e1NTOt.cjs.map +0 -1
- package/dist/random-DbidGSrQ.mjs +0 -2
- package/dist/random-DbidGSrQ.mjs.map +0 -1
- package/dist/random-DpNyGGAZ.d.cts +0 -28
- package/dist/random-DpNyGGAZ.d.mts +0 -28
- package/dist/runtime-DY-8W6Jr.mjs +0 -2
- package/dist/runtime-DY-8W6Jr.mjs.map +0 -1
- package/dist/runtime-T8Kcf7Af.d.cts +0 -28
- package/dist/runtime-T8Kcf7Af.d.mts +0 -28
- package/dist/runtime-peVFcWot.cjs +0 -2
- package/dist/runtime-peVFcWot.cjs.map +0 -1
- package/dist/strings-B0BRwNX9.mjs +0 -3
- package/dist/strings-B0BRwNX9.mjs.map +0 -1
- package/dist/strings-DV446vv-.cjs +0 -3
- package/dist/strings-DV446vv-.cjs.map +0 -1
- package/dist/strings-DhPbrpq7.d.cts +0 -47
- package/dist/strings-DhPbrpq7.d.mts +0 -47
- package/dist/time-8KLG8kBO.d.cts +0 -29
- package/dist/time-D8Wfqzu6.d.mts +0 -29
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files-m1nnj5gT.cjs","sources":["../src/utils/files.ts"],"sourcesContent":["import { readdirSync, statSync } from 'node:fs';\nimport {\n\tbasename,\n\tdirname,\n\textname,\n\tjoin,\n\tparse as pathParse,\n\trelative,\n\tresolve,\n} from 'node:path';\nimport { ByteMagic } from '../constants';\n\n/**\n * Regular expression pattern for parsing byte strings\n *\n * Matches strings in the format: `<number> <unit>` where:\n * - `<number>` is an integer or decimal number\n * - `<unit>` is an optional unit (b, kb, mb, gb, tb, pb, eb, zb, yb)\n *\n * @example\n * ```ts\n * '1024'.match(BYTE_STRING_PATTERN) // ['1024', '1024', undefined]\n * '1.5 MB'.match(BYTE_STRING_PATTERN) // ['1.5 MB', '1.5', 'MB']\n * '100 KB'.match(BYTE_STRING_PATTERN) // ['100 KB', '100', 'KB']\n * '2.5gb'.match(BYTE_STRING_PATTERN) // ['2.5gb', '2.5', 'gb']\n * '500'.match(BYTE_STRING_PATTERN) // ['500', '500', undefined]\n * ```\n */\nconst BYTE_STRING_PATTERN = /^(\\d+(?:\\.\\d+)?)\\s*([a-z]+)?$/i;\n\n/**\n * Format bytes to human readable format\n * @param bytes - Number of bytes\n * @param decimals - Number of decimal places (default: 2)\n * @returns Formatted string (e.g., \"1.5 MB\")\n */\nfunction formatBytes(bytes: number, decimals = 2): string {\n\tif (bytes === 0) return '0 Bytes';\n\tif (bytes < 0) return `-${formatBytes(-bytes, decimals)}`;\n\n\tconst k = ByteMagic.BYTES_PER_KILOBYTE;\n\tconst dm = decimals < 0 ? 0 : decimals;\n\tconst sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n\tconst i = Math.floor(Math.log(bytes) / Math.log(k));\n\n\treturn `${Number.parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;\n}\n\n/**\n * Parse bytes from human readable format\n * @param value - String value (e.g., \"1.5 MB\")\n * @returns Number of bytes\n */\nfunction parseBytes(value: string): number {\n\tconst units: Record<string, number> = {\n\t\tb: ByteMagic.BYTE,\n\t\tbytes: ByteMagic.BYTE,\n\t\tkb: ByteMagic.KILOBYTE,\n\t\tmb: ByteMagic.MEGABYTE,\n\t\tgb: ByteMagic.GIGABYTE,\n\t\ttb: ByteMagic.TERABYTE,\n\t\tpb: ByteMagic.PETABYTE,\n\t\teb: ByteMagic.EXABYTE,\n\t\tzb: ByteMagic.ZETTABYTE,\n\t\tyb: ByteMagic.YOTTABYTE,\n\t};\n\n\tconst match = value.trim().match(BYTE_STRING_PATTERN);\n\tif (!match) throw new Error(`Invalid byte string: ${value}`);\n\n\tconst [, num, unit = 'b'] = match;\n\tconst multiplier = units[unit.toLowerCase()];\n\n\tif (!multiplier) throw new Error(`Unknown unit: ${unit}`);\n\n\treturn Math.floor(Number.parseFloat(num) * multiplier);\n}\n\ninterface GetFilesOptions {\n\t/**\n\t * File extensions to include (e.g., ['.ts', '.js'])\n\t * If not provided, all files are included\n\t */\n\textensions?: string[];\n\n\t/**\n\t * Whether to include dotfiles (default: false)\n\t */\n\tincludeDotFiles?: boolean;\n\n\t/**\n\t * Whether to search recursively (default: true)\n\t */\n\trecursive?: boolean;\n\n\t/**\n\t * Maximum depth for recursive search (default: Infinity)\n\t */\n\tmaxDepth?: number;\n\n\t/**\n\t * Directories to exclude from search\n\t */\n\texcludeDirs?: string[];\n\n\t/**\n\t * Pattern to match file names (regex or string)\n\t */\n\tpattern?: string | RegExp;\n\n\t/**\n\t * Whether to return absolute paths (default: false)\n\t */\n\tabsolutePaths?: boolean;\n\n\t/**\n\t * Custom filter function\n\t */\n\tfilter?: (filePath: string, stats: ReturnType<typeof statSync>) => boolean;\n}\n\n/**\n * Get files from a directory with various filtering options\n * @param dirPath - Directory path to search\n * @param options - Options for filtering files\n * @returns Array of file paths\n */\nfunction getFiles(dirPath: string, options: GetFilesOptions = {}): string[] {\n\tconst {\n\t\textensions,\n\t\tincludeDotFiles = false,\n\t\trecursive = true,\n\t\tmaxDepth = Number.POSITIVE_INFINITY,\n\t\texcludeDirs = ['node_modules', '.git', 'dist', 'build', 'coverage'],\n\t\tpattern,\n\t\tabsolutePaths = false,\n\t\tfilter,\n\t} = options;\n\n\tconst results: string[] = [];\n\tconst basePath = resolve(dirPath);\n\n\tfunction traverse(currentPath: string, depth = 0): void {\n\t\tif (depth > maxDepth) return;\n\n\t\ttry {\n\t\t\tconst entries = readdirSync(currentPath, { withFileTypes: true });\n\n\t\t\tfor (const entry of entries) {\n\t\t\t\tconst fullPath = join(currentPath, entry.name);\n\n\t\t\t\t// Skip dotfiles if not included\n\t\t\t\tif (!includeDotFiles && entry.name.startsWith('.')) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (entry.isDirectory()) {\n\t\t\t\t\t// Skip excluded directories\n\t\t\t\t\tif (excludeDirs.includes(entry.name)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Recurse into subdirectories\n\t\t\t\t\tif (recursive) {\n\t\t\t\t\t\ttraverse(fullPath, depth + 1);\n\t\t\t\t\t}\n\t\t\t\t} else if (entry.isFile()) {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\n\t\t\t\t\t// Apply extension filter\n\t\t\t\t\tif (extensions) {\n\t\t\t\t\t\tconst ext = extname(entry.name);\n\t\t\t\t\t\tif (!extensions.includes(ext)) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Apply pattern filter\n\t\t\t\t\tif (pattern) {\n\t\t\t\t\t\tconst regex =\n\t\t\t\t\t\t\ttypeof pattern === 'string' ? new RegExp(pattern) : pattern;\n\t\t\t\t\t\tif (!regex.test(entry.name)) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// Apply custom filter\n\t\t\t\t\tif (filter && !filter(fullPath, stats)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst resultPath = absolutePaths\n\t\t\t\t\t\t? fullPath\n\t\t\t\t\t\t: relative(basePath, fullPath);\n\t\t\t\t\tresults.push(resultPath);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// Skip directories we don't have permission to read\n\t\t\tconsole.error(`Error reading directory ${currentPath}:`, error);\n\t\t}\n\t}\n\n\ttraverse(dirPath);\n\treturn results;\n}\n\n/**\n * Get file extension including the dot (e.g., \".ts\")\n * @param filePath - File path\n * @returns File extension\n */\nfunction getExtension(filePath: string): string {\n\treturn extname(filePath);\n}\n\n/**\n * Get file name without parent directories, optionally including the extension\n * @param filePath - File path\n * @param includeExtension - Whether to include the file extension (default: true)\n * @returns File name without directories (e.g., \"index.ts\" or \"index\" if includeExtension is false)\n */\nfunction getBaseName(filePath: string, includeExtension = true): string {\n\treturn includeExtension\n\t\t? basename(filePath)\n\t\t: basename(filePath, extname(filePath));\n}\n\n/**\n * Get directory name from file path\n * @param filePath - File path\n * @returns Directory name\n */\nfunction getDirName(filePath: string): string {\n\treturn dirname(filePath);\n}\n\n/**\n * Parse file path into components\n * @param filePath - File path\n * @returns Parsed path object\n */\nfunction parseFilePath(filePath: string) {\n\tconst parsed = pathParse(filePath);\n\treturn {\n\t\troot: parsed.root,\n\t\tdir: parsed.dir,\n\t\tbase: parsed.base,\n\t\text: parsed.ext,\n\t\tname: parsed.name,\n\t};\n}\n\n/**\n * Get file size in bytes\n * @param filePath - File path\n * @returns File size in bytes\n */\nfunction getFileSize(filePath: string): number {\n\ttry {\n\t\treturn statSync(filePath).size;\n\t} catch {\n\t\treturn 0;\n\t}\n}\n\n/**\n * Get human readable file size\n * @param filePath - File path\n * @param decimals - Number of decimal places (default: 2)\n * @returns Formatted file size\n */\nfunction getFileSizeFormatted(filePath: string, decimals = 2): string {\n\treturn formatBytes(getFileSize(filePath), decimals);\n}\n\n/**\n * Check if path is a directory\n * @param path - Path to check\n * @returns True if path is a directory\n */\nfunction isDirectory(path: string): boolean {\n\ttry {\n\t\treturn statSync(path).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Check if path is a file\n * @param path - Path to check\n * @returns True if path is a file\n */\nfunction isFile(path: string): boolean {\n\ttry {\n\t\treturn statSync(path).isFile();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Check if file is a dotfile\n * @param filePath - File path\n * @returns True if file is a dotfile\n */\nfunction isDotFile(filePath: string): boolean {\n\tconst fileName = basename(filePath);\n\treturn fileName.startsWith('.');\n}\n\n/**\n * Normalize file extension (ensure it starts with a dot)\n * @param ext - File extension\n * @returns Normalized extension\n */\nfunction normalizeExtension(ext: string): string {\n\treturn ext.startsWith('.') ? ext : `.${ext}`;\n}\n\n/**\n * Check if file has specific extension\n * @param filePath - File path\n * @param extensions - Extension or array of extensions to check\n * @returns True if file has one of the extensions\n */\nfunction hasExtension(\n\tfilePath: string,\n\textensions: string | string[]\n): boolean {\n\tconst fileExt = extname(filePath).toLowerCase();\n\tconst exts = Array.isArray(extensions) ? extensions : [extensions];\n\n\treturn exts.some((ext) => normalizeExtension(ext).toLowerCase() === fileExt);\n}\n\n/**\n * Group files by extension\n * @param filePaths - Array of file paths\n * @returns Object with extensions as keys and file paths as values\n */\nfunction groupByExtension(filePaths: string[]): Record<string, string[]> {\n\treturn filePaths.reduce(\n\t\t(acc, filePath) => {\n\t\t\tconst ext = extname(filePath) || 'no-extension';\n\t\t\tif (!acc[ext]) {\n\t\t\t\tacc[ext] = [];\n\t\t\t}\n\t\t\tacc[ext].push(filePath);\n\t\t\treturn acc;\n\t\t},\n\t\t{} as Record<string, string[]>\n\t);\n}\n\nexport {\n\tBYTE_STRING_PATTERN,\n\tformatBytes,\n\tparseBytes,\n\tgetFiles,\n\tgetExtension,\n\tgetBaseName,\n\tgetDirName,\n\tparseFilePath,\n\tgetFileSize,\n\tgetFileSizeFormatted,\n\tisDirectory,\n\tisFile,\n\tisDotFile,\n\tnormalizeExtension,\n\thasExtension,\n\tgroupByExtension,\n\ttype GetFilesOptions,\n};\n"],"names":["BYTE_STRING_PATTERN","formatBytes","bytes","decimals","k","ByteMagic","dm","sizes","i","__name","parseBytes","value","units","match","num","unit","multiplier","getFiles","dirPath","options","extensions","includeDotFiles","recursive","maxDepth","excludeDirs","pattern","absolutePaths","filter","results","basePath","resolve","traverse","currentPath","depth","entries","readdirSync","entry","fullPath","join","stats","statSync","ext","extname","resultPath","relative","error","getExtension","filePath","getBaseName","includeExtension","basename","getDirName","dirname","parseFilePath","parsed","pathParse","getFileSize","getFileSizeFormatted","isDirectory","path","isFile","isDotFile","normalizeExtension","hasExtension","fileExt","groupByExtension","filePaths","acc"],"mappings":"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"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("./api/errors.cjs"),i=require("./api/status-codes.cjs"),s=require("./constants/bytes.cjs"),t=require("./constants/discord.cjs"),a=require("./constants/time.cjs"),r=require("./schemas.cjs"),u=require("./arrays-
|
|
1
|
+
"use strict";var e=require("./api/errors.cjs"),i=require("./api/status-codes.cjs"),s=require("./constants/bytes.cjs"),t=require("./constants/discord.cjs"),a=require("./constants/time.cjs"),r=require("./schemas.cjs"),u=require("./arrays-bgbansWs.cjs"),o=require("./files-m1nnj5gT.cjs"),m=require("./mime-types-BmvBrrZ7.cjs"),n=require("./numbers-B_mptknO.cjs"),l=require("./objects-wcO6hNA8.cjs"),d=require("./random-668tofPV.cjs"),c=require("./runtime-Bfs-yn_-.cjs"),q=require("./strings-_1vAPvzS.cjs"),v=require("./time-yNkQSJnQ.cjs");require("zod/v4"),require("node:fs"),require("node:path"),exports.APIError=e.APIError,exports.isAPIError=e.isAPIError,exports.isAPIErrorResponse=e.isAPIErrorResponse,exports.parseError=e.parseError,exports.isStatusCodeText=i.isStatusCodeText,exports.resolveStatusCode=i.resolveStatusCode,exports.statusCodes=i.statusCodes,exports.ByteMagic=s.ByteMagic,exports.DiscordMagic=t.DiscordMagic,exports.TimeMagic=a.TimeMagic,exports.isFieldRequired=r.isFieldRequired,exports.paginationQuerySchema=r.paginationQuerySchema,exports.requiredKeys=r.requiredKeys,exports.signedUrlSchema=r.signedUrlSchema,exports.zodEnumFromObjectKeys=r.zodEnumFromObjectKeys,exports.ArrayUtils=u.arrays,exports.FileUtils=o.files,exports.MimeTypeUtils=m.mimeTypes,exports.NumberUtils=n.numbers,exports.ObjectUtils=l.objects,exports.RandomUtils=d.random,exports.RuntimeUtils=c.runtime,exports.StringUtils=q.strings,exports.TimeUtils=v.time;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -5,13 +5,15 @@ export { ByteMagic } from './constants/bytes.cjs';
|
|
|
5
5
|
export { DiscordMagic } from './constants/discord.cjs';
|
|
6
6
|
export { TimeMagic } from './constants/time.cjs';
|
|
7
7
|
export { FormDataFromSchema, Pagination, SignedUrlSchema, isFieldRequired, paginationQuerySchema, requiredKeys, signedUrlSchema, zodEnumFromObjectKeys } from './schemas.cjs';
|
|
8
|
-
export { a as ArrayUtils } from './arrays-
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export { r as
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
8
|
+
export { a as ArrayUtils } from './arrays-DvPJ1GeR.cjs';
|
|
9
|
+
export { FileUtils } from './utils/index.cjs';
|
|
10
|
+
export { m as MimeTypeUtils } from './mime-types-Dajfhq2c.cjs';
|
|
11
|
+
export { n as NumberUtils } from './numbers-C2680fmA.cjs';
|
|
12
|
+
export { o as ObjectUtils } from './objects-fiFExjsf.cjs';
|
|
13
|
+
export { r as RandomUtils } from './random-BqJDZAPb.cjs';
|
|
14
|
+
export { r as RuntimeUtils } from './runtime-7fkN5_oL.cjs';
|
|
15
|
+
export { s as StringUtils } from './strings-jE1j-qqa.cjs';
|
|
16
|
+
export { t as TimeUtils } from './time-ufhllID1.cjs';
|
|
16
17
|
import 'qs';
|
|
17
18
|
import 'zod/v4';
|
|
19
|
+
import 'node:fs';
|
package/dist/index.d.mts
CHANGED
|
@@ -5,13 +5,15 @@ export { ByteMagic } from './constants/bytes.mjs';
|
|
|
5
5
|
export { DiscordMagic } from './constants/discord.mjs';
|
|
6
6
|
export { TimeMagic } from './constants/time.mjs';
|
|
7
7
|
export { FormDataFromSchema, Pagination, SignedUrlSchema, isFieldRequired, paginationQuerySchema, requiredKeys, signedUrlSchema, zodEnumFromObjectKeys } from './schemas.mjs';
|
|
8
|
-
export { a as ArrayUtils } from './arrays-
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export { r as
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
8
|
+
export { a as ArrayUtils } from './arrays-DvPJ1GeR.mjs';
|
|
9
|
+
export { FileUtils } from './utils/index.mjs';
|
|
10
|
+
export { m as MimeTypeUtils } from './mime-types-Dajfhq2c.mjs';
|
|
11
|
+
export { n as NumberUtils } from './numbers-C2680fmA.mjs';
|
|
12
|
+
export { o as ObjectUtils } from './objects-fiFExjsf.mjs';
|
|
13
|
+
export { r as RandomUtils } from './random-BqJDZAPb.mjs';
|
|
14
|
+
export { r as RuntimeUtils } from './runtime-7fkN5_oL.mjs';
|
|
15
|
+
export { s as StringUtils } from './strings-jE1j-qqa.mjs';
|
|
16
|
+
export { t as TimeUtils } from './time-BrLHgSth.mjs';
|
|
16
17
|
import 'qs';
|
|
17
18
|
import 'zod/v4';
|
|
19
|
+
import 'node:fs';
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{APIError as
|
|
1
|
+
import{APIError as i,isAPIError as m,isAPIErrorResponse as a,parseError as p}from"./api/errors.mjs";import{isStatusCodeText as x,resolveStatusCode as l,statusCodes as d}from"./api/status-codes.mjs";import{ByteMagic as n}from"./constants/bytes.mjs";import{DiscordMagic as c}from"./constants/discord.mjs";import{TimeMagic as y}from"./constants/time.mjs";import{isFieldRequired as S,paginationQuerySchema as A,requiredKeys as M,signedUrlSchema as R,zodEnumFromObjectKeys as T}from"./schemas.mjs";import{a as C}from"./arrays-6DA6GfsQ.mjs";import{f as I}from"./files-DzKYei0a.mjs";import{m as h}from"./mime-types-D_K53zgk.mjs";import{n as q}from"./numbers-lJ6gwIpk.mjs";import{o as O}from"./objects-VXf3mqE5.mjs";import{r as z}from"./random-ihslkInn.mjs";import{r as D}from"./runtime-CE36Va0l.mjs";import{s as Q}from"./strings-CrzGdnZH.mjs";import{t as w}from"./time-DmJNWZeL.mjs";import"zod/v4";import"node:fs";import"node:path";export{i as APIError,C as ArrayUtils,n as ByteMagic,c as DiscordMagic,I as FileUtils,h as MimeTypeUtils,q as NumberUtils,O as ObjectUtils,z as RandomUtils,D as RuntimeUtils,Q as StringUtils,y as TimeMagic,w as TimeUtils,m as isAPIError,a as isAPIErrorResponse,S as isFieldRequired,x as isStatusCodeText,A as paginationQuerySchema,p as parseError,M as requiredKeys,l as resolveStatusCode,R as signedUrlSchema,d as statusCodes,T as zodEnumFromObjectKeys};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mime-types-BmvBrrZ7.cjs","sources":["../src/utils/mime-types.ts"],"sourcesContent":["type MimeKind = 'IMAGE' | 'VIDEO' | 'AUDIO' | 'DOCUMENT' | 'ARCHIVE' | 'OTHER';\ntype MimeKindWithSafe = MimeKind | 'SAFE';\n\nconst imageMimeTypes = [\n\t'image/png',\n\t'image/jpeg',\n\t'image/webp',\n\t'image/gif',\n\t'image/bmp',\n\t'image/svg+xml',\n\t'image/x-icon',\n\t'image/tiff',\n\t'image/heic',\n\t'image/avif',\n\t'image/apng',\n\t'image/jpg',\n] as const;\n\nconst videoMimeTypes = [\n\t'video/mp4',\n\t'video/webm',\n\t'video/ogg',\n\t'video/avi',\n\t'video/mpeg',\n\t'video/quicktime',\n\t'video/x-msvideo',\n\t'video/x-matroska',\n\t'video/x-flv',\n\t'video/x-ms-wmv',\n\t'video/x-mpeg',\n\t'video/x-ms-asf',\n\t'video/x-ms-wmx',\n\t'video/x-ms-wvx',\n\t'video/x-matroska',\n\t'video/x-flash-video',\n] as const;\n\nconst audioMimeTypes = [\n\t'audio/mpeg',\n\t'audio/wav',\n\t'audio/ogg',\n\t'audio/aac',\n\t'audio/flac',\n\t'audio/mp3',\n\t'audio/x-wav',\n\t'audio/x-aiff',\n\t'audio/x-m4a',\n\t'audio/x-ms-wma',\n\t'audio/x-ms-wax',\n\t'audio/x-matroska',\n\t'audio/x-flac',\n\t'audio/x-aac',\n] as const;\n\nconst documentMimeTypes = [\n\t'text/plain',\n\t'text/csv',\n\t'text/rtf',\n\t'text/markdown',\n\t'text/x-markdown',\n\t'text/x-log',\n\t'text/x-ini',\n\t'text/x-yaml',\n\t'text/xml',\n\t'application/x-yaml',\n\t'application/xml',\n\t'application/rtf',\n\t'application/pdf',\n\t'application/msword',\n\t'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n\t'application/vnd.ms-excel',\n\t'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n\t'application/vnd.oasis.opendocument.text',\n\t'application/vnd.oasis.opendocument.spreadsheet',\n] as const;\n\nconst archiveMimeTypes = [\n\t'application/zip',\n\t'application/x-7z-compressed',\n\t'application/x-rar-compressed',\n\t'application/x-tar',\n\t'application/gzip',\n\t'application/x-bzip2',\n\t'application/x-xz',\n\t'application/x-compress',\n\t'application/x-archive',\n\t'application/x-zip-compressed',\n\t'application/x-rar',\n\t'application/x-gzip',\n\t'application/x-bzip',\n] as const;\n\nconst webAssetTypes = [\n\t'text/html',\n\t'text/css',\n\t'text/javascript',\n\t'application/json',\n\t'application/xml',\n\t'application/x-javascript',\n\t'application/x-web-app-manifest+json',\n\t'application/x-font-woff',\n\t'application/x-font-woff2',\n\t'image/svg+xml',\n\t'image/x-icon',\n] as const;\n\nconst safeMimeTypes = [\n\t...imageMimeTypes,\n\t...videoMimeTypes,\n\t...audioMimeTypes,\n\t...documentMimeTypes,\n\t...archiveMimeTypes,\n\t...webAssetTypes,\n] as Array<\n\t| (typeof imageMimeTypes)[number]\n\t| (typeof videoMimeTypes)[number]\n\t| (typeof audioMimeTypes)[number]\n\t| (typeof documentMimeTypes)[number]\n\t| (typeof archiveMimeTypes)[number]\n\t| (typeof webAssetTypes)[number]\n>;\n\nconst mimeTypeMap: Record<MimeKindWithSafe, readonly string[]> = {\n\tIMAGE: imageMimeTypes,\n\tVIDEO: videoMimeTypes,\n\tAUDIO: audioMimeTypes,\n\tDOCUMENT: documentMimeTypes,\n\tARCHIVE: archiveMimeTypes,\n\tSAFE: safeMimeTypes,\n\tOTHER: [],\n};\n\n/**\n * Returns a comma-separated accept string for input elements based on the specified kind\n * @param kind The type of MIME kind to get the accept string for\n */\nconst getInputAccept = (kind: MimeKindWithSafe = 'SAFE'): string => {\n\treturn mimeTypeMap[kind].join(',');\n};\n\nconst isAllowedMimeType = (\n\tmimeType: string,\n\tkind: MimeKindWithSafe = 'SAFE'\n): boolean => {\n\tif (!mimeType || typeof mimeType !== 'string') {\n\t\treturn false;\n\t}\n\n\tconst lowerMimeType = mimeType.toLowerCase().split(';')[0].trim();\n\n\treturn mimeTypeMap[kind].includes(lowerMimeType);\n};\n\nconst inlineContentDispositionMimeTypes = [\n\t'text/plain',\n\t'text/xml',\n\t'application/json',\n\t'application/pdf',\n] as const;\n\nconst isInlineContentDisposition = (mimeType: string): boolean => {\n\tconst lowerMimeType = mimeType.toLowerCase().split(';')[0].trim();\n\treturn (\n\t\tinlineContentDispositionMimeTypes.includes(\n\t\t\tlowerMimeType as (typeof inlineContentDispositionMimeTypes)[number]\n\t\t) ||\n\t\tlowerMimeType.startsWith('image/') ||\n\t\tlowerMimeType.startsWith('video/') ||\n\t\tlowerMimeType.startsWith('audio/')\n\t);\n};\n\nconst mimeTypeResolver = (_mimeType: string): MimeKind => {\n\tconst mimeType = _mimeType.toLowerCase().split(';')[0].trim();\n\n\tif (mimeType.startsWith('image/')) {\n\t\treturn 'IMAGE';\n\t} else if (mimeType.startsWith('video/')) {\n\t\treturn 'VIDEO';\n\t} else if (mimeType.startsWith('audio/')) {\n\t\treturn 'AUDIO';\n\t} else if (\n\t\tdocumentMimeTypes.includes(mimeType as (typeof documentMimeTypes)[number])\n\t) {\n\t\treturn 'DOCUMENT';\n\t} else if (\n\t\tarchiveMimeTypes.includes(mimeType as (typeof archiveMimeTypes)[number])\n\t) {\n\t\treturn 'ARCHIVE';\n\t} else {\n\t\treturn 'OTHER';\n\t}\n};\n\nexport {\n\ttype MimeKind,\n\ttype MimeKindWithSafe,\n\timageMimeTypes,\n\tvideoMimeTypes,\n\taudioMimeTypes,\n\tdocumentMimeTypes,\n\tarchiveMimeTypes,\n\tsafeMimeTypes,\n\tmimeTypeMap,\n\tgetInputAccept,\n\tisAllowedMimeType,\n\tisInlineContentDisposition,\n\tmimeTypeResolver,\n\tinlineContentDispositionMimeTypes,\n};\n"],"names":["imageMimeTypes","videoMimeTypes","audioMimeTypes","documentMimeTypes","archiveMimeTypes","webAssetTypes","safeMimeTypes","mimeTypeMap","getInputAccept","__name","kind","isAllowedMimeType","mimeType","lowerMimeType","inlineContentDispositionMimeTypes","isInlineContentDisposition","mimeTypeResolver","_mimeType"],"mappings":"
|
|
1
|
+
{"version":3,"file":"mime-types-BmvBrrZ7.cjs","sources":["../src/utils/mime-types.ts"],"sourcesContent":["/**\n * MIME type category\n */\ntype MimeKind = 'IMAGE' | 'VIDEO' | 'AUDIO' | 'DOCUMENT' | 'ARCHIVE' | 'OTHER';\n\n/**\n * MIME type category including SAFE (all safe types combined)\n */\ntype MimeKindWithSafe = MimeKind | 'SAFE';\n\n/**\n * List of common image MIME types\n */\nconst imageMimeTypes = [\n\t'image/png',\n\t'image/jpeg',\n\t'image/webp',\n\t'image/gif',\n\t'image/bmp',\n\t'image/svg+xml',\n\t'image/x-icon',\n\t'image/tiff',\n\t'image/heic',\n\t'image/avif',\n\t'image/apng',\n\t'image/jpg',\n] as const;\n\n/**\n * List of common video MIME types\n */\nconst videoMimeTypes = [\n\t'video/mp4',\n\t'video/webm',\n\t'video/ogg',\n\t'video/avi',\n\t'video/mpeg',\n\t'video/quicktime',\n\t'video/x-msvideo',\n\t'video/x-matroska',\n\t'video/x-flv',\n\t'video/x-ms-wmv',\n\t'video/x-mpeg',\n\t'video/x-ms-asf',\n\t'video/x-ms-wmx',\n\t'video/x-ms-wvx',\n\t'video/x-matroska',\n\t'video/x-flash-video',\n] as const;\n\n/**\n * List of common audio MIME types\n */\nconst audioMimeTypes = [\n\t'audio/mpeg',\n\t'audio/wav',\n\t'audio/ogg',\n\t'audio/aac',\n\t'audio/flac',\n\t'audio/mp3',\n\t'audio/x-wav',\n\t'audio/x-aiff',\n\t'audio/x-m4a',\n\t'audio/x-ms-wma',\n\t'audio/x-ms-wax',\n\t'audio/x-matroska',\n\t'audio/x-flac',\n\t'audio/x-aac',\n] as const;\n\n/**\n * List of common document MIME types\n */\nconst documentMimeTypes = [\n\t'text/plain',\n\t'text/csv',\n\t'text/rtf',\n\t'text/markdown',\n\t'text/x-markdown',\n\t'text/x-log',\n\t'text/x-ini',\n\t'text/x-yaml',\n\t'text/xml',\n\t'application/x-yaml',\n\t'application/xml',\n\t'application/rtf',\n\t'application/pdf',\n\t'application/msword',\n\t'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n\t'application/vnd.ms-excel',\n\t'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n\t'application/vnd.oasis.opendocument.text',\n\t'application/vnd.oasis.opendocument.spreadsheet',\n] as const;\n\n/**\n * List of common archive/compression MIME types\n */\nconst archiveMimeTypes = [\n\t'application/zip',\n\t'application/x-7z-compressed',\n\t'application/x-rar-compressed',\n\t'application/x-tar',\n\t'application/gzip',\n\t'application/x-bzip2',\n\t'application/x-xz',\n\t'application/x-compress',\n\t'application/x-archive',\n\t'application/x-zip-compressed',\n\t'application/x-rar',\n\t'application/x-gzip',\n\t'application/x-bzip',\n] as const;\n\n/**\n * List of web asset MIME types (HTML, CSS, JS, fonts, etc.)\n */\nconst webAssetTypes = [\n\t'text/html',\n\t'text/css',\n\t'text/javascript',\n\t'application/json',\n\t'application/xml',\n\t'application/x-javascript',\n\t'application/x-web-app-manifest+json',\n\t'application/x-font-woff',\n\t'application/x-font-woff2',\n\t'image/svg+xml',\n\t'image/x-icon',\n] as const;\n\n/**\n * Combined list of all safe MIME types\n */\nconst safeMimeTypes = [\n\t...imageMimeTypes,\n\t...videoMimeTypes,\n\t...audioMimeTypes,\n\t...documentMimeTypes,\n\t...archiveMimeTypes,\n\t...webAssetTypes,\n] as Array<\n\t| (typeof imageMimeTypes)[number]\n\t| (typeof videoMimeTypes)[number]\n\t| (typeof audioMimeTypes)[number]\n\t| (typeof documentMimeTypes)[number]\n\t| (typeof archiveMimeTypes)[number]\n\t| (typeof webAssetTypes)[number]\n>;\n\n/**\n * Map of MIME kind to list of MIME types\n */\nconst mimeTypeMap: Record<MimeKindWithSafe, readonly string[]> = {\n\tIMAGE: imageMimeTypes,\n\tVIDEO: videoMimeTypes,\n\tAUDIO: audioMimeTypes,\n\tDOCUMENT: documentMimeTypes,\n\tARCHIVE: archiveMimeTypes,\n\tSAFE: safeMimeTypes,\n\tOTHER: [],\n};\n\n/**\n * Returns a comma-separated accept string for input elements based on the specified kind\n * @param kind - The type of MIME kind to get the accept string for\n * @returns Comma-separated MIME types string\n * @example getInputAccept('IMAGE') // \"image/png,image/jpeg,...\"\n */\nconst getInputAccept = (kind: MimeKindWithSafe = 'SAFE'): string => {\n\treturn mimeTypeMap[kind].join(',');\n};\n\n/**\n * Check if a MIME type is allowed for a given kind\n * @param mimeType - MIME type to check\n * @param kind - The type of MIME kind to check against (default: 'SAFE')\n * @returns True if MIME type is allowed\n * @example isAllowedMimeType('image/png', 'IMAGE') // true\n * @example isAllowedMimeType('application/exe', 'SAFE') // false\n */\nconst isAllowedMimeType = (\n\tmimeType: string,\n\tkind: MimeKindWithSafe = 'SAFE'\n): boolean => {\n\tif (!mimeType || typeof mimeType !== 'string') {\n\t\treturn false;\n\t}\n\n\tconst lowerMimeType = mimeType.toLowerCase().split(';')[0].trim();\n\n\treturn mimeTypeMap[kind].includes(lowerMimeType);\n};\n\n/**\n * List of MIME types that should use inline Content-Disposition\n */\nconst inlineContentDispositionMimeTypes = [\n\t'text/plain',\n\t'text/xml',\n\t'application/json',\n\t'application/pdf',\n] as const;\n\n/**\n * Check if a MIME type should use inline Content-Disposition\n * @param mimeType - MIME type to check\n * @returns True if should be inline\n * @example isInlineContentDisposition('image/png') // true\n * @example isInlineContentDisposition('application/zip') // false\n */\nconst isInlineContentDisposition = (mimeType: string): boolean => {\n\tconst lowerMimeType = mimeType.toLowerCase().split(';')[0].trim();\n\treturn (\n\t\tinlineContentDispositionMimeTypes.includes(\n\t\t\tlowerMimeType as (typeof inlineContentDispositionMimeTypes)[number]\n\t\t) ||\n\t\tlowerMimeType.startsWith('image/') ||\n\t\tlowerMimeType.startsWith('video/') ||\n\t\tlowerMimeType.startsWith('audio/')\n\t);\n};\n\n/**\n * Resolve a MIME type to its category\n * @param _mimeType - MIME type to resolve\n * @returns The MIME kind category\n * @example mimeTypeResolver('image/png') // 'IMAGE'\n * @example mimeTypeResolver('video/mp4') // 'VIDEO'\n */\nconst mimeTypeResolver = (_mimeType: string): MimeKind => {\n\tconst mimeType = _mimeType.toLowerCase().split(';')[0].trim();\n\n\tif (mimeType.startsWith('image/')) {\n\t\treturn 'IMAGE';\n\t} else if (mimeType.startsWith('video/')) {\n\t\treturn 'VIDEO';\n\t} else if (mimeType.startsWith('audio/')) {\n\t\treturn 'AUDIO';\n\t} else if (\n\t\tdocumentMimeTypes.includes(mimeType as (typeof documentMimeTypes)[number])\n\t) {\n\t\treturn 'DOCUMENT';\n\t} else if (\n\t\tarchiveMimeTypes.includes(mimeType as (typeof archiveMimeTypes)[number])\n\t) {\n\t\treturn 'ARCHIVE';\n\t} else {\n\t\treturn 'OTHER';\n\t}\n};\n\nexport {\n\ttype MimeKind,\n\ttype MimeKindWithSafe,\n\timageMimeTypes,\n\tvideoMimeTypes,\n\taudioMimeTypes,\n\tdocumentMimeTypes,\n\tarchiveMimeTypes,\n\tsafeMimeTypes,\n\tmimeTypeMap,\n\tgetInputAccept,\n\tisAllowedMimeType,\n\tisInlineContentDisposition,\n\tmimeTypeResolver,\n\tinlineContentDispositionMimeTypes,\n};\n"],"names":["imageMimeTypes","videoMimeTypes","audioMimeTypes","documentMimeTypes","archiveMimeTypes","webAssetTypes","safeMimeTypes","mimeTypeMap","getInputAccept","__name","kind","isAllowedMimeType","mimeType","lowerMimeType","inlineContentDispositionMimeTypes","isInlineContentDisposition","mimeTypeResolver","_mimeType"],"mappings":"4FAaA,MAAMA,EAAiB,CACtB,YACA,aACA,aACA,YACA,YACA,gBACA,eACA,aACA,aACA,aACA,aACA,WACD,EAKMC,EAAiB,CACtB,YACA,aACA,YACA,YACA,aACA,kBACA,kBACA,mBACA,cACA,iBACA,eACA,iBACA,iBACA,iBACA,mBACA,qBACD,EAKMC,EAAiB,CACtB,aACA,YACA,YACA,YACA,aACA,YACA,cACA,eACA,cACA,iBACA,iBACA,mBACA,eACA,aACD,EAKMC,EAAoB,CACzB,aACA,WACA,WACA,gBACA,kBACA,aACA,aACA,cACA,WACA,qBACA,kBACA,kBACA,kBACA,qBACA,0EACA,2BACA,oEACA,0CACA,gDACD,EAKMC,EAAmB,CACxB,kBACA,8BACA,+BACA,oBACA,mBACA,sBACA,mBACA,yBACA,wBACA,+BACA,oBACA,qBACA,oBACD,EAKMC,EAAgB,CACrB,YACA,WACA,kBACA,mBACA,kBACA,2BACA,sCACA,0BACA,2BACA,gBACA,cACD,EAKMC,EAAgB,CACrB,GAAGN,EACH,GAAGC,EACH,GAAGC,EACH,GAAGC,EACH,GAAGC,EACH,GAAGC,CACJ,EAYME,EAA2D,CAChE,MAAOP,EACP,MAAOC,EACP,MAAOC,EACP,SAAUC,EACV,QAASC,EACT,KAAME,EACN,MAAO,CAAA,CACR,EAQME,EAAiBC,EAAA,CAACC,EAAyB,SACzCH,EAAYG,CAAI,EAAE,KAAK,GAAG,EADX,kBAYjBC,EAAoBF,EAAA,CACzBG,EACAF,EAAyB,SACZ,CACb,GAAI,CAACE,GAAY,OAAOA,GAAa,SACpC,MAAO,GAGR,MAAMC,EAAgBD,EAAS,YAAA,EAAc,MAAM,GAAG,EAAE,CAAC,EAAE,KAAA,EAE3D,OAAOL,EAAYG,CAAI,EAAE,SAASG,CAAa,CAChD,EAX0B,qBAgBpBC,EAAoC,CACzC,aACA,WACA,mBACA,iBACD,EASMC,EAA6BN,EAACG,GAA8B,CACjE,MAAMC,EAAgBD,EAAS,YAAA,EAAc,MAAM,GAAG,EAAE,CAAC,EAAE,KAAA,EAC3D,OACCE,EAAkC,SACjCD,CAAA,GAEDA,EAAc,WAAW,QAAQ,GACjCA,EAAc,WAAW,QAAQ,GACjCA,EAAc,WAAW,QAAQ,CAEnC,EAVmC,8BAmB7BG,EAAmBP,EAACQ,GAAgC,CACzD,MAAML,EAAWK,EAAU,YAAA,EAAc,MAAM,GAAG,EAAE,CAAC,EAAE,KAAA,EAEvD,OAAIL,EAAS,WAAW,QAAQ,EACxB,QACGA,EAAS,WAAW,QAAQ,EAC/B,QACGA,EAAS,WAAW,QAAQ,EAC/B,QAEPT,EAAkB,SAASS,CAA8C,EAElE,WAEPR,EAAiB,SAASQ,CAA6C,EAEhE,UAEA,OAET,EApByB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mime-types-D_K53zgk.mjs","sources":["../src/utils/mime-types.ts"],"sourcesContent":["type MimeKind = 'IMAGE' | 'VIDEO' | 'AUDIO' | 'DOCUMENT' | 'ARCHIVE' | 'OTHER';\ntype MimeKindWithSafe = MimeKind | 'SAFE';\n\nconst imageMimeTypes = [\n\t'image/png',\n\t'image/jpeg',\n\t'image/webp',\n\t'image/gif',\n\t'image/bmp',\n\t'image/svg+xml',\n\t'image/x-icon',\n\t'image/tiff',\n\t'image/heic',\n\t'image/avif',\n\t'image/apng',\n\t'image/jpg',\n] as const;\n\nconst videoMimeTypes = [\n\t'video/mp4',\n\t'video/webm',\n\t'video/ogg',\n\t'video/avi',\n\t'video/mpeg',\n\t'video/quicktime',\n\t'video/x-msvideo',\n\t'video/x-matroska',\n\t'video/x-flv',\n\t'video/x-ms-wmv',\n\t'video/x-mpeg',\n\t'video/x-ms-asf',\n\t'video/x-ms-wmx',\n\t'video/x-ms-wvx',\n\t'video/x-matroska',\n\t'video/x-flash-video',\n] as const;\n\nconst audioMimeTypes = [\n\t'audio/mpeg',\n\t'audio/wav',\n\t'audio/ogg',\n\t'audio/aac',\n\t'audio/flac',\n\t'audio/mp3',\n\t'audio/x-wav',\n\t'audio/x-aiff',\n\t'audio/x-m4a',\n\t'audio/x-ms-wma',\n\t'audio/x-ms-wax',\n\t'audio/x-matroska',\n\t'audio/x-flac',\n\t'audio/x-aac',\n] as const;\n\nconst documentMimeTypes = [\n\t'text/plain',\n\t'text/csv',\n\t'text/rtf',\n\t'text/markdown',\n\t'text/x-markdown',\n\t'text/x-log',\n\t'text/x-ini',\n\t'text/x-yaml',\n\t'text/xml',\n\t'application/x-yaml',\n\t'application/xml',\n\t'application/rtf',\n\t'application/pdf',\n\t'application/msword',\n\t'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n\t'application/vnd.ms-excel',\n\t'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n\t'application/vnd.oasis.opendocument.text',\n\t'application/vnd.oasis.opendocument.spreadsheet',\n] as const;\n\nconst archiveMimeTypes = [\n\t'application/zip',\n\t'application/x-7z-compressed',\n\t'application/x-rar-compressed',\n\t'application/x-tar',\n\t'application/gzip',\n\t'application/x-bzip2',\n\t'application/x-xz',\n\t'application/x-compress',\n\t'application/x-archive',\n\t'application/x-zip-compressed',\n\t'application/x-rar',\n\t'application/x-gzip',\n\t'application/x-bzip',\n] as const;\n\nconst webAssetTypes = [\n\t'text/html',\n\t'text/css',\n\t'text/javascript',\n\t'application/json',\n\t'application/xml',\n\t'application/x-javascript',\n\t'application/x-web-app-manifest+json',\n\t'application/x-font-woff',\n\t'application/x-font-woff2',\n\t'image/svg+xml',\n\t'image/x-icon',\n] as const;\n\nconst safeMimeTypes = [\n\t...imageMimeTypes,\n\t...videoMimeTypes,\n\t...audioMimeTypes,\n\t...documentMimeTypes,\n\t...archiveMimeTypes,\n\t...webAssetTypes,\n] as Array<\n\t| (typeof imageMimeTypes)[number]\n\t| (typeof videoMimeTypes)[number]\n\t| (typeof audioMimeTypes)[number]\n\t| (typeof documentMimeTypes)[number]\n\t| (typeof archiveMimeTypes)[number]\n\t| (typeof webAssetTypes)[number]\n>;\n\nconst mimeTypeMap: Record<MimeKindWithSafe, readonly string[]> = {\n\tIMAGE: imageMimeTypes,\n\tVIDEO: videoMimeTypes,\n\tAUDIO: audioMimeTypes,\n\tDOCUMENT: documentMimeTypes,\n\tARCHIVE: archiveMimeTypes,\n\tSAFE: safeMimeTypes,\n\tOTHER: [],\n};\n\n/**\n * Returns a comma-separated accept string for input elements based on the specified kind\n * @param kind The type of MIME kind to get the accept string for\n */\nconst getInputAccept = (kind: MimeKindWithSafe = 'SAFE'): string => {\n\treturn mimeTypeMap[kind].join(',');\n};\n\nconst isAllowedMimeType = (\n\tmimeType: string,\n\tkind: MimeKindWithSafe = 'SAFE'\n): boolean => {\n\tif (!mimeType || typeof mimeType !== 'string') {\n\t\treturn false;\n\t}\n\n\tconst lowerMimeType = mimeType.toLowerCase().split(';')[0].trim();\n\n\treturn mimeTypeMap[kind].includes(lowerMimeType);\n};\n\nconst inlineContentDispositionMimeTypes = [\n\t'text/plain',\n\t'text/xml',\n\t'application/json',\n\t'application/pdf',\n] as const;\n\nconst isInlineContentDisposition = (mimeType: string): boolean => {\n\tconst lowerMimeType = mimeType.toLowerCase().split(';')[0].trim();\n\treturn (\n\t\tinlineContentDispositionMimeTypes.includes(\n\t\t\tlowerMimeType as (typeof inlineContentDispositionMimeTypes)[number]\n\t\t) ||\n\t\tlowerMimeType.startsWith('image/') ||\n\t\tlowerMimeType.startsWith('video/') ||\n\t\tlowerMimeType.startsWith('audio/')\n\t);\n};\n\nconst mimeTypeResolver = (_mimeType: string): MimeKind => {\n\tconst mimeType = _mimeType.toLowerCase().split(';')[0].trim();\n\n\tif (mimeType.startsWith('image/')) {\n\t\treturn 'IMAGE';\n\t} else if (mimeType.startsWith('video/')) {\n\t\treturn 'VIDEO';\n\t} else if (mimeType.startsWith('audio/')) {\n\t\treturn 'AUDIO';\n\t} else if (\n\t\tdocumentMimeTypes.includes(mimeType as (typeof documentMimeTypes)[number])\n\t) {\n\t\treturn 'DOCUMENT';\n\t} else if (\n\t\tarchiveMimeTypes.includes(mimeType as (typeof archiveMimeTypes)[number])\n\t) {\n\t\treturn 'ARCHIVE';\n\t} else {\n\t\treturn 'OTHER';\n\t}\n};\n\nexport {\n\ttype MimeKind,\n\ttype MimeKindWithSafe,\n\timageMimeTypes,\n\tvideoMimeTypes,\n\taudioMimeTypes,\n\tdocumentMimeTypes,\n\tarchiveMimeTypes,\n\tsafeMimeTypes,\n\tmimeTypeMap,\n\tgetInputAccept,\n\tisAllowedMimeType,\n\tisInlineContentDisposition,\n\tmimeTypeResolver,\n\tinlineContentDispositionMimeTypes,\n};\n"],"names":["imageMimeTypes","videoMimeTypes","audioMimeTypes","documentMimeTypes","archiveMimeTypes","webAssetTypes","safeMimeTypes","mimeTypeMap","getInputAccept","__name","kind","isAllowedMimeType","mimeType","lowerMimeType","inlineContentDispositionMimeTypes","isInlineContentDisposition","mimeTypeResolver","_mimeType"],"mappings":"+
|
|
1
|
+
{"version":3,"file":"mime-types-D_K53zgk.mjs","sources":["../src/utils/mime-types.ts"],"sourcesContent":["/**\n * MIME type category\n */\ntype MimeKind = 'IMAGE' | 'VIDEO' | 'AUDIO' | 'DOCUMENT' | 'ARCHIVE' | 'OTHER';\n\n/**\n * MIME type category including SAFE (all safe types combined)\n */\ntype MimeKindWithSafe = MimeKind | 'SAFE';\n\n/**\n * List of common image MIME types\n */\nconst imageMimeTypes = [\n\t'image/png',\n\t'image/jpeg',\n\t'image/webp',\n\t'image/gif',\n\t'image/bmp',\n\t'image/svg+xml',\n\t'image/x-icon',\n\t'image/tiff',\n\t'image/heic',\n\t'image/avif',\n\t'image/apng',\n\t'image/jpg',\n] as const;\n\n/**\n * List of common video MIME types\n */\nconst videoMimeTypes = [\n\t'video/mp4',\n\t'video/webm',\n\t'video/ogg',\n\t'video/avi',\n\t'video/mpeg',\n\t'video/quicktime',\n\t'video/x-msvideo',\n\t'video/x-matroska',\n\t'video/x-flv',\n\t'video/x-ms-wmv',\n\t'video/x-mpeg',\n\t'video/x-ms-asf',\n\t'video/x-ms-wmx',\n\t'video/x-ms-wvx',\n\t'video/x-matroska',\n\t'video/x-flash-video',\n] as const;\n\n/**\n * List of common audio MIME types\n */\nconst audioMimeTypes = [\n\t'audio/mpeg',\n\t'audio/wav',\n\t'audio/ogg',\n\t'audio/aac',\n\t'audio/flac',\n\t'audio/mp3',\n\t'audio/x-wav',\n\t'audio/x-aiff',\n\t'audio/x-m4a',\n\t'audio/x-ms-wma',\n\t'audio/x-ms-wax',\n\t'audio/x-matroska',\n\t'audio/x-flac',\n\t'audio/x-aac',\n] as const;\n\n/**\n * List of common document MIME types\n */\nconst documentMimeTypes = [\n\t'text/plain',\n\t'text/csv',\n\t'text/rtf',\n\t'text/markdown',\n\t'text/x-markdown',\n\t'text/x-log',\n\t'text/x-ini',\n\t'text/x-yaml',\n\t'text/xml',\n\t'application/x-yaml',\n\t'application/xml',\n\t'application/rtf',\n\t'application/pdf',\n\t'application/msword',\n\t'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n\t'application/vnd.ms-excel',\n\t'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n\t'application/vnd.oasis.opendocument.text',\n\t'application/vnd.oasis.opendocument.spreadsheet',\n] as const;\n\n/**\n * List of common archive/compression MIME types\n */\nconst archiveMimeTypes = [\n\t'application/zip',\n\t'application/x-7z-compressed',\n\t'application/x-rar-compressed',\n\t'application/x-tar',\n\t'application/gzip',\n\t'application/x-bzip2',\n\t'application/x-xz',\n\t'application/x-compress',\n\t'application/x-archive',\n\t'application/x-zip-compressed',\n\t'application/x-rar',\n\t'application/x-gzip',\n\t'application/x-bzip',\n] as const;\n\n/**\n * List of web asset MIME types (HTML, CSS, JS, fonts, etc.)\n */\nconst webAssetTypes = [\n\t'text/html',\n\t'text/css',\n\t'text/javascript',\n\t'application/json',\n\t'application/xml',\n\t'application/x-javascript',\n\t'application/x-web-app-manifest+json',\n\t'application/x-font-woff',\n\t'application/x-font-woff2',\n\t'image/svg+xml',\n\t'image/x-icon',\n] as const;\n\n/**\n * Combined list of all safe MIME types\n */\nconst safeMimeTypes = [\n\t...imageMimeTypes,\n\t...videoMimeTypes,\n\t...audioMimeTypes,\n\t...documentMimeTypes,\n\t...archiveMimeTypes,\n\t...webAssetTypes,\n] as Array<\n\t| (typeof imageMimeTypes)[number]\n\t| (typeof videoMimeTypes)[number]\n\t| (typeof audioMimeTypes)[number]\n\t| (typeof documentMimeTypes)[number]\n\t| (typeof archiveMimeTypes)[number]\n\t| (typeof webAssetTypes)[number]\n>;\n\n/**\n * Map of MIME kind to list of MIME types\n */\nconst mimeTypeMap: Record<MimeKindWithSafe, readonly string[]> = {\n\tIMAGE: imageMimeTypes,\n\tVIDEO: videoMimeTypes,\n\tAUDIO: audioMimeTypes,\n\tDOCUMENT: documentMimeTypes,\n\tARCHIVE: archiveMimeTypes,\n\tSAFE: safeMimeTypes,\n\tOTHER: [],\n};\n\n/**\n * Returns a comma-separated accept string for input elements based on the specified kind\n * @param kind - The type of MIME kind to get the accept string for\n * @returns Comma-separated MIME types string\n * @example getInputAccept('IMAGE') // \"image/png,image/jpeg,...\"\n */\nconst getInputAccept = (kind: MimeKindWithSafe = 'SAFE'): string => {\n\treturn mimeTypeMap[kind].join(',');\n};\n\n/**\n * Check if a MIME type is allowed for a given kind\n * @param mimeType - MIME type to check\n * @param kind - The type of MIME kind to check against (default: 'SAFE')\n * @returns True if MIME type is allowed\n * @example isAllowedMimeType('image/png', 'IMAGE') // true\n * @example isAllowedMimeType('application/exe', 'SAFE') // false\n */\nconst isAllowedMimeType = (\n\tmimeType: string,\n\tkind: MimeKindWithSafe = 'SAFE'\n): boolean => {\n\tif (!mimeType || typeof mimeType !== 'string') {\n\t\treturn false;\n\t}\n\n\tconst lowerMimeType = mimeType.toLowerCase().split(';')[0].trim();\n\n\treturn mimeTypeMap[kind].includes(lowerMimeType);\n};\n\n/**\n * List of MIME types that should use inline Content-Disposition\n */\nconst inlineContentDispositionMimeTypes = [\n\t'text/plain',\n\t'text/xml',\n\t'application/json',\n\t'application/pdf',\n] as const;\n\n/**\n * Check if a MIME type should use inline Content-Disposition\n * @param mimeType - MIME type to check\n * @returns True if should be inline\n * @example isInlineContentDisposition('image/png') // true\n * @example isInlineContentDisposition('application/zip') // false\n */\nconst isInlineContentDisposition = (mimeType: string): boolean => {\n\tconst lowerMimeType = mimeType.toLowerCase().split(';')[0].trim();\n\treturn (\n\t\tinlineContentDispositionMimeTypes.includes(\n\t\t\tlowerMimeType as (typeof inlineContentDispositionMimeTypes)[number]\n\t\t) ||\n\t\tlowerMimeType.startsWith('image/') ||\n\t\tlowerMimeType.startsWith('video/') ||\n\t\tlowerMimeType.startsWith('audio/')\n\t);\n};\n\n/**\n * Resolve a MIME type to its category\n * @param _mimeType - MIME type to resolve\n * @returns The MIME kind category\n * @example mimeTypeResolver('image/png') // 'IMAGE'\n * @example mimeTypeResolver('video/mp4') // 'VIDEO'\n */\nconst mimeTypeResolver = (_mimeType: string): MimeKind => {\n\tconst mimeType = _mimeType.toLowerCase().split(';')[0].trim();\n\n\tif (mimeType.startsWith('image/')) {\n\t\treturn 'IMAGE';\n\t} else if (mimeType.startsWith('video/')) {\n\t\treturn 'VIDEO';\n\t} else if (mimeType.startsWith('audio/')) {\n\t\treturn 'AUDIO';\n\t} else if (\n\t\tdocumentMimeTypes.includes(mimeType as (typeof documentMimeTypes)[number])\n\t) {\n\t\treturn 'DOCUMENT';\n\t} else if (\n\t\tarchiveMimeTypes.includes(mimeType as (typeof archiveMimeTypes)[number])\n\t) {\n\t\treturn 'ARCHIVE';\n\t} else {\n\t\treturn 'OTHER';\n\t}\n};\n\nexport {\n\ttype MimeKind,\n\ttype MimeKindWithSafe,\n\timageMimeTypes,\n\tvideoMimeTypes,\n\taudioMimeTypes,\n\tdocumentMimeTypes,\n\tarchiveMimeTypes,\n\tsafeMimeTypes,\n\tmimeTypeMap,\n\tgetInputAccept,\n\tisAllowedMimeType,\n\tisInlineContentDisposition,\n\tmimeTypeResolver,\n\tinlineContentDispositionMimeTypes,\n};\n"],"names":["imageMimeTypes","videoMimeTypes","audioMimeTypes","documentMimeTypes","archiveMimeTypes","webAssetTypes","safeMimeTypes","mimeTypeMap","getInputAccept","__name","kind","isAllowedMimeType","mimeType","lowerMimeType","inlineContentDispositionMimeTypes","isInlineContentDisposition","mimeTypeResolver","_mimeType"],"mappings":"+EAaA,MAAMA,EAAiB,CACtB,YACA,aACA,aACA,YACA,YACA,gBACA,eACA,aACA,aACA,aACA,aACA,WACD,EAKMC,EAAiB,CACtB,YACA,aACA,YACA,YACA,aACA,kBACA,kBACA,mBACA,cACA,iBACA,eACA,iBACA,iBACA,iBACA,mBACA,qBACD,EAKMC,EAAiB,CACtB,aACA,YACA,YACA,YACA,aACA,YACA,cACA,eACA,cACA,iBACA,iBACA,mBACA,eACA,aACD,EAKMC,EAAoB,CACzB,aACA,WACA,WACA,gBACA,kBACA,aACA,aACA,cACA,WACA,qBACA,kBACA,kBACA,kBACA,qBACA,0EACA,2BACA,oEACA,0CACA,gDACD,EAKMC,EAAmB,CACxB,kBACA,8BACA,+BACA,oBACA,mBACA,sBACA,mBACA,yBACA,wBACA,+BACA,oBACA,qBACA,oBACD,EAKMC,EAAgB,CACrB,YACA,WACA,kBACA,mBACA,kBACA,2BACA,sCACA,0BACA,2BACA,gBACA,cACD,EAKMC,EAAgB,CACrB,GAAGN,EACH,GAAGC,EACH,GAAGC,EACH,GAAGC,EACH,GAAGC,EACH,GAAGC,CACJ,EAYME,EAA2D,CAChE,MAAOP,EACP,MAAOC,EACP,MAAOC,EACP,SAAUC,EACV,QAASC,EACT,KAAME,EACN,MAAO,CAAA,CACR,EAQME,EAAiBC,EAAA,CAACC,EAAyB,SACzCH,EAAYG,CAAI,EAAE,KAAK,GAAG,EADX,kBAYjBC,EAAoBF,EAAA,CACzBG,EACAF,EAAyB,SACZ,CACb,GAAI,CAACE,GAAY,OAAOA,GAAa,SACpC,MAAO,GAGR,MAAMC,EAAgBD,EAAS,YAAA,EAAc,MAAM,GAAG,EAAE,CAAC,EAAE,KAAA,EAE3D,OAAOL,EAAYG,CAAI,EAAE,SAASG,CAAa,CAChD,EAX0B,qBAgBpBC,EAAoC,CACzC,aACA,WACA,mBACA,iBACD,EASMC,EAA6BN,EAACG,GAA8B,CACjE,MAAMC,EAAgBD,EAAS,YAAA,EAAc,MAAM,GAAG,EAAE,CAAC,EAAE,KAAA,EAC3D,OACCE,EAAkC,SACjCD,CAAA,GAEDA,EAAc,WAAW,QAAQ,GACjCA,EAAc,WAAW,QAAQ,GACjCA,EAAc,WAAW,QAAQ,CAEnC,EAVmC,8BAmB7BG,EAAmBP,EAACQ,GAAgC,CACzD,MAAML,EAAWK,EAAU,YAAA,EAAc,MAAM,GAAG,EAAE,CAAC,EAAE,KAAA,EAEvD,OAAIL,EAAS,WAAW,QAAQ,EACxB,QACGA,EAAS,WAAW,QAAQ,EAC/B,QACGA,EAAS,WAAW,QAAQ,EAC/B,QAEPT,EAAkB,SAASS,CAA8C,EAElE,WAEPR,EAAiB,SAASQ,CAA6C,EAEhE,UAEA,OAET,EApByB"}
|
|
@@ -1,21 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIME type category
|
|
3
|
+
*/
|
|
1
4
|
type MimeKind = 'IMAGE' | 'VIDEO' | 'AUDIO' | 'DOCUMENT' | 'ARCHIVE' | 'OTHER';
|
|
5
|
+
/**
|
|
6
|
+
* MIME type category including SAFE (all safe types combined)
|
|
7
|
+
*/
|
|
2
8
|
type MimeKindWithSafe = MimeKind | 'SAFE';
|
|
9
|
+
/**
|
|
10
|
+
* List of common image MIME types
|
|
11
|
+
*/
|
|
3
12
|
declare const imageMimeTypes: readonly ["image/png", "image/jpeg", "image/webp", "image/gif", "image/bmp", "image/svg+xml", "image/x-icon", "image/tiff", "image/heic", "image/avif", "image/apng", "image/jpg"];
|
|
13
|
+
/**
|
|
14
|
+
* List of common video MIME types
|
|
15
|
+
*/
|
|
4
16
|
declare const videoMimeTypes: readonly ["video/mp4", "video/webm", "video/ogg", "video/avi", "video/mpeg", "video/quicktime", "video/x-msvideo", "video/x-matroska", "video/x-flv", "video/x-ms-wmv", "video/x-mpeg", "video/x-ms-asf", "video/x-ms-wmx", "video/x-ms-wvx", "video/x-matroska", "video/x-flash-video"];
|
|
17
|
+
/**
|
|
18
|
+
* List of common audio MIME types
|
|
19
|
+
*/
|
|
5
20
|
declare const audioMimeTypes: readonly ["audio/mpeg", "audio/wav", "audio/ogg", "audio/aac", "audio/flac", "audio/mp3", "audio/x-wav", "audio/x-aiff", "audio/x-m4a", "audio/x-ms-wma", "audio/x-ms-wax", "audio/x-matroska", "audio/x-flac", "audio/x-aac"];
|
|
21
|
+
/**
|
|
22
|
+
* List of common document MIME types
|
|
23
|
+
*/
|
|
6
24
|
declare const documentMimeTypes: readonly ["text/plain", "text/csv", "text/rtf", "text/markdown", "text/x-markdown", "text/x-log", "text/x-ini", "text/x-yaml", "text/xml", "application/x-yaml", "application/xml", "application/rtf", "application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.oasis.opendocument.text", "application/vnd.oasis.opendocument.spreadsheet"];
|
|
25
|
+
/**
|
|
26
|
+
* List of common archive/compression MIME types
|
|
27
|
+
*/
|
|
7
28
|
declare const archiveMimeTypes: readonly ["application/zip", "application/x-7z-compressed", "application/x-rar-compressed", "application/x-tar", "application/gzip", "application/x-bzip2", "application/x-xz", "application/x-compress", "application/x-archive", "application/x-zip-compressed", "application/x-rar", "application/x-gzip", "application/x-bzip"];
|
|
29
|
+
/**
|
|
30
|
+
* List of web asset MIME types (HTML, CSS, JS, fonts, etc.)
|
|
31
|
+
*/
|
|
8
32
|
declare const webAssetTypes: readonly ["text/html", "text/css", "text/javascript", "application/json", "application/xml", "application/x-javascript", "application/x-web-app-manifest+json", "application/x-font-woff", "application/x-font-woff2", "image/svg+xml", "image/x-icon"];
|
|
33
|
+
/**
|
|
34
|
+
* Combined list of all safe MIME types
|
|
35
|
+
*/
|
|
9
36
|
declare const safeMimeTypes: Array<(typeof imageMimeTypes)[number] | (typeof videoMimeTypes)[number] | (typeof audioMimeTypes)[number] | (typeof documentMimeTypes)[number] | (typeof archiveMimeTypes)[number] | (typeof webAssetTypes)[number]>;
|
|
37
|
+
/**
|
|
38
|
+
* Map of MIME kind to list of MIME types
|
|
39
|
+
*/
|
|
10
40
|
declare const mimeTypeMap: Record<MimeKindWithSafe, readonly string[]>;
|
|
11
41
|
/**
|
|
12
42
|
* Returns a comma-separated accept string for input elements based on the specified kind
|
|
13
|
-
* @param kind The type of MIME kind to get the accept string for
|
|
43
|
+
* @param kind - The type of MIME kind to get the accept string for
|
|
44
|
+
* @returns Comma-separated MIME types string
|
|
45
|
+
* @example getInputAccept('IMAGE') // "image/png,image/jpeg,..."
|
|
14
46
|
*/
|
|
15
47
|
declare const getInputAccept: (kind?: MimeKindWithSafe) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Check if a MIME type is allowed for a given kind
|
|
50
|
+
* @param mimeType - MIME type to check
|
|
51
|
+
* @param kind - The type of MIME kind to check against (default: 'SAFE')
|
|
52
|
+
* @returns True if MIME type is allowed
|
|
53
|
+
* @example isAllowedMimeType('image/png', 'IMAGE') // true
|
|
54
|
+
* @example isAllowedMimeType('application/exe', 'SAFE') // false
|
|
55
|
+
*/
|
|
16
56
|
declare const isAllowedMimeType: (mimeType: string, kind?: MimeKindWithSafe) => boolean;
|
|
57
|
+
/**
|
|
58
|
+
* List of MIME types that should use inline Content-Disposition
|
|
59
|
+
*/
|
|
17
60
|
declare const inlineContentDispositionMimeTypes: readonly ["text/plain", "text/xml", "application/json", "application/pdf"];
|
|
61
|
+
/**
|
|
62
|
+
* Check if a MIME type should use inline Content-Disposition
|
|
63
|
+
* @param mimeType - MIME type to check
|
|
64
|
+
* @returns True if should be inline
|
|
65
|
+
* @example isInlineContentDisposition('image/png') // true
|
|
66
|
+
* @example isInlineContentDisposition('application/zip') // false
|
|
67
|
+
*/
|
|
18
68
|
declare const isInlineContentDisposition: (mimeType: string) => boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Resolve a MIME type to its category
|
|
71
|
+
* @param _mimeType - MIME type to resolve
|
|
72
|
+
* @returns The MIME kind category
|
|
73
|
+
* @example mimeTypeResolver('image/png') // 'IMAGE'
|
|
74
|
+
* @example mimeTypeResolver('video/mp4') // 'VIDEO'
|
|
75
|
+
*/
|
|
19
76
|
declare const mimeTypeResolver: (_mimeType: string) => MimeKind;
|
|
20
77
|
|
|
21
78
|
type mimeTypes_MimeKind = MimeKind;
|
|
@@ -1,21 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIME type category
|
|
3
|
+
*/
|
|
1
4
|
type MimeKind = 'IMAGE' | 'VIDEO' | 'AUDIO' | 'DOCUMENT' | 'ARCHIVE' | 'OTHER';
|
|
5
|
+
/**
|
|
6
|
+
* MIME type category including SAFE (all safe types combined)
|
|
7
|
+
*/
|
|
2
8
|
type MimeKindWithSafe = MimeKind | 'SAFE';
|
|
9
|
+
/**
|
|
10
|
+
* List of common image MIME types
|
|
11
|
+
*/
|
|
3
12
|
declare const imageMimeTypes: readonly ["image/png", "image/jpeg", "image/webp", "image/gif", "image/bmp", "image/svg+xml", "image/x-icon", "image/tiff", "image/heic", "image/avif", "image/apng", "image/jpg"];
|
|
13
|
+
/**
|
|
14
|
+
* List of common video MIME types
|
|
15
|
+
*/
|
|
4
16
|
declare const videoMimeTypes: readonly ["video/mp4", "video/webm", "video/ogg", "video/avi", "video/mpeg", "video/quicktime", "video/x-msvideo", "video/x-matroska", "video/x-flv", "video/x-ms-wmv", "video/x-mpeg", "video/x-ms-asf", "video/x-ms-wmx", "video/x-ms-wvx", "video/x-matroska", "video/x-flash-video"];
|
|
17
|
+
/**
|
|
18
|
+
* List of common audio MIME types
|
|
19
|
+
*/
|
|
5
20
|
declare const audioMimeTypes: readonly ["audio/mpeg", "audio/wav", "audio/ogg", "audio/aac", "audio/flac", "audio/mp3", "audio/x-wav", "audio/x-aiff", "audio/x-m4a", "audio/x-ms-wma", "audio/x-ms-wax", "audio/x-matroska", "audio/x-flac", "audio/x-aac"];
|
|
21
|
+
/**
|
|
22
|
+
* List of common document MIME types
|
|
23
|
+
*/
|
|
6
24
|
declare const documentMimeTypes: readonly ["text/plain", "text/csv", "text/rtf", "text/markdown", "text/x-markdown", "text/x-log", "text/x-ini", "text/x-yaml", "text/xml", "application/x-yaml", "application/xml", "application/rtf", "application/pdf", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.oasis.opendocument.text", "application/vnd.oasis.opendocument.spreadsheet"];
|
|
25
|
+
/**
|
|
26
|
+
* List of common archive/compression MIME types
|
|
27
|
+
*/
|
|
7
28
|
declare const archiveMimeTypes: readonly ["application/zip", "application/x-7z-compressed", "application/x-rar-compressed", "application/x-tar", "application/gzip", "application/x-bzip2", "application/x-xz", "application/x-compress", "application/x-archive", "application/x-zip-compressed", "application/x-rar", "application/x-gzip", "application/x-bzip"];
|
|
29
|
+
/**
|
|
30
|
+
* List of web asset MIME types (HTML, CSS, JS, fonts, etc.)
|
|
31
|
+
*/
|
|
8
32
|
declare const webAssetTypes: readonly ["text/html", "text/css", "text/javascript", "application/json", "application/xml", "application/x-javascript", "application/x-web-app-manifest+json", "application/x-font-woff", "application/x-font-woff2", "image/svg+xml", "image/x-icon"];
|
|
33
|
+
/**
|
|
34
|
+
* Combined list of all safe MIME types
|
|
35
|
+
*/
|
|
9
36
|
declare const safeMimeTypes: Array<(typeof imageMimeTypes)[number] | (typeof videoMimeTypes)[number] | (typeof audioMimeTypes)[number] | (typeof documentMimeTypes)[number] | (typeof archiveMimeTypes)[number] | (typeof webAssetTypes)[number]>;
|
|
37
|
+
/**
|
|
38
|
+
* Map of MIME kind to list of MIME types
|
|
39
|
+
*/
|
|
10
40
|
declare const mimeTypeMap: Record<MimeKindWithSafe, readonly string[]>;
|
|
11
41
|
/**
|
|
12
42
|
* Returns a comma-separated accept string for input elements based on the specified kind
|
|
13
|
-
* @param kind The type of MIME kind to get the accept string for
|
|
43
|
+
* @param kind - The type of MIME kind to get the accept string for
|
|
44
|
+
* @returns Comma-separated MIME types string
|
|
45
|
+
* @example getInputAccept('IMAGE') // "image/png,image/jpeg,..."
|
|
14
46
|
*/
|
|
15
47
|
declare const getInputAccept: (kind?: MimeKindWithSafe) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Check if a MIME type is allowed for a given kind
|
|
50
|
+
* @param mimeType - MIME type to check
|
|
51
|
+
* @param kind - The type of MIME kind to check against (default: 'SAFE')
|
|
52
|
+
* @returns True if MIME type is allowed
|
|
53
|
+
* @example isAllowedMimeType('image/png', 'IMAGE') // true
|
|
54
|
+
* @example isAllowedMimeType('application/exe', 'SAFE') // false
|
|
55
|
+
*/
|
|
16
56
|
declare const isAllowedMimeType: (mimeType: string, kind?: MimeKindWithSafe) => boolean;
|
|
57
|
+
/**
|
|
58
|
+
* List of MIME types that should use inline Content-Disposition
|
|
59
|
+
*/
|
|
17
60
|
declare const inlineContentDispositionMimeTypes: readonly ["text/plain", "text/xml", "application/json", "application/pdf"];
|
|
61
|
+
/**
|
|
62
|
+
* Check if a MIME type should use inline Content-Disposition
|
|
63
|
+
* @param mimeType - MIME type to check
|
|
64
|
+
* @returns True if should be inline
|
|
65
|
+
* @example isInlineContentDisposition('image/png') // true
|
|
66
|
+
* @example isInlineContentDisposition('application/zip') // false
|
|
67
|
+
*/
|
|
18
68
|
declare const isInlineContentDisposition: (mimeType: string) => boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Resolve a MIME type to its category
|
|
71
|
+
* @param _mimeType - MIME type to resolve
|
|
72
|
+
* @returns The MIME kind category
|
|
73
|
+
* @example mimeTypeResolver('image/png') // 'IMAGE'
|
|
74
|
+
* @example mimeTypeResolver('video/mp4') // 'VIDEO'
|
|
75
|
+
*/
|
|
19
76
|
declare const mimeTypeResolver: (_mimeType: string) => MimeKind;
|
|
20
77
|
|
|
21
78
|
type mimeTypes_MimeKind = MimeKind;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var X=Object.defineProperty;var r=(n,e)=>X(n,"name",{value:e,configurable:!0});const s=r(n=>Number.isInteger(n),"isInt"),I=r(n=>!s(n),"isFloat"),l=r(n=>n%2===0,"isEven"),d=r(n=>n%2!==0,"isOdd"),u=r((n,e=2)=>{const t=10**e;return Math.round(n*t)/t},"roundTo"),M=r((n,e,t)=>Math.min(Math.max(n,e),t),"clamp"),m=r((n,e,t=2)=>e===0?0:u(n/e*100,t),"percentage"),N=r((n,e)=>n/100*e,"percentageOf"),p=r((n,e,t)=>n>=e&&n<=t,"inRange"),f=r((n,e,t)=>n+(e-n)*t,"lerp"),_=r(n=>n.reduce((e,t)=>e+t,0),"sum"),T=r(n=>c(n),"average"),h=2**31-1,b=-2147483648,v=BigInt(2)**BigInt(63)-BigInt(1),A=-(BigInt(2)**BigInt(63)),c=r(n=>n.length===0?null:n.reduce((i,a)=>i+a,0)/n.length,"calculateMean"),E=r(n=>{if(n.length===0)return null;const e=[...n].sort((a,o)=>a-o),t=Math.floor(e.length/2);if(l(e.length)){const a=e[t],o=e[t-1];return(a+o)/2}else return e.length===1?e[0]:e[t]},"calculateMedian"),g=r(n=>{if(n.length===0)return null;const e=c(n);if(typeof e!="number")return null;const t=n.map(a=>(a-e)**2);return c(t)},"calculateVariance"),S=r(n=>{const e=g(n);return typeof e!="number"?null:Math.sqrt(e)},"calculateStandardDeviation"),O=r((n,e)=>typeof e=="bigint"?e>BigInt(Number.MAX_SAFE_INTEGER)?e.toString():Number(e):e,"bigIntSerializationHelper");var B=Object.freeze({__proto__:null,INT32_MAX:h,INT32_MIN:b,INT64_MAX:v,INT64_MIN:A,average:T,bigIntSerializationHelper:O,calculateMean:c,calculateMedian:E,calculateStandardDeviation:S,calculateVariance:g,clamp:M,inRange:p,isEven:l,isFloat:I,isInt:s,isOdd:d,lerp:f,percentage:m,percentageOf:N,roundTo:u,sum:_});exports.INT32_MAX=h,exports.INT32_MIN=b,exports.INT64_MAX=v,exports.INT64_MIN=A,exports.average=T,exports.bigIntSerializationHelper=O,exports.calculateMean=c,exports.calculateMedian=E,exports.calculateStandardDeviation=S,exports.calculateVariance=g,exports.clamp=M,exports.inRange=p,exports.isEven=l,exports.isFloat=I,exports.isInt=s,exports.isOdd=d,exports.lerp=f,exports.numbers=B,exports.percentage=m,exports.percentageOf=N,exports.roundTo=u,exports.sum=_;
|
|
2
|
+
//# sourceMappingURL=numbers-B_mptknO.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numbers-B_mptknO.cjs","sources":["../src/utils/numbers.ts"],"sourcesContent":["/**\n * Check if a number is an integer\n * @param n - Number to check\n * @returns True if number is an integer\n * @example isInt(5) // true, isInt(5.5) // false\n */\nconst isInt = (n: number): boolean => Number.isInteger(n);\n\n/**\n * Check if a number is a float (has decimal places)\n * @param n - Number to check\n * @returns True if number is a float\n * @example isFloat(5.5) // true, isFloat(5) // false\n */\nconst isFloat = (n: number): boolean => !isInt(n);\n\n/**\n * Check if a number is even\n * @param n - Number to check\n * @returns True if number is even\n * @example isEven(4) // true, isEven(5) // false\n */\nconst isEven = (n: number): boolean => n % 2 === 0;\n\n/**\n * Check if a number is odd\n * @param n - Number to check\n * @returns True if number is odd\n * @example isOdd(5) // true, isOdd(4) // false\n */\nconst isOdd = (n: number): boolean => n % 2 !== 0;\n\n/**\n * Round a number to a specific number of decimal places\n * @param value - Number to round\n * @param decimals - Number of decimal places (default: 2)\n * @returns Rounded number\n * @example roundTo(3.14159, 2) // 3.14\n */\nconst roundTo = (value: number, decimals = 2): number => {\n\tconst factor = 10 ** decimals;\n\treturn Math.round(value * factor) / factor;\n};\n\n/**\n * Clamp a number between min and max values\n * @param value - Number to clamp\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns Clamped number\n * @example clamp(15, 0, 10) // 10, clamp(-5, 0, 10) // 0\n */\nconst clamp = (value: number, min: number, max: number): number => {\n\treturn Math.min(Math.max(value, min), max);\n};\n\n/**\n * Calculate percentage of a value relative to a total\n * @param value - The value\n * @param total - The total\n * @param decimals - Number of decimal places (default: 2)\n * @returns Percentage (0-100)\n * @example percentage(25, 100) // 25, percentage(1, 3, 1) // 33.3\n */\nconst percentage = (value: number, total: number, decimals = 2): number => {\n\tif (total === 0) return 0;\n\treturn roundTo((value / total) * 100, decimals);\n};\n\n/**\n * Calculate what value a percentage represents\n * @param percent - Percentage (0-100)\n * @param total - The total\n * @returns The value\n * @example percentageOf(25, 100) // 25, percentageOf(50, 200) // 100\n */\nconst percentageOf = (percent: number, total: number): number => {\n\treturn (percent / 100) * total;\n};\n\n/**\n * Check if a number is within a range (inclusive)\n * @param value - Number to check\n * @param min - Minimum value\n * @param max - Maximum value\n * @returns True if value is in range\n * @example inRange(5, 0, 10) // true, inRange(15, 0, 10) // false\n */\nconst inRange = (value: number, min: number, max: number): boolean => {\n\treturn value >= min && value <= max;\n};\n\n/**\n * Linear interpolation between two values\n * @param start - Start value\n * @param end - End value\n * @param t - Interpolation factor (0-1)\n * @returns Interpolated value\n * @example lerp(0, 100, 0.5) // 50, lerp(0, 100, 0.25) // 25\n */\nconst lerp = (start: number, end: number, t: number): number => {\n\treturn start + (end - start) * t;\n};\n\n/**\n * Sum an array of numbers\n * @param values - Numbers to sum\n * @returns Sum of all values\n * @example sum([1, 2, 3, 4]) // 10\n */\nconst sum = (values: number[]): number => {\n\treturn values.reduce((a, b) => a + b, 0);\n};\n\n/**\n * Get the average (mean) of an array of numbers\n * @param values - Numbers to average\n * @returns Average or null if empty\n * @example average([1, 2, 3, 4]) // 2.5\n */\nconst average = (values: number[]): number | null => calculateMean(values);\n\nconst INT32_MAX: number = 2 ** 31 - 1;\nconst INT32_MIN: number = -(2 ** 31);\nconst INT64_MAX: bigint = BigInt(2) ** BigInt(63) - BigInt(1);\nconst INT64_MIN: bigint = -(BigInt(2) ** BigInt(63));\n\n/**\n * Calculate the mean (average) of an array of numbers\n * @param values - Numbers to calculate mean of\n * @returns Mean or null if empty\n * @example calculateMean([1, 2, 3, 4]) // 2.5\n */\nconst calculateMean = (values: number[]): number | null => {\n\tif (values.length === 0) return null;\n\tconst sum = values.reduce((a, b) => a + b, 0);\n\tconst average = sum / values.length;\n\treturn average;\n};\n\n/**\n * Calculate the median (middle value) of an array of numbers\n * @param values - Numbers to calculate median of\n * @returns Median or null if empty\n * @example calculateMedian([1, 2, 3, 4, 5]) // 3\n */\nconst calculateMedian = (values: number[]): number | null => {\n\tif (values.length === 0) return null;\n\tconst sorted = [...values].sort((a, b) => a - b);\n\tconst middleIndex = Math.floor(sorted.length / 2);\n\tconst isEvenLength = isEven(sorted.length);\n\tif (isEvenLength) {\n\t\tconst a = sorted[middleIndex] as number;\n\t\tconst b = sorted[middleIndex - 1] as number;\n\t\tconst average = (a + b) / 2;\n\t\treturn average;\n\t} else {\n\t\tif (sorted.length === 1) return sorted[0] as number;\n\t\tconst median = sorted[middleIndex] as number;\n\t\treturn median;\n\t}\n};\n\n/**\n * Calculate the variance of an array of numbers\n * @param values - Numbers to calculate variance of\n * @returns Variance or null if empty\n * @example calculateVariance([2, 4, 6, 8]) // 5\n */\nconst calculateVariance = (values: number[]): number | null => {\n\tif (values.length === 0) return null;\n\tconst mean = calculateMean(values);\n\tif (typeof mean !== 'number') return null;\n\tconst squaredDifferences = values.map((value) => (value - mean) ** 2);\n\tconst variance = calculateMean(squaredDifferences);\n\treturn variance;\n};\n\n/**\n * Calculate the standard deviation of an array of numbers\n * @param values - Numbers to calculate standard deviation of\n * @returns Standard deviation or null if empty\n * @example calculateStandardDeviation([2, 4, 6, 8]) // ~2.24\n */\nconst calculateStandardDeviation = (values: number[]): number | null => {\n\tconst variance = calculateVariance(values);\n\tif (typeof variance !== 'number') return null;\n\treturn Math.sqrt(variance);\n};\n\n/**\n * Helper for JSON.stringify to handle BigInt serialization\n * Converts large bigints to strings and small ones to numbers\n * @param _ - Key (unused)\n * @param value - Value to serialize\n * @returns Serializable value\n * @example JSON.stringify({big: 9007199254740992n}, bigIntSerializationHelper)\n */\nconst bigIntSerializationHelper = (_: string, value: unknown): unknown =>\n\ttypeof value === 'bigint'\n\t\t? value > BigInt(Number.MAX_SAFE_INTEGER)\n\t\t\t? value.toString() // Convert large bigints to strings\n\t\t\t: Number(value) // Convert small/safe bigints to numbers\n\t\t: value; // Return other values as is\n\nexport {\n\tisInt,\n\tisFloat,\n\tisEven,\n\tisOdd,\n\troundTo,\n\tclamp,\n\tpercentage,\n\tpercentageOf,\n\tinRange,\n\tlerp,\n\tsum,\n\taverage,\n\tINT32_MAX,\n\tINT32_MIN,\n\tINT64_MAX,\n\tINT64_MIN,\n\tcalculateMean,\n\tcalculateMedian,\n\tcalculateVariance,\n\tcalculateStandardDeviation,\n\tbigIntSerializationHelper,\n};\n"],"names":["isInt","__name","isFloat","isEven","isOdd","roundTo","value","decimals","factor","clamp","min","max","percentage","total","percentageOf","percent","inRange","lerp","start","end","sum","values","a","b","average","calculateMean","INT32_MAX","INT32_MIN","INT64_MAX","INT64_MIN","calculateMedian","sorted","middleIndex","calculateVariance","mean","squaredDifferences","calculateStandardDeviation","variance","bigIntSerializationHelper","_"],"mappings":"4FAMA,MAAMA,EAAQC,EAAC,GAAuB,OAAO,UAAU,CAAC,EAA1C,SAQRC,EAAUD,EAAC,GAAuB,CAACD,EAAM,CAAC,EAAhC,WAQVG,EAASF,EAAC,GAAuB,EAAI,IAAM,EAAlC,UAQTG,EAAQH,EAAC,GAAuB,EAAI,IAAM,EAAlC,SASRI,EAAUJ,EAAA,CAACK,EAAeC,EAAW,IAAc,CACxD,MAAMC,EAAS,IAAMD,EACrB,OAAO,KAAK,MAAMD,EAAQE,CAAM,EAAIA,CACrC,EAHgB,WAaVC,EAAQR,EAAA,CAACK,EAAeI,EAAaC,IACnC,KAAK,IAAI,KAAK,IAAIL,EAAOI,CAAG,EAAGC,CAAG,EAD5B,SAYRC,EAAaX,EAAA,CAACK,EAAeO,EAAeN,EAAW,IACxDM,IAAU,EAAU,EACjBR,EAASC,EAAQO,EAAS,IAAKN,CAAQ,EAF5B,cAYbO,EAAeb,EAAA,CAACc,EAAiBF,IAC9BE,EAAU,IAAOF,EADL,gBAYfG,EAAUf,EAAA,CAACK,EAAeI,EAAaC,IACrCL,GAASI,GAAOJ,GAASK,EADjB,WAYVM,EAAOhB,EAAA,CAACiB,EAAeC,EAAa,IAClCD,GAASC,EAAMD,GAAS,EADnB,QAUPE,EAAMnB,EAACoB,GACLA,EAAO,OAAO,CAACC,EAAGC,IAAMD,EAAIC,EAAG,CAAC,EAD5B,OAUNC,EAAUvB,EAACoB,GAAoCI,EAAcJ,CAAM,EAAzD,WAEVK,EAAoB,GAAK,GAAK,EAC9BC,EAAoB,YACpBC,EAAoB,OAAO,CAAC,GAAK,OAAO,EAAE,EAAI,OAAO,CAAC,EACtDC,EAAoB,EAAE,OAAO,CAAC,GAAK,OAAO,EAAE,GAQ5CJ,EAAgBxB,EAACoB,GAClBA,EAAO,SAAW,EAAU,KACpBA,EAAO,OAAO,CAACC,EAAGC,IAAMD,EAAIC,EAAG,CAAC,EACtBF,EAAO,OAHR,iBAahBS,EAAkB7B,EAACoB,GAAoC,CAC5D,GAAIA,EAAO,SAAW,EAAG,OAAO,KAChC,MAAMU,EAAS,CAAC,GAAGV,CAAM,EAAE,KAAK,CAAC,EAAGE,IAAM,EAAIA,CAAC,EACzCS,EAAc,KAAK,MAAMD,EAAO,OAAS,CAAC,EAEhD,GADqB5B,EAAO4B,EAAO,MAAM,EACvB,CACjB,MAAM,EAAIA,EAAOC,CAAW,EACtBT,EAAIQ,EAAOC,EAAc,CAAC,EAEhC,OADiB,EAAIT,GAAK,CAE3B,KACC,QAAIQ,EAAO,SAAW,EAAUA,EAAO,CAAC,EACzBA,EAAOC,CAAW,CAGnC,EAfwB,mBAuBlBC,EAAoBhC,EAACoB,GAAoC,CAC9D,GAAIA,EAAO,SAAW,EAAG,OAAO,KAChC,MAAMa,EAAOT,EAAcJ,CAAM,EACjC,GAAI,OAAOa,GAAS,SAAU,OAAO,KACrC,MAAMC,EAAqBd,EAAO,IAAKf,IAAWA,EAAQ4B,IAAS,CAAC,EAEpE,OADiBT,EAAcU,CAAkB,CAElD,EAP0B,qBAepBC,EAA6BnC,EAACoB,GAAoC,CACvE,MAAMgB,EAAWJ,EAAkBZ,CAAM,EACzC,OAAI,OAAOgB,GAAa,SAAiB,KAClC,KAAK,KAAKA,CAAQ,CAC1B,EAJmC,8BAc7BC,EAA4BrC,EAAA,CAACsC,EAAWjC,IAC7C,OAAOA,GAAU,SACdA,EAAQ,OAAO,OAAO,gBAAgB,EACrCA,EAAM,WACN,OAAOA,CAAK,EACbA,EAL8B"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a number is an integer
|
|
3
|
+
* @param n - Number to check
|
|
4
|
+
* @returns True if number is an integer
|
|
5
|
+
* @example isInt(5) // true, isInt(5.5) // false
|
|
6
|
+
*/
|
|
7
|
+
declare const isInt: (n: number) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Check if a number is a float (has decimal places)
|
|
10
|
+
* @param n - Number to check
|
|
11
|
+
* @returns True if number is a float
|
|
12
|
+
* @example isFloat(5.5) // true, isFloat(5) // false
|
|
13
|
+
*/
|
|
14
|
+
declare const isFloat: (n: number) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Check if a number is even
|
|
17
|
+
* @param n - Number to check
|
|
18
|
+
* @returns True if number is even
|
|
19
|
+
* @example isEven(4) // true, isEven(5) // false
|
|
20
|
+
*/
|
|
21
|
+
declare const isEven: (n: number) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a number is odd
|
|
24
|
+
* @param n - Number to check
|
|
25
|
+
* @returns True if number is odd
|
|
26
|
+
* @example isOdd(5) // true, isOdd(4) // false
|
|
27
|
+
*/
|
|
28
|
+
declare const isOdd: (n: number) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Round a number to a specific number of decimal places
|
|
31
|
+
* @param value - Number to round
|
|
32
|
+
* @param decimals - Number of decimal places (default: 2)
|
|
33
|
+
* @returns Rounded number
|
|
34
|
+
* @example roundTo(3.14159, 2) // 3.14
|
|
35
|
+
*/
|
|
36
|
+
declare const roundTo: (value: number, decimals?: number) => number;
|
|
37
|
+
/**
|
|
38
|
+
* Clamp a number between min and max values
|
|
39
|
+
* @param value - Number to clamp
|
|
40
|
+
* @param min - Minimum value
|
|
41
|
+
* @param max - Maximum value
|
|
42
|
+
* @returns Clamped number
|
|
43
|
+
* @example clamp(15, 0, 10) // 10, clamp(-5, 0, 10) // 0
|
|
44
|
+
*/
|
|
45
|
+
declare const clamp: (value: number, min: number, max: number) => number;
|
|
46
|
+
/**
|
|
47
|
+
* Calculate percentage of a value relative to a total
|
|
48
|
+
* @param value - The value
|
|
49
|
+
* @param total - The total
|
|
50
|
+
* @param decimals - Number of decimal places (default: 2)
|
|
51
|
+
* @returns Percentage (0-100)
|
|
52
|
+
* @example percentage(25, 100) // 25, percentage(1, 3, 1) // 33.3
|
|
53
|
+
*/
|
|
54
|
+
declare const percentage: (value: number, total: number, decimals?: number) => number;
|
|
55
|
+
/**
|
|
56
|
+
* Calculate what value a percentage represents
|
|
57
|
+
* @param percent - Percentage (0-100)
|
|
58
|
+
* @param total - The total
|
|
59
|
+
* @returns The value
|
|
60
|
+
* @example percentageOf(25, 100) // 25, percentageOf(50, 200) // 100
|
|
61
|
+
*/
|
|
62
|
+
declare const percentageOf: (percent: number, total: number) => number;
|
|
63
|
+
/**
|
|
64
|
+
* Check if a number is within a range (inclusive)
|
|
65
|
+
* @param value - Number to check
|
|
66
|
+
* @param min - Minimum value
|
|
67
|
+
* @param max - Maximum value
|
|
68
|
+
* @returns True if value is in range
|
|
69
|
+
* @example inRange(5, 0, 10) // true, inRange(15, 0, 10) // false
|
|
70
|
+
*/
|
|
71
|
+
declare const inRange: (value: number, min: number, max: number) => boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Linear interpolation between two values
|
|
74
|
+
* @param start - Start value
|
|
75
|
+
* @param end - End value
|
|
76
|
+
* @param t - Interpolation factor (0-1)
|
|
77
|
+
* @returns Interpolated value
|
|
78
|
+
* @example lerp(0, 100, 0.5) // 50, lerp(0, 100, 0.25) // 25
|
|
79
|
+
*/
|
|
80
|
+
declare const lerp: (start: number, end: number, t: number) => number;
|
|
81
|
+
/**
|
|
82
|
+
* Sum an array of numbers
|
|
83
|
+
* @param values - Numbers to sum
|
|
84
|
+
* @returns Sum of all values
|
|
85
|
+
* @example sum([1, 2, 3, 4]) // 10
|
|
86
|
+
*/
|
|
87
|
+
declare const sum: (values: number[]) => number;
|
|
88
|
+
/**
|
|
89
|
+
* Get the average (mean) of an array of numbers
|
|
90
|
+
* @param values - Numbers to average
|
|
91
|
+
* @returns Average or null if empty
|
|
92
|
+
* @example average([1, 2, 3, 4]) // 2.5
|
|
93
|
+
*/
|
|
94
|
+
declare const average: (values: number[]) => number | null;
|
|
95
|
+
declare const INT32_MAX: number;
|
|
96
|
+
declare const INT32_MIN: number;
|
|
97
|
+
declare const INT64_MAX: bigint;
|
|
98
|
+
declare const INT64_MIN: bigint;
|
|
99
|
+
/**
|
|
100
|
+
* Calculate the mean (average) of an array of numbers
|
|
101
|
+
* @param values - Numbers to calculate mean of
|
|
102
|
+
* @returns Mean or null if empty
|
|
103
|
+
* @example calculateMean([1, 2, 3, 4]) // 2.5
|
|
104
|
+
*/
|
|
105
|
+
declare const calculateMean: (values: number[]) => number | null;
|
|
106
|
+
/**
|
|
107
|
+
* Calculate the median (middle value) of an array of numbers
|
|
108
|
+
* @param values - Numbers to calculate median of
|
|
109
|
+
* @returns Median or null if empty
|
|
110
|
+
* @example calculateMedian([1, 2, 3, 4, 5]) // 3
|
|
111
|
+
*/
|
|
112
|
+
declare const calculateMedian: (values: number[]) => number | null;
|
|
113
|
+
/**
|
|
114
|
+
* Calculate the variance of an array of numbers
|
|
115
|
+
* @param values - Numbers to calculate variance of
|
|
116
|
+
* @returns Variance or null if empty
|
|
117
|
+
* @example calculateVariance([2, 4, 6, 8]) // 5
|
|
118
|
+
*/
|
|
119
|
+
declare const calculateVariance: (values: number[]) => number | null;
|
|
120
|
+
/**
|
|
121
|
+
* Calculate the standard deviation of an array of numbers
|
|
122
|
+
* @param values - Numbers to calculate standard deviation of
|
|
123
|
+
* @returns Standard deviation or null if empty
|
|
124
|
+
* @example calculateStandardDeviation([2, 4, 6, 8]) // ~2.24
|
|
125
|
+
*/
|
|
126
|
+
declare const calculateStandardDeviation: (values: number[]) => number | null;
|
|
127
|
+
/**
|
|
128
|
+
* Helper for JSON.stringify to handle BigInt serialization
|
|
129
|
+
* Converts large bigints to strings and small ones to numbers
|
|
130
|
+
* @param _ - Key (unused)
|
|
131
|
+
* @param value - Value to serialize
|
|
132
|
+
* @returns Serializable value
|
|
133
|
+
* @example JSON.stringify({big: 9007199254740992n}, bigIntSerializationHelper)
|
|
134
|
+
*/
|
|
135
|
+
declare const bigIntSerializationHelper: (_: string, value: unknown) => unknown;
|
|
136
|
+
|
|
137
|
+
declare const numbers_INT32_MAX: typeof INT32_MAX;
|
|
138
|
+
declare const numbers_INT32_MIN: typeof INT32_MIN;
|
|
139
|
+
declare const numbers_INT64_MAX: typeof INT64_MAX;
|
|
140
|
+
declare const numbers_INT64_MIN: typeof INT64_MIN;
|
|
141
|
+
declare const numbers_average: typeof average;
|
|
142
|
+
declare const numbers_bigIntSerializationHelper: typeof bigIntSerializationHelper;
|
|
143
|
+
declare const numbers_calculateMean: typeof calculateMean;
|
|
144
|
+
declare const numbers_calculateMedian: typeof calculateMedian;
|
|
145
|
+
declare const numbers_calculateStandardDeviation: typeof calculateStandardDeviation;
|
|
146
|
+
declare const numbers_calculateVariance: typeof calculateVariance;
|
|
147
|
+
declare const numbers_clamp: typeof clamp;
|
|
148
|
+
declare const numbers_inRange: typeof inRange;
|
|
149
|
+
declare const numbers_isEven: typeof isEven;
|
|
150
|
+
declare const numbers_isFloat: typeof isFloat;
|
|
151
|
+
declare const numbers_isInt: typeof isInt;
|
|
152
|
+
declare const numbers_isOdd: typeof isOdd;
|
|
153
|
+
declare const numbers_lerp: typeof lerp;
|
|
154
|
+
declare const numbers_percentage: typeof percentage;
|
|
155
|
+
declare const numbers_percentageOf: typeof percentageOf;
|
|
156
|
+
declare const numbers_roundTo: typeof roundTo;
|
|
157
|
+
declare const numbers_sum: typeof sum;
|
|
158
|
+
declare namespace numbers {
|
|
159
|
+
export {
|
|
160
|
+
numbers_INT32_MAX as INT32_MAX,
|
|
161
|
+
numbers_INT32_MIN as INT32_MIN,
|
|
162
|
+
numbers_INT64_MAX as INT64_MAX,
|
|
163
|
+
numbers_INT64_MIN as INT64_MIN,
|
|
164
|
+
numbers_average as average,
|
|
165
|
+
numbers_bigIntSerializationHelper as bigIntSerializationHelper,
|
|
166
|
+
numbers_calculateMean as calculateMean,
|
|
167
|
+
numbers_calculateMedian as calculateMedian,
|
|
168
|
+
numbers_calculateStandardDeviation as calculateStandardDeviation,
|
|
169
|
+
numbers_calculateVariance as calculateVariance,
|
|
170
|
+
numbers_clamp as clamp,
|
|
171
|
+
numbers_inRange as inRange,
|
|
172
|
+
numbers_isEven as isEven,
|
|
173
|
+
numbers_isFloat as isFloat,
|
|
174
|
+
numbers_isInt as isInt,
|
|
175
|
+
numbers_isOdd as isOdd,
|
|
176
|
+
numbers_lerp as lerp,
|
|
177
|
+
numbers_percentage as percentage,
|
|
178
|
+
numbers_percentageOf as percentageOf,
|
|
179
|
+
numbers_roundTo as roundTo,
|
|
180
|
+
numbers_sum as sum,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export { INT32_MAX as I, isFloat as a, isEven as b, isOdd as c, clamp as d, percentageOf as e, inRange as f, average as g, INT32_MIN as h, isInt as i, INT64_MAX as j, INT64_MIN as k, lerp as l, calculateMean as m, numbers as n, calculateMedian as o, percentage as p, calculateVariance as q, roundTo as r, sum as s, calculateStandardDeviation as t, bigIntSerializationHelper as u };
|