@machinerd/js-module 0.0.9 → 0.0.11

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.
@@ -1 +1 @@
1
- const e=require(`../chunk-Bmb41Sf3.cjs`);let t=require(`js-cookie`);t=e.t(t);let n=require(`query-string`);n=e.t(n);let r=require(`dayjs`);r=e.t(r),require(`dayjs/locale/ko.js`);let i=require(`dayjs/plugin/relativeTime.js`);i=e.t(i);let a=require(`lodash-es`),o=require(`nanoid`),s=require(`slugify`);s=e.t(s);let c=require(`google-libphonenumber`);c=e.t(c);const l=c.default.PhoneNumberFormat,u=c.default.PhoneNumberUtil.getInstance();r.default.extend(i.default);const d=(e,t=`YYYY-MM-DD`,n=`en`)=>{let i=(0,r.default)(e).locale(n);return(0,r.default)().diff(i,`hour`)<12?i.fromNow():i.format(t)},f=e=>t.default.get(e),p=(e,n,r)=>t.default.set(e,n,r),m=(e,t=[])=>{if(typeof window>`u`)return``;let{hash:r,search:i}=window.location,a=n.default.parse(i);Object.keys(e).forEach(t=>{e[t]?a[t]=e[t]:delete a[t]});let o={...a};return Object.keys(a).forEach(e=>{t.includes(e)&&delete o[e]}),`?${n.default.stringify(o,{encode:!0})}${r}`},h=(e,t)=>{let n=0;return e%t===0&&(n=e/t),n=Math.ceil(e/t),n<1&&(n=1),n},g=e=>{let t=[...e];for(let e=t.length-1;e>0;e--){let n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t},_=(e,t)=>{let n=[];for(let r=e;r<t;r++)n.push(r);return n},v=(e,t,n=1)=>{let r=[],i=_(e,t);for(;r.length<n;){let t=Math.ceil(e),n=Math.floor(i.length),a=Math.floor(Math.random()*(n-t))+t,o=i.splice(a,1);r.push(o[0])}return[...r]},y=e=>{let t=document.getElementById(`naverMapLib`);if(!t){let t=document.createElement(`script`);t.src=`https://oapi.map.naver.com/openapi/v3/maps.js?ncpKeyId=ecs1pyoo9b`,t.id=`naverMapLib`,document.body.appendChild(t),t.onload=()=>{e&&e()}}t&&e&&e()},b=(e,t,n)=>t?e===`ko`&&n&&n!==`82`||e!==`ko`&&n?`+${n}-${t.replace(/^0/,``)}`:t:`-`,x=({phone:e,country:t={callingCode:`82`,alpha2Code:`KR`},format:n=l.INTERNATIONAL,locale:r})=>{if(!e||e===`-`)return`-`;try{let i=u.parseAndKeepRawInput(e,t?.alpha2Code||`KR`),a=i.getCountryCode();return r===`ko`&&t?.alpha2Code===`KR`&&a===82?u.format(i,l.NATIONAL):u.format(i,n)}catch{return b(r||`en`,e,t?.callingCode)}},S=(e,...t)=>{s.default.extend({'"':`-`,"”":`-`,"“":`-`,"•":`----`});let n=`${e}`;return t.forEach(e=>{e&&(n=`${n}-${(0,s.default)(e,{lower:!0,trim:!0,locale:`en`,strict:!0})}`)}),n},C=e=>{let t=[];e.i18n?.forEach(e=>{e.locale===`en`&&e.name&&t.push(e.name)});let n=e.series?.i18n.find(e=>e.locale===`en`);return n?.name&&t.push(n.name.toLowerCase()),e.stockNo&&t.push(e.stockNo[0]),S(e.id,...t)},w=e=>{let t=e;return t.length>0?t[0].trim():``},T=(e=`en`,t,n)=>{if(!t||!n||t.length<=0)return``;let r=[...t].sort(D);if(e){let t=r.findIndex(t=>t.locale===e);if(t){let e=r.splice(t,1);r.unshift(e[0])}}for(let e of r){let t=e[n];if(!(Array.isArray(t)&&t.length===0)&&t)return t}return``},E=(e,t,n)=>{if(!t||!n||t.length<=0)return``;let r=[...t].sort(D);if(e){let t=r.findIndex(t=>t.locale===e);if(t){let e=r.splice(t,1);r.unshift(e[0])}}let i=``;for(let e of r){let t=e[n];if(t){i=String(t);break}}return i},D=(e,t)=>e.priority<t.priority?-1:e.priority>t.priority?1:0,O=()=>(0,o.customAlphabet)(`0123456789abcdefghijklmnopqrstuvwxyz`,5)(),k=e=>{for(let t=0;t<e;t++)console.log(O())},A=()=>typeof window>`u`?[]:JSON.parse(localStorage.getItem(`search-history`)||`[]`),j=e=>{let t=(0,a.uniq)([e,...A()]).slice(0,10);return localStorage.setItem(`search-history`,JSON.stringify(t)),t},M=e=>{let t=A();return t.splice(e,1),localStorage.setItem(`search-history`,JSON.stringify(t)),t},N=()=>{localStorage.setItem(`search-history`,JSON.stringify([]))},P=(e,t,n)=>{if(e){let r;r=Array.isArray(e)?e[0]:e;try{return t(r)}catch{return n}}return n},F=(e,t)=>{let{[t]:n,...r}=e;return r},I=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>!t.includes(e))),L=(e,t)=>(0,a.intersection)(e,t).length>0,R=e=>e.endsWith(`/search`),z=e=>R(e)?e:`${e}/search`.replace(`//`,`/`),B=e=>e.replace(`/search`,``).replace(`//`,`/`),V=(e,t)=>{let n=new URLSearchParams(e);return n.delete(t),Object.fromEntries(n)},H=e=>e.split(`:`).pop()?.split(`.`).pop(),U=(e,...t)=>[e,t].flat().join(`.`).replace(`:.`,`.`);function W(e,t=0){if(e==0)return`0 Bytes`;let n=1024,r=t,i=[`Bytes`,`KB`,`MB`,`GB`,`TB`,`PB`,`EB`,`ZB`,`YB`],a=Math.floor(Math.log(e)/Math.log(n));return parseFloat((e/n**+a).toFixed(r))+` `+i[a]}const G=e=>e.split(`.`).slice(0,-1).join(`.`),K=e=>e.split(`.`).pop(),q=(e,t)=>{let n={directory:``,filename:``,extension:``,filenameWithoutExtension:``},r=e.lastIndexOf(`/`),i=r>=0?e.substring(r+1):e,a=i.lastIndexOf(`.`),o=a>0?i.substring(a+1):``,s=a>0?i.substring(0,a):i;if(n.filename=i,n.extension=o,n.filenameWithoutExtension=s,e.startsWith(`http`)){let r=t?`/static/`:`/media/`,i=e.indexOf(r);if(i!==-1){let t=e.substring(i+r.length),a=t.lastIndexOf(`/`);return n.directory=a===-1?``:t.substring(0,a),n}}return n.directory=r===-1?``:e.substring(0,r),n},J=(e=`en`,t)=>{if(t.length<=0)return`-`;let n=t[0];return n?Y(e,n.i18n):`-`},Y=(e=`en`,t)=>{if(t.length===0)return``;let n=T(e,t,`address1`)?.replace(`대한민국`,``)||``,r=t.find(t=>t.locale===e)?.address2,i=[n];return e===`ko`?i.push(r):i.unshift(r),i.filter(Boolean).join(`, `).trim()},X=e=>{let t=0;for(let n of e)t+=n.weight;let n=Math.random()*t,r=0;for(let t of e)if(r+=t.weight,n<r)return t;return e[e.length-1]};exports.appendSearchPath=z,exports.calcPageCount=h,exports.clearQueryByKey=V,exports.clearSearchPath=B,exports.comparePriorityAsc=D,exports.composeKey=U,exports.deleteAllSearchHistory=N,exports.deleteSearchHistory=M,exports.displayDatetime=d,exports.existLeastOne=L,exports.formatBytes=W,exports.formatI18nNumber=x,exports.genNanoID=O,exports.getCookie=f,exports.getFileExtension=K,exports.getFilename=G,exports.getFirstLocationAddress=J,exports.getFullAddress=Y,exports.getI18nKey=H,exports.getI18nValue=E,exports.getI18nValues=T,exports.getModelName=w,exports.getSearchHistory=A,exports.insertSearchHistory=j,exports.isSearchPage=R,exports.link=m,exports.loadExLib=y,exports.parsePath=q,exports.parseQuery=P,exports.printNanoID=k,exports.productSlugify=C,exports.randomNum=v,exports.recomposeI18nNumber=b,exports.selectItemByWeight=X,exports.setCookies=p,exports.shuffle=g,exports.slugify=S,exports.withoutProperties=I,exports.withoutProperty=F;
1
+ const e=require(`../chunk-Bmb41Sf3.cjs`);let t=require(`js-cookie`);t=e.t(t);let n=require(`query-string`);n=e.t(n);let r=require(`lodash-es`),i=require(`slug`);i=e.t(i);let a=require(`google-libphonenumber`);a=e.t(a);let o=require(`dayjs`);o=e.t(o),require(`dayjs/locale/ko.js`);let s=require(`dayjs/plugin/relativeTime.js`);s=e.t(s);let c=require(`nanoid`);const l=e=>t.default.get(e),u=(e,n,r)=>t.default.set(e,n,r),d=()=>typeof window>`u`?[]:JSON.parse(localStorage.getItem(`search-history`)||`[]`),f=e=>{let t=(0,r.uniq)([e,...d()]).slice(0,10);return localStorage.setItem(`search-history`,JSON.stringify(t)),t},p=e=>{let t=d();return t.splice(e,1),localStorage.setItem(`search-history`,JSON.stringify(t)),t},m=()=>{localStorage.setItem(`search-history`,JSON.stringify([]))},h=e=>e.endsWith(`/search`),g=e=>h(e)?e:`${e}/search`.replace(`//`,`/`),_=e=>e.replace(`/search`,``).replace(`//`,`/`),v=(e,t)=>{let n=new URLSearchParams(e);return n.delete(t),Object.fromEntries(n)},y=a.default.PhoneNumberFormat,b=a.default.PhoneNumberUtil.getInstance();i.default.extend({'"':`-`,"”":`-`,"“":`-`,"•":`----`}),i.default.setLocale(`en`);const x=(e,t=[])=>{if(typeof window>`u`)return``;let{hash:r,search:i}=window.location,a=n.default.parse(i);Object.keys(e).forEach(t=>{e[t]?a[t]=e[t]:delete a[t]});let o={...a};return Object.keys(a).forEach(e=>{t.includes(e)&&delete o[e]}),`?${n.default.stringify(o,{encode:!0})}${r}`},S=(e,t)=>{let n=0;return e%t===0&&(n=e/t),n=Math.ceil(e/t),n<1&&(n=1),n},C=e=>{let t=[...e];for(let e=t.length-1;e>0;e--){let n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t},w=e=>{let t=document.getElementById(`naverMapLib`);if(!t){let t=document.createElement(`script`);t.src=`https://oapi.map.naver.com/openapi/v3/maps.js?ncpKeyId=ecs1pyoo9b`,t.id=`naverMapLib`,document.body.appendChild(t),t.onload=()=>{e&&e()}}t&&e&&e()},T=(e,t,n)=>t?e===`ko`&&n&&n!==`82`||e!==`ko`&&n?`+${n}-${t.replace(/^0/,``)}`:t:`-`,E=({phone:e,country:t={callingCode:`82`,alpha2Code:`KR`},format:n=y.INTERNATIONAL,locale:r})=>{if(!e||e===`-`)return`-`;try{let i=b.parseAndKeepRawInput(e,t?.alpha2Code||`KR`),a=i.getCountryCode();return r===`ko`&&t?.alpha2Code===`KR`&&a===82?b.format(i,y.NATIONAL):b.format(i,n)}catch{return T(r||`en`,e,t?.callingCode)}},D=(e,...t)=>{let n=`${e}`;return t.forEach(e=>{e&&(n=`${n}-${(0,i.default)(e)}`)}),n},O=e=>{let t=[];e.i18n?.forEach(e=>{e.locale===`en`&&e.name&&t.push(e.name)});let n=e.series?.i18n.find(e=>e.locale===`en`);return n?.name&&t.push(n.name.toLowerCase()),e.stockNo&&t.push(e.stockNo[0]),D(e.id,...t)},k=e=>{let t=e;return t.length>0?t[0].trim():``},A=(e=`en`,t,n)=>{if(!t||!n||t.length<=0)return``;let r=[...t].sort(M);if(e){let t=r.findIndex(t=>t.locale===e);if(t){let e=r.splice(t,1);r.unshift(e[0])}}for(let e of r){let t=e[n];if(!(Array.isArray(t)&&t.length===0)&&t)return t}return``},j=(e,t,n)=>{if(!t||!n||t.length<=0)return``;let r=[...t].sort(M);if(e){let t=r.findIndex(t=>t.locale===e);if(t){let e=r.splice(t,1);r.unshift(e[0])}}let i=``;for(let e of r){let t=e[n];if(t){i=String(t);break}}return i},M=(e,t)=>e.priority<t.priority?-1:e.priority>t.priority?1:0,N=(e,t,n)=>{if(e){let r;r=Array.isArray(e)?e[0]:e;try{return t(r)}catch{return n}}return n},P=(e,t)=>{let{[t]:n,...r}=e;return r},F=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>!t.includes(e))),I=(e,t)=>(0,r.intersection)(e,t).length>0,L=e=>e.split(`:`).pop()?.split(`.`).pop(),R=(e,...t)=>[e,t].flat().join(`.`).replace(`:.`,`.`),z=(e=`en`,t)=>{if(t.length<=0)return`-`;let n=t[0];return n?B(e,n.i18n):`-`},B=(e=`en`,t)=>{if(t.length===0)return``;let n=A(e,t,`address1`)?.replace(`대한민국`,``)||``,r=t.find(t=>t.locale===e)?.address2,i=[n];return e===`ko`?i.push(r):i.unshift(r),i.filter(Boolean).join(`, `).trim()},V=e=>{let t=0;for(let n of e)t+=n.weight;let n=Math.random()*t,r=0;for(let t of e)if(r+=t.weight,n<r)return t;return e[e.length-1]},H=e=>new Promise(t=>setTimeout(t,e));function U(e,t=0){if(e==0)return`0 Bytes`;let n=1024,r=t,i=[`Bytes`,`KB`,`MB`,`GB`,`TB`,`PB`,`EB`,`ZB`,`YB`],a=Math.floor(Math.log(e)/Math.log(n));return parseFloat((e/n**+a).toFixed(r))+` `+i[a]}const W=e=>e.split(`.`).slice(0,-1).join(`.`),G=e=>e.split(`.`).pop(),K=(e,t)=>{let n={directory:``,filename:``,extension:``,filenameWithoutExtension:``},r=e.lastIndexOf(`/`),i=r>=0?e.substring(r+1):e,a=i.lastIndexOf(`.`),o=a>0?i.substring(a+1):``,s=a>0?i.substring(0,a):i;if(n.filename=i,n.extension=o,n.filenameWithoutExtension=s,e.startsWith(`http`)){let r=t?`/static/`:`/media/`,i=e.indexOf(r);if(i!==-1){let t=e.substring(i+r.length),a=t.lastIndexOf(`/`);return n.directory=a===-1?``:t.substring(0,a),n}}return n.directory=r===-1?``:e.substring(0,r),n};o.default.extend(s.default);const q=(e,t=`YYYY-MM-DD`,n=`en`)=>{let r=(0,o.default)(e).locale(n);return(0,o.default)().diff(r,`hour`)<12?r.fromNow():r.format(t)},J=(e,t)=>{let n=[];for(let r=e;r<t;r++)n.push(r);return n},Y=(e,t,n=1)=>{let r=[],i=J(e,t);for(;r.length<n;){let t=Math.ceil(e),n=Math.floor(i.length),a=Math.floor(Math.random()*(n-t))+t,o=i.splice(a,1);r.push(o[0])}return[...r]},X=()=>(0,c.customAlphabet)(`0123456789abcdefghijklmnopqrstuvwxyz`,5)(),Z=e=>{for(let t=0;t<e;t++)console.log(X())};exports.appendSearchPath=g,exports.calcPageCount=S,exports.clearQueryByKey=v,exports.clearSearchPath=_,exports.comparePriorityAsc=M,exports.composeKey=R,exports.deleteAllSearchHistory=m,exports.deleteSearchHistory=p,exports.displayDatetime=q,exports.existLeastOne=I,exports.formatBytes=U,exports.formatI18nNumber=E,exports.genNanoID=X,exports.getCookie=l,exports.getFileExtension=G,exports.getFilename=W,exports.getFirstLocationAddress=z,exports.getFullAddress=B,exports.getI18nKey=L,exports.getI18nValue=j,exports.getI18nValues=A,exports.getModelName=k,exports.getSearchHistory=d,exports.insertSearchHistory=f,exports.isSearchPage=h,exports.link=x,exports.loadExLib=w,exports.parsePath=K,exports.parseQuery=N,exports.printNanoID=Z,exports.productSlugify=O,exports.randomNum=Y,exports.recomposeI18nNumber=T,exports.selectItemByWeight=V,exports.setCookies=u,exports.shuffle=C,exports.sleep=H,exports.slugify=D,exports.withoutProperties=F,exports.withoutProperty=P;
@@ -1,11 +1,21 @@
1
- //#region src/util/common.d.ts
2
- declare const displayDatetime: (date: string, format?: string, locale?: string) => string;
1
+ //#region src/util/browser.d.ts
3
2
  declare const getCookie: (key: string) => string | undefined;
4
3
  declare const setCookies: (key: string, value: string, options?: Cookies.CookieAttributes) => string | undefined;
4
+ declare const getSearchHistory: () => string[];
5
+ declare const insertSearchHistory: (item: string) => string[];
6
+ declare const deleteSearchHistory: (index: number) => string[];
7
+ declare const deleteAllSearchHistory: () => void;
8
+ declare const isSearchPage: (pathname: string) => boolean;
9
+ declare const appendSearchPath: (pathname: string) => string;
10
+ declare const clearSearchPath: (pathname: string) => string;
11
+ declare const clearQueryByKey: (query: Record<string, any>, key: string) => {
12
+ [k: string]: string;
13
+ };
14
+ //#endregion
15
+ //#region src/util/common.d.ts
5
16
  declare const link: (param: Record<string, string>, deleteKeys?: string[]) => string;
6
17
  declare const calcPageCount: (total: number, perPage: number) => number;
7
18
  declare const shuffle: <T>(arr: T[]) => T[];
8
- declare const randomNum: (min: number, max: number, count?: number) => number[];
9
19
  declare const loadExLib: (callback: () => void) => void;
10
20
  declare const recomposeI18nNumber: (locale: string, number?: string | null, i18nNumber?: string | null) => string;
11
21
  interface Country {
@@ -52,35 +62,13 @@ declare const getI18nValue: <T extends {
52
62
  }>(locale?: string, values?: T[], key?: keyof T) => string;
53
63
  declare const comparePriorityAsc: <T extends {
54
64
  priority: number;
55
- }>(a: T, b: T) => 0 | 1 | -1;
56
- declare const genNanoID: () => string;
57
- declare const printNanoID: (cnt: number) => void;
58
- declare const getSearchHistory: () => string[];
59
- declare const insertSearchHistory: (item: string) => string[];
60
- declare const deleteSearchHistory: (index: number) => string[];
61
- declare const deleteAllSearchHistory: () => void;
65
+ }>(a: T, b: T) => 1 | 0 | -1;
62
66
  declare const parseQuery: <T, F = T>(q: string | string[] | undefined | null, conv: (v: string) => T, fallback: F) => T | F;
63
67
  declare const withoutProperty: <T>(obj: T, property: keyof T) => Omit<T, keyof T>;
64
68
  declare const withoutProperties: <T extends Record<string, unknown>>(obj: T, properties: Array<keyof T>) => T;
65
69
  declare const existLeastOne: <T>(a: T[], b: T[]) => boolean;
66
- declare const isSearchPage: (pathname: string) => boolean;
67
- declare const appendSearchPath: (pathname: string) => string;
68
- declare const clearSearchPath: (pathname: string) => string;
69
- declare const clearQueryByKey: (query: Record<string, any>, key: string) => {
70
- [k: string]: string;
71
- };
72
70
  declare const getI18nKey: (key: string) => string | undefined;
73
71
  declare const composeKey: (prefix?: Array<string | number> | string, ...keys: Array<string | number>) => string;
74
- declare function formatBytes(bytes: number, decimals?: number): string;
75
- declare const getFilename: (s: string) => string;
76
- declare const getFileExtension: (s: string) => string | undefined;
77
- interface PathInfo {
78
- directory: string;
79
- filename: string;
80
- extension: string;
81
- filenameWithoutExtension: string;
82
- }
83
- declare const parsePath: (filepath: string, isStatic?: boolean) => PathInfo;
84
72
  interface Location<I extends LocationI18n = LocationI18n> {
85
73
  i18n: I[];
86
74
  }
@@ -93,5 +81,26 @@ declare const getFullAddress: (locale: string | undefined, values: LocationI18n[
93
81
  declare const selectItemByWeight: <T extends {
94
82
  weight: number;
95
83
  }>(itemsWithWeights: T[]) => T;
84
+ declare const sleep: (ms: number) => Promise<unknown>;
85
+ //#endregion
86
+ //#region src/util/file.d.ts
87
+ declare function formatBytes(bytes: number, decimals?: number): string;
88
+ declare const getFilename: (s: string) => string;
89
+ declare const getFileExtension: (s: string) => string | undefined;
90
+ interface PathInfo {
91
+ directory: string;
92
+ filename: string;
93
+ extension: string;
94
+ filenameWithoutExtension: string;
95
+ }
96
+ declare const parsePath: (filepath: string, isStatic?: boolean) => PathInfo;
97
+ //#endregion
98
+ //#region src/util/date.d.ts
99
+ declare const displayDatetime: (date: string, format?: string, locale?: string) => string;
100
+ //#endregion
101
+ //#region src/util/generator.d.ts
102
+ declare const randomNum: (min: number, max: number, count?: number) => number[];
103
+ declare const genNanoID: () => string;
104
+ declare const printNanoID: (cnt: number) => void;
96
105
  //#endregion
97
- export { I18nNumberProps, appendSearchPath, calcPageCount, clearQueryByKey, clearSearchPath, comparePriorityAsc, composeKey, deleteAllSearchHistory, deleteSearchHistory, displayDatetime, existLeastOne, formatBytes, formatI18nNumber, genNanoID, getCookie, getFileExtension, getFilename, getFirstLocationAddress, getFullAddress, getI18nKey, getI18nValue, getI18nValues, getModelName, getSearchHistory, insertSearchHistory, isSearchPage, link, loadExLib, parsePath, parseQuery, printNanoID, productSlugify, randomNum, recomposeI18nNumber, selectItemByWeight, setCookies, shuffle, slugify, withoutProperties, withoutProperty };
106
+ export { I18nNumberProps, appendSearchPath, calcPageCount, clearQueryByKey, clearSearchPath, comparePriorityAsc, composeKey, deleteAllSearchHistory, deleteSearchHistory, displayDatetime, existLeastOne, formatBytes, formatI18nNumber, genNanoID, getCookie, getFileExtension, getFilename, getFirstLocationAddress, getFullAddress, getI18nKey, getI18nValue, getI18nValues, getModelName, getSearchHistory, insertSearchHistory, isSearchPage, link, loadExLib, parsePath, parseQuery, printNanoID, productSlugify, randomNum, recomposeI18nNumber, selectItemByWeight, setCookies, shuffle, sleep, slugify, withoutProperties, withoutProperty };
@@ -1,13 +1,23 @@
1
1
  import "dayjs/locale/ko.js";
2
2
 
3
- //#region src/util/common.d.ts
4
- declare const displayDatetime: (date: string, format?: string, locale?: string) => string;
3
+ //#region src/util/browser.d.ts
5
4
  declare const getCookie: (key: string) => string | undefined;
6
5
  declare const setCookies: (key: string, value: string, options?: Cookies.CookieAttributes) => string | undefined;
6
+ declare const getSearchHistory: () => string[];
7
+ declare const insertSearchHistory: (item: string) => string[];
8
+ declare const deleteSearchHistory: (index: number) => string[];
9
+ declare const deleteAllSearchHistory: () => void;
10
+ declare const isSearchPage: (pathname: string) => boolean;
11
+ declare const appendSearchPath: (pathname: string) => string;
12
+ declare const clearSearchPath: (pathname: string) => string;
13
+ declare const clearQueryByKey: (query: Record<string, any>, key: string) => {
14
+ [k: string]: string;
15
+ };
16
+ //#endregion
17
+ //#region src/util/common.d.ts
7
18
  declare const link: (param: Record<string, string>, deleteKeys?: string[]) => string;
8
19
  declare const calcPageCount: (total: number, perPage: number) => number;
9
20
  declare const shuffle: <T>(arr: T[]) => T[];
10
- declare const randomNum: (min: number, max: number, count?: number) => number[];
11
21
  declare const loadExLib: (callback: () => void) => void;
12
22
  declare const recomposeI18nNumber: (locale: string, number?: string | null, i18nNumber?: string | null) => string;
13
23
  interface Country {
@@ -54,35 +64,13 @@ declare const getI18nValue: <T extends {
54
64
  }>(locale?: string, values?: T[], key?: keyof T) => string;
55
65
  declare const comparePriorityAsc: <T extends {
56
66
  priority: number;
57
- }>(a: T, b: T) => 0 | 1 | -1;
58
- declare const genNanoID: () => string;
59
- declare const printNanoID: (cnt: number) => void;
60
- declare const getSearchHistory: () => string[];
61
- declare const insertSearchHistory: (item: string) => string[];
62
- declare const deleteSearchHistory: (index: number) => string[];
63
- declare const deleteAllSearchHistory: () => void;
67
+ }>(a: T, b: T) => 1 | 0 | -1;
64
68
  declare const parseQuery: <T, F = T>(q: string | string[] | undefined | null, conv: (v: string) => T, fallback: F) => T | F;
65
69
  declare const withoutProperty: <T>(obj: T, property: keyof T) => Omit<T, keyof T>;
66
70
  declare const withoutProperties: <T extends Record<string, unknown>>(obj: T, properties: Array<keyof T>) => T;
67
71
  declare const existLeastOne: <T>(a: T[], b: T[]) => boolean;
68
- declare const isSearchPage: (pathname: string) => boolean;
69
- declare const appendSearchPath: (pathname: string) => string;
70
- declare const clearSearchPath: (pathname: string) => string;
71
- declare const clearQueryByKey: (query: Record<string, any>, key: string) => {
72
- [k: string]: string;
73
- };
74
72
  declare const getI18nKey: (key: string) => string | undefined;
75
73
  declare const composeKey: (prefix?: Array<string | number> | string, ...keys: Array<string | number>) => string;
76
- declare function formatBytes(bytes: number, decimals?: number): string;
77
- declare const getFilename: (s: string) => string;
78
- declare const getFileExtension: (s: string) => string | undefined;
79
- interface PathInfo {
80
- directory: string;
81
- filename: string;
82
- extension: string;
83
- filenameWithoutExtension: string;
84
- }
85
- declare const parsePath: (filepath: string, isStatic?: boolean) => PathInfo;
86
74
  interface Location<I extends LocationI18n = LocationI18n> {
87
75
  i18n: I[];
88
76
  }
@@ -95,5 +83,26 @@ declare const getFullAddress: (locale: string | undefined, values: LocationI18n[
95
83
  declare const selectItemByWeight: <T extends {
96
84
  weight: number;
97
85
  }>(itemsWithWeights: T[]) => T;
86
+ declare const sleep: (ms: number) => Promise<unknown>;
87
+ //#endregion
88
+ //#region src/util/file.d.ts
89
+ declare function formatBytes(bytes: number, decimals?: number): string;
90
+ declare const getFilename: (s: string) => string;
91
+ declare const getFileExtension: (s: string) => string | undefined;
92
+ interface PathInfo {
93
+ directory: string;
94
+ filename: string;
95
+ extension: string;
96
+ filenameWithoutExtension: string;
97
+ }
98
+ declare const parsePath: (filepath: string, isStatic?: boolean) => PathInfo;
99
+ //#endregion
100
+ //#region src/util/date.d.ts
101
+ declare const displayDatetime: (date: string, format?: string, locale?: string) => string;
102
+ //#endregion
103
+ //#region src/util/generator.d.ts
104
+ declare const randomNum: (min: number, max: number, count?: number) => number[];
105
+ declare const genNanoID: () => string;
106
+ declare const printNanoID: (cnt: number) => void;
98
107
  //#endregion
99
- export { I18nNumberProps, appendSearchPath, calcPageCount, clearQueryByKey, clearSearchPath, comparePriorityAsc, composeKey, deleteAllSearchHistory, deleteSearchHistory, displayDatetime, existLeastOne, formatBytes, formatI18nNumber, genNanoID, getCookie, getFileExtension, getFilename, getFirstLocationAddress, getFullAddress, getI18nKey, getI18nValue, getI18nValues, getModelName, getSearchHistory, insertSearchHistory, isSearchPage, link, loadExLib, parsePath, parseQuery, printNanoID, productSlugify, randomNum, recomposeI18nNumber, selectItemByWeight, setCookies, shuffle, slugify, withoutProperties, withoutProperty };
108
+ export { I18nNumberProps, appendSearchPath, calcPageCount, clearQueryByKey, clearSearchPath, comparePriorityAsc, composeKey, deleteAllSearchHistory, deleteSearchHistory, displayDatetime, existLeastOne, formatBytes, formatI18nNumber, genNanoID, getCookie, getFileExtension, getFilename, getFirstLocationAddress, getFullAddress, getI18nKey, getI18nValue, getI18nValues, getModelName, getSearchHistory, insertSearchHistory, isSearchPage, link, loadExLib, parsePath, parseQuery, printNanoID, productSlugify, randomNum, recomposeI18nNumber, selectItemByWeight, setCookies, shuffle, sleep, slugify, withoutProperties, withoutProperty };
@@ -1 +1 @@
1
- import e from"js-cookie";import t from"query-string";import n from"dayjs";import"dayjs/locale/ko.js";import r from"dayjs/plugin/relativeTime.js";import{intersection as i,uniq as a}from"lodash-es";import{customAlphabet as o}from"nanoid";import s from"slugify";import c from"google-libphonenumber";const l=c.PhoneNumberFormat,u=c.PhoneNumberUtil.getInstance();n.extend(r);const d=(e,t=`YYYY-MM-DD`,r=`en`)=>{let i=n(e).locale(r);return n().diff(i,`hour`)<12?i.fromNow():i.format(t)},f=t=>e.get(t),p=(t,n,r)=>e.set(t,n,r),m=(e,n=[])=>{if(typeof window>`u`)return``;let{hash:r,search:i}=window.location,a=t.parse(i);Object.keys(e).forEach(t=>{e[t]?a[t]=e[t]:delete a[t]});let o={...a};return Object.keys(a).forEach(e=>{n.includes(e)&&delete o[e]}),`?${t.stringify(o,{encode:!0})}${r}`},h=(e,t)=>{let n=0;return e%t===0&&(n=e/t),n=Math.ceil(e/t),n<1&&(n=1),n},g=e=>{let t=[...e];for(let e=t.length-1;e>0;e--){let n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t},_=(e,t)=>{let n=[];for(let r=e;r<t;r++)n.push(r);return n},v=(e,t,n=1)=>{let r=[],i=_(e,t);for(;r.length<n;){let t=Math.ceil(e),n=Math.floor(i.length),a=Math.floor(Math.random()*(n-t))+t,o=i.splice(a,1);r.push(o[0])}return[...r]},y=e=>{let t=document.getElementById(`naverMapLib`);if(!t){let t=document.createElement(`script`);t.src=`https://oapi.map.naver.com/openapi/v3/maps.js?ncpKeyId=ecs1pyoo9b`,t.id=`naverMapLib`,document.body.appendChild(t),t.onload=()=>{e&&e()}}t&&e&&e()},b=(e,t,n)=>t?e===`ko`&&n&&n!==`82`||e!==`ko`&&n?`+${n}-${t.replace(/^0/,``)}`:t:`-`,x=({phone:e,country:t={callingCode:`82`,alpha2Code:`KR`},format:n=l.INTERNATIONAL,locale:r})=>{if(!e||e===`-`)return`-`;try{let i=u.parseAndKeepRawInput(e,t?.alpha2Code||`KR`),a=i.getCountryCode();return r===`ko`&&t?.alpha2Code===`KR`&&a===82?u.format(i,l.NATIONAL):u.format(i,n)}catch{return b(r||`en`,e,t?.callingCode)}},S=(e,...t)=>{s.extend({'"':`-`,"”":`-`,"“":`-`,"•":`----`});let n=`${e}`;return t.forEach(e=>{e&&(n=`${n}-${s(e,{lower:!0,trim:!0,locale:`en`,strict:!0})}`)}),n},C=e=>{let t=[];e.i18n?.forEach(e=>{e.locale===`en`&&e.name&&t.push(e.name)});let n=e.series?.i18n.find(e=>e.locale===`en`);return n?.name&&t.push(n.name.toLowerCase()),e.stockNo&&t.push(e.stockNo[0]),S(e.id,...t)},w=e=>{let t=e;return t.length>0?t[0].trim():``},T=(e=`en`,t,n)=>{if(!t||!n||t.length<=0)return``;let r=[...t].sort(D);if(e){let t=r.findIndex(t=>t.locale===e);if(t){let e=r.splice(t,1);r.unshift(e[0])}}for(let e of r){let t=e[n];if(!(Array.isArray(t)&&t.length===0)&&t)return t}return``},E=(e,t,n)=>{if(!t||!n||t.length<=0)return``;let r=[...t].sort(D);if(e){let t=r.findIndex(t=>t.locale===e);if(t){let e=r.splice(t,1);r.unshift(e[0])}}let i=``;for(let e of r){let t=e[n];if(t){i=String(t);break}}return i},D=(e,t)=>e.priority<t.priority?-1:e.priority>t.priority?1:0,O=()=>o(`0123456789abcdefghijklmnopqrstuvwxyz`,5)(),k=e=>{for(let t=0;t<e;t++)console.log(O())},A=()=>typeof window>`u`?[]:JSON.parse(localStorage.getItem(`search-history`)||`[]`),j=e=>{let t=a([e,...A()]).slice(0,10);return localStorage.setItem(`search-history`,JSON.stringify(t)),t},M=e=>{let t=A();return t.splice(e,1),localStorage.setItem(`search-history`,JSON.stringify(t)),t},N=()=>{localStorage.setItem(`search-history`,JSON.stringify([]))},P=(e,t,n)=>{if(e){let r;r=Array.isArray(e)?e[0]:e;try{return t(r)}catch{return n}}return n},F=(e,t)=>{let{[t]:n,...r}=e;return r},I=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>!t.includes(e))),L=(e,t)=>i(e,t).length>0,R=e=>e.endsWith(`/search`),z=e=>R(e)?e:`${e}/search`.replace(`//`,`/`),B=e=>e.replace(`/search`,``).replace(`//`,`/`),V=(e,t)=>{let n=new URLSearchParams(e);return n.delete(t),Object.fromEntries(n)},H=e=>e.split(`:`).pop()?.split(`.`).pop(),U=(e,...t)=>[e,t].flat().join(`.`).replace(`:.`,`.`);function W(e,t=0){if(e==0)return`0 Bytes`;let n=1024,r=t,i=[`Bytes`,`KB`,`MB`,`GB`,`TB`,`PB`,`EB`,`ZB`,`YB`],a=Math.floor(Math.log(e)/Math.log(n));return parseFloat((e/n**+a).toFixed(r))+` `+i[a]}const G=e=>e.split(`.`).slice(0,-1).join(`.`),K=e=>e.split(`.`).pop(),q=(e,t)=>{let n={directory:``,filename:``,extension:``,filenameWithoutExtension:``},r=e.lastIndexOf(`/`),i=r>=0?e.substring(r+1):e,a=i.lastIndexOf(`.`),o=a>0?i.substring(a+1):``,s=a>0?i.substring(0,a):i;if(n.filename=i,n.extension=o,n.filenameWithoutExtension=s,e.startsWith(`http`)){let r=t?`/static/`:`/media/`,i=e.indexOf(r);if(i!==-1){let t=e.substring(i+r.length),a=t.lastIndexOf(`/`);return n.directory=a===-1?``:t.substring(0,a),n}}return n.directory=r===-1?``:e.substring(0,r),n},J=(e=`en`,t)=>{if(t.length<=0)return`-`;let n=t[0];return n?Y(e,n.i18n):`-`},Y=(e=`en`,t)=>{if(t.length===0)return``;let n=T(e,t,`address1`)?.replace(`대한민국`,``)||``,r=t.find(t=>t.locale===e)?.address2,i=[n];return e===`ko`?i.push(r):i.unshift(r),i.filter(Boolean).join(`, `).trim()},X=e=>{let t=0;for(let n of e)t+=n.weight;let n=Math.random()*t,r=0;for(let t of e)if(r+=t.weight,n<r)return t;return e[e.length-1]};export{z as appendSearchPath,h as calcPageCount,V as clearQueryByKey,B as clearSearchPath,D as comparePriorityAsc,U as composeKey,N as deleteAllSearchHistory,M as deleteSearchHistory,d as displayDatetime,L as existLeastOne,W as formatBytes,x as formatI18nNumber,O as genNanoID,f as getCookie,K as getFileExtension,G as getFilename,J as getFirstLocationAddress,Y as getFullAddress,H as getI18nKey,E as getI18nValue,T as getI18nValues,w as getModelName,A as getSearchHistory,j as insertSearchHistory,R as isSearchPage,m as link,y as loadExLib,q as parsePath,P as parseQuery,k as printNanoID,C as productSlugify,v as randomNum,b as recomposeI18nNumber,X as selectItemByWeight,p as setCookies,g as shuffle,S as slugify,I as withoutProperties,F as withoutProperty};
1
+ import e from"js-cookie";import t from"query-string";import{intersection as n,uniq as r}from"lodash-es";import i from"slug";import a from"google-libphonenumber";import o from"dayjs";import"dayjs/locale/ko.js";import s from"dayjs/plugin/relativeTime.js";import{customAlphabet as c}from"nanoid";const l=t=>e.get(t),u=(t,n,r)=>e.set(t,n,r),d=()=>typeof window>`u`?[]:JSON.parse(localStorage.getItem(`search-history`)||`[]`),f=e=>{let t=r([e,...d()]).slice(0,10);return localStorage.setItem(`search-history`,JSON.stringify(t)),t},p=e=>{let t=d();return t.splice(e,1),localStorage.setItem(`search-history`,JSON.stringify(t)),t},m=()=>{localStorage.setItem(`search-history`,JSON.stringify([]))},h=e=>e.endsWith(`/search`),g=e=>h(e)?e:`${e}/search`.replace(`//`,`/`),_=e=>e.replace(`/search`,``).replace(`//`,`/`),v=(e,t)=>{let n=new URLSearchParams(e);return n.delete(t),Object.fromEntries(n)},y=a.PhoneNumberFormat,b=a.PhoneNumberUtil.getInstance();i.extend({'"':`-`,"”":`-`,"“":`-`,"•":`----`}),i.setLocale(`en`);const x=(e,n=[])=>{if(typeof window>`u`)return``;let{hash:r,search:i}=window.location,a=t.parse(i);Object.keys(e).forEach(t=>{e[t]?a[t]=e[t]:delete a[t]});let o={...a};return Object.keys(a).forEach(e=>{n.includes(e)&&delete o[e]}),`?${t.stringify(o,{encode:!0})}${r}`},S=(e,t)=>{let n=0;return e%t===0&&(n=e/t),n=Math.ceil(e/t),n<1&&(n=1),n},C=e=>{let t=[...e];for(let e=t.length-1;e>0;e--){let n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t},w=e=>{let t=document.getElementById(`naverMapLib`);if(!t){let t=document.createElement(`script`);t.src=`https://oapi.map.naver.com/openapi/v3/maps.js?ncpKeyId=ecs1pyoo9b`,t.id=`naverMapLib`,document.body.appendChild(t),t.onload=()=>{e&&e()}}t&&e&&e()},T=(e,t,n)=>t?e===`ko`&&n&&n!==`82`||e!==`ko`&&n?`+${n}-${t.replace(/^0/,``)}`:t:`-`,E=({phone:e,country:t={callingCode:`82`,alpha2Code:`KR`},format:n=y.INTERNATIONAL,locale:r})=>{if(!e||e===`-`)return`-`;try{let i=b.parseAndKeepRawInput(e,t?.alpha2Code||`KR`),a=i.getCountryCode();return r===`ko`&&t?.alpha2Code===`KR`&&a===82?b.format(i,y.NATIONAL):b.format(i,n)}catch{return T(r||`en`,e,t?.callingCode)}},D=(e,...t)=>{let n=`${e}`;return t.forEach(e=>{e&&(n=`${n}-${i(e)}`)}),n},O=e=>{let t=[];e.i18n?.forEach(e=>{e.locale===`en`&&e.name&&t.push(e.name)});let n=e.series?.i18n.find(e=>e.locale===`en`);return n?.name&&t.push(n.name.toLowerCase()),e.stockNo&&t.push(e.stockNo[0]),D(e.id,...t)},k=e=>{let t=e;return t.length>0?t[0].trim():``},A=(e=`en`,t,n)=>{if(!t||!n||t.length<=0)return``;let r=[...t].sort(M);if(e){let t=r.findIndex(t=>t.locale===e);if(t){let e=r.splice(t,1);r.unshift(e[0])}}for(let e of r){let t=e[n];if(!(Array.isArray(t)&&t.length===0)&&t)return t}return``},j=(e,t,n)=>{if(!t||!n||t.length<=0)return``;let r=[...t].sort(M);if(e){let t=r.findIndex(t=>t.locale===e);if(t){let e=r.splice(t,1);r.unshift(e[0])}}let i=``;for(let e of r){let t=e[n];if(t){i=String(t);break}}return i},M=(e,t)=>e.priority<t.priority?-1:e.priority>t.priority?1:0,N=(e,t,n)=>{if(e){let r;r=Array.isArray(e)?e[0]:e;try{return t(r)}catch{return n}}return n},P=(e,t)=>{let{[t]:n,...r}=e;return r},F=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>!t.includes(e))),I=(e,t)=>n(e,t).length>0,L=e=>e.split(`:`).pop()?.split(`.`).pop(),R=(e,...t)=>[e,t].flat().join(`.`).replace(`:.`,`.`),z=(e=`en`,t)=>{if(t.length<=0)return`-`;let n=t[0];return n?B(e,n.i18n):`-`},B=(e=`en`,t)=>{if(t.length===0)return``;let n=A(e,t,`address1`)?.replace(`대한민국`,``)||``,r=t.find(t=>t.locale===e)?.address2,i=[n];return e===`ko`?i.push(r):i.unshift(r),i.filter(Boolean).join(`, `).trim()},V=e=>{let t=0;for(let n of e)t+=n.weight;let n=Math.random()*t,r=0;for(let t of e)if(r+=t.weight,n<r)return t;return e[e.length-1]},H=e=>new Promise(t=>setTimeout(t,e));function U(e,t=0){if(e==0)return`0 Bytes`;let n=1024,r=t,i=[`Bytes`,`KB`,`MB`,`GB`,`TB`,`PB`,`EB`,`ZB`,`YB`],a=Math.floor(Math.log(e)/Math.log(n));return parseFloat((e/n**+a).toFixed(r))+` `+i[a]}const W=e=>e.split(`.`).slice(0,-1).join(`.`),G=e=>e.split(`.`).pop(),K=(e,t)=>{let n={directory:``,filename:``,extension:``,filenameWithoutExtension:``},r=e.lastIndexOf(`/`),i=r>=0?e.substring(r+1):e,a=i.lastIndexOf(`.`),o=a>0?i.substring(a+1):``,s=a>0?i.substring(0,a):i;if(n.filename=i,n.extension=o,n.filenameWithoutExtension=s,e.startsWith(`http`)){let r=t?`/static/`:`/media/`,i=e.indexOf(r);if(i!==-1){let t=e.substring(i+r.length),a=t.lastIndexOf(`/`);return n.directory=a===-1?``:t.substring(0,a),n}}return n.directory=r===-1?``:e.substring(0,r),n};o.extend(s);const q=(e,t=`YYYY-MM-DD`,n=`en`)=>{let r=o(e).locale(n);return o().diff(r,`hour`)<12?r.fromNow():r.format(t)},J=(e,t)=>{let n=[];for(let r=e;r<t;r++)n.push(r);return n},Y=(e,t,n=1)=>{let r=[],i=J(e,t);for(;r.length<n;){let t=Math.ceil(e),n=Math.floor(i.length),a=Math.floor(Math.random()*(n-t))+t,o=i.splice(a,1);r.push(o[0])}return[...r]},X=()=>c(`0123456789abcdefghijklmnopqrstuvwxyz`,5)(),Z=e=>{for(let t=0;t<e;t++)console.log(X())};export{g as appendSearchPath,S as calcPageCount,v as clearQueryByKey,_ as clearSearchPath,M as comparePriorityAsc,R as composeKey,m as deleteAllSearchHistory,p as deleteSearchHistory,q as displayDatetime,I as existLeastOne,U as formatBytes,E as formatI18nNumber,X as genNanoID,l as getCookie,G as getFileExtension,W as getFilename,z as getFirstLocationAddress,B as getFullAddress,L as getI18nKey,j as getI18nValue,A as getI18nValues,k as getModelName,d as getSearchHistory,f as insertSearchHistory,h as isSearchPage,x as link,w as loadExLib,K as parsePath,N as parseQuery,Z as printNanoID,O as productSlugify,Y as randomNum,T as recomposeI18nNumber,V as selectItemByWeight,u as setCookies,C as shuffle,H as sleep,D as slugify,F as withoutProperties,P as withoutProperty};
package/package.json CHANGED
@@ -1,17 +1,12 @@
1
1
  {
2
2
  "name": "@machinerd/js-module",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/index.mjs",
7
7
  "files": [
8
8
  "dist"
9
9
  ],
10
- "scripts": {
11
- "test": "echo \"Error: no test specified\" && exit 1",
12
- "build": "tsdown",
13
- "build:tsc": "pnpm tsc"
14
- },
15
10
  "exports": {
16
11
  ".": {
17
12
  "import": "./dist/index.mjs",
@@ -25,7 +20,6 @@
25
20
  "keywords": [],
26
21
  "author": "KOMACHINE",
27
22
  "license": "MIT",
28
- "packageManager": "pnpm@10.25.0",
29
23
  "devDependencies": {
30
24
  "@typed/node": "^6.7.0",
31
25
  "@types/google-libphonenumber": "^7.4.30",
@@ -44,5 +38,10 @@
44
38
  "nanoid": "^5.1.6",
45
39
  "query-string": "^9.3.1",
46
40
  "slug": "^11.0.1"
41
+ },
42
+ "scripts": {
43
+ "test": "echo \"Error: no test specified\" && exit 1",
44
+ "build": "tsdown",
45
+ "build:tsc": "pnpm tsc"
47
46
  }
48
- }
47
+ }