UNPKG

@surveycake/utils

Version:

SurveyCake Javascript Utils

1,962 lines (1,810 loc) 44.9 kB
import jwt_decode from 'jwt-decode'; import { Decimal } from 'decimal.js'; /** * @module formatter */ /** * @param source source string. * @param minLength * @param appender item appended on left side. * * ```ts * appendLeft('abc', 1) === 'abc' * appendLeft('abc', 5) === '00abc' * appendLeft('abc', 5, 'QA') === 'QAQAabc' * ``` */ function appendLeft(source, minLength, appender) { if (appender === void 0) { appender = 0; } var str = "" + source; if (str.length >= minLength) { return str; } return "" + ("" + appender).repeat(minLength - str.length) + source; } /** * @module helper.number */ /** * get length of precisions * * ```ts * getPrecisionLength(1.123) === 3 * ``` */ function getPrecisionLength(arg) { if (typeof arg !== 'number' || isNaN(arg)) { throw new Error('arg should be number'); } var precisions = ("" + arg).split('.')[1]; if (precisions === undefined) { return 0; } return precisions.length; } /** * @ignore */ var calculator = { '+': function _(number1, number2, multiplier) { return (number1 * multiplier + number2 * multiplier) / multiplier; }, '-': function _(number1, number2, multiplier) { return (number1 * multiplier - number2 * multiplier) / multiplier; }, '*': function _(number1, number2, multiplier) { return number1 * multiplier * (number2 * multiplier) / (multiplier * multiplier); }, '/': function _(number1, number2, multiplier) { return number1 * multiplier / (number2 * multiplier); }, '%': function _(number1, number2, multiplier) { return number1 * multiplier % (number2 * multiplier) / multiplier; } }; /** * There are some error result on native. Use this method to prevent from that. * * ```ts * 3.1 * 3.04 === 9.424000000000001 * calculate(3.1, '*', 3.04) === 9.424 * ``` */ function calculateNumber(number1, operator, number2) { /** * number1 and nunber2 maybe as zero */ if (typeof number1 !== 'number' || typeof number2 !== 'number' || !operator || !(operator in calculator)) { return NaN; } var dividendPrecision = getPrecisionLength(number1); var divisorPrecision = getPrecisionLength(number2); var biggestDemical = dividendPrecision > divisorPrecision ? dividendPrecision : divisorPrecision; var multiplier = Math.pow(10, biggestDemical); return calculator[operator](number1, number2, multiplier); } /** * @module decorator */ /** * Add debounce to a function. * * @typeparam T type or interface of origin function. * @param time debounce time. * @returns The behavior is the same as origin function, but with debounce. * * ```ts * const origin = () => ...; * const result = debounce(250)(origin); * ``` * * ```ts * class Greeter { * greeting: string; * constructor(message: string) { * this.greeting = message; * } * * @debounce(500) * greet = () => `Hello, ${this.greeting}`; * } * ``` */ function debounce(time) { return function (fn) { var timer; return function () { // @ts-ignore var context = this; clearTimeout(timer); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } timer = setTimeout(fn.bind.apply(fn, [context].concat(args)), time); }; }; } /** * @module decorator */ /** * Add exhaust to a function. * * @typeparam T type or interface of origin function. * @param time debounce time. * @returns The behavior is the same as origin function, but with exhaust. * * ```ts * const origin = () => ...; * const result = exhaust(250)(origin); * ``` * * ```ts * class Greeter { * greeting: string; * constructor(message: string) { * this.greeting = message; * } * * @exhaust(500) * greet = () => `Hello, ${this.greeting}`; * } * ``` */ function exhaust(time) { return function (fn) { var done = true; var timer; return function () { // @ts-ignore var context = this; if (done) { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } fn.apply(context, args); done = false; } if (timer) { clearTimeout(timer); } timer = setTimeout(function () { done = true; }, time); }; }; } /** * @module helper.number */ /** * @param arg source number. * @param precisions length of precisions. * * ```ts * formatPrecision(1.1234, 2) === 1.12 * ``` */ function formatPrecision(arg, precisions) { if (typeof arg !== 'number' || typeof precisions !== 'number') { return NaN; } var size = Math.pow(10, precisions); return Math.round(arg * size) / size; } /** * @module handler */ /** * @ignore */ var isErrorStatus = function isErrorStatus(response) { return response.status >= 400 && response.status < 500; }; /** * handler for fetch api. * @param response response of fetch api. * @param type content-type. */ function handleResponse(response, options) { if (options === void 0) { options = { formatter: function formatter(res) { return res.json(); } }; } if (!response) { throw new Error(); } if (isErrorStatus(response)) { return options.formatter(response).then(function (res) { return Promise.reject(res); }); } return options.formatter(response); } /** * @module validator.array */ function isArrayEmpty(arg) { if (!Array.isArray(arg)) { throw new Error('arg should be array.'); } return arg.length === 0; } /** * @module helper.array */ /** * Remove specific index from source. */ function removeIndex(source, index) { if (!Array.isArray(source)) { throw new Error('source should be array.'); } else if (isArrayEmpty(source)) { return source; } var resolvedIndex = index >= 0 ? index : source.length + index; if (resolvedIndex >= source.length) { return source; } else if (resolvedIndex === 0) { return source.slice(1, source.length); } else if (resolvedIndex === source.length - 1) { return source.slice(0, source.length - 1); } return [].concat(source.slice(0, resolvedIndex), source.slice(resolvedIndex + 1, source.length)); } /** * @module helper.array */ /** * Remove specific item that equal data or finded by finder from source. * * @param finder A factory, data is second param, return a function just like `Array.find`. * * ```ts * removeItem([1, '2', true, { a: 1 }], 0) => [1, '2', true, { a: 1 }] * removeItem([1, '2', true, { a: 1 }], 1) => ['2', true, { a: 1 }] * ``` * * ```ts * removeItem([{ a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }], { a: 3 }, data => item => data.a === item.a) * => * [{ a: 1 }, { a: 2 }, { a: 4 }] * ``` */ function removeItem(source, data, finder) { if (!Array.isArray(source)) { throw new Error('source should be array.'); } else if (isArrayEmpty(source)) { return source; } var index; if (finder) { if (typeof finder !== 'function') { throw new Error('finder should return a function that return boolean.'); } var handler = finder(data); if (typeof handler !== 'function') { throw new Error('finder should return a function that return boolean.'); } index = source.findIndex(handler); } else { index = source.indexOf(data); } if (index !== -1) { return removeIndex(source, index); } return source; } /** * @module helper.array */ /** * Insert data into source and check data is not duplicated. * @param finder * @see removeItem */ function insertItemWithoutDuplicated(source, data, finder) { return [].concat(removeItem(source, data, finder), [data]); } /** * @module helper.array */ /** * Insert items into specific index of source. * * ```ts * insertIndex([1, 2, 3], 0, [4, 5]) => [4, 5, 1, 2, 3] * insertIndex([1, 2, 3], 1, [4, 5]) => [1, 4, 5, 2, 3] * insertIndex([1, 2, 3], 2, [4, 5]) => [1, 2, 4, 5, 3] * ``` */ function insertIndex(source, index, items) { if (items === void 0) { items = []; } if (!Array.isArray(source)) { throw new Error('source should be array.'); } else if (!Array.isArray(items)) { throw new Error('items should be array.'); } else if (isArrayEmpty(items)) { return source; } var start = Math.min(index, source.length); return [].concat(source.slice(0, start), items, source.slice(start, source.length)); } /** * @module dom */ function insertScript(id, src, options) { if (options === void 0) { options = { async: true, defer: true }; } if (document.getElementById(id)) { return false; } var jss = document.getElementsByTagName('script')[0]; var js = document.createElement('script'); js.id = id; js.src = src; if (options.async) { js.async = true; } if (options.defer) { js.defer = true; } if (jss && jss.parentNode) { jss.parentNode.insertBefore(js, jss); } return true; } /** * @module validator */ /** * validate a string is email or not. */ function isEmail(arg) { // tslint:disable-next-line:max-line-length return /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(arg); } /** * @module validator */ /** * validate a string is valid google analytics id or not. */ function isGoogleAnalyticsId(arg) { return /^ua-\d{4,9}-\d{1,4}$/i.test(arg); } /** * @module validator */ /** * validate a string is valid google analytics 4 measurement id or not. */ function isGA4Id(arg) { return /^G-[0-9A-Z]{10,}$/.test(arg); } /** * @module validator */ /** * validate a string is valid google tag manager id or not. */ function isGTMId(arg) { return /^GTM-[0-9A-Z]{6,}$/.test(arg); } /** * @module validator.number */ /** * @param arg argument will be tested if it is integer or not. * @param signs */ function isInteger(arg, signs) { if (signs === void 0) { signs = '+-'; } return new RegExp("^(0|[" + signs + "]?[1-9]\\d*)$").test("" + arg); } /** * @module validator.number */ /** * @param arg argument will be tested if it is numeric or not. */ function isNumeric(arg) { return !Number.isNaN(parseFloat("" + arg)) && isFinite(arg); } /** * @module validator.object */ /** * @param arg argument will be tested if it is object or not. */ function isObject(arg) { return !!(arg && typeof arg === 'object' && !(arg instanceof Array)); } /** * @module validator.object */ /** * If argument is not `Object`, it will throw error. */ function isObjectEmpty(arg) { if (!isObject(arg)) { throw new Error('arg should be object.'); } return Object.keys(arg).length === 0; } /** * @module validator */ /** * validate a string is url or not. */ function isUrl(arg) { // tslint:disable-next-line:max-line-length return /^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(arg); } /** * @module constants */ /** * key of object is keyname. * * value of object is event.keycode. * * Some keycode different in `firefox`. * * ```ts * if(event.keycode === keycode.ENTER) { * // ... * } * ``` */ var keycode = { CANCEL: 3, HELP: 6, BACK_SPACE: 8, TAB: 9, CLEAR: 12, RETURN: 13, ENTER: 14, SHIFT: 16, CONTROL: 17, ALT: 18, PAUSE: 19, CAPS_LOCK: 20, ESCAPE: 27, SPACE: 32, PAGE_UP: 33, PAGE_DOWN: 34, END: 35, HOME: 36, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40, PRINTSCREEN: 44, INSERT: 45, DELETE: 46, 0: 48, 1: 49, 2: 50, 3: 51, 4: 52, 5: 53, 6: 54, 7: 55, 8: 56, 9: 57, SEMICOLON_FIREFOX: 59, EQUALS_FIREFOX: 61, A: 65, B: 66, C: 67, D: 68, E: 69, F: 70, G: 71, H: 72, I: 73, J: 74, K: 75, L: 76, M: 77, N: 78, O: 79, P: 80, Q: 81, R: 82, S: 83, T: 84, U: 85, V: 86, W: 87, X: 88, Y: 89, Z: 90, LEFT_CMD: 91, RIGHT_CMD: 93, CONTEXT_MENU: 93, NUMPAD0: 96, NUMPAD1: 97, NUMPAD2: 98, NUMPAD3: 99, NUMPAD4: 100, NUMPAD5: 101, NUMPAD6: 102, NUMPAD7: 103, NUMPAD8: 104, NUMPAD9: 105, MULTIPLY: 106, ADD: 107, SEPARATOR: 108, SUBTRACT: 109, DECIMAL: 110, DIVIDE: 111, F1: 112, F2: 113, F3: 114, F4: 115, F5: 116, F6: 117, F7: 118, F8: 119, F9: 120, F10: 121, F11: 122, F12: 123, F13: 124, F14: 125, F15: 126, F16: 127, F17: 128, F18: 129, F19: 130, F20: 131, F21: 132, F22: 133, F23: 134, F24: 135, NUM_LOCK: 144, SCROLL_LOCK: 145, SEMICOLON: 186, EQUALS: 187, COMMA: 188, PERIOD: 190, SLASH: 191, BACK_QUOTE: 192, OPEN_BRACKET: 219, BACK_SLASH: 220, CLOSE_BRACKET: 221, QUOTE: 222, CMD_FIREFOX: 224 }; /** * @module transformer */ /** * @ignore */ var alphabetCount = 26; /** * @ignore */ var parseAlphaBet = function parseAlphaBet(index) { return index === 0 ? 'Z' : String.fromCharCode(index + 64); }; /** * Transform number to alphabet. * @param number * @param toLowerCase * * ```ts * numberToAlphabet('1') === 'A' * numberToAlphabet(1) === 'A' * numberToAlphabet(27) === 'AA' * numberToAlphabet(675) === 'YY' * numberToAlphabet(703) === 'AAA' * ``` */ function numberToAlphabet(number, toLowerCase) { if (toLowerCase === void 0) { toLowerCase = false; } var parsedNum = parseInt("" + number, 10); if (parsedNum === 0) { return ''; } var remainder = parsedNum % alphabetCount; var quotient = Math.floor(parsedNum / alphabetCount); if (remainder === 0) { quotient -= 1; } var str = "" + numberToAlphabet(quotient) + parseAlphaBet(remainder); return toLowerCase ? str.toLowerCase() : str; } /** * @module parser */ // tslint:disable:max-line-length /** * @description only use it in frontend, since it use `window.atob`. * @param token jwt token. * * ```ts * parseJwt('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c') === { sub: '1234567890', name: 'John Doe', iat: 1516239022 } * ``` */ function parseJwt(token) { return jwt_decode(token); } /** * @module parser */ /** * get youtubeId from url. */ function parseYoutubeId(url) { var match = url.match(/^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/); if (match && match[7].length === 11) { return match[7]; } return ''; } /** * @module formatter */ /** * random produce a string with regexp `^([a-z0-9]){length}$` * @param length */ function randomHash(length) { if (length === void 0) { length = 13; } return Array.from({ length: length }).map(function () { return Math.floor(Math.random() * 36).toString(36); }).join(''); } /** * @module helper.array */ function randomSort(source) { if (!Array.isArray(source)) { throw new Error('source should be array.'); } return source.sort(function () { return 0.5 - Math.random(); }); } /** * @module helper.image */ /** * return a Promise that will resolve a new dataURL or reject an empty string. * @async */ function resizeImageDataUrl(dataURL, _ref) { var width = _ref.width, height = _ref.height; return new Promise(function (resolve, reject) { var img = document.createElement('img'); var _ref2 = /data:image\/([a-z]*);.*/.exec(dataURL) || [], _ref2$ = _ref2[1], type = _ref2$ === void 0 ? '' : _ref2$; if (!type) { reject(''); } img.onload = function () { var canvas = document.createElement('canvas'); var ctx = canvas.getContext('2d'); canvas.width = width; canvas.height = height; if (ctx) { ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, width, height); resolve(canvas.toDataURL("image/" + type, 1)); } else { reject(''); } }; img.src = dataURL; }); } /** * @module constants */ /** * Selectable fonts (Enterprise only) */ var selectableFonts = { 'Noto Sans TC': { id: 1, name: 'Noto Sans TC', url: 'https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700&display=swap' }, 'Noto Serif TC': { id: 2, name: 'Noto Serif TC', url: 'https://fonts.googleapis.com/css2?family=Noto+Serif+TC:wght@400;500;700&display=swap' }, 'Noto Sans JP': { id: 3, name: 'Noto Sans JP', url: 'https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700&display=swap' }, 'Roboto': { id: 4, name: 'Roboto', url: 'https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap' }, 'Open Sans': { id: 5, name: 'Open Sans', url: 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;500;700&display=swap' }, 'Lato': { id: 6, name: 'Lato', url: 'https://fonts.googleapis.com/css2?family=Lato:wght@400;700&display=swap' }, 'Poppins': { id: 7, name: 'Poppins', url: 'https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&display=swap' }, 'Merriweather': { id: 8, name: 'Merriweather', url: 'https://fonts.googleapis.com/css2?family=Merriweather:wght@400;700&display=swap' }, 'Libre Baskerville': { id: 9, name: 'Libre Baskerville', url: 'https://fonts.googleapis.com/css2?family=Libre+Baskerville:wght@400;700&display=swap' }, 'EB Garamond': { id: 10, name: 'EB Garamond', url: 'https://fonts.googleapis.com/css2?family=EB+Garamond:wght@400;500;700&display=swap' } }; /** * @module comparator */ /** * This is Copy from https://github.com/facebook/react/blob/master/packages/shared/shallowEqual.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ /** * inlined Object.is polyfill to avoid requiring consumers ship their own * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is */ function is(x, y) { if (x === y) { return x !== 0 || 1 / x === 1 / y; } return x !== x && y !== y; } /** * Performs equality by iterating through keys on an object and returning false * when any key has values which are not strictly equal between the arguments. * Returns true when the values of all keys are strictly equal. */ function shallowEqual(objA, objB) { if (is(objA, objB)) { return true; } if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { return false; } var keysA = Object.keys(objA); var keysB = Object.keys(objB); if (keysA.length !== keysB.length) { return false; } // Test for A's keys different from B. // tslint:disable-next-line:prefer-for-of for (var i = 0; i < keysA.length; i += 1) { if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) { return false; } } return true; } /** * @module decorator */ /** * Add throttle to a function. * * @typeparam T type or interface of origin function. * @param time debounce time. * @returns The behavior is the same as origin function, but with throttle. * * ```ts * const origin = () => ...; * const result = throttle(250)(origin); * ``` * * ```ts * class Greeter { * greeting: string; * constructor(message: string) { * this.greeting = message; * } * * @throttle(500) * greet = () => `Hello, ${this.greeting}`; * } * ``` */ function throttle(time) { return function (fn) { var previous; return function () { // @ts-ignore var context = this; var now = +new Date(); if (!previous || now - previous > time) { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } fn.apply(context, args); previous = now; } }; }; } function safeAdd(x, y) { return Decimal.add(x, y).toNumber(); } function safeDiv(x, y) { return Decimal.div(x, y).toNumber(); } function safeMod(x, y) { return Decimal.mod(x, y).toNumber(); } function safeMul(x, y) { return Decimal.mul(x, y).toNumber(); } function safeSub(x, y) { return Decimal.sub(x, y).toNumber(); } /** * @module helper */ /** * will remove T and Z * * eg. timezone: +08:00 getISOString(newDate('2019-04-25T13:00:00Z')) === '2019-04-25 21:00:00' */ function getISOString(date) { if (!date) { return ''; } var year = date.getFullYear(); var month = appendLeft(date.getMonth() + 1, 2); var day = appendLeft(date.getDate(), 2); var hour = appendLeft(date.getHours(), 2); var minutes = appendLeft(date.getMinutes(), 2); var seconds = appendLeft(date.getSeconds(), 2); return year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds; } /** * For memoized. * Like `react hooks`. */ function passThrough(param) { return param; } /** * @module formatter */ /** * strip html by document. */ function stripHtml(html) { if (!html) { return ''; } var tmp = document.createElement('div'); tmp.innerHTML = html; return tmp.textContent || tmp.innerText || ''; } /** * strip html by regexp */ function stripHtmlTags(html) { if (!html) { return ''; } return html.replace(/<[^>]*>/g, '').trim(); } // Note: 這隻檔案跟後端有在 wording 資料夾共用,改動需要跟後端說 var languageCodesData = { tr: { "zh-TW": "土耳其文", en: "Turkish", ja: "トルコ語", th: "ภาษาตุรกี", "zh-hans": "土耳其文", originalName: "Türkçe" }, tw: { "zh-TW": "繁體中文", en: "Traditional Chinese", ja: "繁体字中国語", th: "ภาษาจีนตัวเต็ม", "zh-hans": "繁体中文", originalName: "繁體中文" }, "zh-hans": { "zh-TW": "簡體中文", en: "Simplified Chinese", ja: "簡体字中国語", th: "ภาษาจีนตัวย่อ", "zh-hans": "简体中文", originalName: "简体中文" }, "zh-TW": { "zh-TW": "中文 (繁體)", en: "Chinese (Traditional)", ja: "繁体字中国語", th: "ภาษาจีนดั้งเดิม", "zh-hans": "繁体中文", originalName: "中文 (繁體)" }, "zh-CN": { "zh-TW": "中文 (簡體)", en: "Chinese (Simplified)", ja: "簡体字中国語", th: "ภาษาจีนตัวย่อ", "zh-hans": "简体中文", originalName: "中文(简体)" }, da: { "zh-TW": "丹麥文", en: "Danish", ja: "デンマーク語", th: "ภาษาเดนมาร์ก", "zh-hans": "丹麦文", originalName: "Dansk" }, eu: { "zh-TW": "巴斯克文", en: "Basque", ja: "バスク語", th: "ภาษาบาสก์", "zh-hans": "巴斯克文", originalName: "euskara" }, ja: { "zh-TW": "日文", en: "Japanese", ja: "日本語", th: "ภาษาญี่ปุ่น", "zh-hans": "日文", originalName: "日本語" }, mi: { "zh-TW": "毛利文", en: "Maori", ja: "マオリ語", th: "ภาษาเมารี", "zh-hans": "毛利文", originalName: "Māori" }, jw: { "zh-TW": "爪哇文", en: "Javanese", ja: "ジャワ語", th: "ภาษาชาวา", "zh-hans": "爪哇文", originalName: "Basa Jawa" }, eo: { "zh-TW": "世界語", en: "Esperanto", ja: "エスペラント語", th: "ภาษาเอสเปรันโต", "zh-hans": "世界语", originalName: "世界語" }, gl: { "zh-TW": "加里西亞文", en: "Galician", ja: "ガリシア語", th: "ภาษากาลิเชียน", "zh-hans": "加利西亚文", originalName: "galego" }, ca: { "zh-TW": "加泰羅尼亞文", en: "Catalan", ja: "カタロニア語", th: "ภาษาคาตาลัน", "zh-hans": "加泰罗尼亚文", originalName: "català" }, kn: { "zh-TW": "卡納達文", en: "Kannada", ja: "カンナダ語", th: "ภาษากันนาดา", "zh-hans": "卡纳达文", originalName: "ಕನ್ನಡ" }, ne: { "zh-TW": "尼泊爾文", en: "Nepali", ja: "ネパール語", th: "ภาษาเนปาล", "zh-hans": "尼泊尔文", originalName: "नेपाली" }, af: { "zh-TW": "布爾文", en: "Afrikaans", ja: "アフリカーンス語", th: "ภาษาแอฟริกานส์", "zh-hans": "南非语", originalName: "Afrikaans" }, fy: { "zh-TW": "弗利然文", en: "Frisian", ja: "フリジア語", th: "ภาษาฟริเชียน", "zh-hans": "弗里西亚文", originalName: "Frysk" }, be: { "zh-TW": "白俄羅斯文", en: "Belarusian", ja: "ベラルーシ語", th: "ภาษาเบลารัส", "zh-hans": "白俄罗斯文", originalName: "Беларуская" }, lt: { "zh-TW": "立陶宛文", en: "Lithuanian", ja: "リトアニア語", th: "ภาษาลิทัวเนีย", "zh-hans": "立陶宛文", originalName: "lietuvių" }, ig: { "zh-TW": "伊博文", en: "Igbo", ja: "イボ語", th: "ภาษาอิกโบ", "zh-hans": "伊博文", originalName: "Igbo" }, is: { "zh-TW": "冰島文", en: "Icelandic", ja: "アイスランド語", th: "ภาษาไอซ์แลนด์", "zh-hans": "冰岛文", originalName: "íslenska" }, hu: { "zh-TW": "匈牙利文", en: "Hungarian", ja: "ハンガリー語", th: "ภาษาฮังการี", "zh-hans": "匈牙利文", originalName: "magyar" }, id: { "zh-TW": "印尼文", en: "Indonesian", ja: "インドネシア語", th: "ภาษาอินโดนีเชีย", "zh-hans": "印度尼西亚文", originalName: "Indonesia" }, su: { "zh-TW": "印尼巽他文", en: "Sundanese", ja: "スンダ語", th: "ภาษาซันดา", "zh-hans": "印尼巽他文", originalName: "Basa Sunda" }, hi: { "zh-TW": "印度文", en: "Hindi", ja: "ヒンディー語", th: "ภาษาฮินดี", "zh-hans": "印地文", originalName: "हिन्दी" }, gu: { "zh-TW": "印度古哈拉地文", en: "Gujarati", ja: "グジャラート語", th: "ภาษากูจาราติ", "zh-hans": "古吉拉特文", originalName: "ગુજરાતી" }, ky: { "zh-TW": "吉爾吉斯文", en: "Kyrgyz", ja: "キルギス語", th: "ภาษาคีร์กิซ", "zh-hans": "吉尔吉斯文", originalName: "кыргызча" }, es: { "zh-TW": "西班牙文", en: "Spanish", ja: "スペイン語", th: "ภาษาสเปน", "zh-hans": "西班牙文", originalName: "español" }, hr: { "zh-TW": "克羅埃西亞文", en: "Croatian", ja: "クロアチア語", th: "ภาษาโครเอเชีย", "zh-hans": "克罗地亚文", originalName: "hrvatski" }, iw: { "zh-TW": "希伯來文", en: "Hebrew", ja: "ヘブライ語", th: "ภาษาฮีบรู", "zh-hans": "希伯来文", originalName: "עברית" }, el: { "zh-TW": "希臘文", en: "Greek", ja: "ギリシャ語", th: "ภาษากรีก", "zh-hans": "希腊文", originalName: "Ελληνικά" }, hy: { "zh-TW": "亞美尼亞文", en: "Armenian", ja: "アルメニア語", th: "ภาษาอาร์มีเนีย", "zh-hans": "亚美尼亚文", originalName: "հայերեն" }, az: { "zh-TW": "亞塞拜然文", en: "Azerbaijani", ja: "アゼルバイジャン語", th: "ภาษาอาเซอร์ไบจาน", "zh-hans": "阿塞拜疆文", originalName: "Azərbaycan dili" }, ny: { "zh-TW": "奇切瓦文", en: "Chichewa", ja: "チチェワ語", th: "ภาษาชิเชวา", "zh-hans": "奇切瓦文", originalName: "Chichewa" }, bn: { "zh-TW": "孟加拉文", en: "Bengali", ja: "ベンガル語", th: "ภาษาเบนกาลี", "zh-hans": "孟加拉文", originalName: "বাংলা" }, ps: { "zh-TW": "帕施圖文", en: "Pashto", ja: "パシュトー語", th: "ภาษาปัชโต", "zh-hans": "普什图文", originalName: "پښتو" }, la: { "zh-TW": "拉丁文", en: "Latin", ja: "ラテン語", th: "ภาษาละติน", "zh-hans": "拉丁文", originalName: "lingua latīna" }, lv: { "zh-TW": "拉脫維亞文", en: "Latvian", ja: "ラトビア語", th: "ภาษาลัตเวีย", "zh-hans": "拉脱维亚文", originalName: "latviešu" }, fr: { "zh-TW": "法文", en: "French", ja: "フランス語", th: "ภาษาฝรั่งเศส", "zh-hans": "法文", originalName: "Français" }, bs: { "zh-TW": "波士尼亞文", en: "Bosnian", ja: "ボスニア語", th: "ภาษาบอสเนีย", "zh-hans": "波斯尼亚文", originalName: "bosanski" }, fa: { "zh-TW": "波斯文", en: "Persian", ja: "ペルシア語", th: "ภาษาเปอร์เชีย", "zh-hans": "波斯文", originalName: "فارسی" }, pl: { "zh-TW": "波蘭文", en: "Polish", ja: "ポーランド語", th: "ภาษาโปแลนด์", "zh-hans": "波兰文", originalName: "polski" }, fi: { "zh-TW": "芬蘭文", en: "Finnish", ja: "フィンランド語", th: "ภาษาฟินแลนด์", "zh-hans": "芬兰文", originalName: "suomi" }, am: { "zh-TW": "阿姆哈拉文", en: "Amharic", ja: "アムハラ語", th: "ภาษาอัมฮาริก", "zh-hans": "阿姆哈拉文", originalName: "አማርኛ" }, ar: { "zh-TW": "阿拉伯文", en: "Arabic", ja: "アラビア語", th: "ภาษาอาหรับ", "zh-hans": "阿拉伯文", originalName: "العربية" }, sq: { "zh-TW": "阿爾巴尼亞文", en: "Albanian", ja: "アルバニア語", th: "ภาษาแอลเบเนีย", "zh-hans": "阿尔巴尼亚文", originalName: "Shqip" }, ru: { "zh-TW": "俄文", en: "Russian", ja: "ロシア語", th: "ภาษารัสเซีย", "zh-hans": "俄文", originalName: "русский" }, bg: { "zh-TW": "保加利亞文", en: "Bulgarian", ja: "ブルガリア語", th: "ภาษาบัลแกเรีย", "zh-hans": "保加利亚文", originalName: "български" }, sd: { "zh-TW": "信德文", en: "Sindhi", ja: "シンド語", th: "ภาษาซินดี", "zh-hans": "信德文", originalName: "سنڌي" }, xh: { "zh-TW": "南非柯薩文", en: "Xhosa", ja: "コサ語", th: "ภาษาโคซ่า", "zh-hans": "科萨语", originalName: "IsiXhosa" }, zu: { "zh-TW": "南非祖魯文", en: "Zulu", ja: "ズールー語", th: "ภาษาซูลู", "zh-hans": "祖鲁语", originalName: "isiZulu" }, kk: { "zh-TW": "哈薩克文", en: "Kazakh", ja: "カザフ語", th: "ภาษาคาซัค", "zh-hans": "哈萨克文", originalName: "қазақ" }, cy: { "zh-TW": "威爾斯文", en: "Welsh", ja: "ウェールズ語", th: "ภาษาเวลส์", "zh-hans": "威尔士文", originalName: "Cymraeg" }, co: { "zh-TW": "科西嘉文", en: "Corsican", ja: "コルシカ語", th: "ภาษาคอรฌิกา", "zh-hans": "科西嘉文", originalName: "Corse" }, hmn: { "zh-TW": "苗文", en: "Hmong", ja: "モン語", th: "ภาษามง", "zh-hans": "苗文", originalName: "Hmong" }, en: { "zh-TW": "英文", en: "English", ja: "英語", th: "ภาษาอังกฤษ", "zh-hans": "英文", originalName: "English" }, haw: { "zh-TW": "夏威夷文", en: "Hawaiian", ja: "ハワイ語", th: "ภาษาฮาวาย", "zh-hans": "夏威夷文", originalName: "Ōlelo Hawaiʻi" }, ku: { "zh-TW": "庫德文", en: "Kurdish (Kurmanji)", ja: "クルド語", th: "ภาษาเคิร์ด", "zh-hans": "库尔德文", originalName: "Kurdî" }, no: { "zh-TW": "挪威文", en: "Norwegian", ja: "ノルウェー語", th: "ภาษานอร์เวย์", "zh-hans": "挪威文", originalName: "norsk" }, pa: { "zh-TW": "旁遮普文", en: "Punjabi", ja: "パンジャーブ語", th: "ภาษาปัญจาบ", "zh-hans": "旁遮普文", originalName: "ਪੰਜਾਬੀ" }, th: { "zh-TW": "泰文", en: "Thai", ja: "タイ語", th: "ภาษาไทย", "zh-hans": "泰文", originalName: "ภาษาไทย" }, ta: { "zh-TW": "泰米爾文", en: "Tamil", ja: "タミル語", th: "ภาษาทมิฬ", "zh-hans": "泰米尔文", originalName: "தமிழ்" }, te: { "zh-TW": "泰盧固文", en: "Telugu", ja: "テルグ語", th: "ภาษาเตลูกู", "zh-hans": "泰卢固文", originalName: "తెలుగు" }, ht: { "zh-TW": "海地克里奧文", en: "Haitian Creole", ja: "ハイチクリオール語", th: "ภาษาเครีโอลไฮติ", "zh-hans": "海地克里奥尔文", originalName: "Kreyòl Ayisyen" }, uk: { "zh-TW": "烏克蘭文", en: "Ukrainian", ja: "ウクライナ語", th: "ภาษายูเครน", "zh-hans": "乌克兰文", originalName: "українська" }, uz: { "zh-TW": "烏茲別克文", en: "Uzbek", ja: "ウズベク語", th: "ภาษาอุซเบก", "zh-hans": "乌兹别克文", originalName: "O'zbek" }, ur: { "zh-TW": "烏爾都文", en: "Urdu", ja: "ウルドゥー語", th: "ภาษาอูรดู", "zh-hans": "乌尔都文", originalName: "اردو" }, so: { "zh-TW": "索馬里文", en: "Somali", ja: "ソマリ語", th: "ภาษาโซมาลี", "zh-hans": "索马里文", originalName: "Soomaali" }, mt: { "zh-TW": "馬耳他文", en: "Maltese", ja: "マルタ語", th: "ภาษามอลตา", "zh-hans": "马耳他文", originalName: "Malti" }, ms: { "zh-TW": "馬來文", en: "Malay", ja: "マレー語", th: "ภาษามาเลย์", "zh-hans": "马来文", originalName: "Melayu" }, mk: { "zh-TW": "馬其頓文", en: "Macedonian", ja: "マケドニア語", th: "ภาษามาซิโดเนีย", "zh-hans": "马其顿文", originalName: "македонски" }, mg: { "zh-TW": "馬拉加斯文", en: "Malagasy", ja: "マラガシ語", th: "ภาษามาลากาซี", "zh-hans": "马拉加斯文", originalName: "Malagasy" }, mr: { "zh-TW": "馬拉地文", en: "Marathi", ja: "マラーティー語", th: "ภาษามราฐี", "zh-hans": "马拉地文", originalName: "मराठी" }, ml: { "zh-TW": "馬拉雅拉姆文", en: "Malayalam", ja: "マラヤーラム語", th: "ภาษามาลายาลัม", "zh-hans": "马拉雅拉姆文", originalName: "മലയാളം" }, km: { "zh-TW": "高棉文", en: "Khmer", ja: "クメール語", th: "ภาษาเขมร", "zh-hans": "高棉文", originalName: "ខ្មែរ" }, ceb: { "zh-TW": "宿霧文", en: "Cebuano", ja: "セブアノ語", th: "ภาษาเซบูอาโน", "zh-hans": "宿务文", originalName: "Cebuano" }, cs: { "zh-TW": "捷克文", en: "Czech", ja: "チェコ語", th: "ภาษาเช็ค", "zh-hans": "捷克文", originalName: "čeština" }, sn: { "zh-TW": "紹納文", en: "Shona", ja: "ショナ語", th: "ภาษาโชนา", "zh-hans": "绍纳文", originalName: "ChiShona" }, nl: { "zh-TW": "荷蘭文", en: "Dutch", ja: "オランダ語", th: "ภาษาดัตช์", "zh-hans": "荷兰文", originalName: "Nederlands" }, ka: { "zh-TW": "喬治亞文", en: "Georgian", ja: "グルジア語", th: "ภาษาจอร์เจีย", "zh-hans": "格鲁吉亚文", originalName: "ქართული" }, sw: { "zh-TW": "斯瓦希里文", en: "Swahili", ja: "スワヒリ語", th: "ภาษาสวาฮิลี", "zh-hans": "斯瓦希里文", originalName: "Kiswahili" }, sk: { "zh-TW": "斯洛伐克文", en: "Slovak", ja: "スロバキア語", th: "ภาษาสโลวัก", "zh-hans": "斯洛伐克文", originalName: "slovenčina" }, sl: { "zh-TW": "斯洛維尼亞文", en: "Slovenian", ja: "スロベニア語", th: "ภาษาสโลวีเนีย", "zh-hans": "斯洛文尼亚文", originalName: "slovenščina" }, tl: { "zh-TW": "菲律賓文", en: "Filipino", ja: "フィリピン語", th: "ภาษาฟิลิปปินส์", "zh-hans": "菲律宾文", originalName: "Filipino" }, vi: { "zh-TW": "越南文", en: "Vietnamese", ja: "ベトナム語", th: "ภาษาเวียดนาม", "zh-hans": "越南文", originalName: "Tiếng Việt" }, tg: { "zh-TW": "塔吉克文", en: "Tajik", ja: "タジク語", th: "ภาษาทาจิก", "zh-hans": "塔吉克文", originalName: "Тоҷикӣ" }, sr: { "zh-TW": "塞爾維亞文", en: "Serbian", ja: "セルビア語", th: "ภาษาเซอร์เบีย", "zh-hans": "塞尔维亚文", originalName: "српски" }, yi: { "zh-TW": "意第緒文", en: "Yiddish", ja: "イーディッシュ語", th: "ภาษายิดดิช", "zh-hans": "意第绪文", originalName: "יידיש" }, et: { "zh-TW": "愛沙尼亞文", en: "Estonian", ja: "エストニア語", th: "ภาษาเอสโตเนีย", "zh-hans": "爱沙尼亚文", originalName: "eesti" }, ga: { "zh-TW": "愛爾蘭文", en: "Irish", ja: "アイルランド語", th: "ภาษาไอริช", "zh-hans": "爱尔兰文", originalName: "Gaeilge" }, sv: { "zh-TW": "瑞典文", en: "Swedish", ja: "スウェーデン語", th: "ภาษาสวีเดน", "zh-hans": "瑞典文", originalName: "svenska" }, st: { "zh-TW": "瑟索托文", en: "Sesotho", ja: "セソト語", th: "ภาษาเซโซโต", "zh-hans": "塞索托文", originalName: "Sesotho" }, it: { "zh-TW": "義大利文", en: "Italian", ja: "イタリア語", th: "ภาษาอิตาลี", "zh-hans": "意大利文", originalName: "Italiano" }, pt: { "zh-TW": "葡萄牙文", en: "Portuguese", ja: "ポルトガル語", th: "ภาษาโปรตุเกส", "zh-hans": "葡萄牙文", originalName: "Português" }, mn: { "zh-TW": "蒙古文", en: "Mongolian", ja: "モンゴル語", th: "ภาษามองโกล", "zh-hans": "蒙古文", originalName: "Монгол" }, ha: { "zh-TW": "豪沙文", en: "Hausa", ja: "ハウサ語", th: "ภาษาเฮาซา", "zh-hans": "豪沙文", originalName: "Hausa" }, lo: { "zh-TW": "寮文", en: "Lao", ja: "ラオ語", th: "ภาษาลาว", "zh-hans": "老文", originalName: "ລາວ" }, de: { "zh-TW": "德文", en: "German", ja: "ドイツ語", th: "ภาษาเยอรมัน", "zh-hans": "德文", originalName: "Deutsch" }, my: { "zh-TW": "緬甸文", en: "Myanmar (Burmese)", ja: "ミャンマー語", th: "ภาษาพม่า", "zh-hans": "缅甸文", originalName: "မြန်မာ (မြန်မာ)" }, lb: { "zh-TW": "盧森堡文", en: "Luxembourgish", ja: "ルクセンブルク語", th: "ภาษาลักเซมเบิร์ก", "zh-hans": "卢森堡文", originalName: "Lëtzebuergesch" }, si: { "zh-TW": "錫蘭文", en: "Sinhala", ja: "シンハラ語", th: "ภาษาสิงหล", "zh-hans": "僧伽罗文", originalName: "සිංහල" }, yo: { "zh-TW": "優魯巴文", en: "Yoruba", ja: "ヨルバ語", th: "ภาษาโยรูบา", "zh-hans": "约鲁巴文", originalName: "Èdè Yorùbá" }, ko: { "zh-TW": "韓文", en: "Korean", ja: "韓国語", th: "ภาษาเกาหลี", "zh-hans": "韩文", originalName: "한국어" }, sm: { "zh-TW": "薩摩亞文", en: "Samoan", ja: "サモア語", th: "ภาษาซามัว", "zh-hans": "萨摩亚文", originalName: "Sāmoa" }, ro: { "zh-TW": "羅馬尼亞文", en: "Romanian", ja: "ルーマニア語", th: "ภาษาโรมัน", "zh-hans": "罗马尼亚文", originalName: "Română" }, gd: { "zh-TW": "蘇格蘭的蓋爾文", en: "Scots Gaelic", ja: "スコットランドゲール語", th: "ภาษาเกลส์สกอต", "zh-hans": "苏格兰盖尔语", originalName: "Gàidhlig" } }; // Below is for old use case, not standard language code var languageCodesDataForOldUseCase = { tw: { "zh-TW": "中文 (繁體)", en: "Chinese (Traditional)", originalName: "中文 (繁體)" }, cz: { "zh-TW": "捷克文", en: "Czech", originalName: "čeština" } }; var defaultLanguageCodeData = { "default": { "zh-TW": "預設", en: "Default", originalName: "Default" } }; export { appendLeft, calculateNumber, debounce, defaultLanguageCodeData, exhaust, formatPrecision, getISOString, handleResponse, insertIndex, insertItemWithoutDuplicated, insertScript, isArrayEmpty, isEmail, isGA4Id, isGTMId, isGoogleAnalyticsId, isInteger, isNumeric, isObject, isObjectEmpty, isUrl, keycode, languageCodesData, languageCodesDataForOldUseCase, numberToAlphabet, parseJwt, parseYoutubeId, passThrough, randomHash, randomSort, removeIndex, removeItem, resizeImageDataUrl, safeAdd, safeDiv, safeMod, safeMul, safeSub, selectableFonts, shallowEqual, stripHtml, stripHtmlTags, throttle }; //# sourceMappingURL=utils.esm.js.map