basant307/AI_Governance_Project
048
1import { convertEmojiSequenceToUTF16, convertEmojiSequenceToUTF32 } from "./convert.js";2const defaultUnicodeOptions = {3 prefix: "",4 separator: "",5 case: "lower",6 format: "utf-32",7 add0: false,8 throwOnError: true9};10/**11* Convert number to string12*/13function convert(sequence, options) {14 const prefix = options.prefix;15 const func = options.case === "upper" ? "toUpperCase" : "toLowerCase";16 return (options.format === "utf-16" ? convertEmojiSequenceToUTF16(sequence) : convertEmojiSequenceToUTF32(sequence, options.throwOnError)).map((code) => {17 let str = code.toString(16);18 if (options.add0 && str.length < 4) str = "0".repeat(4 - str.length) + str;19 return prefix + str[func]();20 }).join(options.separator);21}22/**23* Convert unicode number to string24*25* Example:26* 0x1F600 => '1F600'27*/28function getEmojiUnicodeString(code, options = {}) {29 return convert([code], {30 ...defaultUnicodeOptions,31 ...options32 });33}34const defaultSequenceOptions = {35 ...defaultUnicodeOptions,36 separator: "-"37};38/**39* Convert unicode numbers sequence to string40*41* Example:42* [0x1f441, 0xfe0f] => '1f441-fe0f'43*/44function getEmojiSequenceString(sequence, options = {}) {45 return convert(sequence, {46 ...defaultSequenceOptions,47 ...options48 });49}50/**51* Convert unicode numbers sequence to string52*53* Simple version of `getEmojiSequenceString()` without options that otherwise add to bundle54*/55function getEmojiSequenceKeyword(sequence) {56 return sequence.map((code) => code.toString(16)).join("-");57}58export { getEmojiSequenceKeyword, getEmojiSequenceString, getEmojiUnicodeString };59 