xjs-common 11.0.0-alpha.1 → 11.0.0-alpha.2
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/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var t,n,e,r
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["xjs-common"]=e():t["xjs-common"]=e()}(this,()=>(()=>{"use strict";var t,e,n,r,o={d:(t,e)=>{for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},i={};o.r(i),o.d(i,{DType:()=>g,Gender:()=>n,HttpMethod:()=>r,TimeUnit:()=>e,Type:()=>t,UArray:()=>O,UHttp:()=>S,UObj:()=>M,UString:()=>w,UType:()=>j,XjsErr:()=>a,array2map:()=>p,bitor:()=>m,delay:()=>y,getJSTDate:()=>l,int2array:()=>d,resolveCcy:()=>u,retry:()=>h,s_ccy:()=>c,transaction:()=>P}),function(t){t.string="string",t.number="number",t.bigint="bigint",t.boolean="boolean",t.symbol="symbol",t.object="object",t[void 0]="undefined",t.null="null"}(t||(t={})),function(t){t[t.Year=1]="Year",t[t.Month=2]="Month",t[t.Day=3]="Day",t[t.Hour=4]="Hour",t[t.Min=5]="Min",t[t.Sec=6]="Sec",t[t.Msec=7]="Msec"}(e||(e={})),function(t){t[t.Male=0]="Male",t[t.Female=1]="Female"}(n||(n={})),function(t){t.Get="GET",t.Put="PUT",t.Post="POST",t.Delete="DELETE",t.Patch="PATCH",t.Connect="CONNECT"}(r||(r={}));const s={jpy:{crossUsd:"usd/jpy"},usd:{crossUsd:null},gbp:{crossUsd:"gbp/usd"},eur:{crossUsd:"eur/usd"},cad:{crossUsd:"cad/usd"},aud:{crossUsd:"aud/usd"}},c=(Object.entries(s).forEach(t=>{t[1].symbol=t[0],s[t[0]]=Object.freeze(t[1])}),Object.freeze(s));function u(t){const e=Object.keys(c).find(e=>t?.toLowerCase()==e);return e&&c[e]}class a extends Error{code;origin;constructor(t,e,n){super(`[XJS] ${e}`),this.code=t,this.origin=n}}const f=10;function l(t){return new Date((t?t.getTime():Date.now())+324e5)}function y(t){return new Promise(e=>setTimeout(e,1e3*t))}function d(t){const e=Number(t);if(Number.isNaN(e))throw new a(f,"size of the argument is not number.");return Array.from(Array(e).keys())}function p(t,e){const n=new Map;for(const r of t){const t=e(r);n.has(t)?n.get(t).push(r):n.set(t,[r])}return n}function m(...t){return t.reduce((t,e)=>t|e)}function h(t,e){const n=e?.logger??console,r=e?.count??1,o=t=>!(e?.errorCriterion&&!e.errorCriterion(t)||(n.warn(t),0)),i=n=>{if(n<0)throw new a(f,"failure exceeds retryable count.");let s=null;const c=()=>{try{s=t()}catch(t){if(!o(t))throw t;s=i(n-1)}return s instanceof Promise?new Promise((t,e)=>s.then(t).catch(r=>{o(r)?t(i(n-1)):e(r)})):s};return n<r&&e?.intervalPredicate&&(s=e?.intervalPredicate()),s instanceof Promise?s.then(()=>c()):c()};return i(r)}const b=Symbol.for("xjs:typeMap");var g,j,M,w,O,S;!function(e){function n(t,e,n){r(t,e,t=>{if(t.t)throw new a(30,"decorator to express type is duplicate.");t.t=n})}function r(t,e,n){const r=t[b]?Object.assign({},t[b]):{};r[e]??={t:null,req:!1,rec:!1,ary:null};const o=r[e];n(o);let i=null,s=null;if(o.t&&o.rec&&(i="type",s="recursive flag"),o.t&&o.ary&&(i="type",s="array"),o.ary&&o.rec&&(i="array",s="recursive flag"),i&&s)throw new a(30,`decorator to express ${i} and ${s} are exclusive.`);Object.defineProperty(t,b,{value:r,configurable:!0})}e.string=function(e,r){n(e,r,t.string)},e.number=function(e,r){n(e,r,t.number)},e.boolean=function(e,r){n(e,r,t.boolean)},e.required=function(t,e){r(t,e,t=>t.req=!0)},e.array=function(t={}){return(e,n)=>r(e,n,e=>e.ary=t)},e.recursive=function(t,e){r(t,e,t=>t.rec=!0)},e.keep=function(t,e){r(t,e,t=>{})}}(g||(g={})),function(e){function n(e){return null===e||typeof e===t.undefined}function r(t){return t[b]?Object.entries(t[b]).flatMap(e=>o(e[0],t[e[0]],e[1])):[]}function o(t,e,i){return n(e)?i.req?[t]:[]:i.t&&typeof e!==i.t?[t]:i.ary?Array.isArray(e)?e.flatMap(e=>o(t,e,i.ary)):[t]:i.rec?r(e).flatMap(e=>`${t}.${e}`):[]}e.isDefined=function(e){return typeof e!==t.undefined},e.isEmpty=n,e.isString=function(e){return typeof e===t.string},e.isNumber=function(e){return typeof e===t.number},e.isBigint=function(e){return typeof e===t.bigint},e.isBoolean=function(e){return typeof e===t.boolean},e.isSymbol=function(e){return typeof e===t.symbol},e.isObject=function(e){return typeof e===t.object},e.isArray=function(t,e){return Array.isArray(t)&&(!e||t.every(t=>typeof t===e))},e.validate=r,e.takeAsArray=function(t){return Array.isArray(t)?t:[t]}}(j||(j={})),function(t){t.assignProperties=function t(e,n,r,o){for(const i of r??Object.keys(n))j.isDefined(n[i])&&(o&&j.isObject(e[i])&&j.isObject(n[i])&&e[i]?.[b]?t(e[i],n[i],null,!0):e[i]=n[i]);return e},t.crop=function t(e,n,r){if(!n&&!e[b])return{};const o=n??Object.keys(e[b]);return Object.keys(e).filter(i=>(!n&&e[b]?.[i]?.rec&&e[i]&&t(e[i]),!!r===o.includes(i))).forEach(t=>delete e[t]),e}}(M||(M={})),function(t){function n(t,e){const n=t.toString().split("."),r=n[0].split("").reverse().join("");let o="";const i=Math.ceil(r.length/3);for(let t=0;t<i;t++)o+=t===i-1?r.substring(3*t):r.substring(3*t,3*(t+1))+",";const s=e+o.split("").reverse().join("");return 1===n.length?s:s+"."+n[1]}t.eq=function(t,e){return j.isString(t)&&j.isString(e)?t.trim()===e.trim():t===e},t.repeat=function(t,e){return d(e).map(e=>t).join("")},t.simpleTime=function(t){const n=(t?.date??new Date).toISOString().split(".")[0].replace(/[-T:]/g,"");return t?.unit===e.Msec?n:n.substring(0,14-2*(6-(t?.unit??e.Sec)))},t.generateRandomString=function(t){return d(t).map(t=>{let e=Math.floor(62*Math.random());const n=e-52;return n>=0?n.toString():(e>26&&(e+=6),String.fromCharCode(e+65))}).join("")},t.idx2az=function(t){let e="",n=t;for(;n>=0;)e=String.fromCharCode(n%26+97)+e,n=Math.floor(n/26)-1;return e.toUpperCase()},t.az2idx=function(t){if(!t?.match(/^[a-zA-Z]+$/))throw new a(20,"the parameter isn't az(AZ) format.");return t.toLowerCase().split("").map(t=>t.charCodeAt(0)-97).reverse().map((t,e)=>(t+1)*26**e).reduce((t,e)=>t+e)-1},t.asJpy=function(t){return j.isEmpty(t)?"":n(Math.floor(t),"¥")},t.asUsd=function(t){return j.isEmpty(t)?"":n(Number(t.toFixed(2)),"$")},t.asPercentage=function(t){if(j.isEmpty(t))return"";let e=(100*t).toFixed(2);for(;e.endsWith("0");)e=e.substring(0,e.length-1);return e.endsWith(".")&&(e=e.substring(0,e.length-1)),e+"%"},t.is_yyyy=function(t){return!!t?.match(/^[1-9]\d{3}$/)},t.is_yyyyMM=function(t){return!!t?.match(/^[1-9]\d{3}(0[1-9]|1[0-2])$/)},t.is_yyyyMMdd=function(t){return!!t?.match(/^[1-9]\d{3}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|[3][0-1])$/)},t.is_yyyyMMddhh=function(t){return!!t?.match(/^[1-9]\d{3}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|[3][0-1])([01]\d|2[0-3])$/)},t.is_yyyyMMddhhmm=function(t){return!!t?.match(/^[1-9]\d{3}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|[3][0-1])([01]\d|2[0-3])[0-5]\d$/)},t.is_yyyyMMddhhmmss=function(t){return!!t?.match(/^[1-9]\d{3}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|[3][0-1])([01]\d|2[0-3])[0-5]\d[0-5]\d$/)}}(w||(w={})),function(t){function e(t,e=!0){const n=Math.floor(t.length*Math.random()),r=t[n];return e&&t.splice(n,1),r}t.eq=function(t,e,n={}){const{sort:r,useStrictEqual:o}=Object.assign({sort:!0,useStrictEqual:!0},n);if(t&&!e||!t&&e)return!1;if(!t)return!0;if(t.length!==e.length)return!1;const i=r?[...t].sort():t,s=r?[...e].sort():e;return i.every((t,e)=>o?t===s[e]:t==s[e])},t.distinct=function(t,e){if(!t||0===t.length)return[];if(e?.k)return Array.from(p(t,t=>t[e.k]).values()).map(t=>e?.takeLast?t.pop():t.shift());const n=e?.takeLast?[...t].reverse():[...t],r=e?.predicate??((t,e)=>t==e),o=[n.shift()];return n.forEach(t=>o.some(e=>r(t,e))?{}:o.push(t)),o},t.chop=function(t,e){return[...Array(Math.ceil(t.length/e)).keys()].map(n=>{let r=(n+1)*e;return r>t.length&&(r=t.length),t.slice(n*e,r)})},t.remove=function(t,e){const n=t.indexOf(e);-1!==n&&t.splice(n,1)},t.randomPick=e,t.shuffle=function(t){const n=[...t];return d(t.length).map(t=>e(n))},t.takeOut=function(t,e){const n=[];for(let r=t.length-1;r>=0;r--)e(t[r],r)&&(n.unshift(t[r]),t.splice(r,1));return n}}(O||(O={})),function(t){function e(t){return Math.floor(t/100)}t.isHttpSuccess=function(t){return 2===e(t)},t.statusCategoryOf=e,t.concatParamsWithEncoding=function(t,e){if(!e||0===Object.keys(e).length)return t;const n=Object.entries(e).flatMap(t=>Array.isArray(t[1])?t[1].map(e=>[t[0],e]):[t]);let r=t?t+"?":"";for(var o of n)r+=o[0]+"="+encodeURIComponent(o[1])+"&";return r.substring(0,r.length-1)},t.normalizeHeaders=function(t){return t?Object.entries(t).reduce((t,e)=>(t[e[0].toLowerCase()]=e[1],t),{}):{}}}(S||(S={}));const v=100;function P(t){let e=0;const n=t?.timeoutSec??30;return(t,r,o)=>{const i=o.value;o.value=async function(...t){const r=Date.now()+1e3*n;for(;e>0;){if(r<=Date.now())throw new a(v,"An exclusive process to execute was already running by other request.");await y(1)}try{e++;const n=i.apply(this,t);return n instanceof Promise?await n:n}finally{e--}}}}return i})());
|