qsu 0.5.3 → 1.0.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/README.md CHANGED
@@ -1,158 +1,522 @@
1
- <div align="center">
2
-
3
- ![logo](qsu-logo.png)
4
- ### Node.js Quick & Simple Utility for JavaScript
5
-
6
- [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jooy2/qsu/blob/master/LICENSE)
7
- ![Programming Language Usage](https://img.shields.io/github/languages/top/jooy2/qsu)
8
- [![npm latest package](https://img.shields.io/npm/v/qsu/latest.svg)](https://www.npmjs.com/package/qsu)
9
- ![minified size](https://img.shields.io/bundlephobia/min/qsu)
10
- ![github repo size](https://img.shields.io/github/repo-size/jooy2/qsu)
11
- [![npm downloads](https://img.shields.io/npm/dm/qsu.svg)](https://www.npmjs.com/package/qsu)
12
- [![Followers](https://img.shields.io/github/followers/jooy2?style=social)](https://github.com/jooy2)
13
- </div>
14
-
15
- A collection of complex or useful features that are often used in JavaScript. It is implemented to be used in both a client or server environment.
16
-
17
- qsu is optimized for modern development environments, so older browsers such as Internet Explorer 11 and Legacy Edge (Not Chromium) may not support it unless you use a transcompiler. Some functions use ES6 or higher JS standard syntax.
18
-
19
- Some solutions partially referenced external documentation (e.g. [Stack Overflow](https://stackoverflow.com)).
20
-
21
- # Installation
22
- Qsu requires Node.js 12.x or higher, and the repository is serviced through NPM.
23
- After configuring the node environment, you can simply run the following command.
24
- ```bash
25
- $ npm i --save qsu
26
- ```
27
-
28
- # Usage
29
- ### Using multiple utilities simultaneously with one object
30
- ```javascript
31
- const _ = require('qsu');
32
-
33
- function main () {
34
- console.log(_.date.today()); // '20xx-xx-xx'
35
- }
36
- ```
37
-
38
- ### Using multiple utilities in a single require
39
- ```javascript
40
- const { date, format } = require('qsu');
41
-
42
- function main () {
43
- console.log(date.today()); // '20xx-xx-xx'
44
- console.log(format.number('1234')); // '1,234'
45
- }
46
- ```
47
-
48
- ### To use only one utility, import and use only the necessary parts as follows.
49
- ```javascript
50
- const _ = require('qsu/date'); // or require('qsu').date
51
-
52
- function main () {
53
- return _.today(); // '20xx-xx-xx'
54
- }
55
- ```
56
- OR
57
- ```javascript
58
- const { today } = require('qsu/date'); // or require('qsu').date
59
-
60
- function main () {
61
- return today(); // '20xx-xx-xx'
62
- }
63
- ```
64
-
65
- # Reference
66
- ```
67
- qsu.{{Util}}.{{Method}}({{Params1}}, {{Params2}})
68
- ```
69
-
70
- ## qsu.array
71
- Utility to help process array type data.
72
-
73
- | Method | Params | Description | Example |
74
- | --- | --- | --- | --- |
75
- | .shuffle | array **{Array}** | Shuffle the order of the given array and return | `shuffle([1, 2, 3, 4]) // [4, 2, 3, 1]...` |
76
- | .setWithDefault | <li>defaultValue **{Any}**</li><li>arrayLength **{Number&#124;null}**</li> | Initialize an array with a default value of a specific length. | `setWithDefault('abc', 4) // ['abc', 'abc', 'abc', 'abc']`<br/>`setWithDefault(null, 3) // [null, null, null]` |
77
- | .unique | array **{Array}** | Remove duplicate values from array and two-dimensional array data. In the case of 2d arrays, json type data duplication is not removed. | `unique([1, 2, 2, 3]) // [1, 2, 3]`<br/>`unique([[1], [1], [2]) // [[1], [2]]` |
78
- | .setWithNumber | <li>start **{Number}**</li><li>end **{Number}**</li> | Creates and returns an Array in the order of start...end values. | `setWithNumber(1, 3) // [1, 2, 3]`<br/>`setWithNumber(0, 3) // [0, 1, 2, 3]` |
79
- | .average | <li>array **{Array}**</li> | Returns the average of all numeric values in an array. | `average([1, 5, 15, 50]) // 17.75` |
80
-
81
- ## qsu.string
82
- Utility to help process string type data.
83
-
84
- | Method | Params | Description | Example |
85
- | --- |--------------------------------------------------------------------------------------------------------------------------------------| --- |----------------------------------------------------------------------------------------|
86
- | .removeSpecialChar | <li>string **{String}**</li><li>withoutSpace **{Boolean}**</li> | Returns after removing all special characters, including spaces. | `removeSpecialChar('Hello, World!') // 'HelloWorld'` |
87
- | .removeNewLine | string **{String}** | Removes \n, \r characters or replaces them with specified characters. | `removeNewLine('ab\ncd') // 'abcd'`<br/>`removeNewLine('ab\r\ncd', '-') // 'ab-cd'` |
88
- | .capitalizeFirst | string **{String}** | Converts the first letter of the entire string to uppercase and returns. | `capitalizeFirst('abcd') // 'Abcd'` |
89
- | .capitalizeEachWords | <li>string **{String}**</li><li>naturally **{Boolean}**</li> | Converts every word with spaces to uppercase. If the naturally argument is true, only some special cases (such as prepositions) are kept lowercase. | `capitalizeEachWords('hello world') // 'Hello World'` |
90
- | .count | <li>string **{String}**</li><li>search **{String}**</li> | Returns the number of times the second String character is contained in the first String argument. | `count('abcabc', 'a') // 2` |
91
- | .shuffle | <li>string **{String}**</li> | Randomly shuffles the received string and returns it. | `shuffle('abcdefg') // 'bgafced'` |
92
- | .createRandom | <li>length **{Number}**</li> | Returns a random String containing numbers or uppercase and lowercase letters of the given length. The default return length is 12. | `createRandom(5) // 'CHy2M'` |
93
- | .hideRandom | <li>str **{String}**</li><li>hideLength **{Number}**</li><li>hideStr **{String}**</li> | Replaces strings at random locations with a specified number of characters (default 1) with characters (default *). | `hideRandom('hello', 2, '#') // '#el#o'` |
94
- | .truncate | <li>str **{String}**</li><li>length **{Number}**</li><li>ellipsis **{String&#124;null}**</li> | Truncates a long string to a specified length, optionally appending an ellipsis after the string. | `truncate('hello', 3) // 'hel'`<br/>`truncate('hello', 2, '...') // 'he...'` |
95
- | .encrypt | <li>str **{String}**</li><li>secret **{String}**</li><li>algorithm **{String&#124;null}**</li><li>ivSize **{Number&#124;null}**</li> | Encrypt with the algorithm of your choice (algorithm default: aes-256-cbc, ivSize default: 16) using a string and a secret (secret). | `encrypt('test', 'secret-key')` |
96
- | .decrypt | <li>str **{String}**</li><li>secret **{String}**</li><li>algorithm **{String&#124;null}**</li> | Decrypt with the specified algorithm (default: `aes-256-cbc`) using a string and a secret (secret). | `decrypt('61ba43b65fc...', 'secret-key') // 'test'` |
97
- | .md5 | <li>str **{String}**</li> | Converts String data to md5 hash value and returns it. | `md5('test') // '098f6bcd4621d373cade4e832627b4f6'` |
98
- | .sha1 | <li>str **{String}**</li> | Converts String data to sha1 hash value and returns it. | `sha1('test') // 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'` |
99
- | .sha256 | <li>str **{String}**</li> | Converts String data to sha256 hash value and returns it. | `sha256('test') // '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'` |
100
- | .unique | <li>str **{String}**</li> | Remove duplicate characters from a given string and output only one. | `unique('aaabbbcc') // 'abc'` |
101
-
102
- ## qsu.math
103
- Utility for arithmetic on numbers.
104
-
105
- | Method | Params | Description | Example |
106
- | --- | --- | --- | --- |
107
- | .rand | <li>min **{Number&#124;null}**</li><li>max **{Number&#124;null}**</li> | Returns a random number (0 to max or between min and max). | `rand() // 0-1`<br/>`rand(10) // 0~10`<br/>`rand(10, 20) // 10~20` |
108
- | .add | <li>...numbers **{Number&#124;Array}**</li> | Returns after adding up all the n arguments of numbers or the values of a single array of numbers. | `add(1, 2, 3) // 6`<br/>`add([1, 2, 3, 4]) // 10` |
109
- | .mul | <li>...numbers **{Number&#124;Array}**</li> | Returns after multiplying all n arguments of numbers or the values of a single array of numbers. | `mul(1, 2, 3) // 6`<br/>`mul([1, 2, 3, 4]) // 24` |
110
-
111
- ## qsu.verify
112
- Utility for data inspection.
113
-
114
- | Method | Params | Description | Example |
115
- | --- |-----------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| --- |
116
- | .empty | data **{Any}** | Returns true if the passed data is empty or has a length of 0. | `empty([]) // true`<br/>`empty('') // true`<br/>`empty('abc') // false` |
117
- | .isUrl | <li>url **{String}**</li><li>withProtocol **{Boolean&#124;null}**</li><li>strict **{Boolean&#124;null}**</li> | Returns true if the given data is in the correct URL format. If withProtocol is true, it is automatically appended to the URL when the protocol does not exist. If strict is true, URLs without commas (.) return false. | `isUrl('google.com') // false`<br/>`isUrl('google.com', true) // true`<br/>`isUrl('https://google.com') // true` |
118
- | .contains | <li>string **{String}**</li><li>searchData **{Array&#124;String}**</li><li>exact **{Boolean}**</li> | Returns true if the first string argument contains the second argument "string" or "one or more of the strings listed in the array". If the exact value is true, it returns true only for an exact match. | `contains('abc', 'a') // true`<br/>`contains('abc', 'd') // false`<br/>`contains('abc', ['a', 'd']) // true` |
119
- | .is2dArray | array **{Array}** | Returns true if the given array is a two-dimensional array. | `is2dArray([1]) // false`<br/>`is2dArray([[1], [2]) // true` |
120
- | .between | <li>value **{Number}**</li><li>range **{[min, max]}</li><li>inclusive **{Boolean&#124;null}**</li>** | Returns true if the first argument is in the range of the second argument ([min, max]). To allow the minimum and maximum values to be in the range, pass true for the third argument. | `between(10, [10, 20]) // false`<br/>`between(10, [10, 20], true) // true` |
121
- | .length | <li>data **{Any}**</li> | Returns the length of any type of data. If the argument value is null or undefined, 0 is returned. | `length('12345') // 5`<br/>`length([1, 2, 3]]) // 3` |
122
- | .isBotAgent | <li>userAgent **{String}**</li> | Analyze the user agent value to determine if it's a bot for a search engine. Returns true if it's a bot. | `isBotAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)') // true` |
123
-
124
- ## qsu.format
125
- Utility that converts to Human-Readable String format.
126
-
127
- | Method | Params | Description | Example |
128
- | --- | --- | --- | --- |
129
- | .number | val **{String&#124;Number}** | Return in number format including comma symbol. | `number(1234567) // 1,234,567` |
130
- | .fileName | <li>filePath **{String}**</li><li>withExtension **{Boolean}**</li> | Extract the file name from the path. Include the extension if withExtension is true. | `fileName('C:\Temp\hello.txt') // 'hello.txt'`<br/>`fileName('C:\Temp\file.mp3', true) // 'file.mp3'` |
131
- | .fileSize | <li>bytes **{Number}**</li><li>decimals **{Number}**</li> | Converts the file size in bytes to human-readable and returns it. The return value is a String and includes the file units (Bytes, MB, GB...). If the second optional argument value is included, you can display as many decimal places as you like. | `fileSize(2000, 3) // '1.953 KB'`<br/>`fileSize(250000000) // '238.42 MB'` |
132
- | .fileExt | <li>filePath **{String}**</li> | Returns only the extensions in the file path. If unknown, returns 'Unknown'. | `fileExt('C:\Temp\hello.txt') // 'txt'`<br/>`fileExt('this-is-file.mp3') // 'mp3'` |
133
- | .msToTime | <li>milliseconds **{Number}**</li><li>withMilliseconds **{Boolean}**</li><li>separator **{String}**</li> | Converts milliseconds to hours, minutes, seconds, and milliseconds and returns. If the second argument is true, milliseconds are also printed. You can put any separator (String) between hours, minutes, and seconds in the third argument. | `msToTime(100000) // '00:01:40'`<br/>`msToTime(100000, true, '-') // '00-01-40.0'` |
134
- | .secToTime | <li>seconds **{Number}**</li><li>separator **{String}**</li><li>onlyHour **{Boolean}**</li> | Converts seconds to hours, minutes, seconds and returns. You can put any separator (String) between hours, minutes, and seconds in the third argument. | `secToTime(3800) // '01:03:20'`<br/>`secToTime(60, '-') // '00-01-00'` |
135
- | .license | <li>type(Required, Currently only 'mit' is supported) **{String}**</li><li>author(Required) **{String}**</li><li>yearStart(Required) **{String}**</li><li>yearEnd **{String}**</li><li>email **{string}**</li><li>htmlBr **{string}**</li> | Returns text in a specific license format based on the author information of the given argument. The argument uses the Object type. | `license({ holder: 'example', email: 'example@example.com', yearStart: 2020, yearEnd: 2021, htmlBr: true })` |
136
-
137
- ## qsu.date
138
- Utility to simplify date format printing or calculation.
139
-
140
- | Method | Params | Description | Example |
141
- | --- | --- | --- | --- |
142
- | .dayDiff | <li>date1 **{String&#124;Date}**</li><li>date2 **{String&#124;Date&#124;null}**</li> | Calculates the difference between two given dates and returns the number of days. | `daydiff('2021-01-01', '2021-01-03') // 2` |
143
- | .today | dateFormat **{String}** | Returns today's date. | `today('YYYY-MM-DD') // 2021-01-01` |
144
- | .convertDate | <li>dateString **{String}**</li><li>dateFormat **{String}** | Returns a date in YYYY-MM-DD or desired format based on the first argument (date in String format). | `convertDate('2021-01-01', 'YYYY') // 2021`<br/>`convertDate('2021', 'YYYY_MM_DD') // 2021_01_01` |
145
- | .isRealDate | dateString (YYYY-MM-DD) **{String}** | Checks if a given date actually exists. Check only in YYYY-MM-DD format. | `isRealDate('2021-01-01') // true`<br/>`isRealDate('2021-02-30') // false` |
146
-
147
- ## qsu.misc
148
- Various utilities that help with convenience codes or complex operations.
149
-
150
- | Method | Params | Description | Example |
151
- | --- | --- | --- | --- |
152
- | .sleep | milliseconds **{Number}** | Sleep function using Promise. | `await sleep(1000) // 1s`<br/>`sleep(5000).then(() => { ... })` |
153
-
154
- # Contribute
155
- You can report issues on GitHub Issue. You can also request a pull to fix bugs and add frequently used features.
156
-
157
- # License
158
- Copyright © 2021 Jooy2 Released under the MIT license.
1
+ <div align="center">
2
+
3
+ ![logo](qsu-logo.png)
4
+ ### Node.js Quick & Simple Utility for JavaScript
5
+
6
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jooy2/qsu/blob/master/LICENSE)
7
+ ![Programming Language Usage](https://img.shields.io/github/languages/top/jooy2/qsu)
8
+ [![npm latest package](https://img.shields.io/npm/v/qsu/latest.svg)](https://www.npmjs.com/package/qsu)
9
+ ![minified size](https://img.shields.io/bundlephobia/min/qsu)
10
+ ![github repo size](https://img.shields.io/github/repo-size/jooy2/qsu)
11
+ [![npm downloads](https://img.shields.io/npm/dm/qsu.svg)](https://www.npmjs.com/package/qsu)
12
+ [![Followers](https://img.shields.io/github/followers/jooy2?style=social)](https://github.com/jooy2)
13
+ </div>
14
+
15
+ A collection of complex or useful features that are often used in JavaScript. It is implemented to be used in both a client or server environment.
16
+
17
+ qsu is optimized for modern development environments, so older browsers such as Internet Explorer 11 and Legacy Edge (Not Chromium) may not support it unless you use a transcompiler. Some functions use ES6 or higher JS standard syntax.
18
+
19
+ Some solutions partially referenced external documentation (e.g. [Stack Overflow](https://stackoverflow.com)).
20
+
21
+ # Installation
22
+ Qsu requires Node.js 14.x or higher, and the repository is serviced through NPM.
23
+ After configuring the node environment, you can simply run the following command.
24
+ ```bash
25
+ $ npm i --save qsu
26
+ ```
27
+
28
+ # Usage
29
+ ```javascript
30
+ import _ from 'qsu';
31
+
32
+ function main () {
33
+ console.log(_.today()); // '20xx-xx-xx'
34
+ }
35
+ ```
36
+
37
+ # Methods
38
+
39
+ ### `_.sleep (Promise:boolean)`
40
+
41
+ Sleep function using Promise.
42
+ - `milliseconds::number`
43
+
44
+ ```javascript
45
+ await _.sleep(1000); // 1s
46
+ _.sleep(5000).then(() => {
47
+ // continue
48
+ });
49
+ ```
50
+
51
+ ### `_.numRandom (number)`
52
+
53
+ Returns a random number (Between min and max).
54
+ - `min::number`
55
+ - `max::number`
56
+
57
+ ```javascript
58
+ _.rand(1, 5); // Returns 1~5
59
+ _.rand(10, 20); // Returns 10~20
60
+ ```
61
+
62
+ ### `_.sum (number)`
63
+
64
+ Returns after adding up all the n arguments of numbers or the values of a single array of numbers.
65
+ - `numbers::...number[]`
66
+
67
+ ```javascript
68
+ _.sum(1, 2, 3); // Returns 6
69
+ _.sum([1, 2, 3, 4]); // Returns 10
70
+ ```
71
+
72
+ ### `_.mul (number)`
73
+
74
+ Returns after multiplying all n arguments of numbers or the values of a single array of numbers.
75
+ - `numbers::...number[]`
76
+
77
+ ```javascript
78
+ _.mul(1, 2, 3); // Returns 6
79
+ _.mul([1, 2, 3, 4]); // Returns 24
80
+ ```
81
+
82
+ ### `_.dayDiff (number)`
83
+
84
+ Calculates the difference between two given dates and returns the number of days.
85
+ - `date1::Date`
86
+ - `date2::Date?`
87
+
88
+ ```javascript
89
+ _.daydiff(new Date('2021-01-01'), new Date('2021-01-03')); // Returns 2
90
+ ```
91
+
92
+ ### `_.today (string)`
93
+
94
+ Returns today's date.
95
+ - `dateFormat::string?`
96
+
97
+ ```javascript
98
+ _.today(); // Returns YYYY-MM-DD
99
+ _.today('YYYY'); // Returns YYYY
100
+ ```
101
+
102
+ ### `_.isRealDate (boolean)`
103
+
104
+ Checks if a given date actually exists. Check only in YYYY-MM-DD format.
105
+ - `date::string|Date`
106
+
107
+ ```javascript
108
+ _.isRealDate('2021-01-01'); // Returns true
109
+ _.isRealDate('2021-02-30'); // Returns false
110
+ ```
111
+
112
+ ### `_.convertDate (string)`
113
+
114
+ Returns a date in YYYY-MM-DD or desired format based on the first argument (date in String format).
115
+ - `date::string`
116
+ - `format::string?`
117
+
118
+ ```javascript
119
+ _.convertDate('2021-01-01', 'YYYY'); // Returns 2021
120
+ _.convertDate('2021', 'YYYY_MM_DD'); // Returns 2021_01_01
121
+ ```
122
+
123
+ ### `_.arrShuffle (any[])`
124
+
125
+ Shuffle the order of the given array and return.
126
+ - `array::any[]`
127
+
128
+ ```javascript
129
+ _.arrShuffle([1, 2, 3, 4]); // Returns [4, 2, 3, 1]
130
+ ```
131
+
132
+ ### `_.arrWithDefault (any[])`
133
+
134
+ Initialize an array with a default value of a specific length.
135
+ - `defaultValue::any`
136
+ - `length::number || 0`
137
+
138
+ ```javascript
139
+ _.arrWithDefault('abc', 4); // Returns ['abc', 'abc', 'abc', 'abc']
140
+ _.arrWithDefault(null, 3); // Returns [null, null, null]
141
+ ```
142
+
143
+ ### `_.arrWithNumber (number[])`
144
+
145
+ Creates and returns an Array in the order of start...end values.
146
+ - `start::number`
147
+ - `end::number`
148
+
149
+ ```javascript
150
+ _.arrWithNumber(1, 3); // Returns [1, 2, 3]
151
+ _.arrWithNumber(0, 3); // Returns [0, 1, 2, 3]
152
+ ```
153
+
154
+ ### `_.arrUnique (any[])`
155
+
156
+ Remove duplicate values from array and two-dimensional array data. In the case of 2d arrays, json type data duplication is not removed.
157
+ - `array::any[]`
158
+
159
+ ```javascript
160
+ _.arrUnique([1, 2, 2, 3]); // Returns [1, 2, 3]
161
+ _.arrUnique([[1], [1], [2]]); // Returns [[1], [2]]
162
+ ```
163
+
164
+ ### `_.average (number)`
165
+
166
+ Returns the average of all numeric values in an array.
167
+ - `array::number[]`
168
+
169
+ ```javascript
170
+ _.average([1, 5, 15, 50]); // Returns 17.75
171
+ ```
172
+
173
+ ### `_.arrMove (any[])`
174
+
175
+ Moves the position of a specific element in an array to the specified position. (Position starts from 0.)
176
+ - `array::any[]`
177
+ - `from::number`
178
+ - `to::number`
179
+
180
+ ```javascript
181
+ _.arrMove([1, 2, 3, 4], 1, 0); // Returns [2, 1, 3, 4]
182
+ ```
183
+
184
+ ### `_.removeSpecialChar (string)`
185
+
186
+ Returns after removing all special characters, including spaces.
187
+ - `str::string`
188
+ - `withoutSpace::boolean`
189
+
190
+ ```javascript
191
+ _.removeSpecialChar('Hello, World!'); // Returns 'HelloWorld'
192
+ ```
193
+
194
+ ### `_.removeNewLine (string)`
195
+
196
+ Removes `\n`, `\r` characters or replaces them with specified characters.
197
+ - `str::string`
198
+ - `replaceTo::string || ''`
199
+
200
+ ```javascript
201
+ _.removeNewLine('ab\ncd'); // Returns 'abcd'
202
+ _.removeNewLine('ab\r\ncd', '-'); // Returns 'ab-cd'
203
+ ```
204
+
205
+ ### `_.capitalizeFirst (string)`
206
+
207
+ Converts the first letter of the entire string to uppercase and returns.
208
+ - `str::string`
209
+
210
+ ```javascript
211
+ _.capitalizeFirst('abcd'); // Returns 'Abcd'
212
+ ```
213
+
214
+ ### `_.capitalizeEachWords (string)`
215
+
216
+ Converts every word with spaces to uppercase. If the naturally argument is true, only some special cases (such as prepositions) are kept lowercase.
217
+ - `str::string`
218
+ - `natural::boolean || false`
219
+
220
+ ```javascript
221
+ _.capitalizeEachWords('abcd'); // Returns 'Abcd'
222
+ ```
223
+
224
+ ### `_.strNumberOf (number)`
225
+
226
+ Returns the number of times the second String character is contained in the first String argument.
227
+ - `str::string`
228
+ - `search::string`
229
+
230
+ ```javascript
231
+ _.count('abcabc', 'a'); // Returns 2
232
+ ```
233
+
234
+ ### `_.strShuffle (string)`
235
+
236
+ Randomly shuffles the received string and returns it.
237
+ - `str::string`
238
+
239
+ ```javascript
240
+ _.shuffle('abcdefg'); // Returns 'bgafced'
241
+ ```
242
+
243
+ ### `_.strRandom (string)`
244
+
245
+ Returns a random String containing numbers or uppercase and lowercase letters of the given length. The default return length is 12.
246
+ - `length::number`
247
+ - `additionalCharacters::string?`
248
+
249
+ ```javascript
250
+ _.strRandom(5); // Returns 'CHy2M'
251
+ ```
252
+
253
+ ### `_.strBlindRandom (string)`
254
+
255
+ Replaces strings at random locations with a specified number of characters (default 1) with characters (default *).
256
+ - `str::string`
257
+ - `blindLength::number`
258
+ - `blindStr::string || '*'`
259
+
260
+ ```javascript
261
+ _.hideRandom('hello', 2, '#'); // Returns '#el#o'
262
+ ```
263
+
264
+ ### `_.truncate (string)`
265
+
266
+ Truncates a long string to a specified length, optionally appending an ellipsis after the string.
267
+ - `str::string`
268
+ - `length::number`
269
+ - `ellipsis::string || ''`
270
+
271
+ ```javascript
272
+ _.truncate('hello', 3); // Returns 'hel'
273
+ _.truncate('hello', 2, '...'); // Returns 'he...'
274
+ ```
275
+
276
+ ### `_.encrypt (string)`
277
+
278
+ Encrypt with the algorithm of your choice (algorithm default: `aes-256-cbc`, ivSize default: `16`) using a string and a secret (secret).
279
+ - `str::string`
280
+ - `secret::string`
281
+ - `algorithm::string || 'aes-256-cbc'`
282
+ - `ivSize::number || 16`
283
+
284
+ ```javascript
285
+ _.encrypt('test', 'secret-key');
286
+ ```
287
+
288
+ ### `_.decrypt (string)`
289
+
290
+ Decrypt with the specified algorithm (default: `aes-256-cbc`) using a string and a secret (secret).
291
+ - `str::string`
292
+ - `secret::string`
293
+ - `algorithm::string || 'aes-256-cbc'`
294
+
295
+ ```javascript
296
+ _.decrypt('61ba43b65fc...', 'secret-key');
297
+ ```
298
+
299
+ ### `_.md5 (string)`
300
+
301
+ Converts String data to md5 hash value and returns it.
302
+ - `str::string`
303
+
304
+ ```javascript
305
+ _.md5('test'); // Returns '098f6bcd4621d373cade4e832627b4f6'
306
+ ```
307
+
308
+ ### `_.sha1 (string)`
309
+
310
+ Converts String data to sha1 hash value and returns it.
311
+ - `str::string`
312
+
313
+ ```javascript
314
+ _.sha1('test'); // Returns 'a94a8fe5ccb19ba61c4c0873d391e987982fbbd3'
315
+ ```
316
+
317
+ ### `_.sha256 (string)`
318
+
319
+ Converts String data to sha256 hash value and returns it.
320
+ - `str::string`
321
+
322
+ ```javascript
323
+ _.sha256('test'); // Returns '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08'
324
+ ```
325
+
326
+ ### `_.encodeBase64 (string)`
327
+
328
+ Base64-encode the given string.
329
+ - `str::string`
330
+
331
+ ```javascript
332
+ _.encodeBase64('this is test'); // Returns 'dGhpcyBpcyB0ZXN0'
333
+ ```
334
+
335
+ ### `_.decodeBase64 (string)`
336
+
337
+ Decodes an encoded base64 string to a plain string.
338
+ - `encodedStr::string`
339
+
340
+ ```javascript
341
+ _.decodeBase64('dGhpcyBpcyB0ZXN0'); // Returns 'this is test'
342
+ ```
343
+
344
+ ### `_.strUnique (string)`
345
+
346
+ Remove duplicate characters from a given string and output only one.
347
+ - `str::string`
348
+
349
+ ```javascript
350
+ _.strUnique('aaabbbcc'); // Returns 'abc'
351
+ ```
352
+
353
+ ### `_.isEmpty (boolean)`
354
+
355
+ Returns true if the passed data is empty or has a length of 0.
356
+ - `data::any?`
357
+
358
+ ```javascript
359
+ _.isEmpty([]); // Returns true
360
+ _.isEmpty(''); // Returns true
361
+ _.isEmpty('abc'); // Returns false
362
+ ```
363
+
364
+ ### `_.isUrl (boolean)`
365
+
366
+ Returns `true` if the given data is in the correct URL format. If withProtocol is `true`, it is automatically appended to the URL when the protocol does not exist. If strict is `true`, URLs without commas (`.`) return `false`.
367
+ - `url::string`
368
+ - `withProtocol::boolean || false`
369
+ - `strict::boolean || false`
370
+
371
+ ```javascript
372
+ _.isUrl('google.com'); // Returns false
373
+ _.isUrl('google.com', true); // Returns true
374
+ _.isUrl('https://google.com'); // Returns true
375
+ ```
376
+
377
+ ### `_.contains (boolean)`
378
+
379
+ Returns `true` if the first string argument contains the second argument "string" or "one or more of the strings listed in the array". If the exact value is `true`, it returns true only for an exact match.
380
+ - `str::any[]|string`
381
+ - `search::any[]|string`
382
+ - `exact::boolean || false`
383
+
384
+ ```javascript
385
+ _.contains('abc', 'a'); // Returns true
386
+ _.contains('abc', 'd'); // Returns false
387
+ _.contains('abc', ['a', 'd']); // Returns true
388
+ ```
389
+
390
+ ### `_.is2dArray (boolean)`
391
+
392
+ Returns `true` if the given array is a two-dimensional array.
393
+ - `array::any[]`
394
+
395
+ ```javascript
396
+ _.is2dArray([1]); // Returns false
397
+ _.is2dArray([[1], [2]]); // Returns true
398
+ ```
399
+
400
+ ### `_.between (boolean)`
401
+
402
+ Returns `true` if the first argument is in the range of the second argument (`[min, max]`). To allow the minimum and maximum values to be in the range, pass `true` for the third argument.
403
+ - `range::[number, number]`
404
+ - `number::number`
405
+ - `inclusive::boolean || false`
406
+
407
+ ```javascript
408
+ _.between([10, 20], 10); // Returns false
409
+ _.between([10, 20], 10, true); // Returns true
410
+ ```
411
+
412
+ ### `_.len (number)`
413
+
414
+ Returns the length of any type of data. If the argument value is `null` or `undefined`, `0` is returned.
415
+ - `data::any`
416
+
417
+ ```javascript
418
+ _.len('12345'); // Returns 5
419
+ _.len([1, 2, 3]); // Returns 3
420
+ ```
421
+
422
+ ### `_.isBotAgent (boolean)`
423
+
424
+ Analyze the user agent value to determine if it's a bot for a search engine. Returns `true` if it's a bot.
425
+ - `userAgent::string`
426
+
427
+ ```javascript
428
+ _.isBotAgent('Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'); // Returns true
429
+ ```
430
+
431
+ ### `_.numberFormat (string)`
432
+
433
+ Return number format including comma symbol.
434
+ - `number::number`
435
+
436
+ ```javascript
437
+ _.number(1234567); // Returns 1,234,567
438
+ ```
439
+
440
+ ### `_.fileName (string)`
441
+
442
+ Extract the file name from the path. Include the extension if withExtension is `true`.
443
+ - `filePath::string`
444
+ - `withExtension::boolean || false`
445
+
446
+ ```javascript
447
+ _.fileName('C:\Temp\hello.txt'); // Returns 'hello.txt'
448
+ _.fileName('C:\Temp\file.mp3', true); // Returns 'file.mp3'
449
+ ```
450
+
451
+ ### `_.fileSize (string)`
452
+
453
+ Converts the file size in bytes to human-readable and returns it. The return value is a String and includes the file units (Bytes, MB, GB...). If the second optional argument value is included, you can display as many decimal places as you like.
454
+ - `bytes::number`
455
+ - `decimals::number || 2`
456
+
457
+ ```javascript
458
+ _.fileSize(2000, 3); // Returns '1.953 KB'
459
+ _.fileSize(250000000); // Returns '238.42 MB'
460
+ ```
461
+
462
+ ### `_.fileExt (string)`
463
+
464
+ Returns only the extensions in the file path. If unknown, returns 'Unknown'.
465
+ - `filePath::string`
466
+
467
+ ```javascript
468
+ _.fileExt('C:\Temp\hello.txt'); // Returns 'txt'
469
+ _.fileExt('this-is-file.mp3'); // Returns 'mp3'
470
+ ```
471
+
472
+ ### `_.msToTime (string)`
473
+
474
+ Converts milliseconds to hours, minutes, seconds, and milliseconds and returns. If the second argument is true, milliseconds are also printed. You can put any separator (String) between hours, minutes, and seconds in the third argument.
475
+ - `milliseconds::number`
476
+ - `withMilliseconds::boolean || false`
477
+ - `separator::string || ':'`
478
+
479
+ ```javascript
480
+ _.msToTime(100000); // 'Returns '00:01:40'
481
+ _.msToTime(100000, true, '-'); // Returns '00-01-40.0'
482
+ ```
483
+
484
+ ### `_.secToTime (string)`
485
+
486
+ Converts seconds to hours, minutes, seconds and returns. You can put any separator (String) between hours, minutes, and seconds in the third argument.
487
+ - `seconds::number`
488
+ - `onlyHour::boolean || false`
489
+ - `separator::string || ':'`
490
+
491
+ ```javascript
492
+ _.secToTime(3800); // Returns '01:03:20'
493
+ _.secToTime(60, '-'); // Returns '00-01-00'
494
+ ```
495
+
496
+ ### `_.license (string)`
497
+
498
+ Returns text in a specific license format based on the author information of the given argument. The argument uses the Object type.
499
+ - `options::LicenseOption{
500
+ author: string,
501
+ email: string?,
502
+ yearStart: string|number,
503
+ yearEnd: string?,
504
+ htmlBr: boolean?,
505
+ type: 'mit' | 'apache20'
506
+ }`
507
+
508
+ ```javascript
509
+ _.license({
510
+ holder: 'example',
511
+ email: 'example@example.com',
512
+ yearStart: 2020,
513
+ yearEnd: 2021,
514
+ htmlBr: true
515
+ });
516
+ ```
517
+
518
+ # Contribute
519
+ You can report issues on GitHub Issue. You can also request a pull to fix bugs and add frequently used features.
520
+
521
+ # License
522
+ Copyright © 2021 Jooy2 Released under the MIT license.