{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["/**\n * Check if a character is ASCII.\n *\n * @param character - The character to check.\n * @returns True if the character is ASCII, false otherwise.\n */\nconst isASCII = (character: string): boolean =>\n    (character.codePointAt(0) ?? 0) <= 127;\n\n/**\n * Encode Unicode characters in a string to Unicode escapes.\n *\n * @param string - The string to be encoded.\n * @returns The encoded string.\n *\n * @example\n * ```\n * import { encodeUnicodeEscapes } from './unicode-escapes';\n *\n * console.log(encodeUnicodeEscapes('Hello, โลก'));\n * //=> 'Hello, \\u{e42}\\u{e25}\\u{e01}'\n * ```\n */\nexport function encodeUnicodeEscapes(string: string): string {\n    return [...string]\n        .map((character) =>\n            isASCII(character)\n                ? character\n                : `\\\\u{${(character.codePointAt(0) ?? 0).toString(16)}}`\n        )\n        .join('');\n}\n\n/**\n * Decode Unicode escapes in a string to Unicode characters.\n *\n * @param string - The string to be decoded.\n * @returns The decoded string.\n *\n * @example\n * ```\n * import { decodeUnicodeEscapes } from './unicode-escapes';\n *\n * console.log(decodeUnicodeEscapes('Hello, \\u{e42}\\u{e25}\\u{e01}'));\n * //=> 'Hello, โลก'\n * ```\n */\nexport function decodeUnicodeEscapes(string: string): string {\n    return string.replaceAll(\n        /\\\\u{([\\da-f]{1,6})}|\\\\u([\\da-f]{4})/gi,\n        (_, p1, p2) => String.fromCodePoint(Number.parseInt(p1 ?? p2, 16))\n    );\n}\n"],"names":[],"mappings":";;AAMA,MAAM,UAAU,CAAC,eACZ,UAAU,YAAY,CAAC,KAAK,MAAM;AAgBjC,SAAU,qBAAqB,QAAc;AACxC,SAAA,CAAC,GAAG,MAAM,EACZ,IAAI,CAAC,cACF,QAAQ,SAAS,IACX,YACA,QAAQ,UAAU,YAAY,CAAC,KAAK,GAAG,SAAS,EAAE,CAAC,GAAG,EAE/D,KAAK,EAAE;AAChB;AAgBM,SAAU,qBAAqB,QAAc;AAC/C,SAAO,OAAO,WACV,yCACA,CAAC,GAAG,IAAI,OAAO,OAAO,cAAc,OAAO,SAAS,MAAM,IAAI,EAAE,CAAC,CAAC;AAE1E;;;"}