UNPKG

@clerk/shared

Version:

Internal package utils used by the Clerk SDKs

1 lines 1.41 kB
{"version":3,"file":"file.mjs","names":[],"sources":["../src/file.ts"],"sourcesContent":["/**\n * Read an expected JSON type File.\n *\n * Probably paired with:\n * <input type='file' accept='application/JSON' ... />\n */\nexport function readJSONFile(file: File): Promise<unknown> {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n reader.addEventListener('load', function () {\n const result = JSON.parse(reader.result as string);\n resolve(result);\n });\n\n reader.addEventListener('error', reject);\n reader.readAsText(file);\n });\n}\n\nconst MimeTypeToExtensionMap = Object.freeze({\n 'image/png': 'png',\n 'image/jpeg': 'jpg',\n 'image/gif': 'gif',\n 'image/webp': 'webp',\n 'image/x-icon': 'ico',\n 'image/vnd.microsoft.icon': 'ico',\n} as const);\n\nexport type SupportedMimeType = keyof typeof MimeTypeToExtensionMap;\n\nexport const extension = (mimeType: SupportedMimeType): string => {\n return MimeTypeToExtensionMap[mimeType];\n};\n"],"mappings":";;;;;;;AAMA,SAAgB,aAAa,MAA8B;CACzD,OAAO,IAAI,SAAS,SAAS,WAAW;EACtC,MAAM,SAAS,IAAI,WAAW;EAC9B,OAAO,iBAAiB,QAAQ,WAAY;GAE1C,QADe,KAAK,MAAM,OAAO,MACpB,CAAC;EAChB,CAAC;EAED,OAAO,iBAAiB,SAAS,MAAM;EACvC,OAAO,WAAW,IAAI;CACxB,CAAC;AACH;AAEA,MAAM,yBAAyB,OAAO,OAAO;CAC3C,aAAa;CACb,cAAc;CACd,aAAa;CACb,cAAc;CACd,gBAAgB;CAChB,4BAA4B;AAC9B,CAAU;AAIV,MAAa,aAAa,aAAwC;CAChE,OAAO,uBAAuB;AAChC"}