@machinerd/js-module 0.0.1
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.cjs +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.mjs +1 -0
- package/dist/util/index.cjs +1 -0
- package/dist/util/index.d.cts +98 -0
- package/dist/util/index.d.mts +99 -0
- package/dist/util/index.mjs +1 -0
- package/package.json +47 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t){return e+t}function t(e,t){return e-t}function n(e,t){return e*t}function r(e,t){return e/t}exports.add=e,exports.divide=r,exports.multiply=n,exports.subtract=t;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
declare function add(a: number, b: number): number;
|
|
3
|
+
declare function subtract(a: number, b: number): number;
|
|
4
|
+
declare function multiply(a: number, b: number): number;
|
|
5
|
+
declare function divide(a: number, b: number): number;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { add, divide, multiply, subtract };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
declare function add(a: number, b: number): number;
|
|
3
|
+
declare function subtract(a: number, b: number): number;
|
|
4
|
+
declare function multiply(a: number, b: number): number;
|
|
5
|
+
declare function divide(a: number, b: number): number;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { add, divide, multiply, subtract };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t){return e+t}function t(e,t){return e-t}function n(e,t){return e*t}function r(e,t){return e/t}export{e as add,r as divide,n as multiply,t as subtract};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`dayjs`);c=s(c),require(`dayjs/locale/ko`);let l=require(`dayjs/plugin/relativeTime`);l=s(l);let u=require(`google-libphonenumber`),d=require(`js-cookie`);d=s(d);let f=require(`lodash-es`),p=require(`nanoid`),m=require(`query-string`);m=s(m);let h=require(`slugify`);h=s(h);const g=u.PhoneNumberUtil.getInstance();c.default.extend(l.default);const _=e=>d.default.get(e),v=(e,t,n)=>d.default.set(e,t,n),y=(e,t=[])=>{if(typeof window>`u`)return``;let{hash:n,search:r}=window.location,i=m.default.parse(r);Object.keys(e).forEach(t=>{e[t]?i[t]=e[t]:delete i[t]});let a={...i};return Object.keys(i).forEach(e=>{t.includes(e)&&delete a[e]}),`?${m.default.stringify(a,{encode:!0})}${n}`},b=(e,t)=>{let n=0;return e%t===0&&(n=e/t),n=Math.ceil(e/t),n<1&&(n=1),n},x=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},S=(e,t)=>{let n=[];for(let r=e;r<t;r++)n.push(r);return n},C=(e,t,n=1)=>{let r=[],i=S(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]},ee=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()},w=(e,t,n)=>t?e===`ko`&&n&&n!==`82`||e!==`ko`&&n?`+${n}-${t.replace(/^0/,``)}`:t:`-`,T=({phone:e,country:t={callingCode:`82`,alpha2Code:`KR`},format:n=u.PhoneNumberFormat.INTERNATIONAL,locale:r})=>{if(!e||e===`-`)return`-`;try{let i=g.parseAndKeepRawInput(e,t?.alpha2Code||`KR`),a=i.getCountryCode();return r===`ko`&&t?.alpha2Code===`KR`&&a===82?g.format(i,u.PhoneNumberFormat.NATIONAL):g.format(i,n)}catch{return w(r||`en`,e,t?.callingCode)}},E=(e,...t)=>{h.default.extend({'"':`-`,"”":`-`,"“":`-`,"•":`----`});let n=`${e}`;return t.forEach(e=>{e&&(n=`${n}-${(0,h.default)(e,{lower:!0,trim:!0,locale:`en`,strict:!0})}`)}),n},D=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]),E(e.id,...t)},O=e=>{let t=e;return t.length>0?t[0].trim():``},k=(e=`en`,t,n)=>{if(!t||!n||t.length<=0)return``;let r=[...t].sort(j);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``},A=(e,t,n)=>{if(!t||!n||t.length<=0)return``;let r=[...t].sort(j);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},j=(e,t)=>e.priority<t.priority?-1:e.priority>t.priority?1:0,M=()=>(0,p.customAlphabet)(`0123456789abcdefghijklmnopqrstuvwxyz`,5)(),N=e=>{for(let t=0;t<e;t++)console.log(M())},P=()=>typeof window>`u`?[]:JSON.parse(localStorage.getItem(`search-history`)||`[]`),F=e=>{let t=(0,f.uniq)([e,...P()]).slice(0,10);return localStorage.setItem(`search-history`,JSON.stringify(t)),t},I=e=>{let t=P();return t.splice(e,1),localStorage.setItem(`search-history`,JSON.stringify(t)),t},L=()=>{localStorage.setItem(`search-history`,JSON.stringify([]))},R=(e,t,n)=>{if(e){let r;r=Array.isArray(e)?e[0]:e;try{return t(r)}catch{return n}}return n},z=(e,t)=>{let{[t]:n,...r}=e;return r},B=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>!t.includes(e))),V=(e,t)=>(0,f.intersection)(e,t).length>0,H=e=>e.endsWith(`/search`),U=e=>H(e)?e:`${e}/search`.replace(`//`,`/`),W=e=>e.replace(`/search`,``).replace(`//`,`/`),G=(e,t)=>{let n=new URLSearchParams(e);return n.delete(t),Object.fromEntries(n)},K=e=>e.split(`:`).pop()?.split(`.`).pop(),q=(e,...t)=>[e,t].flat().join(`.`).replace(`:.`,`.`);function J(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 Y=e=>e.split(`.`).slice(0,-1).join(`.`),X=e=>e.split(`.`).pop(),Z=(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},Q=(e=`en`,t)=>{if(t.length<=0)return`-`;let n=t[0];return n?$(e,n.i18n):`-`},$=(e=`en`,t)=>{if(t.length===0)return``;let n=k(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()},te=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=U,exports.calcPageCount=b,exports.clearQueryByKey=G,exports.clearSearchPath=W,exports.comparePriorityAsc=j,exports.composeKey=q,exports.deleteAllSearchHistory=L,exports.deleteSearchHistory=I,exports.existLeastOne=V,exports.formatBytes=J,exports.formatI18nNumber=T,exports.genNanoID=M,exports.getCookie=_,exports.getFileExtension=X,exports.getFilename=Y,exports.getFirstLocationAddress=Q,exports.getFullAddress=$,exports.getI18nKey=K,exports.getI18nValue=A,exports.getI18nValues=k,exports.getModelName=O,exports.getSearchHistory=P,exports.insertSearchHistory=F,exports.isSearchPage=H,exports.link=y,exports.loadExLib=ee,exports.parsePath=Z,exports.parseQuery=R,exports.printNanoID=N,exports.productSlugify=D,exports.randomNum=C,exports.recomposeI18nNumber=w,exports.selectItemByWeight=te,exports.setCookies=v,exports.shuffle=x,exports.slugify=E,exports.withoutProperties=B,exports.withoutProperty=z;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { PhoneNumberFormat } from "google-libphonenumber";
|
|
2
|
+
|
|
3
|
+
//#region src/util/common.d.ts
|
|
4
|
+
declare const getCookie: (key: string) => string | undefined;
|
|
5
|
+
declare const setCookies: (key: string, value: string, options?: Cookies.CookieAttributes) => string | undefined;
|
|
6
|
+
declare const link: (param: Record<string, string>, deleteKeys?: string[]) => string;
|
|
7
|
+
declare const calcPageCount: (total: number, perPage: number) => number;
|
|
8
|
+
declare const shuffle: <T>(arr: T[]) => T[];
|
|
9
|
+
declare const randomNum: (min: number, max: number, count?: number) => number[];
|
|
10
|
+
declare const loadExLib: (callback: () => void) => void;
|
|
11
|
+
declare const recomposeI18nNumber: (locale: string, number?: string | null, i18nNumber?: string | null) => string;
|
|
12
|
+
interface Country {
|
|
13
|
+
alpha2Code: string;
|
|
14
|
+
callingCode: string;
|
|
15
|
+
}
|
|
16
|
+
interface I18nNumberProps<C extends Country = Country> {
|
|
17
|
+
phone?: string | null;
|
|
18
|
+
country?: C | null;
|
|
19
|
+
format?: PhoneNumberFormat;
|
|
20
|
+
locale?: string | null;
|
|
21
|
+
}
|
|
22
|
+
declare const formatI18nNumber: ({
|
|
23
|
+
phone,
|
|
24
|
+
country,
|
|
25
|
+
format,
|
|
26
|
+
locale
|
|
27
|
+
}: I18nNumberProps) => string;
|
|
28
|
+
declare const slugify: (base: string | number, ...args: Array<string | undefined>) => string;
|
|
29
|
+
interface Product<I extends I18n = I18n> {
|
|
30
|
+
id: number;
|
|
31
|
+
stockNo?: string[];
|
|
32
|
+
series?: Series<I> | null;
|
|
33
|
+
i18n: I[];
|
|
34
|
+
}
|
|
35
|
+
interface Series<I extends I18n = I18n> {
|
|
36
|
+
i18n: I[];
|
|
37
|
+
}
|
|
38
|
+
interface I18n {
|
|
39
|
+
name?: string | null;
|
|
40
|
+
locale: string;
|
|
41
|
+
priority: number;
|
|
42
|
+
}
|
|
43
|
+
declare const productSlugify: (product: Product) => string;
|
|
44
|
+
declare const getModelName: (modelName: string[]) => string;
|
|
45
|
+
declare const getI18nValues: <T extends {
|
|
46
|
+
locale: string;
|
|
47
|
+
priority: number;
|
|
48
|
+
}, K extends keyof T>(locale: string | undefined, values: T[], key: K) => T[K];
|
|
49
|
+
declare const getI18nValue: <T extends {
|
|
50
|
+
locale: string;
|
|
51
|
+
priority: number;
|
|
52
|
+
[key: string]: string | number | null | undefined;
|
|
53
|
+
}>(locale?: string, values?: T[], key?: keyof T) => string;
|
|
54
|
+
declare const comparePriorityAsc: <T extends {
|
|
55
|
+
priority: number;
|
|
56
|
+
}>(a: T, b: T) => 0 | 1 | -1;
|
|
57
|
+
declare const genNanoID: () => string;
|
|
58
|
+
declare const printNanoID: (cnt: number) => void;
|
|
59
|
+
declare const getSearchHistory: () => string[];
|
|
60
|
+
declare const insertSearchHistory: (item: string) => string[];
|
|
61
|
+
declare const deleteSearchHistory: (index: number) => string[];
|
|
62
|
+
declare const deleteAllSearchHistory: () => void;
|
|
63
|
+
declare const parseQuery: <T, F = T>(q: string | string[] | undefined | null, conv: (v: string) => T, fallback: F) => T | F;
|
|
64
|
+
declare const withoutProperty: <T>(obj: T, property: keyof T) => Omit<T, keyof T>;
|
|
65
|
+
declare const withoutProperties: <T extends Record<string, unknown>>(obj: T, properties: Array<keyof T>) => T;
|
|
66
|
+
declare const existLeastOne: <T>(a: T[], b: T[]) => boolean;
|
|
67
|
+
declare const isSearchPage: (pathname: string) => boolean;
|
|
68
|
+
declare const appendSearchPath: (pathname: string) => string;
|
|
69
|
+
declare const clearSearchPath: (pathname: string) => string;
|
|
70
|
+
declare const clearQueryByKey: (query: Record<string, any>, key: string) => {
|
|
71
|
+
[k: string]: string;
|
|
72
|
+
};
|
|
73
|
+
declare const getI18nKey: (key: string) => string | undefined;
|
|
74
|
+
declare const composeKey: (prefix?: Array<string | number> | string, ...keys: Array<string | number>) => string;
|
|
75
|
+
declare function formatBytes(bytes: number, decimals?: number): string;
|
|
76
|
+
declare const getFilename: (s: string) => string;
|
|
77
|
+
declare const getFileExtension: (s: string) => string | undefined;
|
|
78
|
+
interface PathInfo {
|
|
79
|
+
directory: string;
|
|
80
|
+
filename: string;
|
|
81
|
+
extension: string;
|
|
82
|
+
filenameWithoutExtension: string;
|
|
83
|
+
}
|
|
84
|
+
declare const parsePath: (filepath: string, isStatic?: boolean) => PathInfo;
|
|
85
|
+
interface Location<I extends LocationI18n = LocationI18n> {
|
|
86
|
+
i18n: I[];
|
|
87
|
+
}
|
|
88
|
+
interface LocationI18n extends I18n {
|
|
89
|
+
address1?: string | null;
|
|
90
|
+
address2?: string | null;
|
|
91
|
+
}
|
|
92
|
+
declare const getFirstLocationAddress: (locale: string | undefined, locations: Location[]) => string;
|
|
93
|
+
declare const getFullAddress: (locale: string | undefined, values: LocationI18n[]) => string;
|
|
94
|
+
declare const selectItemByWeight: <T extends {
|
|
95
|
+
weight: number;
|
|
96
|
+
}>(itemsWithWeights: T[]) => T;
|
|
97
|
+
//#endregion
|
|
98
|
+
export { I18nNumberProps, appendSearchPath, calcPageCount, clearQueryByKey, clearSearchPath, comparePriorityAsc, composeKey, deleteAllSearchHistory, deleteSearchHistory, 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 };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import "dayjs/locale/ko";
|
|
2
|
+
import { PhoneNumberFormat } from "google-libphonenumber";
|
|
3
|
+
|
|
4
|
+
//#region src/util/common.d.ts
|
|
5
|
+
declare const getCookie: (key: string) => string | undefined;
|
|
6
|
+
declare const setCookies: (key: string, value: string, options?: Cookies.CookieAttributes) => string | undefined;
|
|
7
|
+
declare const link: (param: Record<string, string>, deleteKeys?: string[]) => string;
|
|
8
|
+
declare const calcPageCount: (total: number, perPage: number) => number;
|
|
9
|
+
declare const shuffle: <T>(arr: T[]) => T[];
|
|
10
|
+
declare const randomNum: (min: number, max: number, count?: number) => number[];
|
|
11
|
+
declare const loadExLib: (callback: () => void) => void;
|
|
12
|
+
declare const recomposeI18nNumber: (locale: string, number?: string | null, i18nNumber?: string | null) => string;
|
|
13
|
+
interface Country {
|
|
14
|
+
alpha2Code: string;
|
|
15
|
+
callingCode: string;
|
|
16
|
+
}
|
|
17
|
+
interface I18nNumberProps<C extends Country = Country> {
|
|
18
|
+
phone?: string | null;
|
|
19
|
+
country?: C | null;
|
|
20
|
+
format?: PhoneNumberFormat;
|
|
21
|
+
locale?: string | null;
|
|
22
|
+
}
|
|
23
|
+
declare const formatI18nNumber: ({
|
|
24
|
+
phone,
|
|
25
|
+
country,
|
|
26
|
+
format,
|
|
27
|
+
locale
|
|
28
|
+
}: I18nNumberProps) => string;
|
|
29
|
+
declare const slugify: (base: string | number, ...args: Array<string | undefined>) => string;
|
|
30
|
+
interface Product<I extends I18n = I18n> {
|
|
31
|
+
id: number;
|
|
32
|
+
stockNo?: string[];
|
|
33
|
+
series?: Series<I> | null;
|
|
34
|
+
i18n: I[];
|
|
35
|
+
}
|
|
36
|
+
interface Series<I extends I18n = I18n> {
|
|
37
|
+
i18n: I[];
|
|
38
|
+
}
|
|
39
|
+
interface I18n {
|
|
40
|
+
name?: string | null;
|
|
41
|
+
locale: string;
|
|
42
|
+
priority: number;
|
|
43
|
+
}
|
|
44
|
+
declare const productSlugify: (product: Product) => string;
|
|
45
|
+
declare const getModelName: (modelName: string[]) => string;
|
|
46
|
+
declare const getI18nValues: <T extends {
|
|
47
|
+
locale: string;
|
|
48
|
+
priority: number;
|
|
49
|
+
}, K extends keyof T>(locale: string | undefined, values: T[], key: K) => T[K];
|
|
50
|
+
declare const getI18nValue: <T extends {
|
|
51
|
+
locale: string;
|
|
52
|
+
priority: number;
|
|
53
|
+
[key: string]: string | number | null | undefined;
|
|
54
|
+
}>(locale?: string, values?: T[], key?: keyof T) => string;
|
|
55
|
+
declare const comparePriorityAsc: <T extends {
|
|
56
|
+
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;
|
|
64
|
+
declare const parseQuery: <T, F = T>(q: string | string[] | undefined | null, conv: (v: string) => T, fallback: F) => T | F;
|
|
65
|
+
declare const withoutProperty: <T>(obj: T, property: keyof T) => Omit<T, keyof T>;
|
|
66
|
+
declare const withoutProperties: <T extends Record<string, unknown>>(obj: T, properties: Array<keyof T>) => T;
|
|
67
|
+
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
|
+
declare const getI18nKey: (key: string) => string | undefined;
|
|
75
|
+
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
|
+
interface Location<I extends LocationI18n = LocationI18n> {
|
|
87
|
+
i18n: I[];
|
|
88
|
+
}
|
|
89
|
+
interface LocationI18n extends I18n {
|
|
90
|
+
address1?: string | null;
|
|
91
|
+
address2?: string | null;
|
|
92
|
+
}
|
|
93
|
+
declare const getFirstLocationAddress: (locale: string | undefined, locations: Location[]) => string;
|
|
94
|
+
declare const getFullAddress: (locale: string | undefined, values: LocationI18n[]) => string;
|
|
95
|
+
declare const selectItemByWeight: <T extends {
|
|
96
|
+
weight: number;
|
|
97
|
+
}>(itemsWithWeights: T[]) => T;
|
|
98
|
+
//#endregion
|
|
99
|
+
export { I18nNumberProps, appendSearchPath, calcPageCount, clearQueryByKey, clearSearchPath, comparePriorityAsc, composeKey, deleteAllSearchHistory, deleteSearchHistory, 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 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"dayjs";import"dayjs/locale/ko";import t from"dayjs/plugin/relativeTime";import{PhoneNumberFormat as n,PhoneNumberUtil as r}from"google-libphonenumber";import i from"js-cookie";import{intersection as a,uniq as o}from"lodash-es";import{customAlphabet as s}from"nanoid";import c from"query-string";import l from"slugify";const u=r.getInstance();e.extend(t);const d=e=>i.get(e),f=(e,t,n)=>i.set(e,t,n),p=(e,t=[])=>{if(typeof window>`u`)return``;let{hash:n,search:r}=window.location,i=c.parse(r);Object.keys(e).forEach(t=>{e[t]?i[t]=e[t]:delete i[t]});let a={...i};return Object.keys(i).forEach(e=>{t.includes(e)&&delete a[e]}),`?${c.stringify(a,{encode:!0})}${n}`},m=(e,t)=>{let n=0;return e%t===0&&(n=e/t),n=Math.ceil(e/t),n<1&&(n=1),n},h=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},g=(e,t)=>{let n=[];for(let r=e;r<t;r++)n.push(r);return n},_=(e,t,n=1)=>{let r=[],i=g(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]},v=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()},y=(e,t,n)=>t?e===`ko`&&n&&n!==`82`||e!==`ko`&&n?`+${n}-${t.replace(/^0/,``)}`:t:`-`,b=({phone:e,country:t={callingCode:`82`,alpha2Code:`KR`},format:r=n.INTERNATIONAL,locale:i})=>{if(!e||e===`-`)return`-`;try{let a=u.parseAndKeepRawInput(e,t?.alpha2Code||`KR`),o=a.getCountryCode();return i===`ko`&&t?.alpha2Code===`KR`&&o===82?u.format(a,n.NATIONAL):u.format(a,r)}catch{return y(i||`en`,e,t?.callingCode)}},x=(e,...t)=>{l.extend({'"':`-`,"”":`-`,"“":`-`,"•":`----`});let n=`${e}`;return t.forEach(e=>{e&&(n=`${n}-${l(e,{lower:!0,trim:!0,locale:`en`,strict:!0})}`)}),n},S=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]),x(e.id,...t)},C=e=>{let t=e;return t.length>0?t[0].trim():``},w=(e=`en`,t,n)=>{if(!t||!n||t.length<=0)return``;let r=[...t].sort(E);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``},T=(e,t,n)=>{if(!t||!n||t.length<=0)return``;let r=[...t].sort(E);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},E=(e,t)=>e.priority<t.priority?-1:e.priority>t.priority?1:0,D=()=>s(`0123456789abcdefghijklmnopqrstuvwxyz`,5)(),O=e=>{for(let t=0;t<e;t++)console.log(D())},k=()=>typeof window>`u`?[]:JSON.parse(localStorage.getItem(`search-history`)||`[]`),A=e=>{let t=o([e,...k()]).slice(0,10);return localStorage.setItem(`search-history`,JSON.stringify(t)),t},j=e=>{let t=k();return t.splice(e,1),localStorage.setItem(`search-history`,JSON.stringify(t)),t},M=()=>{localStorage.setItem(`search-history`,JSON.stringify([]))},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)=>a(e,t).length>0,L=e=>e.endsWith(`/search`),R=e=>L(e)?e:`${e}/search`.replace(`//`,`/`),z=e=>e.replace(`/search`,``).replace(`//`,`/`),B=(e,t)=>{let n=new URLSearchParams(e);return n.delete(t),Object.fromEntries(n)},V=e=>e.split(`:`).pop()?.split(`.`).pop(),H=(e,...t)=>[e,t].flat().join(`.`).replace(`:.`,`.`);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},q=(e=`en`,t)=>{if(t.length<=0)return`-`;let n=t[0];return n?J(e,n.i18n):`-`},J=(e=`en`,t)=>{if(t.length===0)return``;let n=w(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()},Y=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{R as appendSearchPath,m as calcPageCount,B as clearQueryByKey,z as clearSearchPath,E as comparePriorityAsc,H as composeKey,M as deleteAllSearchHistory,j as deleteSearchHistory,I as existLeastOne,U as formatBytes,b as formatI18nNumber,D as genNanoID,d as getCookie,G as getFileExtension,W as getFilename,q as getFirstLocationAddress,J as getFullAddress,V as getI18nKey,T as getI18nValue,w as getI18nValues,C as getModelName,k as getSearchHistory,A as insertSearchHistory,L as isSearchPage,p as link,v as loadExLib,K as parsePath,N as parseQuery,O as printNanoID,S as productSlugify,_ as randomNum,y as recomposeI18nNumber,Y as selectItemByWeight,f as setCookies,h as shuffle,x as slugify,F as withoutProperties,P as withoutProperty};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@machinerd/js-module",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "",
|
|
6
|
+
"main": "dist/index.mjs",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
12
|
+
"build": "tsdown",
|
|
13
|
+
"build:tsc": "pnpm tsc"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/index.mjs",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./util": {
|
|
21
|
+
"import": "./dist/util/index.mjs",
|
|
22
|
+
"require": "./dist/util/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"keywords": [],
|
|
26
|
+
"author": "KOMACHINE",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"packageManager": "pnpm@10.24.0",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@typed/node": "^6.7.0",
|
|
31
|
+
"@types/google-libphonenumber": "^7.4.30",
|
|
32
|
+
"@types/js-cookie": "^3.0.6",
|
|
33
|
+
"@types/lodash-es": "^4.17.12",
|
|
34
|
+
"@types/node": "^24.10.1",
|
|
35
|
+
"tsdown": "0.17.0-beta.5",
|
|
36
|
+
"typescript": "^5.9.3"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"dayjs": "^1.11.19",
|
|
40
|
+
"google-libphonenumber": "^3.2.43",
|
|
41
|
+
"js-cookie": "^3.0.5",
|
|
42
|
+
"lodash-es": "^4.17.21",
|
|
43
|
+
"nanoid": "^5.1.6",
|
|
44
|
+
"query-string": "^9.3.1",
|
|
45
|
+
"slugify": "^1.6.6"
|
|
46
|
+
}
|
|
47
|
+
}
|