jell-utils 0.0.18 → 0.1.0

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/index.d.ts CHANGED
@@ -6,12 +6,11 @@ declare const util: {
6
6
  */
7
7
  isKorean: (message: string) => boolean;
8
8
  /**
9
- * @description return deep copied object by original object.
10
- * @todo need change Record<string, unknown> to Object(Typescript warning)
11
- * @param obj Record<string, unknown>
12
- * @returns Record<string, unknown>
9
+ * @description return deep copied object by original object using structuredClone or JSON fallback.
10
+ * @param obj object to deep clone
11
+ * @returns deep cloned object
13
12
  */
14
- clone: (obj: Record<string, unknown>) => Record<string, unknown>;
13
+ clone: <T>(obj: T) => T;
15
14
  /**
16
15
  * @description encode uri parsing (like &lt; => <, &gt; => >)
17
16
  * @param txt Original string
@@ -19,17 +18,18 @@ declare const util: {
19
18
  */
20
19
  parseTag: (txt: string) => string;
21
20
  /**
22
- * @description parseNumber with defaultvalue
23
- * @param target original string
24
- * @param defaultValue return default value
25
- * @returns parsed number value.
21
+ * @description parseNumber with defaultvalue and proper validation
22
+ * @param target original string to parse
23
+ * @param defaultValue return default value if parsing fails
24
+ * @param isFloat whether to parse as float or integer
25
+ * @returns parsed number value or default value
26
26
  */
27
27
  parseNumber: (target: string, defaultValue: number, isFloat?: boolean) => number;
28
28
  /**
29
- *
30
- * @param target required format such as '00:11:22' / '11:22'
31
- * @param defaultValue
32
- * @returns
29
+ * @description parse time string to milliseconds
30
+ * @param target required format such as '00:11:22' (HH:MM:SS) or '11:22' (MM:SS)
31
+ * @param defaultValue default value if parsing fails
32
+ * @returns parsed milliseconds or default value
33
33
  */
34
34
  parseTime: (target: string, defaultValue: number) => number;
35
35
  /**
@@ -39,9 +39,11 @@ declare const util: {
39
39
  getNowDate: () => string;
40
40
  /**
41
41
  * @description generate string from inputed time with korean date format.
42
+ * @param dateString date input (Date object or string)
43
+ * @param isYear whether to include year in output
42
44
  * @returns string korean date format
43
45
  */
44
- getKoreanDate: (dateString?: Date, isYear?: boolean) => string;
46
+ getKoreanDate: (dateString?: Date | string, isYear?: boolean) => string;
45
47
  /**
46
48
  * @description convert date to yyyy-mm-dd format string.
47
49
  * @param date date formatted string.
@@ -64,53 +66,150 @@ declare const util: {
64
66
  */
65
67
  replaceBetween: (str: string, txt: string, startIndex: number, endIndex: number) => string;
66
68
  /**
67
- * @description make camel cased word.
68
- * @param txt
69
- * @returns
69
+ * @description convert string to camelCase format
70
+ * @param txt input string to convert (supports snake_case and space-separated)
71
+ * @returns camelCase formatted string
70
72
  */
71
73
  toCamelCase: (txt: string) => string;
72
74
  /**
73
- * @description make snake cased word.
74
- * @param txt
75
- * @returns
75
+ * @description convert string to snake_case format
76
+ * @param txt input string to convert
77
+ * @returns snake_case formatted string
76
78
  */
77
79
  toSnakeCase: (txt: string) => string;
78
80
  /**
79
- * @description make title case string(first character capital and word space)
80
- * @param txt
81
- * @returns
81
+ * @description make title case string (first character capital and word space)
82
+ * @param txt input string to convert
83
+ * @returns title case string with proper spacing
82
84
  */
83
85
  toTitleCase: (txt: string) => string;
84
86
  /**
85
- * @description br tag to line break.
86
- * @param txt
87
- * @returns
87
+ * @description convert HTML br tags to line breaks
88
+ * @param txt input string with br tags
89
+ * @returns string with br tags converted to newlines
88
90
  */
89
91
  toText: (txt: string) => string;
90
92
  /**
91
- * @description line break to br tag.
92
- * @param txt
93
- * @returns
93
+ * @description convert line breaks to HTML br tags
94
+ * @param txt input string with newlines
95
+ * @returns string with newlines converted to br tags
94
96
  */
95
97
  toHtml: (txt: string) => string;
96
98
  /**
97
- * @description remove tag brace text.
98
- * @param txt string
99
- * @param isError (beta) check 'suggestCheck' tag.
100
- * @returns
99
+ * @description safely remove HTML tags from text, preventing XSS attacks
100
+ * @param txt input string with HTML tags
101
+ * @param preserveErrorTags whether to preserve elements with 'suggestCheck' class
102
+ * @returns sanitized text with specified tags removed
101
103
  */
102
- clearTag: (txt: string, isError?: boolean) => string;
104
+ clearTag: (txt: string, preserveErrorTags?: boolean) => string;
103
105
  /**
104
- * @description check same between two array.
105
- * @param a array
106
- * @param b array
107
- * @returns
106
+ * @description check if two arrays are equal (shallow comparison)
107
+ * @param a first array to compare
108
+ * @param b second array to compare
109
+ * @returns true if arrays are equal, false otherwise
108
110
  */
109
111
  equalArrays: (a: unknown[], b: unknown[]) => boolean;
110
112
  /**
111
113
  * @description check iOS device client with user agent.
112
- * @returns client is iOS?
114
+ * @returns true if client is iOS device, false otherwise
113
115
  */
114
116
  isiOS: () => boolean;
117
+ /**
118
+ * @description validate Korean business registration number (사업자등록번호)
119
+ * @param businessNumber business registration number string (10 digits)
120
+ * @returns true if valid, false otherwise
121
+ */
122
+ isBusinessNumber: (businessNumber: string) => boolean;
123
+ /**
124
+ * @description get nested object value by path string
125
+ * @param obj target object
126
+ * @param path path string (e.g., 'user.profile.name')
127
+ * @param defaultValue default value if path not found
128
+ * @returns value at path or default value
129
+ */
130
+ getByPath: <T = unknown>(obj: Record<string, unknown>, path: string, defaultValue?: T) => T;
131
+ /**
132
+ * @description set nested object value by path string
133
+ * @param obj target object
134
+ * @param path path string (e.g., 'user.profile.name')
135
+ * @param value value to set
136
+ */
137
+ setByPath: (obj: Record<string, unknown>, path: string, value: unknown) => void;
138
+ /**
139
+ * @description group array of objects by key
140
+ * @param array array to group
141
+ * @param key key to group by
142
+ * @returns grouped object
143
+ */
144
+ groupBy: <T extends Record<string, unknown>>(array: T[], key: keyof T) => Record<string, T[]>;
145
+ /**
146
+ * @description extract only numbers from string
147
+ * @param str input string
148
+ * @returns string containing only numbers
149
+ */
150
+ extractNumbers: (str: string) => string;
151
+ /**
152
+ * @description get file extension from filename or path
153
+ * @param filename filename or path
154
+ * @returns file extension without dot (e.g., 'jpg', 'pdf')
155
+ */
156
+ getFileExtension: (filename: string) => string;
157
+ /**
158
+ * @description calculate difference between two dates
159
+ * @param date1 first date
160
+ * @param date2 second date
161
+ * @returns object with days, hours, minutes, seconds difference
162
+ */
163
+ dateDiff: (date1: Date | string, date2?: Date | string) => {
164
+ days: number;
165
+ hours: number;
166
+ minutes: number;
167
+ seconds: number;
168
+ };
169
+ /**
170
+ * @description deep merge two objects
171
+ * @param target target object
172
+ * @param source source object
173
+ * @returns merged object
174
+ */
175
+ deepMerge: <T extends Record<string, unknown>>(target: T, source: Partial<T>) => T;
176
+ /**
177
+ * @description retry async function with exponential backoff
178
+ * @param fn async function to retry
179
+ * @param maxRetries maximum number of retries
180
+ * @param delay initial delay in milliseconds
181
+ * @returns promise with function result
182
+ */
183
+ retry: <T>(fn: () => Promise<T>, maxRetries?: number, delay?: number) => Promise<T>;
184
+ /**
185
+ * @description search Korean string by chosung (초성)
186
+ * @param str target string to search in
187
+ * @param search chosung search string
188
+ * @returns true if chosung matches
189
+ */
190
+ chosungSearch: (str: string, search: string) => boolean;
191
+ /**
192
+ * @description sort array of objects by key
193
+ * @param array array to sort
194
+ * @param key key to sort by
195
+ * @param order sort order ('asc' or 'desc')
196
+ * @returns sorted array
197
+ */
198
+ sortBy: <T extends Record<string, unknown>>(array: T[], key: keyof T, order?: "asc" | "desc") => T[];
199
+ /**
200
+ * @description convert object to URL query string
201
+ * @param obj object to convert
202
+ * @returns query string (e.g., 'key1=value1&key2=value2')
203
+ */
204
+ objectToQueryString: (obj: Record<string, unknown>) => string;
205
+ /**
206
+ * @description mask sensitive string (e.g., credit card, phone)
207
+ * @param str string to mask
208
+ * @param visibleStart number of visible characters at start
209
+ * @param visibleEnd number of visible characters at end
210
+ * @param maskChar character to use for masking
211
+ * @returns masked string
212
+ */
213
+ maskString: (str: string, visibleStart?: number, visibleEnd?: number, maskChar?: string) => string;
115
214
  };
116
215
  export default util;