utiller 1.0.448 → 1.0.450
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/lib/spider/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),_index=require("../index.js");class Spider{constructor(e,{visible:t=!1,host:i=""}){(0,_defineProperty2.default)(this,"browser",null),(0,_defineProperty2.default)(this,"puppeteer",void 0),(0,_defineProperty2.default)(this,"visible",!0),(0,_defineProperty2.default)(this,"getBrowser",async()=>{const e=await this.puppeteer.launch({headless:!this.visible});for(const t of await e.pages())await t.close();return e}),(0,_defineProperty2.default)(this,"initial",async()=>{this.browser=await this.getBrowser()}),(0,_defineProperty2.default)(this,"getPuTeerPage",async({browser:e=this.browser,type:t="desktop",incognito:i=!1,href:o="",timeout:a=0})=>{let r;if(i){const t=await e.createBrowserContext();r=await t.newPage()}else r=await e.newPage();return await this.randomViewport({page:r,type:t}),_index.utiller.isUndefinedNullEmpty(o)||await r.goto(o,{waitUntil:"networkidle2",timeout:a}),r}),(0,_defineProperty2.default)(this,"randomViewport",async({page:e,type:t="desktop"})=>{const i=_index.utiller.getRandomValue(1080,1920),o=_index.utiller.getRandomValue(1680,1920);await e.setViewport({width:i,height:o})}),(0,_defineProperty2.default)(this,"getPageOfSilent",async({browser:e=this.browser,type:t="desktop",timeout:i=0})=>this.getPuTeerPage({browser:e,type:t,timeout:i})),(0,_defineProperty2.default)(this,"activatePage4Load",async({browser:e=this.browser,href:t="",type:i="desktop",timeout:o=0,incognito:a=!1})=>await this.getPuTeerPage({browser:e,href:t,type:i,timeout:o,incognito:a})),(0,_defineProperty2.default)(this,"activatePage4Task",async({browser:e=this.browser,href:t="",type:i="desktop",timeout:o=0,fetcher:a=async e=>!0,incognito:r=!1})=>{const n=await this.activatePage4Load({browser:e,href:t,type:i,timeout:o,incognito:r}),s=await a(n);return await this.close(n),s}),(0,_defineProperty2.default)(this,"auto",async({page:e,incognito:t=!1,href:i,timeout:o=0})=>this.isPuTeerPage(e)?(_index.utiller.isUndefinedNullEmpty(i)||await e.goto(i,{waitUntil:"networkidle2",timeout:o}),await this.randomViewport(e),e):await this.activatePage4Load({incognito:t,timeout:o,href:i})),(0,_defineProperty2.default)(this,"isPuTeerPage",e=>e?.focus),(0,_defineProperty2.default)(this,"clickNextPageTilEnd",async({page:e,selector:t=".pagination-container .pagination > *",sign:i="»"})=>{try{const o=await e.$$(t);if(!o||0===o.length)return console.log("⚠️ 找不到頁面按鈕們"),!1;console.log(`📍 找到 ${o.length} 個頁面按鈕`);let a=null;for(const e of[...o].reverse())if(await this.fetchAttributeOfEl(e,await this.isElementTagBy(e,"a")?"":"a","innerText")===i){a=e;break}return a?(console.log("✅ 找到下一頁按鈕"),await a.evaluate(e=>e.disabled||e.classList.contains("disabled"))?(console.log("⚠️ 下一頁按鈕已禁用 (已是最後一頁)"),!1):(console.log("🖱️ 點擊下一頁按鈕..."),await a.click(),await e.waitForNavigation({waitUntil:"networkidle2",timeout:0}).catch(()=>{}),console.log("✅ 成功翻到下一頁"),!0)):(console.log("⚠️ 找不到下一頁按鈕 (»)"),!1)}catch(e){return console.log(`❌ 點擊下一頁出錯: ${e.message}`),!1}}),(0,_defineProperty2.default)(this,"
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),_index=require("../index.js");class Spider{constructor(e,{visible:t=!1,host:i=""}){(0,_defineProperty2.default)(this,"browser",null),(0,_defineProperty2.default)(this,"puppeteer",void 0),(0,_defineProperty2.default)(this,"visible",!0),(0,_defineProperty2.default)(this,"getBrowser",async()=>{const e=await this.puppeteer.launch({headless:!this.visible});for(const t of await e.pages())await t.close();return e}),(0,_defineProperty2.default)(this,"initial",async()=>{this.browser=await this.getBrowser()}),(0,_defineProperty2.default)(this,"getPuTeerPage",async({browser:e=this.browser,type:t="desktop",incognito:i=!1,href:o="",timeout:a=0})=>{let r;if(i){const t=await e.createBrowserContext();r=await t.newPage()}else r=await e.newPage();return await this.randomViewport({page:r,type:t}),_index.utiller.isUndefinedNullEmpty(o)||await r.goto(o,{waitUntil:"networkidle2",timeout:a}),r}),(0,_defineProperty2.default)(this,"randomViewport",async({page:e,type:t="desktop"})=>{const i=_index.utiller.getRandomValue(1080,1920),o=_index.utiller.getRandomValue(1680,1920);await e.setViewport({width:i,height:o})}),(0,_defineProperty2.default)(this,"getPageOfSilent",async({browser:e=this.browser,type:t="desktop",timeout:i=0})=>this.getPuTeerPage({browser:e,type:t,timeout:i})),(0,_defineProperty2.default)(this,"activatePage4Load",async({browser:e=this.browser,href:t="",type:i="desktop",timeout:o=0,incognito:a=!1})=>await this.getPuTeerPage({browser:e,href:t,type:i,timeout:o,incognito:a})),(0,_defineProperty2.default)(this,"activatePage4Task",async({browser:e=this.browser,href:t="",type:i="desktop",timeout:o=0,fetcher:a=async e=>!0,incognito:r=!1})=>{const n=await this.activatePage4Load({browser:e,href:t,type:i,timeout:o,incognito:r}),s=await a(n);return await this.close(n),s}),(0,_defineProperty2.default)(this,"auto",async({page:e,incognito:t=!1,href:i,timeout:o=0})=>this.isPuTeerPage(e)?(_index.utiller.isUndefinedNullEmpty(i)||await e.goto(i,{waitUntil:"networkidle2",timeout:o}),await this.randomViewport(e),e):await this.activatePage4Load({incognito:t,timeout:o,href:i})),(0,_defineProperty2.default)(this,"isPuTeerPage",e=>e?.focus),(0,_defineProperty2.default)(this,"clickNextPageTilEnd",async({page:e,selector:t=".pagination-container .pagination > *",sign:i="»"})=>{try{const o=await e.$$(t);if(!o||0===o.length)return console.log("⚠️ 找不到頁面按鈕們"),!1;console.log(`📍 找到 ${o.length} 個頁面按鈕`);let a=null;for(const e of[...o].reverse())if(await this.fetchAttributeOfEl(e,await this.isElementTagBy(e,"a")?"":"a","innerText")===i){a=e;break}return a?(console.log("✅ 找到下一頁按鈕"),await a.evaluate(e=>e.disabled||e.classList.contains("disabled"))?(console.log("⚠️ 下一頁按鈕已禁用 (已是最後一頁)"),!1):(console.log("🖱️ 點擊下一頁按鈕..."),await a.click(),await e.waitForNavigation({waitUntil:"networkidle2",timeout:0}).catch(()=>{}),console.log("✅ 成功翻到下一頁"),!0)):(console.log("⚠️ 找不到下一頁按鈕 (»)"),!1)}catch(e){return console.log(`❌ 點擊下一頁出錯: ${e.message}`),!1}}),(0,_defineProperty2.default)(this,"wait4Until",async(e,{timeout:t=0}={})=>{await e.waitForNavigation({waitUntil:"networkidle2",timeout:t}).catch(()=>{})}),(0,_defineProperty2.default)(this,"fetchElementsTilPageScrollEnd",async({page:e,href:t="",fetcher:i=async e=>{},stringOfLoadingSelector:o,incognito:a=!1,timeout:r})=>{const n=await this.auto({page:e,incognito:a,href:t,timeout:r});await this.scrollToBottomAndCheck(n,{stringOfLoadingSelector:o});const s=await i(n);return await this.close(n),s}),(0,_defineProperty2.default)(this,"fetchAttributesOfEl",async(e,t,i)=>{let o;if(t&&""!==t.trim()){if(o=await e.$(t),!o)return console.warn(`⚠️ 找不到元素: ${t}`),{}}else o=e;const a={},r={};for(const[e,t]of Object.entries(i)){if("object"==typeof t&&null!==t&&!Array.isArray(t)){Object.assign(r,t);continue}const i=String(t);if(i.startsWith("$$$")){const t=i.substring(3),o=parseFloat(t);isNaN(o)?(console.warn(`⚠️ 無法解析數字: ${i}`),r[e]=void 0):r[e]=o;continue}if(i.startsWith("###")){const t=i.substring(3);r[e]=t;continue}if(i.startsWith("@@@")){const t=i.substring(3).toLowerCase().trim();let o;"true"===t||"1"===t||"yes"===t||"y"===t||"on"===t?o=!0:("false"===t||"0"===t||"no"===t||"n"===t||"off"===t||""===t||console.warn(`⚠️ 無法解析布林值: ${i},默認為 false`),o=!1),r[e]=o;continue}a[e]=t}const n=await o.evaluate((e,t)=>{const i={};for(const[o,a]of Object.entries(t)){const t=void 0!==e[a]?e[a]:e.getAttribute(a);i[o]=null!==t?t:void 0}return i},a);return{...n,...r}}),(0,_defineProperty2.default)(this,"fetchAttributeOfEl",async(e,t,i)=>{let o;if(t&&""!==t.trim()){if(o=await e.$(t),!o)return void console.warn(`⚠️ 找不到元素: ${t}`)}else o=e;return await o.evaluate((e,t)=>{const i=void 0!==e[t]?e[t]:e.getAttribute(t);return null!==i?i:void 0},i)}),(0,_defineProperty2.default)(this,"isElementTagBy",async(e,t)=>await e.evaluate((e,t)=>e.tagName.toLowerCase()===t.toLowerCase(),t)),(0,_defineProperty2.default)(this,"waitForLoadingToVanish",async(e,t,i=1e4)=>{if(!t)return!0;try{return await e.waitForSelector(t,{hidden:!0,timeout:i}),!0}catch(e){return console.warn(`警告: Loading Bar ${t} 在 ${i}ms 內未消失,將強制繼續執行。`),!1}}),(0,_defineProperty2.default)(this,"scrollToBottomAndCheck",async(e,{minDelay:t=2e3,maxRetries:i=3,stringOfLoadingSelector:o,loadingTimeout:a=6e3}={})=>{console.log("🚀 開始執行智能滾動檢查...");let r=await e.evaluate(()=>document.body.scrollHeight),n=0;for(;;){await e.evaluate(()=>window.scrollTo(0,document.body.scrollHeight)),await new Promise(e=>setTimeout(e,t)),o&&await this.waitForLoadingToVanish(e,o,a);let s=await e.evaluate(()=>document.body.scrollHeight);if(s===r){if(n++,n>=i){console.log(`✅ 連續 ${i} 次未檢測到新內容,判定已到達最底部。`);break}console.log(`🔄 高度未變化,正在重試等待... (${n}/${i})`),await new Promise(e=>setTimeout(e,1e3))}else console.log(`⬇️ 檢測到新內容 (高度: ${r} -> ${s}),繼續滾動...`),r=s,n=0}}),(0,_defineProperty2.default)(this,"getSelectorRoute",async(e,t)=>await e.evaluate(e=>(e=>{if(e.id)return`#${e.id}`;let t=[];for(;e.parentElement;){let i=e.tagName.toLowerCase();Array.from(e.parentElement.children).filter(t=>t.tagName===e.tagName).length>1&&(i+=`:nth-child(${Array.prototype.indexOf.call(e.parentElement.children,e)+1})`),t.unshift(i),e=e.parentElement}return t.join(" > ")})(e),t)),(0,_defineProperty2.default)(this,"waitSelectorTilAppear",async(e,t,i=1e4)=>{try{return await e.waitForSelector(t,{visible:!0,timeout:i}),console.log(`元素 ${t} 已在 ${e.url()} 上出現!`),!0}catch(e){const o=`元素 ${t} 未在 ${i/1e3} 秒內出現。`;console.error(o,e)}}),(0,_defineProperty2.default)(this,"close",async e=>{if(e)try{const t=e.browserContext();t===e.browser().defaultBrowserContext()?await e.close():await t.close()}catch(e){console.error("關閉頁面/Context 時發生錯誤:",e)}}),(0,_defineProperty2.default)(this,"terminate",async()=>{await this.browser.close()}),this.puppeteer=e,this.visible=t,this.host=i}async fetchElementsTilPageEnd({page:e,href:t="",fetcher:i=async e=>[],selectorOfPagingN:o,signOfPagingN:a="»",incognito:r=!1,timeout:n=0}){const s=await this.auto({page:e,incognito:r,href:t,timeout:n});let l=[];try{do{await _index.utiller.syncDelay(10);const e=await i(s);l=l.concat(e)}while(await this.clickNextPageTilEnd({page:s,selector:o,sign:a}))}catch(e){return console.error(`抓取失敗: ${e.message}`),[]}finally{await this.close(s)}return l}async clearCookies(e){await e.deleteCookie(...await e.cookies())}async checkSelectorExists(e,t){return!!await e.$(t)}async finish(){await this.browser.close()}async clickSolution(e,t){await e.evaluate(e=>{e.click()},t)}async managePages(e,t=this.browser){const i=e=>{try{const t=new URL(e);return _index.utiller.getUrlPath(this.host,t.pathname)}catch(e){return null}};t.on("targetcreated",async t=>{if("page"===t.type())try{const o=await t.page();if(!o)return;const a=o.url();if("about:blank"===a)return;const r=i(a);r&&r!==e&&(console.log(`[攔截新分頁] 偵測到非法網址: ${r} (目標應為: ${e}),正在關閉...`),await o.close())}catch(e){console.error(`[新分頁檢查錯誤] 無法處理頁面: ${e.message}`)}});try{const o=await t.pages();for(const t of o){const o=t.url();if(t.isClosed()||"about:blank"===o)continue;const a=i(o);a&&a!==e&&(console.log(`[清理舊分頁] 發現非法網址: ${a} (目標應為: ${e}),正在關閉...`),await t.close())}}catch(e){console.error(`[舊分頁清理錯誤] ${e.message}`)}console.log("頁面管理已啟動,保持監聽 10 秒..."),await new Promise(e=>setTimeout(e,1e4))}async checkElementVisibleWithRetry(e,t,i=3e4,o=1e3){const a=Date.now();try{for(;Date.now()-a<i;){if(await e.$(t)){if(await e.evaluate(e=>{const t=document.querySelector(e);if(!t)return!1;const i=window.getComputedStyle(t);return"none"!==i.display&&"hidden"!==i.visibility&&"0"!==i.opacity},t))return console.log(`元素 ${t} 存在且可見`),!0;console.log(`元素 ${t} 存在但不可見,繼續等待...`)}else console.log(`元素 ${t} 不存在,繼續等待...`);await new Promise(e=>setTimeout(e,o))}return console.log(`超時:元素 ${t} 未在 ${i/1e3} 秒內變為可見`),!1}catch(e){return console.error(`發生錯誤: ${e.message}`),!1}}}var _default=exports.default=Spider;
|
package/lib/utiller/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),_lodash=_interopRequireDefault(require("lodash")),_cryptoJs=_interopRequireDefault(require("crypto-js")),_configerer=require("configerer"),_exceptioner=_interopRequireDefault(require("../exceptioner")),_momentTimezone=_interopRequireDefault(require("moment-timezone")),_uuid=require("uuid"),_nodeHtmlParser=require("node-html-parser");String.format=function(){let e=[];for(let t=0,r=arguments.length;t<r;t++)e.push(arguments[t]);let t=e[0];return e.shift(),t.replace(/\{(\d+)\}/g,function(t,r){return e[r]})};class Utiller{removeAttributeBy(e,t=e=>_lodash.default.isUndefined(e)){for(const r in e)t(e[r])&&delete e[r]}getUrlPath(...e){return e.filter(e=>null!=e&&""!==e).map(e=>String(e)).map(e=>e.replace(/^\/+|\/+$/g,"")).filter(e=>""!==e).join("/").replace(/^(https?):\/(?!\/)/,"$1://")}getNumberOfNormalize(e,t=0){if(_lodash.default.isNumber(e))return e;try{const r=_lodash.default.toNumber(e);return _lodash.default.isNumber(r)&&!isNaN(r)?r:t}catch(e){Util.appendError(`448561684561 ${e.message}`)}return t}getStringOfNormalize(e,t="",r=!1){if(_lodash.default.isString(e))return r?_lodash.default.trim(e):e;try{const a=_lodash.default.toString(e);return this.isOrEquals(a,"","undefined")?t:r?_lodash.default.trim(a):a}catch(e){Util.appendError(`448616845453 ${e.message}`)}return t}isValidVersionOfString(e){if(this.isUndefinedNullEmpty(e))return!1;const t=e.split(".");for(const e of t){const t=_lodash.default.toNumber(e);if(!_lodash.default.isNumber(t)||isNaN(t))return!1}return!0}getSeparatorOfUnique(){return"།།"}getStringOfVersionIncrement(e,t=1){const r=e.split(".").map(e=>_lodash.default.toNumber(e)),a=r.length-1;return r[a]=r[a]+t,r.join(".")}setLocaleOfMoment(e="en"){_momentTimezone.default.locale(e)}getUuidOfV4(){return(0,_uuid.v4)()}constructor(){(0,_defineProperty2.default)(this,"mapOfIdNTimeoutId",{}),(0,_defineProperty2.default)(this,"getEnvironment",()=>this.env),(0,_defineProperty2.default)(this,"isProductionEnvironment",()=>_lodash.default.isEqual(this.getEnvironment(),"prod")),(0,_defineProperty2.default)(this,"asyncUnitTaskFunction",(e=2e3,t="預設的param",r)=>async(a=this.getRandomHash(10))=>{const n=this.getRandomValue(e,1.2*e);try{const e=n;if(this.appendInfo(`before executed ===> i'm symbol of ${e}, ready to be executed, inner param = ${t}`),await this.syncDelay(n),_lodash.default.isFunction(r)&&r(a))throw Error("force to made error happen");return this.appendInfo(`after executed ===> i'm symbol of ${e}, the task cost ${n} million-seconds ${a?`i hav params ===> ${a}`:""}`),{randomValue:n,symbol:e,param:a}}catch(e){this.appendError(new Error(`asyncUnitTask() catch error ${e.message}`))}finally{this.appendInfo("wow.... finally got you")}}),(0,_defineProperty2.default)(this,"test",e=>async()=>(await Util.syncDelay(3e3),console.log("經過了三秒"),await Util.syncDelay(4e3),console.log("經過了四秒"),await Util.syncDelay(5e3),console.log("經過了五秒"),await Util.syncDelay(6e3),console.log("經過了六秒"),`3423809432804 ${e}`)),(0,_defineProperty2.default)(this,"findLowestValue",(e,t="price")=>{const r=_lodash.default.minBy(e,t)[t];return Math.floor(r)}),(0,_defineProperty2.default)(this,"findHighestValue",(e,t="price")=>{const r=_lodash.default.maxBy(e,t)[t];return Math.floor(r)}),(0,_defineProperty2.default)(this,"getStringOfValueRange",(e,t="price",r="$")=>{const a=_lodash.default.minBy(e,t)[t],n=_lodash.default.maxBy(e,t)[t];return n===a?`$${a}`:`${r}${a} - ${r}${n}`}),(0,_defineProperty2.default)(this,"getCallersName",()=>{let e;try{throw new Error}catch(t){let r,a=/(\w+)@|at (\w+) \(/g,n=t.stack;a.exec(n),r=a.exec(n),_lodash.default.isNull(r)||(e=r[1]||r[2])}return _lodash.default.startsWith("asyncGeneratorStep",e)&&(e=""),e}),(0,_defineProperty2.default)(this,"getRandomValue",(e,t)=>(e=Math.ceil(e),t=Math.floor(t),Math.floor(Math.random()*(t-e+1))+e)),(0,_defineProperty2.default)(this,"insertToArray",(e,t,...r)=>{if(!Array.isArray(e))throw new Error("First argument must be an array.");const a=Math.max(0,Math.min(t+1,e.length));e.splice(a,0,...r)}),(0,_defineProperty2.default)(this,"getStringOfYearADConvertToMinguoYear",(e,t=!1)=>{const r=e-1911;return r>0?`${t?"民國":""}${r}${t?"年":""}`:`${t?"民國":""}前${Math.abs(r)}${t?"年":""}`}),(0,_defineProperty2.default)(this,"convertDateToTimestamp",e=>(0,_momentTimezone.default)(e).valueOf()),(0,_defineProperty2.default)(this,"measureExecutionTime",async(e,...t)=>{const r=Date.now();await e(...t);const a=Date.now()-r,n=_momentTimezone.default.duration(a,"milliseconds"),i=Math.floor(n.asHours()),o=n.minutes(),s=n.seconds(),l=n.milliseconds(),d=(a/1e3).toFixed(3);return{second:d,zh_TW:`${i}小時 ${o}分 ${s}.${l.toString().padStart(3,"0")}秒 (合計 ${d} 秒)`}}),(0,_defineProperty2.default)(this,"formatPriceWithCurrency",(e,t)=>{if("number"!=typeof e||"string"!=typeof t)throw new TypeError("Invalid input: number must be a number and locale must be a string.");return new Intl.NumberFormat(t,{style:"currency",currency:new Intl.Locale(t).maximize().currency||"USD",minimumFractionDigits:0}).format(e)}),(0,_defineProperty2.default)(this,"formatPrice",(e,t)=>{if("number"!=typeof e)throw new TypeError("Invalid input: number must be a number.");return t?new Intl.NumberFormat(t,{style:"currency",currency:new Intl.Locale(t).maximize().currency||"USD",minimumFractionDigits:0}).format(e):e.toLocaleString("en-US")}),(0,_defineProperty2.default)(this,"generateUniversalKeywords",(e,t=50,r=4)=>{if(!e||"string"!=typeof e)return[];if(void 0===_lodash.default)return console.error("Lodash is not available. Please ensure it is imported."),[];let a=e.trim(),n=[];r=Math.max(2,r),a.length>t&&(console.warn(`警告:輸入字串長度為 ${a.length},已根據 maxLength: ${t} 截斷。`),a=a.substring(0,t)),(a.match(/[a-zA-Z]+/g)||[]).forEach(e=>{if(e.length>=2){n.push(e.toUpperCase()),n.push(e.toLowerCase());const t=e.charAt(0).toUpperCase()+e.slice(1).toLowerCase();n.push(t)}});const i=(a.match(/\b[0-9]+[a-zA-Z]{1,4}\b|\b[0-9]{1,3}(w|ml|g|oz|k)\b|[\u4e00-\u9fa5a-zA-Z0-9]{1,4}(色|號)[\u4e00-\u9fa5a-zA-Z0-9]{0,2}/gi)||[]).filter(e=>e.length>=2).map(e=>e.toLowerCase());n.push(...i);let o=a.toLowerCase();o=o.replace(/[0-9]+([\u4e00-\u9fa5a-z]{1,4}|[\/\-\~\\])/g," ").replace(/\b[a-z]{1,4}\b/g," ").replace(/\b[0-9]{1,3}\b/g," "),o=o.replace(/[!@#$%^&*()_+={}\[\]:;"'<>,.?\/\\|`~]/g," ").replace(/系列|一組|單色|多款|套組|全套|專用|迷你|頂級|高品質|超閃|奢華|最新|款式|新款|超亮|的|與|和|閃|美甲/g," ").replace(/\s+/g,"").trim();for(let e=2;e<=r;e++)for(let t=0;t<=o.length-e;t++){const r=o.substring(t,t+e);n.push(r)}return _lodash.default.chain(n).filter(e=>e.length>=2).filter(e=>e.length>2||!/^[\u4e00-\u9fa5a-z0-9]$/.test(e)).uniq().sortBy().value()}),(0,_defineProperty2.default)(this,"mutateIndexOfArrayItem",(e,t,r=0)=>{if(!Array.isArray(e)||!_lodash.default.isObject(t))return e;const a=_lodash.default.findIndex(e,e=>_lodash.default.isEqual(e,t));if(-1===a)return e;e.splice(a,1);const n=_lodash.default.clamp(r,0,e.length);return e.splice(n,0,t),e}),(0,_defineProperty2.default)(this,"getArrayOfModifyObject2Index",(e,t,r=0)=>{if(!Array.isArray(e)||!_lodash.default.isObject(t))return e;const a=_lodash.default.cloneDeep(e),n=_lodash.default.findIndex(a,e=>_lodash.default.isEqual(e,t));if(-1===n)return e;a.splice(n,1);const i=_lodash.default.clamp(r,0,a.length);return a.splice(i,0,t),a}),(0,_defineProperty2.default)(this,"generateLabelValuePairsWithOrigin",(e=[{label:"aa",value:1203},{label:"cc",value:1204},{label:"gg",value:2}],t=["aa","bb"])=>{const r=new Set(e.map(e=>e.value));return _lodash.default.chain(t).uniq().map(t=>{const a=_lodash.default.find(e,{label:t});if(a)return{label:t,value:a.value};let n;do{n=_lodash.default.random(2,999999999)}while(r.has(n));return r.add(n),{label:t,value:n}}).value()}),(0,_defineProperty2.default)(this,"getItemsOfMarkMatching",(e=[],t=[],r="value",a="belong")=>{const n=new Set(t);return _lodash.default.map(e,e=>({...e,[a]:n.has(e[r])}))}),(0,_defineProperty2.default)(this,"generateVariants",(e,t="|",r="-")=>{const a=e.filter(e=>e.length>0);return 0===a.length?[]:1===a.length?a[0].map(e=>({label:e.label,value:e.value})):_lodash.default.reduce(a,(e,t)=>_lodash.default.flatMap(e,e=>t.map(t=>[...e,t])),[[]]).map(e=>({label:e.map(e=>e.label).join(t),value:e.map(e=>e.value).join(r)}))}),(0,_defineProperty2.default)(this,"renameKeysInArray",(e,...t)=>{const r=Object.fromEntries(t);return e.map(e=>_lodash.default.mapKeys(e,(e,t)=>r[t]||t))}),(0,_defineProperty2.default)(this,"getArrayOfMergeBySpecificId",(e,t,r="id")=>{if(!Array.isArray(t))return e;const a=_lodash.default.keyBy(t,e=>_lodash.default.get(e,r));return e.map(e=>{const t=_lodash.default.get(e,r),n=a[t];return n?_lodash.default.merge({},e,n):e})}),(0,_defineProperty2.default)(this,"toPercentageDecimal",e=>{if(_lodash.default.isNil(e))return 1;_lodash.default.isString(e)&&(e=e.replace(/%/g,"").trim());const t=_lodash.default.toNumber(e);return _lodash.default.isFinite(t)?_lodash.default.round(t/100,10):1}),(0,_defineProperty2.default)(this,"getNumberOfMultiplyCeil",(e,t,r=0)=>{const a=Math.pow(10,r);return Math.ceil(e*t*a)/a}),(0,_defineProperty2.default)(this,"generateGoogleCalendarLink",({title:e,startDate:t,startTime:r,endDate:a,endTime:n,location:i,details:o})=>{const s=(0,_momentTimezone.default)(`${t} ${r}`,"YYYY/MM/DD HH:mm").format("YYYYMMDDTHHmmss"),l=(0,_momentTimezone.default)(`${a} ${n}`,"YYYY/MM/DD HH:mm").format("YYYYMMDDTHHmmss"),d=new URLSearchParams;return e&&d.append("text",e),s&&l&&d.append("dates",`${s}/${l}`),o&&d.append("details",o),i&&d.append("location",i),d.append("ctz","Asia/Taipei"),d.append("trp","true"),`https://calendar.google.com/calendar/r/eventedit?${d.toString()}`}),(0,_defineProperty2.default)(this,"generateTimeTreeLink",({title:e,startDate:t,startTime:r,endDate:a,endTime:n,location:i,memo:o})=>{const s=new URLSearchParams;return e&&s.append("title",e),t&&s.append("start_date",t.replace(/\//g,"-")),r&&s.append("start_time",r),a&&s.append("end_date",a.replace(/\//g,"-")),n&&s.append("end_time",n),i&&s.append("location",i),o&&s.append("memo",o),`https://timetreeapp.com/plans/new?${s.toString()}`}),(0,_defineProperty2.default)(this,"generateIcsContent",({title:e,startDate:t,startTime:r,endDate:a,endTime:n,location:i,details:o})=>{const s=_momentTimezone.default.tz(`${t} ${r}`,"YYYY/MM/DD HH:mm","Asia/Taipei").format("YYYYMMDDTHHmmss"),l=_momentTimezone.default.tz(`${a} ${n}`,"YYYY/MM/DD HH:mm","Asia/Taipei").format("YYYYMMDDTHHmmss"),d=(0,_momentTimezone.default)().utc().format("YYYYMMDDTHHmmss")+"Z",u=e=>e.replace(/\\/g,"\\\\").replace(/,/g,"\\,").replace(/;/g,"\\;").replace(/\n/g,"\\n"),f=["BEGIN:VCALENDAR","VERSION:2.0","PRODID:-//Gemini AI//NONSGML v1.0//EN","BEGIN:VEVENT","UID:"+(Date.now().toString(36)+Math.random().toString(36).substring(2,5)+"@gemini-app.com"),`DTSTAMP:${d}`];return s&&f.push(`DTSTART;TZID=Asia/Taipei:${s}`),l&&f.push(`DTEND;TZID=Asia/Taipei:${l}`),e&&f.push(`SUMMARY:${u(e)}`),i&&f.push(`LOCATION:${u(i)}`),o&&f.push(`DESCRIPTION:${u(o)}`),f.push("END:VEVENT","END:VCALENDAR"),f.join("\r\n")}),(0,_defineProperty2.default)(this,"generateAllCalendarLinks",e=>{const t=this.generateGoogleCalendarLink(e),r={...e,memo:e.details},a=this.generateTimeTreeLink(r),n=this.generateIcsContent(e);return{google:t,timeTree:a,ics:`data:text/calendar;charset=utf8,${encodeURIComponent(n)}`}}),(0,_defineProperty2.default)(this,"getArrayOfMappingRef",(e,t)=>_lodash.default.map(e,e=>{const r=_lodash.default.find(t,{value:e.value});return r?_lodash.default.merge({},e,r):e})),(0,_defineProperty2.default)(this,"areAllValuesTheSameOnKeys",(e,...t)=>{if(!e||e.length<=1||0===t.length)return!0;for(const r of t){const t=e[0]?.[r];if(!_lodash.default.every(e,e=>e[r]===t))return!1}return!0}),this.init(),this.env="dev"}performActionWithoutTimingIssue(e=()=>!0,t=10){this.syncDelay(t).then(()=>e())}executeTimeoutTask(e,t=1e3,r=this.getRandomHash(),...a){const n=this,i=this.mapOfIdNTimeoutId[r];i&&clearTimeout(i);const o=setTimeout(async(...t)=>{await e(),delete n.mapOfIdNTimeoutId[r]},t,...a);n.mapOfIdNTimeoutId[r]=o}printLogMessage(e,t=!1,...r){this.isProductionEnvironment()||(t?this.appendError(e,...r):this.appendInfo(e,...r))}init(){}setEnvironment(e){this.env=e}appendInfo(...e){this.isProductionEnvironment()||console.log(...e)}appendError(...e){this.isProductionEnvironment()||console.error(...e)}async syncDelay(e=2e3){return new Promise(t=>{setTimeout(()=>{t(e)},e)})}startWithRegex(e="",t="."){return new RegExp(`^${t}`,"i").test(e)}accumulate(e,t){let r=e;for(const e of t)void 0!==e&&_lodash.default.isFunction(e)&&(r=e(r));return r}isOrEquals(e,...t){for(const r of t)if(_lodash.default.isEqual(e,r))return!0;return!1}isAndEquals(...e){for(const t of e)if(!t())return!1;return!0}getStringOfHeadMatch(e,t,r="g"){const a=e.match(new RegExp(t,r));return this.isUndefinedNullEmpty(a)?void 0:a[0]}or(...e){for(const t of e)if(_lodash.default.isBoolean(t)&&t)return!0;return!1}and(...e){for(const t of e)if(!t)return!1;return!0}nth(e,t=-1){return _lodash.default.nth(e,t%_lodash.default.size(e))}getExistOne(...e){for(const t of e)if(t)return t}getStringOfDropHeadSign(e,t){return _lodash.default.dropWhile(Array.from(e),e=>_lodash.default.isEqual(e,t)).join("")}isAndWith(e,t,...r){for(const a of r)if(!t(e,a))return!1;return!0}async syncDelayRandom(e=3e3,t=5e3){const r=this.getRandomValue(e,t);return await this.syncDelay(r),r}has(e,t,r=!1){return _lodash.default.isArray(e)?r?_lodash.default.findIndex(e,e=>_lodash.default.isEqual(t,e))>-1:_lodash.default.indexOf(e,t)>-1:_lodash.default.isObject(t)?e[t]:!!_lodash.default.isString(e)&&e.indexOf(t)>-1}containsBy(e,t){return _lodash.default.findIndex(e,e=>_lodash.default.isEqual(e,t))>=0}getStringOfInsideParentheses(e,t="."){return this.getStringOfRule(e,t,"(",")")}getStringOfInsideBrackets(e,t="."){return this.getStringOfRule(e,t,"[","]")}getStringOfInsideBraces(e,t="."){return this.getStringOfRule(e,t,"{","}")}getStringOfRule(e,t=".",r="{",a="}"){return this.getStringOfHeadMatch(e,`(?<=\\${r})${t}+?(?=\\${a})`)}getRandomHash(e=20){const t=_cryptoJs.default.lib.WordArray.random(e);return _cryptoJs.default.enc.Base64.stringify(t).substring(0,e)}getRandomHashV2(e){let t="";for(let r=0;r<e;r++){const e=Math.floor(62*Math.random());t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(e)}return t}getEncryptString(e,t=_configerer.configerer.ENCRYPT_KEY,r=!1){if(t.length>22)throw new _exceptioner.default(8010,_lodash.default.size(t));const a=_cryptoJs.default.enc.Base64.parse("thisIsIVWeNeedToGenerateTheSameValue"),n=r?_cryptoJs.default.enc.Base64.parse(`${t}${_lodash.default.range(0,22-t.length).join("")}`):t;return _cryptoJs.default.AES.encrypt(e,n,{iv:a}).toString()}getEncryptStringV2(e,t=_configerer.configerer.ENCRYPT_KEY,r=!1){if(t.length>22)throw new _exceptioner.default(8010,_lodash.default.size(t));const a=_cryptoJs.default.enc.Base64.parse("thisIsIVWeNeedToGenerateTheSameValue"),n=r?_cryptoJs.default.enc.Base64.parse(`${t}${_lodash.default.range(0,22-t.length).join("")}`):t;return _cryptoJs.default.AES.encrypt(JSON.stringify({content:e}),n,{iv:a}).toString()}getDecryptString(e,t=_configerer.configerer.ENCRYPT_KEY){if(t.length>22)throw new _exceptioner.default(8010,_lodash.default.size(t));const r=_cryptoJs.default.enc.Base64.parse("thisIsIVWeNeedToGenerateTheSameValue");try{const a=_cryptoJs.default.AES.decrypt(e,t,{iv:r}).toString(_cryptoJs.default.enc.Utf8);if(!_lodash.default.isEmpty(a.trim()))return a}catch(e){}return _cryptoJs.default.AES.decrypt(e,_cryptoJs.default.enc.Base64.parse(`${t}${_lodash.default.range(0,22-t.length).join("")}`),{iv:r}).toString(_cryptoJs.default.enc.Utf8)}getDecryptStringV2(e,t=_configerer.configerer.ENCRYPT_KEY){if(t.length>22)throw new _exceptioner.default(8010,_lodash.default.size(t));const r=_cryptoJs.default.enc.Base64.parse("thisIsIVWeNeedToGenerateTheSameValue");try{const a=_cryptoJs.default.AES.decrypt(e,t,{iv:r}).toString(_cryptoJs.default.enc.Utf8);if(!_lodash.default.isEmpty(a.trim()))return JSON.parse(a).content}catch(e){}const a=_cryptoJs.default.AES.decrypt(e,_cryptoJs.default.enc.Base64.parse(`${t}${_lodash.default.range(0,22-t.length).join("")}`),{iv:r}).toString(_cryptoJs.default.enc.Utf8);return JSON.parse(a).content}getFirebaseFormattedString(e){return _lodash.default.replace(e,/[\.\#\$\[\]]/g,"-").trim()}formalizeNamesToArray(e){let t=e;for(t=t.split(_configerer.configerer.SEPARATE_TONE_SINGER)[0].trim(),t=_lodash.default.replace(t,/[,\/#!$%\^&\*;:{}=_`、~()()]/g,"_").trim(),t=this.getFirebaseFormattedString(t),t=_lodash.default.replace(t,/\_\_+/g,"_").trim();_lodash.default.endsWith(t,"_");)t=t.slice(0,-1).trim();const r=t.split("_");return _lodash.default.map(r,e=>_lodash.default.trim(e))}getShuffledArrayWithLimitCountHighPerformance(e,t){let r=new Array(t),a=e.length,n=new Array(a);for(t>a&&(t=a);t--;){let i=Math.floor(Math.random()*a);r[t]=e[i in n?n[i]:i],n[i]=--a in n?n[a]:a}return r}getFileNameFromPath(e,t=!1){const r=e.split("/").pop();return t?r:r.split(".").shift()}getFileNameExtensionFromPath(e){return e.split("/").pop()}getPathOfReplaceLastDir(e,t){const r=e.split("/");return r.pop(),r.push(t),r.join("/")}getExtensionFromPath(e){const t=e.split("/").pop().split(".");return _lodash.default.size(t)>1?t.pop():""}getFolderPathOfSpecificPath(e){const t=e.split("/");return t.pop(),t.join("/")}getFolderNameOfFilePath(e){if(this.isValidFilePath(e)){const t=e.split("/");return _lodash.default.nth(t,-2)}throw new _exceptioner.default(9999,`64255615 path is not valid '${e}'`)}isUnderTargetPath(e,t){const r=e.split("/");return this.has(r,t)}getFileDirPath(e,t=!0){return _lodash.default.join(_lodash.default.initial(_lodash.default.split(e,"/")),"/")+(t?"/":"")}isPathEqualsFileType(e,t){const r=e.split(".").pop();return _lodash.default.isEqual(r,t)}isValidFilePath(e){const t=this.getExtensionFromPath(e);return _lodash.default.size(t)>0}getArrayOfSize(e,t=1){return _lodash.default.take(e,t)}getShuffledArrayWithLimitCount(e,t){return this.getShuffledArrayWithLimitCountHighPerformance(e,t)}getRandomItemOfArray(e,...t){if(!_lodash.default.isArray(e))throw new _exceptioner.default(9999,`why are you so stupid, typeof array should be array, not ==> ${e} `);const r=_lodash.default.without(e,...t),a=_lodash.default.size(r)>0?r:e,n=this.getShuffledArrayWithLimitCount(a,1);return n.length>0?n[0]:void 0}appendMapOfKeyArray(e,t,...r){this.isUndefinedNullEmpty(e[t])?e[t]=[...r]:e[t].push(...r)}getMergedArrayBy(e=[],t=[],r){if(!r||0===e.length||0===t.length)return[...e];const a=new Map(t.map(e=>[e[r],e]));return e.map(e=>({...a.get(e[r])||{},...e}))}getShuffledItemFromArray(e){return _lodash.default.shuffle(e)[0]}getShuffledArray(e){return _lodash.default.shuffle(e)}isJson(e){e="string"!=typeof e?JSON.stringify(e):e;try{e=JSON.parse(e)}catch(e){return!1}return"object"==typeof e&&null!==e}getObjectValue(e){return _lodash.default.isObject(e)?Object.values(e)[0]:""}getObject(e,t){const r={};return r[e]=t,r}getStringOfCreditCardFormatted(e=0){return e.replace(/\D/g,"").replace(/(\d{4})(?=\d)/g,"$1-").slice(0,19)}getObjectKey(e){return _lodash.default.isObject(e)?Object.keys(e)[0]:""}printf(){this.appendInfo("i can use in web || react.js")}isKeywordRule(e){if(_lodash.default.isUndefined(e)||_lodash.default.isEmpty(e))throw new Error("PARAMS CAN NOT BE EMPTY");if(!_lodash.default.isString(e))throw new Error("PARAMS SHOULD BE STRING");if(e.length>20)throw new Error("EXCEED 20 WORDS IS NOT ALLOWED")}getItsKeyByValue(e,t){return Object.keys(e).find(r=>e[r]===t)}startWiths(e,t=[]){for(const r of t)if(_lodash.default.startsWith(e,r))return!0;return!1}replaceAll(e,t,r){return _lodash.default.replace(e,new RegExp(`${t}`,"g"),r)}replaceAllWithSets(e="",...t){let r=e;for(const e of t){if(this.isOrEquals(void 0,e.from,e.to))throw(0,_exceptioner.default)(9999,"from or to can't be empty");r=this.replaceAll(r,e.from,e.to)}return r}replaceArrayByContentIndex(e,t,r){e[_lodash.default.indexOf(e,t)]=r}deepFlat(e,t="_"){let r="";const a=[[e,""]];for(;a.length>0;){const[e,n]=a.pop();if(_lodash.default.isArray(e))for(let t=e.length-1;t>=0;t--)a.push([e[t],n]);else if(_lodash.default.isObject(e)){const r=Object.keys(e);for(let i=r.length-1;i>=0;i--){const o=r[i];a.push([e[o],n+o+t])}}else{const a=_lodash.default.trim(String(e));a.length>0?r+=(r.length>0?t:"")+n+a:n.length>0&&r.length>0?r+=t:n.length>0&&0===r.length&&(r+=n.endsWith(t)?n.slice(0,-t.length):n)}}return r.endsWith(t)&&(r=r.slice(0,-t.length)),r}joinEscapeChar(e){return(e+"").replace(/[\\"']/g,"\\$&").replace(/\u0000/g,"\\0")}getValueWithIntegerType(e){try{const t=parseInt(e);return isNaN(t)?0:t}catch(e){return 0}}getValueOfPriority(...e){for(const t of e)if(!this.isUndefinedNullEmpty(t))return t}async asyncPool(e,t,r){const a=[],n=[];for(const i of t){const o=Promise.resolve().then(()=>r(i,t));if(a.push(o),e<=t.length){const t=o.then(()=>n.splice(n.indexOf(t),1));n.push(t),n.length>=e&&await Promise.race(n)}}return Promise.all(a)}getAttrValueInSequence(e,...t){for(const r of t)if(!_lodash.default.isEmpty(e[r]))return e[r];return e}toDBC(e){for(var t="",r=0;r<e.length;r++)32===e.charCodeAt(r)&&(t+=String.fromCharCode(12288)),e.charCodeAt(r)<127&&(t+=String.fromCharCode(e.charCodeAt(r)+65248));return t}toCDB(e){for(var t="",r=0;r<e.length;r++)12288!==e.charCodeAt(r)?e.charCodeAt(r)>65280&&e.charCodeAt(r)<65375?t+=String.fromCharCode(e.charCodeAt(r)-65248):t+=String.fromCharCode(e.charCodeAt(r)):t+=String.fromCharCode(e.charCodeAt(r)-12256);return t}findIndexes(e,t){const r=[];let a=!0,n=0;for(;a;)n=_lodash.default.findIndex(e,t,n+1),n>-1?r.push(n):a=!1;return r}getSliceArrayOfSpecificIndexes(e,...t){const r=[],a=_lodash.default.size(e);for(const n of t){if(!_lodash.default.isNumber(n))throw new _exceptioner.default(9999,`59941278 index should be number => ${n}, ${e}`);if(n>a-1)throw new _exceptioner.default(9999,`5994123 index=>${n} is not valid, exceed than array size=${a}, ${e}`);r.push(_lodash.default.nth(e,n))}return r}indexesOf(e,t){const r=[];let a=-1;for(;-1!==(a=e.indexOf(t,a+1));)r.push(a);return r}getIndexOfContext(e,t){return _lodash.default.findIndex(e,e=>_lodash.default.isEqual(e.trim(),t))}toOneLineString(e){return _lodash.default.join(_lodash.default.split(e,"\n"),"")}toSpaceLessString(e){return _lodash.default.split(e,"").map(e=>_lodash.default.trim(e)).join("")}toNewLineLessString(e){return _lodash.default.split(e,"\n").map(e=>_lodash.default.trim(e)).join("")}exist(e){return!_lodash.default.isNull(e)&&!_lodash.default.isUndefined(e)}isUndefinedNullEmpty(e){const t=null==e,r=!!(_lodash.default.isString(e)||_lodash.default.isArray(e)||_lodash.default.isObject(e))&&_lodash.default.isEmpty(e);return t||r}isAndConditionOfUndefinedNullEmpty(...e){for(const t of e)if(!this.isUndefinedNullEmpty(t))return!1;return!0}isOrConditionOfUndefinedNullEmpty(...e){for(const t of e)if(this.isUndefinedNullEmpty(t))return!0;return!1}getStringHandledByEachLine(e,t=(e,t,r)=>!0,r="\n"){const a=e.split(r);for(const e of a)t(e,_lodash.default.indexOf(a,e),a);return a.join(r)}getSegmentsOfEachLine(e){return e.split("\n")}getNormalizedStringEndWith(e,t){e=this.toCDB(e),t=this.toCDB(t);const r=_lodash.default.join(_lodash.default.dropRightWhile(e,e=>!_lodash.default.isEqual(e,t)),"");return _lodash.default.isEmpty(r)?e:r}getNormalizedStringNotStartWith(e,...t){e=this.toCDB(e);const r=_lodash.default.join(_lodash.default.dropWhile(e,e=>this.has(t,e)),"");return _lodash.default.isEmpty(r)?e:r}getNormalizedStringNotEndWith(e,...t){e=this.toCDB(e);const r=_lodash.default.join(_lodash.default.dropRightWhile(e,e=>this.has(t,e)),"");return _lodash.default.isEmpty(r)?e:r}getTodayTimeFormat(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YYYY-MM-DD")}getCustomFormatOfDatePresent(e,t="YY/MM"){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format(t)}getSimpleDateYYMMDDFormat(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YY/MM/DD")}getSimpleTimeYYMMDDHHmmFormat(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YY/MM/DD HH:mm")}getECPayCurrentTimeFormat(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YYYY/MM/DD HH:mm:ss")}getCurrentTimeFormatV2(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YYYY/MM/DD HH:mm:ss")}getCurrentTimeFormatYMDHM(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YYYY/MM/DD HH:mm")}getCurrentTimeFormatYMDHMS(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YYYY/MM/DD HH:mm:ss")}getCurrentTimeFormat(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YYYY-MM-DD-HH-mm-ss")}getCurrentMillionSecTimeFormat(e){return(0,_momentTimezone.default)(e||void 0).format("YYYY-MM-DD-HH-mm-ss-SSS")}isBetweenTimeStamp(e=this.getCurrentTimeStamp(),t,r){return(0,_momentTimezone.default)(e).isBetween(t,r)}isBeforeTimeStamp(e=this.getCurrentTimeStamp(),t){return(0,_momentTimezone.default)(e).isBefore(t)}isAfterTimeStamp(e=this.getCurrentTimeStamp(),t){return(0,_momentTimezone.default)(e).isAfter(t)}formatTimeByLocale(e,t="zh-TW",r="Asia/Taipei",a=!0){_momentTimezone.default.locale(t);const n=a?"YYYY/MM/DD HH:mm":"YYYY/MM/DD hh:mm A";return(0,_momentTimezone.default)(e).tz(r).format(n)}getTimeStampWithConditions(e={days:0,months:0,years:0,minutes:0,seconds:0,hours:0},t=this.getCurrentTimeStamp()){let r=(0,_momentTimezone.default)(t);for(const t in e){const a=e[t],n=t;a>0&&(r=r.add(a,n)),a<0&&(r=r.subtract(Math.abs(a),n))}return r.valueOf()}getTimeStampByStringFormat(e){return this.getTimeStampFromSpecificFormat(e,"YYYY/MM/DD HH:mm:ss").valueOf()}getTimeStampFromSpecificFormat(e,t="YYYY/MM/DD HH:mm:ss"){return(0,_momentTimezone.default)(e,t).valueOf()}getTimeStampFromECPayStringFormat(e){return this.getTimeStampFromSpecificFormat(e,"YYYY/MM/DD HH:mm:ss").valueOf()}getTimeFormatOfDurationToMillionSecond(e){return _momentTimezone.default.utc(e).format("HH小時mm分鐘ss秒SSS")}getTimeFormatOfDurationToSecond(e){return _momentTimezone.default.utc(e).format("HH小時mm分鐘ss秒")}getTimeFormatOfDurationToDay(e){return _momentTimezone.default.utc(e).format("DD天HH小時mm分鐘ss秒")}getChineseTimeFormat(e){return _momentTimezone.default.locale("zh-TW"),(0,_momentTimezone.default)(e).format("LLLL")}getMinuteFormatOfDuration(e){return _momentTimezone.default.duration(e).asMinutes()}getSecondFormatOfDuration(e){return _momentTimezone.default.duration(e).asSeconds()}getDayFormatOfDuration(e){return _momentTimezone.default.duration(e).asDays()}getDurationOfMillionSec(e){const t=this.getCurrentTimeStamp(),r=(0,_momentTimezone.default)(e).valueOf(),a=_lodash.default.sortBy([{ts:t},{ts:r}],e=>e.ts).map(e=>e.ts);let n=(0,_momentTimezone.default)(a.pop()),i=(0,_momentTimezone.default)(a.shift());return _momentTimezone.default.duration(n.diff(i)).asMilliseconds()}getCurrentTimeStamp(){return(0,_momentTimezone.default)().valueOf()}isStringContainInLines(e,t){for(let r of _lodash.default.split(e,"\n"))if(this.has(r,t))return!0;return!1}camel(...e){return _lodash.default.camelCase(e.join("_"))}upperCamel(...e){return _lodash.default.upperFirst(this.camel(...e))}array2Obj(e){const t={};for(const r of e)t[`${this.getObjectKey(r)}`]=this.getObjectValue(r);return t}arrayToObjWith(e,t){const r={};for(const a of e){const e=t(a),n=r[e];n&&_lodash.default.isArray(n)?n.push(a):r[e]=[a]}return r}isEmptyString(e){return _lodash.default.isEqual(_lodash.default.trim(e),"")}mergeObject(...e){return _lodash.default.merge(...e)}syncSetTimeout(e,t,r=()=>{}){!function a(n){n?r():setTimeout(function(){e(),a(!0)},t)}()}mergeArrayBy(e="id",...t){return Object.values(t.flat().reduce((t,r)=>(r[e]&&(t[r[e]]={...t[r[e]]||{},...r}),t),{}))}getRelativePath(e,t){return _lodash.default.dropWhile(e,(e,r)=>_lodash.default.isEqual(e,t[r])).join("")}dropItemsByIndex(e,t,r){_lodash.default.remove(e,(e,a,n)=>r>=a&&a>=t)}isEven(e){return e%2==0}isOdd(e){return 1===Math.abs(e%2)}enrichZhTw(){_momentTimezone.default.locale("zh-tw",{months:"一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"),monthsShort:"1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"),weekdays:"星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"),weekdaysShort:"周日_周一_周二_周三_周四_周五_周六".split("_"),weekdaysMin:"日_一_二_三_四_五_六".split("_"),longDateFormat:{LT:"Ah點mm分",LTS:"Ah點m分s秒",L:"YYYY-MM-DD",LL:"YYYY年MMMD日",LLL:"YYYY年MMMD日Ah點mm分",LLLL:"YYYY年MMMD日ddddAh點mm分",l:"YYYY-MM-DD",ll:"YYYY年MMMD日",lll:"YYYY年MMMD日Ah點mm分",llll:"YYYY年MMMD日ddddAh點mm分"},meridiemParse:/凌晨|早上|上午|中午|下午|晚上/,meridiemHour:function(e,t){let r=e;return 12===r&&(r=0),"凌晨"===t||"早上"===t||"上午"===t?r:"下午"===t||"晚上"===t?r+12:r>=11?r:r+12},meridiem:function(e,t,r){const a=100*e+t;return a<600?"凌晨":a<900?"早上":a<1130?"上午":a<1230?"中午":a<1800?"下午":"晚上"},calendar:{sameDay:function(){return 0===this.minutes()?"[今天]Ah[點整]":"[今天]LT"},nextDay:function(){return 0===this.minutes()?"[明天]Ah[點整]":"[明天]LT"},lastDay:function(){return 0===this.minutes()?"[昨天]Ah[點整]":"[昨天]LT"},nextWeek:function(){let e,t;return e=(0,_momentTimezone.default)().startOf("week"),t=this.diff(e,"days")>=7?"[下]":"[本]",0===this.minutes()?t+"dddA點整":t+"dddAh點mm"},lastWeek:function(){let e,t;return e=(0,_momentTimezone.default)().startOf("week"),t=this.unix()<e.unix()?"[上]":"[本]",0===this.minutes()?t+"dddAh點整":t+"dddAh點mm"},sameElse:"LL"},ordinalParse:/\d{1,2}(日|月|周)/,ordinal:function(e,t){switch(t){case"d":case"D":case"DDD":return e+"日";case"M":return e+"月";case"w":case"W":return e+"周";default:return e}},relativeTime:{future:"%s内",past:"%s前",s:"幾秒",m:"1 分鐘",mm:"%d 分鐘",h:"1 小時",hh:"%d 小時",d:"1 天",dd:"%d 天",M:"1 個月",MM:"%d 个月",y:"1 年",yy:"%d 年"},week:{dow:1,doy:4}})}getVisibleOrHidden(e){return{visibility:e?"visible":"hidden"}}getNumberOfPercentageToFloat(e){let t=e.replace("%","");return parseFloat(t)/100}getVisibleOrNone(e,t=!1){return{display:e?t?"flex":"inherit":"none"}}stringToInteger(e){switch(e=_lodash.default.toUpper(e)){case"A":return 0;case"B":return 1;case"C":return 2;case"D":return 3;case"E":return 4;case"F":return 5;case"G":return 6;case"H":return 7;case"I":return 8;case"J":return 9;case"K":return 10;case"L":return 11;case"M":return 12;case"N":return 13;default:return 101}}integerToString(e){switch(e){case 0:return"A";case 1:return"B";case 2:return"C";case 3:return"D";case 4:return"E";case 5:return"F";case 6:return"G";case 7:return"H";case 8:return"I";case 9:return"J";case 10:return"K";case 11:return"L";case 12:return"M";case 13:return"N";default:return"Z"}}toObjectMap(e,...t){const r=[];for(const a of e){const e={};for(const r of t){const t=r.func?r.func:e=>e;e[r.to]=this.isUndefinedNullEmpty(r.from)||!_lodash.default.isObject(a)?t(a):t(a[r.from])}r.push(e)}return r}exeAll(e,...t){if(_lodash.default.isArray(e))for(const r of e)for(const e of t)e(r);else{if(!_lodash.default.isObject(e))throw new _exceptioner.default(9999,"7841212 type can't be array or object");for(const r in e)for(const a of t)e[r]=a(e[r])}return e}getObjectWhile(e,t,r=e=>!0){const a={};for(const n in e)r(e,t,n)&&(a[n]=e[n]);return a}getIntersectionObject(e,t){return this.getObjectWhile(e,t,(e,t,r)=>void 0!==t[r])}getDifferenceObject(e,t){return this.getObjectWhile(e,t,(e,t,r)=>void 0===t[r])}isObjectContainAndEqual(e,t){let r=!0;for(const a in e)if(void 0===t[a]||t[a]!==e[a]){r=!1;break}return r}getStringOfPop(e,t){if(!_lodash.default.isString(e))throw new _exceptioner.default(9999,"445115,type should be string but ==> "+typeof e);const r=e.split(t);return r.pop(),r.join(t)}getStringOfShift(e,t){if(!_lodash.default.isString(e))throw new _exceptioner.default(9999,"445116,type should be string but ==> "+typeof e);const r=e.split(t);return r.shift(),r.join(t)}toObjectWithAttributeKey(e,t){const r={};for(const a of e){const e=a[t];if(this.isUndefinedNullEmpty(e))throw new _exceptioner.default(9999,`48157232 pk can't be empty => '${e}'`);r[e]=a}return r}getObjectOfArraySpecifyAttr(e,t){return this.toObjectWithAttributeKey(e,t)}getStateOfStringContainsSign(e,...t){for(const r of t)if(this.has(e,r))return{exists:!0,sign:r};return{exists:!1}}constraintOfParam(e,t,...r){let a=!1;const n=!!_lodash.default.isEmpty(r)||this.and(...r.map(e=>e.logic));switch(t){case"array":_lodash.default.isArray(e)&&n&&(a=!0);break;case"object":_lodash.default.isObject(e)&&n&&(a=!0);break;case"string":_lodash.default.isString(e)&&n&&(a=!0);break;case"number":_lodash.default.isNumber(e)&&n&&(a=!0);break;case"other":if(n)return!0}const i=_lodash.default.isEmpty(r)?"":`, ${r.map(e=>e.message).join(" | ")}`;if(!1===a)throw new _exceptioner.default(9999,`7474423 type should be ${t} but get '${typeof t}' ${i} `)}getSliceArrayWithMutate(e,t){return _lodash.default.remove(e,(e,r)=>r<t)}getArrayOfInteraction(e,t){return e.filter(e=>!t.includes(e))}getArrayOfMoveToSpecificIndex(e,t,r){if(!Array.isArray(e))throw new Error("First argument must be an array.");const a=e.length;if(t<0||t>=a||r<0||r>=a)return console.warn("Invalid 'from' or 'to' index for getArrayOfMoveToSpecificIndexOptimized."),[...e];if(t===r)return[...e];const n=[...e],[i]=n.splice(t,1);return n.splice(r,0,i),n}getArrayOfMoveItemToSpecificIndex(e,t,r){const a=_lodash.default.indexOf(e,t);return this.getArrayOfMoveToSpecificIndex(e,a,r)}getArrayOfMoveSpecificItemToAside(e,t,r=!0){const a=_lodash.default.indexOf(e,t);return this.getArrayOfMoveSpecificIndexToAside(e,a,r)}getArrayOfMoveSpecificIndexToAside(e,t,r=!0){const a=_lodash.default.size(e)-1;return this.getArrayOfMoveToSpecificIndex(e,t,r?a:0)}getECPayCheckMacValue(e,t="5294y06JbISpM5x9",r="v77hoKGq4kWxNNIS"){const a=_lodash.default.cloneDeep(e);delete a.CheckMacValue;const n=Object.keys(a).sort((e,t)=>e>t?1:-1);let i="";for(const e of n)i+=`${e}=${a[e]}&`;return i=`HashKey=${t}&${i}HashIV=${r}`,i=encodeURIComponent(i).toLowerCase(),i=i.replace(/%20/g,"+").replace(/%2d/g,"-").replace(/%5f/g,"_").replace(/%2e/g,".").replace(/%21/g,"!").replace(/%2a/g,"*").replace(/%28/g,"(").replace(/%29/g,")").replace(/%20/g,"+"),_lodash.default.toUpper(_cryptoJs.default.SHA256(i).toString(_cryptoJs.default.enc.Hex))}getStringOfHandledHtml(e,t=e=>{console.log(e)}){const r=(0,_nodeHtmlParser.parse)(e);return t(r),r.toString()}getSpecifyObjectBy(e,t){for(const r of e)if(t(r))return r}validatePayloadObjectValid(e,t=[],r=this.getRandomHash(10)){if(this.isUndefinedNullEmpty(e))throw new _exceptioner.default(9999,`${r} content(pay-load) is undefined || empty`);for(const a of t)if(_lodash.default.isString(a)){if(this.isUndefinedNullEmpty(e[a]))throw new _exceptioner.default(9999,`${r} ATTRIBUTE:'${a}' is not Exist`)}else if(_lodash.default.isObject(a)){const t=this.getObjectKey(a);if(!this.getObjectValue(a)(e[t]))throw new _exceptioner.default(9999,`${r} ATTRIBUTE:'${t}' is not valid of custom rule`)}return!0}getArrayOfSummarizeBy(e,t,r){const a={};for(const n of e){const e=n[t];void 0!==a[e]?a[e]=a[e]+n[r]:a[e]=n[r]}const n=[];for(const e in a){const i={};i[t]=e,i[r]=a[e],n.push(i)}return n}getHeadStringSplitBy(e,t=this.getSeparatorOfUnique()){return _lodash.default.split(e,t).shift()}getTailStringSplitBy(e,t=this.getSeparatorOfUnique()){return _lodash.default.split(e,t).pop()}getSlicesByIndexes(e=[],t=[]){const r=[];return _lodash.default.each(t,(a,n,i)=>{if(_lodash.default.isEqual(n,t.length-1))return!1;const o=_lodash.default.slice(e,a,t[n+1]);r.push(o)}),r}findIndexes(e,t){const r=[];let a=!0,n=0;for(;a;)n=_lodash.default.findIndex(e,t,n+1),n>-1?r.push(n):a=!1;return r}isOverSpecificAge(e,t=18){return(0,_momentTimezone.default)().diff((0,_momentTimezone.default)(e,"YYYY-MM-DD"),"years")>=t}isValidEmail(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}isValidTaiwaneseID(e){if(!/^[A-Z][1-2]\d{8}$/.test(e))return!1;const t=[1,9,8,7,6,5,4,3,2,1];let r=10*(e.charCodeAt(0)-65)+parseInt(e.slice(1));for(let a=0;a<t.length;a++)r+=parseInt(e.charAt(a+1))*t[a];return r%10==0}validatePersonalInfoInput(e,t,r,a,n,i=12){return e.length<2?{valid:!1,message:"姓名至少要兩個字"}:/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)?/^[A-Z][1-2]\d{8}$/.test(r)?/^09\d{8}$/.test(a)?this.isUndefinedNullEmpty(n)?{valid:!1,message:"出生日期格式不正確"}:(0,_momentTimezone.default)().diff(n,"years")<i?{valid:!1,message:`年齡不得小於 ${i} 歲`}:{valid:!0,message:"格式檢查通過"}:{valid:!1,message:"手機號碼格式不正確"}:{valid:!1,message:"身分證號碼格式不正確"}:{valid:!1,message:"電子郵件格式不正確"}}getStringOfFormatTimestampRange(e,t){const r=(0,_momentTimezone.default)(e),a=(0,_momentTimezone.default)(t),n=e=>e.format("YY/MM/DD");return r.year()===a.year()?`${n(r)} - ${a.format("MM/DD")}`:`${n(r)} - ${n(a)}`}getStringOfCalculateClassTime(e,t,r){const a=(0,_momentTimezone.default)(e),n=(0,_momentTimezone.default)(t).diff(a,"days")+1,i=Math.ceil(n/7)*r,o=Math.floor(i/60),s=i%60;return 0===s?`${o}小時`:`${o}小時${s}分鐘`}getNumberOfPeriodMinute(e,t){const r=(0,_momentTimezone.default)(e).format("HH:mm"),a=(0,_momentTimezone.default)(t).format("HH:mm"),n=(0,_momentTimezone.default)(r,"HH:mm"),i=(0,_momentTimezone.default)(a,"HH:mm");return _momentTimezone.default.duration(i.diff(n)).asMinutes()}getStringOfWeekTime(e,t,r){if(e<1||e>7)throw new Error("day 必須在 1 到 7 之間");const a=(0,_momentTimezone.default)(t).format("HH:mm"),n=(0,_momentTimezone.default)(r).format("HH:mm");return`${{1:"週一",2:"週二",3:"週三",4:"週四",5:"週五",6:"週六",7:"週日"}[e]} ${a}-${n}`}extractNumber(e){if(this.isUndefinedNullEmpty(e))return-1;const t=e.match(/\d+/);return t?Number(t[0]):-1}async fetchElementAttribute(e,t="innerText",r=""){return await e.evaluate(e=>e[t])}async fetchElementAttributes(e,t,r="",...a){const n=await e.$(t);if(!this.isUndefinedNullEmpty(n))try{return await n.evaluate((e,t)=>1===t.length?e[t.shift()]:{...t.map(t=>e[t])},a)}catch(e){return this.appendError(`1581532 ${t} fetch ${JSON.stringify(a)} fail, element is not found`),r}return r}async writeElementAttributes(e,t,...r){const a=await e.$(t);this.isUndefinedNullEmpty(a)?this.appendError(`1231232 ${t} fetch ${JSON.stringify(r)} fail, element is not found`):await a.evaluate((e,t)=>{t.map(t=>{const r=Object.entries(t),a=r[0][0],n=r[0][1];e[a]=n})},r)}getSliceArrayOfUnique(e){if(!Array.isArray(e)||0===e.length)return[];const t=e[0];if(_lodash.default.isObject(t)&&key){const t=new Map(e.map(e=>[e[key],e]));return Array.from(t.values())}return _lodash.default.isObject(t)?(console.warn("getSliceArrayOfUniqueOptimized: No key provided for object array, using potentially slow deep comparison."),_lodash.default.uniqWith(e,_lodash.default.isEqual)):Array.from(new Set(e))}getUniqueValuesBy(e,t="valueOfType"){return _lodash.default.uniq(e.map(e=>e[t]))}generateCombinations(...e){const t=e.map(e=>e.key),r=(_lodash.default.keyBy(e,"key"),e.map(e=>e.options.map(t=>({key:e.key,value:t.value,label:t.label})))),a=_lodash.default.reduce(r,(e,t)=>_lodash.default.flatMap(e,e=>t.map(t=>[...e,t])),[[]]).map(e=>{const t={},r=[],a=[];for(const{key:n,value:i,label:o}of e)t[n]=i,r.push(`${n}_${i}`),a.push(`${o}`);return{trait:t,id:r.join("_"),content:a.join("|")}});return _lodash.default.sortBy(a,e=>t.map(t=>e.trait[t]))}extractStaticSegments(e,t=[":"]){return e.trim().replace(/^\.?\/*|\/*$/g,"").split("/").filter(e=>e&&!t.some(t=>e.startsWith(t)))}mutateRemoveKeys(e,t){_lodash.default.forEach(e,(e,r)=>{const a=Object.fromEntries(Object.entries(e).filter(([e])=>!t.includes(e)));Object.keys(e).forEach(t=>delete e[t]),Object.assign(e,a)})}removeKeysFromArrayObjects(e,t){return _lodash.default.map(e,e=>Object.fromEntries(Object.entries(e).filter(([e])=>!t.includes(e))))}formatTextWithEllipsis(e,t){if(_lodash.default.size(e)<=t)return e;if(t<=6)return"";const r=t-6,a=Math.floor(r/2),n=r-a;return`${_lodash.default.truncate(e,{length:a,omission:""})}......${_lodash.default.takeRight(e,n).join("")}`}getObjectBy(e,t=e=>!0!==e.checked){return _lodash.default.fromPairs(_lodash.default.toPairs(e).filter(([e,r])=>t(r)))}mutateBy(e,t=e=>e){const r=_lodash.default.sortBy(e,t);e.splice(0,e.length,...r)}findUniqueStrings(...e){const t=_lodash.default.flatten(e),r=_lodash.default.countBy(t);return _lodash.default.chain(r).pickBy(e=>1===e).keys().compact().value()}getObjectOfSpecifyKey(e,t){const r={};return r[t]=e,r}findUniqueNonReferenceStrings(...e){if(0===e.length)return[];const[t,...r]=e,a=_lodash.default.flatten(r),n=_lodash.default.countBy(a);return _lodash.default.chain(n).pickBy((e,r)=>1===e&&!t.includes(r)).keys().compact().value()}getArrayOfFillMissingValues(e){const t=()=>_lodash.default.times(8,()=>_lodash.default.sample("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")).join(""),r=new Set(e.map(e=>e.value).filter(Boolean));return e.map(e=>{if(_lodash.default.isEmpty(e.value)){let a;do{a=t()}while(r.has(a));return r.add(a),{...e,value:a}}return e})}isFirestoreAutoId(e){return _lodash.default.isString(e)&&20===e.length&&/^[A-Za-z0-9]{20}$/.test(e)}getAutoIdOfFirestore(){return this.getRandomHashV2(20)}getStringOfConvertTimeRange(e){const[t,r]=e.split("|"),a=t.split("(")[0],[n,i]=r.split("-"),o=e=>(0,_momentTimezone.default)(`${a} ${e}`,"YYYY/MM/DD HH:mm").format("YYYYMMDDHHmm");return`${o(n)}-${o(i)}`}getTSOfSpecificDate(e,{end:t=!1}={}){return Number((0,_lodash.default)(e).thru(e=>(0,_momentTimezone.default)(e.split("(")[0],"YYYY/MM/DD")).thru(e=>t?e.endOf("day"):e.startOf("day")).value().format("YYYYMMDDHHmmss"))}isHttpsURL(e){if(!_lodash.default.isString(e))return!1;try{const t=decodeURIComponent(e.trim());return"https:"===new URL(t).protocol}catch(e){return!1}}generateUniqueCodeMap(e,t=3){if(t<2)throw new Error("代碼長度最少必須為 2。");const r=new Set,a=new Set;return _lodash.default.transform(e,(e,n)=>{if(a.has(n))throw new Error(`23125453 Duplicate key detected: "${n}"`);a.add(n),e[n]=(()=>{const e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",a=e+"0123456789";let n;do{n=e[Math.floor(52*Math.random())];for(let e=1;e<t;e++)n+=a[Math.floor(62*Math.random())]}while(r.has(n));return r.add(n),n})()},{})}getPriceOfPercentageBehavior(e,t,r=!1){const a=this.toPercentageDecimal(t);return this.getNumberOfMultiplyCeil(e,r?1-a:1+a)}getFeeOfDiscount(e,t){return Math.round(_lodash.default.multiply(e,this.toPercentageDecimal(t)))}mergeArrayByKey(e){if(!Array.isArray(e))return e;const t={};for(const r of e)if(_lodash.default.isPlainObject(r))for(const[e,a]of Object.entries(r))t[e]?_lodash.default.merge(t[e],a):t[e]=_lodash.default.cloneDeep(a);return e.length=0,Object.entries(t).forEach(([t,r])=>{e.push({[t]:r})}),e}getObjectOfStartEndDateTime(e){if(!e||"string"!=typeof e)return{startDate:"",startTime:"",endDate:"",endTime:""};const t=e.replace(/|/g," ").replace(/-/g,"-").replace(/\s+/g," ").trim(),r=/(\d{4}\/\d{1,2}\/\d{1,2})(?:\s*\([^)]*\))?\s*(\d{2}:\d{2})\s*-\s*(\d{4}\/\d{1,2}\/\d{1,2})(?:\s*\([^)]*\))?\s*(\d{2}:\d{2})/,a=/(\d{4}\/\d{1,2}\/\d{1,2})(?:\s*\([^)]*\))?\s*(\d{2}:\d{2})\s*-\s*(\d{2}:\d{2})/;let n,i,o,s;if(r.test(t))[,n,i,o,s]=t.match(r);else{if(!a.test(t))return{startDate:"",startTime:"",endDate:"",endTime:""};[,n,i,s]=t.match(a),o=n}const l=new Date(`${n} ${i}`);if(new Date(`${o} ${s}`)<l)throw new Error(`End time cannot be earlier than start time: ${e}`);return{startDate:n,startTime:i,endDate:o,endTime:s}}getFilteredHeraPeriods(e,t){return _lodash.default.chain(e).filter(e=>e.idOfBooze!==t).uniqBy(e=>`${e.idOfBooze}_${e.idOfVariant}`).value()}checkPeriodConflict(e,t,r=1){const[a,n]=e.content.split("|"),i=(0,_momentTimezone.default)(a.split(" ")[0],"YYYY/MM/DD"),[o,s]=n.split("-"),l=(0,_momentTimezone.default)(`${i.format("YYYY/MM/DD")} ${o}`,"YYYY/MM/DD HH:mm"),d=(0,_momentTimezone.default)(`${i.format("YYYY/MM/DD")} ${s}`,"YYYY/MM/DD HH:mm"),u=_lodash.default.filter(t,e=>{const[t,r]=e.period.split("-"),a=(0,_momentTimezone.default)(t,"YYYYMMDDHHmm"),n=(0,_momentTimezone.default)(r,"YYYYMMDDHHmm");return l.isBefore(n)&&d.isAfter(a)});return{conflict:u.length>=r,items:u}}}var _default=exports.default=Utiller;
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),_lodash=_interopRequireDefault(require("lodash")),_cryptoJs=_interopRequireDefault(require("crypto-js")),_configerer=require("configerer"),_exceptioner=_interopRequireDefault(require("../exceptioner")),_momentTimezone=_interopRequireDefault(require("moment-timezone")),_uuid=require("uuid"),_nodeHtmlParser=require("node-html-parser");String.format=function(){let e=[];for(let t=0,r=arguments.length;t<r;t++)e.push(arguments[t]);let t=e[0];return e.shift(),t.replace(/\{(\d+)\}/g,function(t,r){return e[r]})};class Utiller{removeAttributeBy(e,t=e=>_lodash.default.isUndefined(e)){for(const r in e)t(e[r])&&delete e[r]}getUrlPath(...e){return e.filter(e=>null!=e&&""!==e).map(e=>String(e)).map(e=>e.replace(/^\/+|\/+$/g,"")).filter(e=>""!==e).join("/").replace(/^(https?):\/(?!\/)/,"$1://")}getNumberOfNormalize(e,t=0){if(_lodash.default.isNumber(e))return e;try{const r=_lodash.default.toNumber(e);return _lodash.default.isNumber(r)&&!isNaN(r)?r:t}catch(e){Util.appendError(`448561684561 ${e.message}`)}return t}getStringOfNormalize(e,t="",r=!1){if(_lodash.default.isString(e))return r?_lodash.default.trim(e):e;try{const a=_lodash.default.toString(e);return this.isOrEquals(a,"","undefined")?t:r?_lodash.default.trim(a):a}catch(e){Util.appendError(`448616845453 ${e.message}`)}return t}isValidVersionOfString(e){if(this.isUndefinedNullEmpty(e))return!1;const t=e.split(".");for(const e of t){const t=_lodash.default.toNumber(e);if(!_lodash.default.isNumber(t)||isNaN(t))return!1}return!0}getSeparatorOfUnique(){return"།།"}getStringOfVersionIncrement(e,t=1){const r=e.split(".").map(e=>_lodash.default.toNumber(e)),a=r.length-1;return r[a]=r[a]+t,r.join(".")}setLocaleOfMoment(e="en"){_momentTimezone.default.locale(e)}getUuidOfV4(){return(0,_uuid.v4)()}constructor(){(0,_defineProperty2.default)(this,"mapOfIdNTimeoutId",{}),(0,_defineProperty2.default)(this,"getEnvironment",()=>this.env),(0,_defineProperty2.default)(this,"isProductionEnvironment",()=>_lodash.default.isEqual(this.getEnvironment(),"prod")),(0,_defineProperty2.default)(this,"asyncUnitTaskFunction",(e=2e3,t="預設的param",r)=>async(a=this.getRandomHash(10))=>{const n=this.getRandomValue(e,1.2*e);try{const e=n;if(this.appendInfo(`before executed ===> i'm symbol of ${e}, ready to be executed, inner param = ${t}`),await this.syncDelay(n),_lodash.default.isFunction(r)&&r(a))throw Error("force to made error happen");return this.appendInfo(`after executed ===> i'm symbol of ${e}, the task cost ${n} million-seconds ${a?`i hav params ===> ${a}`:""}`),{randomValue:n,symbol:e,param:a}}catch(e){this.appendError(new Error(`asyncUnitTask() catch error ${e.message}`))}finally{this.appendInfo("wow.... finally got you")}}),(0,_defineProperty2.default)(this,"test",e=>async()=>(await Util.syncDelay(3e3),console.log("經過了三秒"),await Util.syncDelay(4e3),console.log("經過了四秒"),await Util.syncDelay(5e3),console.log("經過了五秒"),await Util.syncDelay(6e3),console.log("經過了六秒"),`3423809432804 ${e}`)),(0,_defineProperty2.default)(this,"findLowestValue",(e,t="price")=>{const r=_lodash.default.minBy(e,t)[t];return Math.floor(r)}),(0,_defineProperty2.default)(this,"findHighestValue",(e,t="price")=>{const r=_lodash.default.maxBy(e,t)[t];return Math.floor(r)}),(0,_defineProperty2.default)(this,"getStringOfValueRange",(e,t="price",r="$")=>{const a=_lodash.default.minBy(e,t)[t],n=_lodash.default.maxBy(e,t)[t];return n===a?`$${a}`:`${r}${a} - ${r}${n}`}),(0,_defineProperty2.default)(this,"getCallersName",()=>{let e;try{throw new Error}catch(t){let r,a=/(\w+)@|at (\w+) \(/g,n=t.stack;a.exec(n),r=a.exec(n),_lodash.default.isNull(r)||(e=r[1]||r[2])}return _lodash.default.startsWith("asyncGeneratorStep",e)&&(e=""),e}),(0,_defineProperty2.default)(this,"getRandomValue",(e,t)=>(e=Math.ceil(e),t=Math.floor(t),Math.floor(Math.random()*(t-e+1))+e)),(0,_defineProperty2.default)(this,"insertToArray",(e,t,...r)=>{if(!Array.isArray(e))throw new Error("First argument must be an array.");const a=Math.max(0,Math.min(t+1,e.length));e.splice(a,0,...r)}),(0,_defineProperty2.default)(this,"getStringOfYearADConvertToMinguoYear",(e,t=!1)=>{const r=e-1911;return r>0?`${t?"民國":""}${r}${t?"年":""}`:`${t?"民國":""}前${Math.abs(r)}${t?"年":""}`}),(0,_defineProperty2.default)(this,"convertDateToTimestamp",e=>(0,_momentTimezone.default)(e).valueOf()),(0,_defineProperty2.default)(this,"measureExecutionTime",async(e,...t)=>{const r=Date.now();await e(...t);const a=Date.now()-r,n=_momentTimezone.default.duration(a,"milliseconds"),i=Math.floor(n.asHours()),o=n.minutes(),s=n.seconds(),l=n.milliseconds(),u=(a/1e3).toFixed(3);return{second:u,zh_TW:`${i}小時 ${o}分 ${s}.${l.toString().padStart(3,"0")}秒 (合計 ${u} 秒)`}}),(0,_defineProperty2.default)(this,"formatPriceWithCurrency",(e,t)=>{if("number"!=typeof e||"string"!=typeof t)throw new TypeError("Invalid input: number must be a number and locale must be a string.");return new Intl.NumberFormat(t,{style:"currency",currency:new Intl.Locale(t).maximize().currency||"USD",minimumFractionDigits:0}).format(e)}),(0,_defineProperty2.default)(this,"formatPrice",(e,t)=>{if("number"!=typeof e)throw new TypeError("Invalid input: number must be a number.");return t?new Intl.NumberFormat(t,{style:"currency",currency:new Intl.Locale(t).maximize().currency||"USD",minimumFractionDigits:0}).format(e):e.toLocaleString("en-US")}),(0,_defineProperty2.default)(this,"generateUniversalKeywords",(e,t=50,r=4)=>{if(!e||"string"!=typeof e)return[];if(void 0===_lodash.default)return console.error("Lodash is not available. Please ensure it is imported."),[];let a=e.trim(),n=[];r=Math.max(2,r),a.length>t&&(console.warn(`警告:輸入字串長度為 ${a.length},已根據 maxLength: ${t} 截斷。`),a=a.substring(0,t)),(a.match(/[a-zA-Z]+/g)||[]).forEach(e=>{if(e.length>=2){n.push(e.toUpperCase()),n.push(e.toLowerCase());const t=e.charAt(0).toUpperCase()+e.slice(1).toLowerCase();n.push(t)}});const i=(a.match(/\b[0-9]+[a-zA-Z]{1,4}\b|\b[0-9]{1,3}(w|ml|g|oz|k)\b|[\u4e00-\u9fa5a-zA-Z0-9]{1,4}(色|號)[\u4e00-\u9fa5a-zA-Z0-9]{0,2}/gi)||[]).filter(e=>e.length>=2).map(e=>e.toLowerCase());n.push(...i);let o=a.toLowerCase();o=o.replace(/[0-9]+([\u4e00-\u9fa5a-z]{1,4}|[\/\-\~\\])/g," ").replace(/\b[a-z]{1,4}\b/g," ").replace(/\b[0-9]{1,3}\b/g," "),o=o.replace(/[!@#$%^&*()_+={}\[\]:;"'<>,.?\/\\|`~]/g," ").replace(/系列|一組|單色|多款|套組|全套|專用|迷你|頂級|高品質|超閃|奢華|最新|款式|新款|超亮|的|與|和|閃|美甲/g," ").replace(/\s+/g,"").trim();for(let e=2;e<=r;e++)for(let t=0;t<=o.length-e;t++){const r=o.substring(t,t+e);n.push(r)}return _lodash.default.chain(n).filter(e=>e.length>=2).filter(e=>e.length>2||!/^[\u4e00-\u9fa5a-z0-9]$/.test(e)).uniq().sortBy().value()}),(0,_defineProperty2.default)(this,"mutateIndexOfArrayItem",(e,t,r=0)=>{if(!Array.isArray(e)||!_lodash.default.isObject(t))return e;const a=_lodash.default.findIndex(e,e=>_lodash.default.isEqual(e,t));if(-1===a)return e;e.splice(a,1);const n=_lodash.default.clamp(r,0,e.length);return e.splice(n,0,t),e}),(0,_defineProperty2.default)(this,"getArrayOfModifyObject2Index",(e,t,r=0)=>{if(!Array.isArray(e)||!_lodash.default.isObject(t))return e;const a=_lodash.default.cloneDeep(e),n=_lodash.default.findIndex(a,e=>_lodash.default.isEqual(e,t));if(-1===n)return e;a.splice(n,1);const i=_lodash.default.clamp(r,0,a.length);return a.splice(i,0,t),a}),(0,_defineProperty2.default)(this,"generateLabelValuePairsWithOrigin",(e=[{label:"aa",value:1203},{label:"cc",value:1204},{label:"gg",value:2}],t=["aa","bb"])=>{const r=new Set(e.map(e=>e.value));return _lodash.default.chain(t).uniq().map(t=>{const a=_lodash.default.find(e,{label:t});if(a)return{label:t,value:a.value};let n;do{n=_lodash.default.random(2,999999999)}while(r.has(n));return r.add(n),{label:t,value:n}}).value()}),(0,_defineProperty2.default)(this,"getItemsOfMarkMatching",(e=[],t=[],r="value",a="belong")=>{const n=new Set(t);return _lodash.default.map(e,e=>({...e,[a]:n.has(e[r])}))}),(0,_defineProperty2.default)(this,"generateVariants",(e,t="|",r="-")=>{const a=e.filter(e=>e.length>0);return 0===a.length?[]:1===a.length?a[0].map(e=>({label:e.label,value:e.value})):_lodash.default.reduce(a,(e,t)=>_lodash.default.flatMap(e,e=>t.map(t=>[...e,t])),[[]]).map(e=>({label:e.map(e=>e.label).join(t),value:e.map(e=>e.value).join(r)}))}),(0,_defineProperty2.default)(this,"renameKeysInArray",(e,...t)=>{const r=Object.fromEntries(t);return e.map(e=>_lodash.default.mapKeys(e,(e,t)=>r[t]||t))}),(0,_defineProperty2.default)(this,"getArrayOfMergeBySpecificId",(e,t,r="id")=>{if(!Array.isArray(t))return e;const a=_lodash.default.keyBy(t,e=>_lodash.default.get(e,r));return e.map(e=>{const t=_lodash.default.get(e,r),n=a[t];return n?_lodash.default.merge({},e,n):e})}),(0,_defineProperty2.default)(this,"toPercentageDecimal",e=>{if(_lodash.default.isNil(e))return 1;_lodash.default.isString(e)&&(e=e.replace(/%/g,"").trim());const t=_lodash.default.toNumber(e);return _lodash.default.isFinite(t)?_lodash.default.round(t/100,10):1}),(0,_defineProperty2.default)(this,"getNumberOfMultiplyCeil",(e,t,r=0)=>{const a=Math.pow(10,r);return Math.ceil(e*t*a)/a}),(0,_defineProperty2.default)(this,"generateGoogleCalendarLink",({title:e,startDate:t,startTime:r,endDate:a,endTime:n,location:i,details:o})=>{const s=(0,_momentTimezone.default)(`${t} ${r}`,"YYYY/MM/DD HH:mm").format("YYYYMMDDTHHmmss"),l=(0,_momentTimezone.default)(`${a} ${n}`,"YYYY/MM/DD HH:mm").format("YYYYMMDDTHHmmss"),u=new URLSearchParams;return e&&u.append("text",e),s&&l&&u.append("dates",`${s}/${l}`),o&&u.append("details",o),i&&u.append("location",i),u.append("ctz","Asia/Taipei"),u.append("trp","true"),`https://calendar.google.com/calendar/r/eventedit?${u.toString()}`}),(0,_defineProperty2.default)(this,"generateTimeTreeLink",({title:e,startDate:t,startTime:r,endDate:a,endTime:n,location:i,memo:o})=>{const s=new URLSearchParams;return e&&s.append("title",e),t&&s.append("start_date",t.replace(/\//g,"-")),r&&s.append("start_time",r),a&&s.append("end_date",a.replace(/\//g,"-")),n&&s.append("end_time",n),i&&s.append("location",i),o&&s.append("memo",o),`https://timetreeapp.com/plans/new?${s.toString()}`}),(0,_defineProperty2.default)(this,"generateIcsContent",({title:e,startDate:t,startTime:r,endDate:a,endTime:n,location:i,details:o})=>{const s=_momentTimezone.default.tz(`${t} ${r}`,"YYYY/MM/DD HH:mm","Asia/Taipei").format("YYYYMMDDTHHmmss"),l=_momentTimezone.default.tz(`${a} ${n}`,"YYYY/MM/DD HH:mm","Asia/Taipei").format("YYYYMMDDTHHmmss"),u=(0,_momentTimezone.default)().utc().format("YYYYMMDDTHHmmss")+"Z",d=e=>e.replace(/\\/g,"\\\\").replace(/,/g,"\\,").replace(/;/g,"\\;").replace(/\n/g,"\\n"),f=["BEGIN:VCALENDAR","VERSION:2.0","PRODID:-//Gemini AI//NONSGML v1.0//EN","BEGIN:VEVENT","UID:"+(Date.now().toString(36)+Math.random().toString(36).substring(2,5)+"@gemini-app.com"),`DTSTAMP:${u}`];return s&&f.push(`DTSTART;TZID=Asia/Taipei:${s}`),l&&f.push(`DTEND;TZID=Asia/Taipei:${l}`),e&&f.push(`SUMMARY:${d(e)}`),i&&f.push(`LOCATION:${d(i)}`),o&&f.push(`DESCRIPTION:${d(o)}`),f.push("END:VEVENT","END:VCALENDAR"),f.join("\r\n")}),(0,_defineProperty2.default)(this,"generateAllCalendarLinks",e=>{const t=this.generateGoogleCalendarLink(e),r={...e,memo:e.details},a=this.generateTimeTreeLink(r),n=this.generateIcsContent(e);return{google:t,timeTree:a,ics:`data:text/calendar;charset=utf8,${encodeURIComponent(n)}`}}),(0,_defineProperty2.default)(this,"getArrayOfMappingRef",(e,t)=>_lodash.default.map(e,e=>{const r=_lodash.default.find(t,{value:e.value});return r?_lodash.default.merge({},e,r):e})),(0,_defineProperty2.default)(this,"areAllValuesTheSameOnKeys",(e,...t)=>{if(!e||e.length<=1||0===t.length)return!0;for(const r of t){const t=e[0]?.[r];if(!_lodash.default.every(e,e=>e[r]===t))return!1}return!0}),(0,_defineProperty2.default)(this,"execute4Tasks",async(e=[],t)=>{if(!t||"function"!=typeof t)throw new Error("Task function is required and must be a function.");if("AsyncFunction"!==t.constructor.name)throw new Error("Task function must be an asynchronous function (async function) to ensure proper Promise handling.");return 0===e.length?Promise.resolve([]):await Promise.all(e.map(async(r,a)=>t(r,a,e)))}),this.init(),this.env="dev"}performActionWithoutTimingIssue(e=()=>!0,t=10){this.syncDelay(t).then(()=>e())}executeTimeoutTask(e,t=1e3,r=this.getRandomHash(),...a){const n=this,i=this.mapOfIdNTimeoutId[r];i&&clearTimeout(i);const o=setTimeout(async(...t)=>{await e(),delete n.mapOfIdNTimeoutId[r]},t,...a);n.mapOfIdNTimeoutId[r]=o}printLogMessage(e,t=!1,...r){this.isProductionEnvironment()||(t?this.appendError(e,...r):this.appendInfo(e,...r))}init(){}setEnvironment(e){this.env=e}appendInfo(...e){this.isProductionEnvironment()||console.log(...e)}appendError(...e){this.isProductionEnvironment()||console.error(...e)}async syncDelay(e=2e3){return new Promise(t=>{setTimeout(()=>{t(e)},e)})}startWithRegex(e="",t="."){return new RegExp(`^${t}`,"i").test(e)}accumulate(e,t){let r=e;for(const e of t)void 0!==e&&_lodash.default.isFunction(e)&&(r=e(r));return r}isOrEquals(e,...t){for(const r of t)if(_lodash.default.isEqual(e,r))return!0;return!1}isAndEquals(...e){for(const t of e)if(!t())return!1;return!0}getStringOfHeadMatch(e,t,r="g"){const a=e.match(new RegExp(t,r));return this.isUndefinedNullEmpty(a)?void 0:a[0]}or(...e){for(const t of e)if(_lodash.default.isBoolean(t)&&t)return!0;return!1}and(...e){for(const t of e)if(!t)return!1;return!0}nth(e,t=-1){return _lodash.default.nth(e,t%_lodash.default.size(e))}getExistOne(...e){for(const t of e)if(t)return t}getStringOfDropHeadSign(e,t){return _lodash.default.dropWhile(Array.from(e),e=>_lodash.default.isEqual(e,t)).join("")}isAndWith(e,t,...r){for(const a of r)if(!t(e,a))return!1;return!0}async syncDelayRandom(e=3e3,t=5e3){const r=this.getRandomValue(e,t);return await this.syncDelay(r),r}has(e,t,r=!1){return _lodash.default.isArray(e)?r?_lodash.default.findIndex(e,e=>_lodash.default.isEqual(t,e))>-1:_lodash.default.indexOf(e,t)>-1:_lodash.default.isObject(t)?e[t]:!!_lodash.default.isString(e)&&e.indexOf(t)>-1}containsBy(e,t){return _lodash.default.findIndex(e,e=>_lodash.default.isEqual(e,t))>=0}getStringOfInsideParentheses(e,t="."){return this.getStringOfRule(e,t,"(",")")}getStringOfInsideBrackets(e,t="."){return this.getStringOfRule(e,t,"[","]")}getStringOfInsideBraces(e,t="."){return this.getStringOfRule(e,t,"{","}")}getStringOfRule(e,t=".",r="{",a="}"){return this.getStringOfHeadMatch(e,`(?<=\\${r})${t}+?(?=\\${a})`)}getRandomHash(e=20){const t=_cryptoJs.default.lib.WordArray.random(e);return _cryptoJs.default.enc.Base64.stringify(t).substring(0,e)}getRandomHashV2(e){let t="";for(let r=0;r<e;r++){const e=Math.floor(62*Math.random());t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(e)}return t}getEncryptString(e,t=_configerer.configerer.ENCRYPT_KEY,r=!1){if(t.length>22)throw new _exceptioner.default(8010,_lodash.default.size(t));const a=_cryptoJs.default.enc.Base64.parse("thisIsIVWeNeedToGenerateTheSameValue"),n=r?_cryptoJs.default.enc.Base64.parse(`${t}${_lodash.default.range(0,22-t.length).join("")}`):t;return _cryptoJs.default.AES.encrypt(e,n,{iv:a}).toString()}getEncryptStringV2(e,t=_configerer.configerer.ENCRYPT_KEY,r=!1){if(t.length>22)throw new _exceptioner.default(8010,_lodash.default.size(t));const a=_cryptoJs.default.enc.Base64.parse("thisIsIVWeNeedToGenerateTheSameValue"),n=r?_cryptoJs.default.enc.Base64.parse(`${t}${_lodash.default.range(0,22-t.length).join("")}`):t;return _cryptoJs.default.AES.encrypt(JSON.stringify({content:e}),n,{iv:a}).toString()}getDecryptString(e,t=_configerer.configerer.ENCRYPT_KEY){if(t.length>22)throw new _exceptioner.default(8010,_lodash.default.size(t));const r=_cryptoJs.default.enc.Base64.parse("thisIsIVWeNeedToGenerateTheSameValue");try{const a=_cryptoJs.default.AES.decrypt(e,t,{iv:r}).toString(_cryptoJs.default.enc.Utf8);if(!_lodash.default.isEmpty(a.trim()))return a}catch(e){}return _cryptoJs.default.AES.decrypt(e,_cryptoJs.default.enc.Base64.parse(`${t}${_lodash.default.range(0,22-t.length).join("")}`),{iv:r}).toString(_cryptoJs.default.enc.Utf8)}getDecryptStringV2(e,t=_configerer.configerer.ENCRYPT_KEY){if(t.length>22)throw new _exceptioner.default(8010,_lodash.default.size(t));const r=_cryptoJs.default.enc.Base64.parse("thisIsIVWeNeedToGenerateTheSameValue");try{const a=_cryptoJs.default.AES.decrypt(e,t,{iv:r}).toString(_cryptoJs.default.enc.Utf8);if(!_lodash.default.isEmpty(a.trim()))return JSON.parse(a).content}catch(e){}const a=_cryptoJs.default.AES.decrypt(e,_cryptoJs.default.enc.Base64.parse(`${t}${_lodash.default.range(0,22-t.length).join("")}`),{iv:r}).toString(_cryptoJs.default.enc.Utf8);return JSON.parse(a).content}getFirebaseFormattedString(e){return _lodash.default.replace(e,/[\.\#\$\[\]]/g,"-").trim()}formalizeNamesToArray(e){let t=e;for(t=t.split(_configerer.configerer.SEPARATE_TONE_SINGER)[0].trim(),t=_lodash.default.replace(t,/[,\/#!$%\^&\*;:{}=_`、~()()]/g,"_").trim(),t=this.getFirebaseFormattedString(t),t=_lodash.default.replace(t,/\_\_+/g,"_").trim();_lodash.default.endsWith(t,"_");)t=t.slice(0,-1).trim();const r=t.split("_");return _lodash.default.map(r,e=>_lodash.default.trim(e))}getShuffledArrayWithLimitCountHighPerformance(e,t){let r=new Array(t),a=e.length,n=new Array(a);for(t>a&&(t=a);t--;){let i=Math.floor(Math.random()*a);r[t]=e[i in n?n[i]:i],n[i]=--a in n?n[a]:a}return r}getFileNameFromPath(e,t=!1){const r=e.split("/").pop();return t?r:r.split(".").shift()}getFileNameExtensionFromPath(e){return e.split("/").pop()}getPathOfReplaceLastDir(e,t){const r=e.split("/");return r.pop(),r.push(t),r.join("/")}getExtensionFromPath(e){const t=e.split("/").pop().split(".");return _lodash.default.size(t)>1?t.pop():""}getFolderPathOfSpecificPath(e){const t=e.split("/");return t.pop(),t.join("/")}getFolderNameOfFilePath(e){if(this.isValidFilePath(e)){const t=e.split("/");return _lodash.default.nth(t,-2)}throw new _exceptioner.default(9999,`64255615 path is not valid '${e}'`)}isUnderTargetPath(e,t){const r=e.split("/");return this.has(r,t)}getFileDirPath(e,t=!0){return _lodash.default.join(_lodash.default.initial(_lodash.default.split(e,"/")),"/")+(t?"/":"")}isPathEqualsFileType(e,t){const r=e.split(".").pop();return _lodash.default.isEqual(r,t)}isValidFilePath(e){const t=this.getExtensionFromPath(e);return _lodash.default.size(t)>0}getArrayOfSize(e,t=1){return _lodash.default.take(e,t)}getShuffledArrayWithLimitCount(e,t){return this.getShuffledArrayWithLimitCountHighPerformance(e,t)}getRandomItemOfArray(e,...t){if(!_lodash.default.isArray(e))throw new _exceptioner.default(9999,`why are you so stupid, typeof array should be array, not ==> ${e} `);const r=_lodash.default.without(e,...t),a=_lodash.default.size(r)>0?r:e,n=this.getShuffledArrayWithLimitCount(a,1);return n.length>0?n[0]:void 0}appendMapOfKeyArray(e,t,...r){this.isUndefinedNullEmpty(e[t])?e[t]=[...r]:e[t].push(...r)}getMergedArrayBy(e=[],t=[],r){if(!r||0===e.length||0===t.length)return[...e];const a=new Map(t.map(e=>[e[r],e]));return e.map(e=>({...a.get(e[r])||{},...e}))}getShuffledItemFromArray(e){return _lodash.default.shuffle(e)[0]}getShuffledArray(e){return _lodash.default.shuffle(e)}isJson(e){e="string"!=typeof e?JSON.stringify(e):e;try{e=JSON.parse(e)}catch(e){return!1}return"object"==typeof e&&null!==e}getObjectValue(e){return _lodash.default.isObject(e)?Object.values(e)[0]:""}getObject(e,t){const r={};return r[e]=t,r}getStringOfCreditCardFormatted(e=0){return e.replace(/\D/g,"").replace(/(\d{4})(?=\d)/g,"$1-").slice(0,19)}getObjectKey(e){return _lodash.default.isObject(e)?Object.keys(e)[0]:""}printf(){this.appendInfo("i can use in web || react.js")}isKeywordRule(e){if(_lodash.default.isUndefined(e)||_lodash.default.isEmpty(e))throw new Error("PARAMS CAN NOT BE EMPTY");if(!_lodash.default.isString(e))throw new Error("PARAMS SHOULD BE STRING");if(e.length>20)throw new Error("EXCEED 20 WORDS IS NOT ALLOWED")}getItsKeyByValue(e,t){return Object.keys(e).find(r=>e[r]===t)}startWiths(e,t=[]){for(const r of t)if(_lodash.default.startsWith(e,r))return!0;return!1}replaceAll(e,t,r){return _lodash.default.replace(e,new RegExp(`${t}`,"g"),r)}replaceAllWithSets(e="",...t){let r=e;for(const e of t){if(this.isOrEquals(void 0,e.from,e.to))throw(0,_exceptioner.default)(9999,"from or to can't be empty");r=this.replaceAll(r,e.from,e.to)}return r}replaceArrayByContentIndex(e,t,r){e[_lodash.default.indexOf(e,t)]=r}deepFlat(e,t="_"){let r="";const a=[[e,""]];for(;a.length>0;){const[e,n]=a.pop();if(_lodash.default.isArray(e))for(let t=e.length-1;t>=0;t--)a.push([e[t],n]);else if(_lodash.default.isObject(e)){const r=Object.keys(e);for(let i=r.length-1;i>=0;i--){const o=r[i];a.push([e[o],n+o+t])}}else{const a=_lodash.default.trim(String(e));a.length>0?r+=(r.length>0?t:"")+n+a:n.length>0&&r.length>0?r+=t:n.length>0&&0===r.length&&(r+=n.endsWith(t)?n.slice(0,-t.length):n)}}return r.endsWith(t)&&(r=r.slice(0,-t.length)),r}joinEscapeChar(e){return(e+"").replace(/[\\"']/g,"\\$&").replace(/\u0000/g,"\\0")}getValueWithIntegerType(e){try{const t=parseInt(e);return isNaN(t)?0:t}catch(e){return 0}}getValueOfPriority(...e){for(const t of e)if(!this.isUndefinedNullEmpty(t))return t}async asyncPool(e,t,r){const a=[],n=[];for(const i of t){const o=Promise.resolve().then(()=>r(i,t));if(a.push(o),e<=t.length){const t=o.then(()=>n.splice(n.indexOf(t),1));n.push(t),n.length>=e&&await Promise.race(n)}}return Promise.all(a)}getAttrValueInSequence(e,...t){for(const r of t)if(!_lodash.default.isEmpty(e[r]))return e[r];return e}toDBC(e){for(var t="",r=0;r<e.length;r++)32===e.charCodeAt(r)&&(t+=String.fromCharCode(12288)),e.charCodeAt(r)<127&&(t+=String.fromCharCode(e.charCodeAt(r)+65248));return t}toCDB(e){for(var t="",r=0;r<e.length;r++)12288!==e.charCodeAt(r)?e.charCodeAt(r)>65280&&e.charCodeAt(r)<65375?t+=String.fromCharCode(e.charCodeAt(r)-65248):t+=String.fromCharCode(e.charCodeAt(r)):t+=String.fromCharCode(e.charCodeAt(r)-12256);return t}findIndexes(e,t){const r=[];let a=!0,n=0;for(;a;)n=_lodash.default.findIndex(e,t,n+1),n>-1?r.push(n):a=!1;return r}getSliceArrayOfSpecificIndexes(e,...t){const r=[],a=_lodash.default.size(e);for(const n of t){if(!_lodash.default.isNumber(n))throw new _exceptioner.default(9999,`59941278 index should be number => ${n}, ${e}`);if(n>a-1)throw new _exceptioner.default(9999,`5994123 index=>${n} is not valid, exceed than array size=${a}, ${e}`);r.push(_lodash.default.nth(e,n))}return r}indexesOf(e,t){const r=[];let a=-1;for(;-1!==(a=e.indexOf(t,a+1));)r.push(a);return r}getIndexOfContext(e,t){return _lodash.default.findIndex(e,e=>_lodash.default.isEqual(e.trim(),t))}toOneLineString(e){return _lodash.default.join(_lodash.default.split(e,"\n"),"")}toSpaceLessString(e){return _lodash.default.split(e,"").map(e=>_lodash.default.trim(e)).join("")}toNewLineLessString(e){return _lodash.default.split(e,"\n").map(e=>_lodash.default.trim(e)).join("")}exist(e){return!_lodash.default.isNull(e)&&!_lodash.default.isUndefined(e)}isUndefinedNullEmpty(e){const t=null==e,r=!!(_lodash.default.isString(e)||_lodash.default.isArray(e)||_lodash.default.isObject(e))&&_lodash.default.isEmpty(e);return t||r}isAndConditionOfUndefinedNullEmpty(...e){for(const t of e)if(!this.isUndefinedNullEmpty(t))return!1;return!0}isOrConditionOfUndefinedNullEmpty(...e){for(const t of e)if(this.isUndefinedNullEmpty(t))return!0;return!1}getStringHandledByEachLine(e,t=(e,t,r)=>!0,r="\n"){const a=e.split(r);for(const e of a)t(e,_lodash.default.indexOf(a,e),a);return a.join(r)}getSegmentsOfEachLine(e){return e.split("\n")}getNormalizedStringEndWith(e,t){e=this.toCDB(e),t=this.toCDB(t);const r=_lodash.default.join(_lodash.default.dropRightWhile(e,e=>!_lodash.default.isEqual(e,t)),"");return _lodash.default.isEmpty(r)?e:r}getNormalizedStringNotStartWith(e,...t){e=this.toCDB(e);const r=_lodash.default.join(_lodash.default.dropWhile(e,e=>this.has(t,e)),"");return _lodash.default.isEmpty(r)?e:r}getNormalizedStringNotEndWith(e,...t){e=this.toCDB(e);const r=_lodash.default.join(_lodash.default.dropRightWhile(e,e=>this.has(t,e)),"");return _lodash.default.isEmpty(r)?e:r}getTodayTimeFormat(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YYYY-MM-DD")}getCustomFormatOfDatePresent(e,t="YY/MM"){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format(t)}getSimpleDateYYMMDDFormat(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YY/MM/DD")}getSimpleTimeYYMMDDHHmmFormat(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YY/MM/DD HH:mm")}getECPayCurrentTimeFormat(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YYYY/MM/DD HH:mm:ss")}getCurrentTimeFormatV2(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YYYY/MM/DD HH:mm:ss")}getCurrentTimeFormatYMDHM(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YYYY/MM/DD HH:mm")}getCurrentTimeFormatYMDHMS(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YYYY/MM/DD HH:mm:ss")}getCurrentTimeFormat(e){return(0,_momentTimezone.default)(e||this.getCurrentTimeStamp()).format("YYYY-MM-DD-HH-mm-ss")}getCurrentMillionSecTimeFormat(e){return(0,_momentTimezone.default)(e||void 0).format("YYYY-MM-DD-HH-mm-ss-SSS")}isBetweenTimeStamp(e=this.getCurrentTimeStamp(),t,r){return(0,_momentTimezone.default)(e).isBetween(t,r)}isBeforeTimeStamp(e=this.getCurrentTimeStamp(),t){return(0,_momentTimezone.default)(e).isBefore(t)}isAfterTimeStamp(e=this.getCurrentTimeStamp(),t){return(0,_momentTimezone.default)(e).isAfter(t)}formatTimeByLocale(e,t="zh-TW",r="Asia/Taipei",a=!0){_momentTimezone.default.locale(t);const n=a?"YYYY/MM/DD HH:mm":"YYYY/MM/DD hh:mm A";return(0,_momentTimezone.default)(e).tz(r).format(n)}getTimeStampWithConditions(e={days:0,months:0,years:0,minutes:0,seconds:0,hours:0},t=this.getCurrentTimeStamp()){let r=(0,_momentTimezone.default)(t);for(const t in e){const a=e[t],n=t;a>0&&(r=r.add(a,n)),a<0&&(r=r.subtract(Math.abs(a),n))}return r.valueOf()}getTimeStampByStringFormat(e){return this.getTimeStampFromSpecificFormat(e,"YYYY/MM/DD HH:mm:ss").valueOf()}getTimeStampFromSpecificFormat(e,t="YYYY/MM/DD HH:mm:ss"){return(0,_momentTimezone.default)(e,t).valueOf()}getTimeStampFromECPayStringFormat(e){return this.getTimeStampFromSpecificFormat(e,"YYYY/MM/DD HH:mm:ss").valueOf()}getTimeFormatOfDurationToMillionSecond(e){return _momentTimezone.default.utc(e).format("HH小時mm分鐘ss秒SSS")}getTimeFormatOfDurationToSecond(e){return _momentTimezone.default.utc(e).format("HH小時mm分鐘ss秒")}getTimeFormatOfDurationToDay(e){return _momentTimezone.default.utc(e).format("DD天HH小時mm分鐘ss秒")}getChineseTimeFormat(e){return _momentTimezone.default.locale("zh-TW"),(0,_momentTimezone.default)(e).format("LLLL")}getMinuteFormatOfDuration(e){return _momentTimezone.default.duration(e).asMinutes()}getSecondFormatOfDuration(e){return _momentTimezone.default.duration(e).asSeconds()}getDayFormatOfDuration(e){return _momentTimezone.default.duration(e).asDays()}getDurationOfMillionSec(e){const t=this.getCurrentTimeStamp(),r=(0,_momentTimezone.default)(e).valueOf(),a=_lodash.default.sortBy([{ts:t},{ts:r}],e=>e.ts).map(e=>e.ts);let n=(0,_momentTimezone.default)(a.pop()),i=(0,_momentTimezone.default)(a.shift());return _momentTimezone.default.duration(n.diff(i)).asMilliseconds()}getCurrentTimeStamp(){return(0,_momentTimezone.default)().valueOf()}isStringContainInLines(e,t){for(let r of _lodash.default.split(e,"\n"))if(this.has(r,t))return!0;return!1}camel(...e){return _lodash.default.camelCase(e.join("_"))}upperCamel(...e){return _lodash.default.upperFirst(this.camel(...e))}array2Obj(e){const t={};for(const r of e)t[`${this.getObjectKey(r)}`]=this.getObjectValue(r);return t}arrayToObjWith(e,t){const r={};for(const a of e){const e=t(a),n=r[e];n&&_lodash.default.isArray(n)?n.push(a):r[e]=[a]}return r}isEmptyString(e){return _lodash.default.isEqual(_lodash.default.trim(e),"")}mergeObject(...e){return _lodash.default.merge(...e)}syncSetTimeout(e,t,r=()=>{}){!function a(n){n?r():setTimeout(function(){e(),a(!0)},t)}()}mergeArrayBy(e="id",...t){return Object.values(t.flat().reduce((t,r)=>(r[e]&&(t[r[e]]={...t[r[e]]||{},...r}),t),{}))}getRelativePath(e,t){return _lodash.default.dropWhile(e,(e,r)=>_lodash.default.isEqual(e,t[r])).join("")}dropItemsByIndex(e,t,r){_lodash.default.remove(e,(e,a,n)=>r>=a&&a>=t)}isEven(e){return e%2==0}isOdd(e){return 1===Math.abs(e%2)}enrichZhTw(){_momentTimezone.default.locale("zh-tw",{months:"一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split("_"),monthsShort:"1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"),weekdays:"星期日_星期一_星期二_星期三_星期四_星期五_星期六".split("_"),weekdaysShort:"周日_周一_周二_周三_周四_周五_周六".split("_"),weekdaysMin:"日_一_二_三_四_五_六".split("_"),longDateFormat:{LT:"Ah點mm分",LTS:"Ah點m分s秒",L:"YYYY-MM-DD",LL:"YYYY年MMMD日",LLL:"YYYY年MMMD日Ah點mm分",LLLL:"YYYY年MMMD日ddddAh點mm分",l:"YYYY-MM-DD",ll:"YYYY年MMMD日",lll:"YYYY年MMMD日Ah點mm分",llll:"YYYY年MMMD日ddddAh點mm分"},meridiemParse:/凌晨|早上|上午|中午|下午|晚上/,meridiemHour:function(e,t){let r=e;return 12===r&&(r=0),"凌晨"===t||"早上"===t||"上午"===t?r:"下午"===t||"晚上"===t?r+12:r>=11?r:r+12},meridiem:function(e,t,r){const a=100*e+t;return a<600?"凌晨":a<900?"早上":a<1130?"上午":a<1230?"中午":a<1800?"下午":"晚上"},calendar:{sameDay:function(){return 0===this.minutes()?"[今天]Ah[點整]":"[今天]LT"},nextDay:function(){return 0===this.minutes()?"[明天]Ah[點整]":"[明天]LT"},lastDay:function(){return 0===this.minutes()?"[昨天]Ah[點整]":"[昨天]LT"},nextWeek:function(){let e,t;return e=(0,_momentTimezone.default)().startOf("week"),t=this.diff(e,"days")>=7?"[下]":"[本]",0===this.minutes()?t+"dddA點整":t+"dddAh點mm"},lastWeek:function(){let e,t;return e=(0,_momentTimezone.default)().startOf("week"),t=this.unix()<e.unix()?"[上]":"[本]",0===this.minutes()?t+"dddAh點整":t+"dddAh點mm"},sameElse:"LL"},ordinalParse:/\d{1,2}(日|月|周)/,ordinal:function(e,t){switch(t){case"d":case"D":case"DDD":return e+"日";case"M":return e+"月";case"w":case"W":return e+"周";default:return e}},relativeTime:{future:"%s内",past:"%s前",s:"幾秒",m:"1 分鐘",mm:"%d 分鐘",h:"1 小時",hh:"%d 小時",d:"1 天",dd:"%d 天",M:"1 個月",MM:"%d 个月",y:"1 年",yy:"%d 年"},week:{dow:1,doy:4}})}getVisibleOrHidden(e){return{visibility:e?"visible":"hidden"}}getNumberOfPercentageToFloat(e){let t=e.replace("%","");return parseFloat(t)/100}getVisibleOrNone(e,t=!1){return{display:e?t?"flex":"inherit":"none"}}stringToInteger(e){switch(e=_lodash.default.toUpper(e)){case"A":return 0;case"B":return 1;case"C":return 2;case"D":return 3;case"E":return 4;case"F":return 5;case"G":return 6;case"H":return 7;case"I":return 8;case"J":return 9;case"K":return 10;case"L":return 11;case"M":return 12;case"N":return 13;default:return 101}}integerToString(e){switch(e){case 0:return"A";case 1:return"B";case 2:return"C";case 3:return"D";case 4:return"E";case 5:return"F";case 6:return"G";case 7:return"H";case 8:return"I";case 9:return"J";case 10:return"K";case 11:return"L";case 12:return"M";case 13:return"N";default:return"Z"}}toObjectMap(e,...t){const r=[];for(const a of e){const e={};for(const r of t){const t=r.func?r.func:e=>e;e[r.to]=this.isUndefinedNullEmpty(r.from)||!_lodash.default.isObject(a)?t(a):t(a[r.from])}r.push(e)}return r}exeAll(e,...t){if(_lodash.default.isArray(e))for(const r of e)for(const e of t)e(r);else{if(!_lodash.default.isObject(e))throw new _exceptioner.default(9999,"7841212 type can't be array or object");for(const r in e)for(const a of t)e[r]=a(e[r])}return e}getObjectWhile(e,t,r=e=>!0){const a={};for(const n in e)r(e,t,n)&&(a[n]=e[n]);return a}getIntersectionObject(e,t){return this.getObjectWhile(e,t,(e,t,r)=>void 0!==t[r])}getDifferenceObject(e,t){return this.getObjectWhile(e,t,(e,t,r)=>void 0===t[r])}isObjectContainAndEqual(e,t){let r=!0;for(const a in e)if(void 0===t[a]||t[a]!==e[a]){r=!1;break}return r}getStringOfPop(e,t){if(!_lodash.default.isString(e))throw new _exceptioner.default(9999,"445115,type should be string but ==> "+typeof e);const r=e.split(t);return r.pop(),r.join(t)}getStringOfShift(e,t){if(!_lodash.default.isString(e))throw new _exceptioner.default(9999,"445116,type should be string but ==> "+typeof e);const r=e.split(t);return r.shift(),r.join(t)}toObjectWithAttributeKey(e,t){const r={};for(const a of e){const e=a[t];if(this.isUndefinedNullEmpty(e))throw new _exceptioner.default(9999,`48157232 pk can't be empty => '${e}'`);r[e]=a}return r}getObjectOfArraySpecifyAttr(e,t){return this.toObjectWithAttributeKey(e,t)}getStateOfStringContainsSign(e,...t){for(const r of t)if(this.has(e,r))return{exists:!0,sign:r};return{exists:!1}}constraintOfParam(e,t,...r){let a=!1;const n=!!_lodash.default.isEmpty(r)||this.and(...r.map(e=>e.logic));switch(t){case"array":_lodash.default.isArray(e)&&n&&(a=!0);break;case"object":_lodash.default.isObject(e)&&n&&(a=!0);break;case"string":_lodash.default.isString(e)&&n&&(a=!0);break;case"number":_lodash.default.isNumber(e)&&n&&(a=!0);break;case"other":if(n)return!0}const i=_lodash.default.isEmpty(r)?"":`, ${r.map(e=>e.message).join(" | ")}`;if(!1===a)throw new _exceptioner.default(9999,`7474423 type should be ${t} but get '${typeof t}' ${i} `)}getSliceArrayWithMutate(e,t){return _lodash.default.remove(e,(e,r)=>r<t)}getArrayOfInteraction(e,t){return e.filter(e=>!t.includes(e))}getArrayOfMoveToSpecificIndex(e,t,r){if(!Array.isArray(e))throw new Error("First argument must be an array.");const a=e.length;if(t<0||t>=a||r<0||r>=a)return console.warn("Invalid 'from' or 'to' index for getArrayOfMoveToSpecificIndexOptimized."),[...e];if(t===r)return[...e];const n=[...e],[i]=n.splice(t,1);return n.splice(r,0,i),n}getArrayOfMoveItemToSpecificIndex(e,t,r){const a=_lodash.default.indexOf(e,t);return this.getArrayOfMoveToSpecificIndex(e,a,r)}getArrayOfMoveSpecificItemToAside(e,t,r=!0){const a=_lodash.default.indexOf(e,t);return this.getArrayOfMoveSpecificIndexToAside(e,a,r)}getArrayOfMoveSpecificIndexToAside(e,t,r=!0){const a=_lodash.default.size(e)-1;return this.getArrayOfMoveToSpecificIndex(e,t,r?a:0)}getECPayCheckMacValue(e,t="5294y06JbISpM5x9",r="v77hoKGq4kWxNNIS"){const a=_lodash.default.cloneDeep(e);delete a.CheckMacValue;const n=Object.keys(a).sort((e,t)=>e>t?1:-1);let i="";for(const e of n)i+=`${e}=${a[e]}&`;return i=`HashKey=${t}&${i}HashIV=${r}`,i=encodeURIComponent(i).toLowerCase(),i=i.replace(/%20/g,"+").replace(/%2d/g,"-").replace(/%5f/g,"_").replace(/%2e/g,".").replace(/%21/g,"!").replace(/%2a/g,"*").replace(/%28/g,"(").replace(/%29/g,")").replace(/%20/g,"+"),_lodash.default.toUpper(_cryptoJs.default.SHA256(i).toString(_cryptoJs.default.enc.Hex))}getStringOfHandledHtml(e,t=e=>{console.log(e)}){const r=(0,_nodeHtmlParser.parse)(e);return t(r),r.toString()}getSpecifyObjectBy(e,t){for(const r of e)if(t(r))return r}validatePayloadObjectValid(e,t=[],r=this.getRandomHash(10)){if(this.isUndefinedNullEmpty(e))throw new _exceptioner.default(9999,`${r} content(pay-load) is undefined || empty`);for(const a of t)if(_lodash.default.isString(a)){if(this.isUndefinedNullEmpty(e[a]))throw new _exceptioner.default(9999,`${r} ATTRIBUTE:'${a}' is not Exist`)}else if(_lodash.default.isObject(a)){const t=this.getObjectKey(a);if(!this.getObjectValue(a)(e[t]))throw new _exceptioner.default(9999,`${r} ATTRIBUTE:'${t}' is not valid of custom rule`)}return!0}getArrayOfSummarizeBy(e,t,r){const a={};for(const n of e){const e=n[t];void 0!==a[e]?a[e]=a[e]+n[r]:a[e]=n[r]}const n=[];for(const e in a){const i={};i[t]=e,i[r]=a[e],n.push(i)}return n}getHeadStringSplitBy(e,t=this.getSeparatorOfUnique()){return _lodash.default.split(e,t).shift()}getTailStringSplitBy(e,t=this.getSeparatorOfUnique()){return _lodash.default.split(e,t).pop()}getSlicesByIndexes(e=[],t=[]){const r=[];return _lodash.default.each(t,(a,n,i)=>{if(_lodash.default.isEqual(n,t.length-1))return!1;const o=_lodash.default.slice(e,a,t[n+1]);r.push(o)}),r}findIndexes(e,t){const r=[];let a=!0,n=0;for(;a;)n=_lodash.default.findIndex(e,t,n+1),n>-1?r.push(n):a=!1;return r}isOverSpecificAge(e,t=18){return(0,_momentTimezone.default)().diff((0,_momentTimezone.default)(e,"YYYY-MM-DD"),"years")>=t}isValidEmail(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}isValidTaiwaneseID(e){if(!/^[A-Z][1-2]\d{8}$/.test(e))return!1;const t=[1,9,8,7,6,5,4,3,2,1];let r=10*(e.charCodeAt(0)-65)+parseInt(e.slice(1));for(let a=0;a<t.length;a++)r+=parseInt(e.charAt(a+1))*t[a];return r%10==0}validatePersonalInfoInput(e,t,r,a,n,i=12){return e.length<2?{valid:!1,message:"姓名至少要兩個字"}:/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)?/^[A-Z][1-2]\d{8}$/.test(r)?/^09\d{8}$/.test(a)?this.isUndefinedNullEmpty(n)?{valid:!1,message:"出生日期格式不正確"}:(0,_momentTimezone.default)().diff(n,"years")<i?{valid:!1,message:`年齡不得小於 ${i} 歲`}:{valid:!0,message:"格式檢查通過"}:{valid:!1,message:"手機號碼格式不正確"}:{valid:!1,message:"身分證號碼格式不正確"}:{valid:!1,message:"電子郵件格式不正確"}}getStringOfFormatTimestampRange(e,t){const r=(0,_momentTimezone.default)(e),a=(0,_momentTimezone.default)(t),n=e=>e.format("YY/MM/DD");return r.year()===a.year()?`${n(r)} - ${a.format("MM/DD")}`:`${n(r)} - ${n(a)}`}getStringOfCalculateClassTime(e,t,r){const a=(0,_momentTimezone.default)(e),n=(0,_momentTimezone.default)(t).diff(a,"days")+1,i=Math.ceil(n/7)*r,o=Math.floor(i/60),s=i%60;return 0===s?`${o}小時`:`${o}小時${s}分鐘`}getNumberOfPeriodMinute(e,t){const r=(0,_momentTimezone.default)(e).format("HH:mm"),a=(0,_momentTimezone.default)(t).format("HH:mm"),n=(0,_momentTimezone.default)(r,"HH:mm"),i=(0,_momentTimezone.default)(a,"HH:mm");return _momentTimezone.default.duration(i.diff(n)).asMinutes()}getStringOfWeekTime(e,t,r){if(e<1||e>7)throw new Error("day 必須在 1 到 7 之間");const a=(0,_momentTimezone.default)(t).format("HH:mm"),n=(0,_momentTimezone.default)(r).format("HH:mm");return`${{1:"週一",2:"週二",3:"週三",4:"週四",5:"週五",6:"週六",7:"週日"}[e]} ${a}-${n}`}extractNumber(e){if(this.isUndefinedNullEmpty(e))return-1;const t=e.match(/\d+/);return t?Number(t[0]):-1}async fetchElementAttribute(e,t="innerText",r=""){return await e.evaluate(e=>e[t])}async fetchElementAttributes(e,t,r="",...a){const n=await e.$(t);if(!this.isUndefinedNullEmpty(n))try{return await n.evaluate((e,t)=>1===t.length?e[t.shift()]:{...t.map(t=>e[t])},a)}catch(e){return this.appendError(`1581532 ${t} fetch ${JSON.stringify(a)} fail, element is not found`),r}return r}async writeElementAttributes(e,t,...r){const a=await e.$(t);this.isUndefinedNullEmpty(a)?this.appendError(`1231232 ${t} fetch ${JSON.stringify(r)} fail, element is not found`):await a.evaluate((e,t)=>{t.map(t=>{const r=Object.entries(t),a=r[0][0],n=r[0][1];e[a]=n})},r)}getSliceArrayOfUnique(e){if(!Array.isArray(e)||0===e.length)return[];const t=e[0];if(_lodash.default.isObject(t)&&key){const t=new Map(e.map(e=>[e[key],e]));return Array.from(t.values())}return _lodash.default.isObject(t)?(console.warn("getSliceArrayOfUniqueOptimized: No key provided for object array, using potentially slow deep comparison."),_lodash.default.uniqWith(e,_lodash.default.isEqual)):Array.from(new Set(e))}getUniqueValuesBy(e,t="valueOfType"){return _lodash.default.uniq(e.map(e=>e[t]))}generateCombinations(...e){const t=e.map(e=>e.key),r=(_lodash.default.keyBy(e,"key"),e.map(e=>e.options.map(t=>({key:e.key,value:t.value,label:t.label})))),a=_lodash.default.reduce(r,(e,t)=>_lodash.default.flatMap(e,e=>t.map(t=>[...e,t])),[[]]).map(e=>{const t={},r=[],a=[];for(const{key:n,value:i,label:o}of e)t[n]=i,r.push(`${n}_${i}`),a.push(`${o}`);return{trait:t,id:r.join("_"),content:a.join("|")}});return _lodash.default.sortBy(a,e=>t.map(t=>e.trait[t]))}extractStaticSegments(e,t=[":"]){return e.trim().replace(/^\.?\/*|\/*$/g,"").split("/").filter(e=>e&&!t.some(t=>e.startsWith(t)))}mutateRemoveKeys(e,t){_lodash.default.forEach(e,(e,r)=>{const a=Object.fromEntries(Object.entries(e).filter(([e])=>!t.includes(e)));Object.keys(e).forEach(t=>delete e[t]),Object.assign(e,a)})}removeKeysFromArrayObjects(e,t){return _lodash.default.map(e,e=>Object.fromEntries(Object.entries(e).filter(([e])=>!t.includes(e))))}formatTextWithEllipsis(e,t){if(_lodash.default.size(e)<=t)return e;if(t<=6)return"";const r=t-6,a=Math.floor(r/2),n=r-a;return`${_lodash.default.truncate(e,{length:a,omission:""})}......${_lodash.default.takeRight(e,n).join("")}`}getObjectBy(e,t=e=>!0!==e.checked){return _lodash.default.fromPairs(_lodash.default.toPairs(e).filter(([e,r])=>t(r)))}mutateBy(e,t=e=>e){const r=_lodash.default.sortBy(e,t);e.splice(0,e.length,...r)}findUniqueStrings(...e){const t=_lodash.default.flatten(e),r=_lodash.default.countBy(t);return _lodash.default.chain(r).pickBy(e=>1===e).keys().compact().value()}getObjectOfSpecifyKey(e,t){const r={};return r[t]=e,r}findUniqueNonReferenceStrings(...e){if(0===e.length)return[];const[t,...r]=e,a=_lodash.default.flatten(r),n=_lodash.default.countBy(a);return _lodash.default.chain(n).pickBy((e,r)=>1===e&&!t.includes(r)).keys().compact().value()}getArrayOfFillMissingValues(e){const t=()=>_lodash.default.times(8,()=>_lodash.default.sample("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")).join(""),r=new Set(e.map(e=>e.value).filter(Boolean));return e.map(e=>{if(_lodash.default.isEmpty(e.value)){let a;do{a=t()}while(r.has(a));return r.add(a),{...e,value:a}}return e})}isFirestoreAutoId(e){return _lodash.default.isString(e)&&20===e.length&&/^[A-Za-z0-9]{20}$/.test(e)}getAutoIdOfFirestore(){return this.getRandomHashV2(20)}getStringOfConvertTimeRange(e){const[t,r]=e.split("|"),a=t.split("(")[0],[n,i]=r.split("-"),o=e=>(0,_momentTimezone.default)(`${a} ${e}`,"YYYY/MM/DD HH:mm").format("YYYYMMDDHHmm");return`${o(n)}-${o(i)}`}getTSOfSpecificDate(e,{end:t=!1}={}){return Number((0,_lodash.default)(e).thru(e=>(0,_momentTimezone.default)(e.split("(")[0],"YYYY/MM/DD")).thru(e=>t?e.endOf("day"):e.startOf("day")).value().format("YYYYMMDDHHmmss"))}isHttpsURL(e){if(!_lodash.default.isString(e))return!1;try{const t=decodeURIComponent(e.trim());return"https:"===new URL(t).protocol}catch(e){return!1}}generateUniqueCodeMap(e,t=3){if(t<2)throw new Error("代碼長度最少必須為 2。");const r=new Set,a=new Set;return _lodash.default.transform(e,(e,n)=>{if(a.has(n))throw new Error(`23125453 Duplicate key detected: "${n}"`);a.add(n),e[n]=(()=>{const e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",a=e+"0123456789";let n;do{n=e[Math.floor(52*Math.random())];for(let e=1;e<t;e++)n+=a[Math.floor(62*Math.random())]}while(r.has(n));return r.add(n),n})()},{})}getPriceOfPercentageBehavior(e,t,r=!1){const a=this.toPercentageDecimal(t);return this.getNumberOfMultiplyCeil(e,r?1-a:1+a)}getFeeOfDiscount(e,t){return Math.round(_lodash.default.multiply(e,this.toPercentageDecimal(t)))}mergeArrayByKey(e){if(!Array.isArray(e))return e;const t={};for(const r of e)if(_lodash.default.isPlainObject(r))for(const[e,a]of Object.entries(r))t[e]?_lodash.default.merge(t[e],a):t[e]=_lodash.default.cloneDeep(a);return e.length=0,Object.entries(t).forEach(([t,r])=>{e.push({[t]:r})}),e}getObjectOfStartEndDateTime(e){if(!e||"string"!=typeof e)return{startDate:"",startTime:"",endDate:"",endTime:""};const t=e.replace(/|/g," ").replace(/-/g,"-").replace(/\s+/g," ").trim(),r=/(\d{4}\/\d{1,2}\/\d{1,2})(?:\s*\([^)]*\))?\s*(\d{2}:\d{2})\s*-\s*(\d{4}\/\d{1,2}\/\d{1,2})(?:\s*\([^)]*\))?\s*(\d{2}:\d{2})/,a=/(\d{4}\/\d{1,2}\/\d{1,2})(?:\s*\([^)]*\))?\s*(\d{2}:\d{2})\s*-\s*(\d{2}:\d{2})/;let n,i,o,s;if(r.test(t))[,n,i,o,s]=t.match(r);else{if(!a.test(t))return{startDate:"",startTime:"",endDate:"",endTime:""};[,n,i,s]=t.match(a),o=n}const l=new Date(`${n} ${i}`);if(new Date(`${o} ${s}`)<l)throw new Error(`End time cannot be earlier than start time: ${e}`);return{startDate:n,startTime:i,endDate:o,endTime:s}}getFilteredHeraPeriods(e,t){return _lodash.default.chain(e).filter(e=>e.idOfBooze!==t).uniqBy(e=>`${e.idOfBooze}_${e.idOfVariant}`).value()}checkPeriodConflict(e,t,r=1){const[a,n]=e.content.split("|"),i=(0,_momentTimezone.default)(a.split(" ")[0],"YYYY/MM/DD"),[o,s]=n.split("-"),l=(0,_momentTimezone.default)(`${i.format("YYYY/MM/DD")} ${o}`,"YYYY/MM/DD HH:mm"),u=(0,_momentTimezone.default)(`${i.format("YYYY/MM/DD")} ${s}`,"YYYY/MM/DD HH:mm"),d=_lodash.default.filter(t,e=>{const[t,r]=e.period.split("-"),a=(0,_momentTimezone.default)(t,"YYYYMMDDHHmm"),n=(0,_momentTimezone.default)(r,"YYYYMMDDHHmm");return l.isBefore(n)&&u.isAfter(a)});return{conflict:d.length>=r,items:d}}}var _default=exports.default=Utiller;
|
package/package.json
CHANGED