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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- (()=>{"use strict";var t,n,e,r;!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"}(n||(n={})),function(t){t[t.Male=0]="Male",t[t.Female=1]="Female"}(e||(e={})),function(t){t.Get="GET",t.Put="PUT",t.Post="POST",t.Delete="DELETE",t.Patch="PATCH",t.Connect="CONNECT"}(r||(r={}));const o={jpy:{crossUsd:"usd/jpy"},usd:{crossUsd:null},gbp:{crossUsd:"gbp/usd"},eur:{crossUsd:"eur/usd"},cad:{crossUsd:"cad/usd"},aud:{crossUsd:"aud/usd"}};Object.entries(o).forEach(t=>{t[1].symbol=t[0],o[t[0]]=Object.freeze(t[1])}),Object.freeze(o);class i extends Error{code;origin;constructor(t,n,e){super(`[XJS] ${n}`),this.code=t,this.origin=e}}function s(t){const n=Number(t);if(Number.isNaN(n))throw new i(10,"size of the argument is not number.");return Array.from(Array(n).keys())}const u=Symbol.for("xjs:typeMap");var c,a,f,l,y,d;!function(n){function e(t,n,e){r(t,n,t=>{if(t.t)throw new i(30,"decorator to express type is duplicate.");t.t=e})}function r(t,n,e){const r=t[u]?Object.assign({},t[u]):{};r[n]??={t:null,req:!1,rec:!1,ary:null};const o=r[n];e(o);let s=null,c=null;if(o.t&&o.rec&&(s="type",c="recursive flag"),o.t&&o.ary&&(s="type",c="array"),o.ary&&o.rec&&(s="array",c="recursive flag"),s&&c)throw new i(30,`decorator to express ${s} and ${c} are exclusive.`);Object.defineProperty(t,u,{value:r,configurable:!0})}n.string=function(n,r){e(n,r,t.string)},n.number=function(n,r){e(n,r,t.number)},n.boolean=function(n,r){e(n,r,t.boolean)},n.required=function(t,n){r(t,n,t=>t.req=!0)},n.array=function(t={}){return(n,e)=>r(n,e,n=>n.ary=t)},n.recursive=function(t,n){r(t,n,t=>t.rec=!0)},n.keep=function(t,n){r(t,n,t=>{})}}(c||(c={})),function(n){function e(n){return null===n||typeof n===t.undefined}function r(t){return t[u]?Object.entries(t[u]).flatMap(n=>o(n[0],t[n[0]],n[1])):[]}function o(t,n,i){return e(n)?i.req?[t]:[]:i.t&&typeof n!==i.t?[t]:i.ary?Array.isArray(n)?n.flatMap(n=>o(t,n,i.ary)):[t]:i.rec?r(n).flatMap(n=>`${t}.${n}`):[]}n.isDefined=function(n){return typeof n!==t.undefined},n.isEmpty=e,n.isString=function(n){return typeof n===t.string},n.isNumber=function(n){return typeof n===t.number},n.isBigint=function(n){return typeof n===t.bigint},n.isBoolean=function(n){return typeof n===t.boolean},n.isSymbol=function(n){return typeof n===t.symbol},n.isObject=function(n){return typeof n===t.object},n.isArray=function(t,n){return Array.isArray(t)&&(!n||t.every(t=>typeof t===n))},n.validate=r,n.takeAsArray=function(t){return Array.isArray(t)?t:[t]}}(a||(a={})),function(t){t.assignProperties=function t(n,e,r,o){for(const i of r??Object.keys(e))a.isDefined(e[i])&&(o&&a.isObject(n[i])&&a.isObject(e[i])&&n[i]?.[u]?t(n[i],e[i],null,!0):n[i]=e[i]);return n},t.crop=function t(n,e,r){if(!e&&!n[u])return{};const o=e??Object.keys(n[u]);return Object.keys(n).filter(i=>(!e&&n[u]?.[i]?.rec&&n[i]&&t(n[i]),!!r===o.includes(i))).forEach(t=>delete n[t]),n}}(f||(f={})),function(t){function e(t,n){const e=t.toString().split("."),r=e[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=n+o.split("").reverse().join("");return 1===e.length?s:s+"."+e[1]}t.eq=function(t,n){return a.isString(t)&&a.isString(n)?t.trim()===n.trim():t===n},t.repeat=function(t,n){return s(n).map(n=>t).join("")},t.simpleTime=function(t){const e=(t?.date??new Date).toISOString().split(".")[0].replace(/[-T:]/g,"");return t?.unit===n.Msec?e:e.substring(0,14-2*(6-(t?.unit??n.Sec)))},t.generateRandomString=function(t){return s(t).map(t=>{let n=Math.floor(62*Math.random());const e=n-52;return e>=0?e.toString():(n>26&&(n+=6),String.fromCharCode(n+65))}).join("")},t.idx2az=function(t){let n="",e=t;for(;e>=0;)n=String.fromCharCode(e%26+97)+n,e=Math.floor(e/26)-1;return n.toUpperCase()},t.az2idx=function(t){if(!t?.match(/^[a-zA-Z]+$/))throw new i(20,"the parameter isn't az(AZ) format.");return t.toLowerCase().split("").map(t=>t.charCodeAt(0)-97).reverse().map((t,n)=>(t+1)*26**n).reduce((t,n)=>t+n)-1},t.asJpy=function(t){return a.isEmpty(t)?"":e(Math.floor(t),"¥")},t.asUsd=function(t){return a.isEmpty(t)?"":e(Number(t.toFixed(2)),"$")},t.asPercentage=function(t){if(a.isEmpty(t))return"";let n=(100*t).toFixed(2);for(;n.endsWith("0");)n=n.substring(0,n.length-1);return n.endsWith(".")&&(n=n.substring(0,n.length-1)),n+"%"},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$/)}}(l||(l={})),function(t){function n(t,n=!0){const e=Math.floor(t.length*Math.random()),r=t[e];return n&&t.splice(e,1),r}t.eq=function(t,n,e={}){const{sort:r,useStrictEqual:o}=Object.assign({sort:!0,useStrictEqual:!0},e);if(t&&!n||!t&&n)return!1;if(!t)return!0;if(t.length!==n.length)return!1;const i=r?[...t].sort():t,s=r?[...n].sort():n;return i.every((t,n)=>o?t===s[n]:t==s[n])},t.distinct=function(t,n){if(!t||0===t.length)return[];if(n?.k)return Array.from(function(t,n){const e=new Map;for(const r of t){const t=n(r);e.has(t)?e.get(t).push(r):e.set(t,[r])}return e}(t,t=>t[n.k]).values()).map(t=>n?.takeLast?t.pop():t.shift());const e=n?.takeLast?[...t].reverse():[...t],r=n?.predicate??((t,n)=>t==n),o=[e.shift()];return e.forEach(t=>o.some(n=>r(t,n))?{}:o.push(t)),o},t.chop=function(t,n){return[...Array(Math.ceil(t.length/n)).keys()].map(e=>{let r=(e+1)*n;return r>t.length&&(r=t.length),t.slice(e*n,r)})},t.remove=function(t,n){const e=t.indexOf(n);-1!==e&&t.splice(e,1)},t.randomPick=n,t.shuffle=function(t){const e=[...t];return s(t.length).map(t=>n(e))},t.takeOut=function(t,n){const e=[];for(let r=t.length-1;r>=0;r--)n(t[r],r)&&(e.unshift(t[r]),t.splice(r,1));return e}}(y||(y={})),function(t){function n(t){return Math.floor(t/100)}t.isHttpSuccess=function(t){return 2===n(t)},t.statusCategoryOf=n,t.concatParamsWithEncoding=function(t,n){if(!n||0===Object.keys(n).length)return t;const e=Object.entries(n).flatMap(t=>Array.isArray(t[1])?t[1].map(n=>[t[0],n]):[t]);let r=t?t+"?":"";for(var o of e)r+=o[0]+"="+encodeURIComponent(o[1])+"&";return r.substring(0,r.length-1)},t.normalizeHeaders=function(t){return t?Object.entries(t).reduce((t,n)=>(t[n[0].toLowerCase()]=n[1],t),{}):{}}}(d||(d={}))})();
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})());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xjs-common",
3
- "version": "11.0.0-alpha.1",
3
+ "version": "11.0.0-alpha.2",
4
4
  "description": "library modules for typescript that bundled general-purpose implementations.",
5
5
  "repository": {
6
6
  "type": "git",