qsu 0.5.5 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +2 -0
- package/.eslintrc.cjs +44 -0
- package/LICENSE +21 -21
- package/README.md +522 -159
- package/dist/index.d.ts +57 -0
- package/dist/index.js +349 -0
- package/package.json +55 -38
- package/tsconfig.json +23 -0
- package/.babelrc +0 -7
- package/.eslintrc.js +0 -25
- package/.idea/git_toolbox_prj.xml +0 -20
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/jsLinters/eslint.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/qsu.iml +0 -12
- package/.idea/vcs.xml +0 -6
- package/array.js +0 -57
- package/date.js +0 -36
- package/format.js +0 -80
- package/index.js +0 -17
- package/math.js +0 -32
- package/misc.js +0 -7
- package/string.js +0 -145
- package/verify.js +0 -88
package/README.md
CHANGED
|
@@ -1,159 +1,522 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-
### Node.js Quick & Simple Utility for JavaScript
|
|
5
|
-
|
|
6
|
-
[](https://github.com/jooy2/qsu/blob/master/LICENSE)
|
|
7
|
-

|
|
8
|
-
[](https://www.npmjs.com/package/qsu)
|
|
9
|
-

|
|
10
|
-

|
|
11
|
-
[](https://www.npmjs.com/package/qsu)
|
|
12
|
-
[](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
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
```javascript
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
### Node.js Quick & Simple Utility for JavaScript
|
|
5
|
+
|
|
6
|
+
[](https://github.com/jooy2/qsu/blob/master/LICENSE)
|
|
7
|
+

|
|
8
|
+
[](https://www.npmjs.com/package/qsu)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
[](https://www.npmjs.com/package/qsu)
|
|
12
|
+
[](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.
|