@hypernym/utils 3.4.4 → 3.4.6

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/LICENSE.txt CHANGED
@@ -1,6 +1,7 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Ivo Dolenc, Hypernym Studio
3
+ Copyright (c) 2025, Ivo Dolenc <https://github.com/ivodolenc>
4
+ Copyright (c) 2025, Hypernym Studio <https://github.com/hypernym-studio>
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <h1 align="center">Utils</h1>
1
+ <h1 align="center">@hypernym/utils</h1>
2
2
 
3
3
  <p align="center">A collection of reusable utilities.</p>
4
4
 
@@ -48,7 +48,7 @@ Also, it is possible to download files manually and serve them accordingly.
48
48
 
49
49
  ```html
50
50
  <script type="module">
51
- import { isNull, isString, ... } from 'https://unpkg.com/@hypernym/utils/dist/index.min.mjs'
51
+ import { isNull, isString, ... } from 'https://unpkg.com/@hypernym/utils/dist/index.min.js'
52
52
  </script>
53
53
  ```
54
54
 
@@ -72,7 +72,7 @@ Also, it is possible to download files manually and serve them accordingly.
72
72
 
73
73
  ## Usage
74
74
 
75
- After installation, import `Hyperutils` into your project:
75
+ After installation, import `utils` into your project:
76
76
 
77
77
  ```ts
78
78
  // ESM & TS
@@ -104,7 +104,7 @@ Returns a boolean if the given value is a `null`.
104
104
  ```ts
105
105
  import { isNull } from '@hypernym/utils'
106
106
 
107
- isNull(null) // => true
107
+ isNull(null) // true
108
108
  ```
109
109
 
110
110
  ### isUndefined
@@ -114,7 +114,7 @@ Returns a boolean if the given value is a `undefined`.
114
114
  ```ts
115
115
  import { isUndefined } from '@hypernym/utils'
116
116
 
117
- isUndefined(undefined) // => true
117
+ isUndefined(undefined) // true
118
118
  ```
119
119
 
120
120
  ### isString
@@ -124,7 +124,307 @@ Returns a boolean if the given value is a `string`.
124
124
  ```ts
125
125
  import { isString } from '@hypernym/utils'
126
126
 
127
- isString('@hypernym/utils') // => true
127
+ isString('@hypernym/utils') // true
128
+ ```
129
+
130
+ ### isStringEmpty
131
+
132
+ Returns a boolean if the given value is an empty `string`.
133
+
134
+ ```ts
135
+ import { isStringEmpty } from '@hypernym/utils'
136
+
137
+ isStringEmpty('') // true
138
+ ```
139
+
140
+ ### isBoolean
141
+
142
+ Returns a boolean if the given value is a `boolean`.
143
+
144
+ ```ts
145
+ import { isBoolean } from '@hypernym/utils'
146
+
147
+ isBoolean(true) // true
148
+ ```
149
+
150
+ ### isTrue
151
+
152
+ Returns a boolean if the given value is a `true`.
153
+
154
+ ```ts
155
+ import { isTrue } from '@hypernym/utils'
156
+
157
+ isTrue(true) // true
158
+ ```
159
+
160
+ ### isFalse
161
+
162
+ Returns a boolean if the given value is a `false`.
163
+
164
+ ```ts
165
+ import { isFalse } from '@hypernym/utils'
166
+
167
+ isFalse(false) // true
168
+ ```
169
+
170
+ ### isNumber
171
+
172
+ Returns a boolean if the given value is a `number`.
173
+
174
+ ```ts
175
+ import { isNumber } from '@hypernym/utils'
176
+
177
+ isNumber(33) // true
178
+ ```
179
+
180
+ ### isArray
181
+
182
+ Returns a boolean if the given value is a `array`.
183
+
184
+ ```ts
185
+ import { isArray } from '@hypernym/utils'
186
+
187
+ isArray([]) // true
188
+ ```
189
+
190
+ ### isArrayEmpty
191
+
192
+ Returns a boolean if the given value is an empty `array`.
193
+
194
+ ```ts
195
+ import { isArrayEmpty } from '@hypernym/utils'
196
+
197
+ isArrayEmpty([]) // true
198
+ ```
199
+
200
+ ### isObject
201
+
202
+ Returns a boolean if the given value is a `object`.
203
+
204
+ ```ts
205
+ import { isObject } from '@hypernym/utils'
206
+
207
+ isObject({}) // true
208
+ ```
209
+
210
+ ### isObjectEmpty
211
+
212
+ Returns a boolean if the given value is an empty `object`.
213
+
214
+ ```ts
215
+ import { isObjectEmpty } from '@hypernym/utils'
216
+
217
+ isObjectEmpty({}) // true
218
+ ```
219
+
220
+ ### isFunction
221
+
222
+ Returns a boolean if the given value is a `Function`.
223
+
224
+ ```ts
225
+ import { isFunction } from '@hypernym/utils'
226
+
227
+ isFunction(() => {}) // true
228
+ ```
229
+
230
+ ### isNanValue
231
+
232
+ Returns a boolean if the given value is a `NaN`.
233
+
234
+ ```ts
235
+ import { isNaNValue } from '@hypernym/utils'
236
+
237
+ isNaNValue(NaN) // true
238
+ ```
239
+
240
+ ### isRegExp
241
+
242
+ Returns a boolean if the given value is a `RegExp`.
243
+
244
+ ```ts
245
+ import { isRegExp } from '@hypernym/utils'
246
+
247
+ isRegExp(/^hypernym/) // true
248
+ ```
249
+
250
+ ### isMap
251
+
252
+ Returns a boolean if the given value is a `Map`.
253
+
254
+ ```ts
255
+ import { isMap } from '@hypernym/utils'
256
+
257
+ isMap(new Map()) // true
258
+ ```
259
+
260
+ ### isWeakMap
261
+
262
+ Returns a boolean if the given value is a `WeakMap`.
263
+
264
+ ```ts
265
+ import { isWeakMap } from '@hypernym/utils'
266
+
267
+ isWeakMap(new WeakMap()) // true
268
+ ```
269
+
270
+ ### isSet
271
+
272
+ Returns a boolean if the given value is a `Set`.
273
+
274
+ ```ts
275
+ import { isSet } from '@hypernym/utils'
276
+
277
+ isSet(new Set()) // true
278
+ ```
279
+
280
+ ### isWeakSet
281
+
282
+ Returns a boolean if the given value is a `WeakSet`.
283
+
284
+ ```ts
285
+ import { isWeakSet } from '@hypernym/utils'
286
+
287
+ isWeakSet(new WeakSet()) // true
288
+ ```
289
+
290
+ ### isSymbol
291
+
292
+ Returns a boolean if the given value is a `symbol`.
293
+
294
+ ```ts
295
+ import { isSymbol } from '@hypernym/utils'
296
+
297
+ isSymbol(Symboly('hypernym')) // true
298
+ ```
299
+
300
+ ### isDate
301
+
302
+ Returns a boolean if the given value is a `Date`.
303
+
304
+ ```ts
305
+ import { isDate } from '@hypernym/utils'
306
+
307
+ isDate(new Date()) // true
308
+ ```
309
+
310
+ ### isBigInt
311
+
312
+ Returns a boolean if the given value is a `bigint`.
313
+
314
+ ```ts
315
+ import { isBigInt } from '@hypernym/utils'
316
+
317
+ isBigInt(1n) // true
318
+ ```
319
+
320
+ ### isInfinity
321
+
322
+ Returns a boolean if the given value is a `Infinity`.
323
+
324
+ ```ts
325
+ import { isInfinity } from '@hypernym/utils'
326
+
327
+ isInfinity(Infinity) // true
328
+ ```
329
+
330
+ ### isURL
331
+
332
+ Returns a boolean if the given value is a `URL`.
333
+
334
+ ```ts
335
+ import { isURL } from '@hypernym/utils'
336
+
337
+ isURL(new URL('https://localhost:3000')) // true
338
+ ```
339
+
340
+ ### isError
341
+
342
+ Returns a boolean if the given value is a `Error`.
343
+
344
+ ```ts
345
+ import { isError } from '@hypernym/utils'
346
+
347
+ isError(new Error()) // true
348
+ ```
349
+
350
+ ### isPrimitive
351
+
352
+ Returns a boolean if the given value is a `Primitive`.
353
+
354
+ ```ts
355
+ import { isPrimitive } from '@hypernym/utils'
356
+
357
+ isPrimitive(true) // true
358
+ ```
359
+
360
+ ### isElement
361
+
362
+ Returns a boolean if the given value is a `Element`.
363
+
364
+ ```ts
365
+ import { isElement } from '@hypernym/utils'
366
+
367
+ isElement(el) // true
368
+ ```
369
+
370
+ ### isHtmlElement
371
+
372
+ Returns a boolean if the given value is a `HTMLElement`.
373
+
374
+ ```ts
375
+ import { isHtmlElement } from '@hypernym/utils'
376
+
377
+ isHtmlElement(htmlEl) // true
378
+ ```
379
+
380
+ ### isSvgElement
381
+
382
+ Returns a boolean if the given value is a `SVGElement`.
383
+
384
+ ```ts
385
+ import { isSvgElement } from '@hypernym/utils'
386
+
387
+ isSvgElement(svgEl) // true
388
+ ```
389
+
390
+ ### isNodeList
391
+
392
+ Returns a boolean if the given value is a `NodeList`.
393
+
394
+ ```ts
395
+ import { isNodeList } from '@hypernym/utils'
396
+
397
+ isNodeList(document.querySelectorAll('div')) // true
398
+ ```
399
+
400
+ ### isNodeListEmpty
401
+
402
+ Returns a boolean if the given value is an empty `NodeList`.
403
+
404
+ ```ts
405
+ import { isNodeListEmpty } from '@hypernym/utils'
406
+
407
+ isNodeListEmpty(document.querySelectorAll('divs')) // true
408
+ ```
409
+
410
+ ### isHtmlCollection
411
+
412
+ Returns a boolean if the given value is a `HTMLCollection`.
413
+
414
+ ```ts
415
+ import { isHtmlCollection } from '@hypernym/utils'
416
+
417
+ isHtmlCollection(document.getElementsByClassName('el')) // true
418
+ ```
419
+
420
+ ### isHtmlCollectionEmpty
421
+
422
+ Returns a boolean if the given value is an empty `HTMLCollection`.
423
+
424
+ ```ts
425
+ import { isHtmlCollectionEmpty } from '@hypernym/utils'
426
+
427
+ isHtmlCollectionEmpty(document.getElementsByClassName('els')) // true
128
428
  ```
129
429
 
130
430
  ## fs
@@ -136,7 +436,7 @@ Checks if the `file` or `directory` exists.
136
436
  ```ts
137
437
  import { exists } from '@hypernym/utils/fs'
138
438
 
139
- await exists('dir/file.ts') // => true
439
+ await exists('dir/file.ts') // true
140
440
  ```
141
441
 
142
442
  ### read
@@ -207,6 +507,66 @@ await remove('src/subdir/file.ts')
207
507
 
208
508
  ## Types
209
509
 
510
+ ### Primitive
511
+
512
+ Matches any primitive value.
513
+
514
+ ```ts
515
+ import type { Primitive } from '@hypernym/utils'
516
+
517
+ type OnlyPrimitives<T> = T extends Primitive ? T : never
518
+
519
+ type Filtered = OnlyPrimitives<string | number | {} | Date> // string | number
520
+ ```
521
+
522
+ ### BuiltIn
523
+
524
+ Matches any `Primitive`, `Date` or `RegExp` value.
525
+
526
+ ```ts
527
+ import type { BuiltIn } from '@hypernym/utils'
528
+
529
+ type OnlyBuiltIns<T> = T extends BuiltIn ? T : never
530
+
531
+ type Filtered = OnlyBuiltIns<string | Date | {} | RegExp> // string | Date | RegExp
532
+ ```
533
+
534
+ ### IsNull
535
+
536
+ Returns a boolean if the given type is a `null`.
537
+
538
+ ```ts
539
+ import type { IsNull } from '@hypernym/utils'
540
+
541
+ type A = IsNull<null> // true
542
+ type B = IsNull<string> // false
543
+ type C = IsNull<undefined> // false
544
+ ```
545
+
546
+ ### IsAny
547
+
548
+ Returns a boolean if the given type is a `any`.
549
+
550
+ ```ts
551
+ import type { IsAny } from '@hypernym/utils'
552
+
553
+ type A = IsAny<any> // true
554
+ type B = IsAny<string> // false
555
+ type C = IsAny<unknown> // false
556
+ ```
557
+
558
+ ### IsNever
559
+
560
+ Returns a boolean if the given type is a `never`.
561
+
562
+ ```ts
563
+ import type { IsNever } from '@hypernym/utils'
564
+
565
+ type A = IsNever<never> // true
566
+ type B = IsNever<number> // false
567
+ type C = IsNever<undefined> // false
568
+ ```
569
+
210
570
  ### PartialDeep
211
571
 
212
572
  Constructs a type by recursively setting all properties as optional.
@@ -214,6 +574,8 @@ Constructs a type by recursively setting all properties as optional.
214
574
  Use `Partial<T>` for one level.
215
575
 
216
576
  ```ts
577
+ import type { PartialDeep } from '@hypernym/utils'
578
+
217
579
  type PartialObject = PartialDeep<Object>
218
580
 
219
581
  // Disables recursive mode for arrays and tuples.
@@ -227,18 +589,14 @@ Constructs a type by recursively setting all properties as required.
227
589
  Use `Required<T>` for one level.
228
590
 
229
591
  ```ts
592
+ import type { RequiredDeep } from '@hypernym/utils'
593
+
230
594
  type RequiredObject = RequiredDeep<Object>
231
595
 
232
596
  // Disables recursive mode for arrays and tuples.
233
597
  type RequiredObject = RequiredDeep<Object, { arrays: false }>
234
598
  ```
235
599
 
236
- ## Community
237
-
238
- Feel free to ask questions or share new ideas.
239
-
240
- Use the official [discussions](https://github.com/hypernym-studio/utils/discussions) to get involved.
241
-
242
600
  ## License
243
601
 
244
602
  Developed in 🇭🇷 Croatia, © Hypernym Studio.