@hypernym/utils 3.0.0 → 3.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/README.md CHANGED
@@ -5,7 +5,7 @@ A collection of reusable utilities.
5
5
  <sub><a href="https://github.com/hypernym-studio/utils">Repository</a> | <a href="https://www.npmjs.com/package/@hypernym/utils">Package</a> | <a href="https://github.com/hypernym-studio/utils/releases">Releases</a> | <a href="https://github.com/hypernym-studio/utils/discussions">Discussions</a></sub>
6
6
 
7
7
  ```sh
8
- npm i @hypernym/utils
8
+ pnpm add @hypernym/utils
9
9
  ```
10
10
 
11
11
  ## Features
@@ -32,8 +32,6 @@ Use the official [discussions](https://github.com/hypernym-studio/utils/discussi
32
32
 
33
33
  ## License
34
34
 
35
- Developed in 🇭🇷 Croatia.
35
+ Developed in 🇭🇷 Croatia, © Hypernym Studio.
36
36
 
37
37
  Released under the [MIT](LICENSE.txt) license.
38
-
39
- © Hypernym Studio
package/dist/index.mjs CHANGED
@@ -24,11 +24,11 @@ const isSet = (v) => v instanceof Set;
24
24
  const isWeakSet = (v) => v instanceof WeakSet;
25
25
  const isSymbol = (v) => toString(v) === "Symbol";
26
26
  const isDate = (v) => v instanceof Date && !isNaN(v.valueOf());
27
- const isBigint = (v) => typeof v === "bigint";
27
+ const isBigInt = (v) => typeof v === "bigint";
28
28
  const isInfinity = (v) => v === Infinity || v === -Infinity;
29
29
  const isURL = (v) => v instanceof URL;
30
30
  const isError = (v) => v instanceof Error;
31
- const isPrimitive = (v) => isString(v) || isNumber(v) || isBigint(v) || isBoolean(v) || isSymbol(v) || isNull(v) || isUndefined(v);
31
+ const isPrimitive = (v) => isString(v) || isNumber(v) || isBigInt(v) || isBoolean(v) || isSymbol(v) || isNull(v) || isUndefined(v);
32
32
  const isElement = (v) => v instanceof Element;
33
33
  const isHtmlElement = (v) => v instanceof HTMLElement;
34
34
  const isSvgElement = (v) => v instanceof SVGElement;
@@ -37,4 +37,4 @@ const isNodeListEmpty = (v) => isNodeList(v) && v.length === 0;
37
37
  const isHtmlCollection = (v) => v instanceof HTMLCollection;
38
38
  const isHtmlCollectionEmpty = (v) => isHtmlCollection(v) && v.length === 0;
39
39
 
40
- export { isArray, isArrayEmpty, isBigint, isBoolean, isBrowser, isDate, isElement, isError, isFalse, isFunction, isHtmlCollection, isHtmlCollectionEmpty, isHtmlElement, isInfinity, isMap, isNaNValue, isNodeList, isNodeListEmpty, isNull, isNumber, isObject, isObjectEmpty, isPrimitive, isRegExp, isSet, isString, isStringEmpty, isSvgElement, isSymbol, isTrue, isURL, isUndefined, isWeakMap, isWeakSet, noop, toString };
40
+ export { isArray, isArrayEmpty, isBigInt, isBoolean, isBrowser, isDate, isElement, isError, isFalse, isFunction, isHtmlCollection, isHtmlCollectionEmpty, isHtmlElement, isInfinity, isMap, isNaNValue, isNodeList, isNodeListEmpty, isNull, isNumber, isObject, isObjectEmpty, isPrimitive, isRegExp, isSet, isString, isStringEmpty, isSvgElement, isSymbol, isTrue, isURL, isUndefined, isWeakMap, isWeakSet, noop, toString };
@@ -7,6 +7,8 @@ import { writeFile as writeFile$1 } from 'node:fs/promises';
7
7
  *
8
8
  * ```ts
9
9
  * import { exists } from '@hypernym/utils/fs'
10
+ *
11
+ * exists('dir/file.ts') // => true
10
12
  * ```
11
13
  */
12
14
  declare function exists(path: string): Promise<boolean>;
@@ -18,6 +20,8 @@ declare function exists(path: string): Promise<boolean>;
18
20
  *
19
21
  * ```ts
20
22
  * import { writeFile } from '@hypernym/utils/fs'
23
+ *
24
+ * writeFile('dir/subdir/file.ts', `console.log('Hello World!')`)
21
25
  * ```
22
26
  */
23
27
  declare function writeFile(path: string, data: Parameters<typeof writeFile$1>[1], options?: Parameters<typeof writeFile$1>[2]): Promise<void>;
@@ -1,9 +1,25 @@
1
1
  /**
2
2
  * An empty arrow function that performs no operation.
3
+ *
4
+ * @example
5
+ *
6
+ * ```ts
7
+ * import { noop } from '@hypernym/utils'
8
+ *
9
+ * noop()
10
+ * ```
3
11
  */
4
12
  declare const noop: () => void;
5
13
  /**
6
14
  * Returns a string representing the object.
15
+ *
16
+ * @example
17
+ *
18
+ * ```ts
19
+ * import { toString } from '@hypernym/utils'
20
+ *
21
+ * toString({}) // => 'Object'
22
+ * ```
7
23
  */
8
24
  declare const toString: (v: any) => string;
9
25
 
@@ -18,138 +34,408 @@ type BuiltIn = Primitive | Date | RegExp;
18
34
 
19
35
  /**
20
36
  * Checks if the code is running in the browser.
37
+ *
38
+ * @example
39
+ *
40
+ * ```ts
41
+ * import { isBrowser } from '@hypernym/utils'
42
+ *
43
+ * isBrowser // true
44
+ * ```
21
45
  */
22
46
  declare const isBrowser: boolean;
23
47
  /**
24
48
  * Returns a boolean if the given value is a `null`.
49
+ *
50
+ * @example
51
+ *
52
+ * ```ts
53
+ * import { isNull } from '@hypernym/utils'
54
+ *
55
+ * isNull(null) // => true
56
+ * ```
25
57
  */
26
58
  declare const isNull: (v: any) => v is null;
27
59
  /**
28
60
  * Returns a boolean if the given value is a `undefined`.
61
+ *
62
+ * @example
63
+ *
64
+ * ```ts
65
+ * import { isUndefined } from '@hypernym/utils'
66
+ *
67
+ * isUndefined(undefined) // => true
68
+ * ```
29
69
  */
30
70
  declare const isUndefined: (v: any) => v is undefined;
31
71
  /**
32
72
  * Returns a boolean if the given value is a `string`.
73
+ *
74
+ * @example
75
+ *
76
+ * ```ts
77
+ * import { isString } from '@hypernym/utils'
78
+ *
79
+ * isString('@hypernym/utils') // => true
80
+ * ```
33
81
  */
34
82
  declare const isString: (v: any) => v is string;
35
83
  /**
36
84
  * Returns a boolean if the given value is an empty `string`.
85
+ *
86
+ * @example
87
+ *
88
+ * ```ts
89
+ * import { isStringEmpty } from '@hypernym/utils'
90
+ *
91
+ * isStringEmpty('') // => true
92
+ * ```
37
93
  */
38
94
  declare const isStringEmpty: (v: any) => v is string;
39
95
  /**
40
96
  * Returns a boolean if the given value is a `boolean`.
97
+ *
98
+ * @example
99
+ *
100
+ * ```ts
101
+ * import { isBoolean } from '@hypernym/utils'
102
+ *
103
+ * isBoolean(true) // => true
104
+ * ```
41
105
  */
42
106
  declare const isBoolean: (v: any) => v is boolean;
43
107
  /**
44
108
  * Returns a boolean if the given value is a `true`.
109
+ *
110
+ * @example
111
+ *
112
+ * ```ts
113
+ * import { isTrue } from '@hypernym/utils'
114
+ *
115
+ * isTrue(true) // => true
116
+ * ```
45
117
  */
46
118
  declare const isTrue: (v: any) => v is true;
47
119
  /**
48
120
  * Returns a boolean if the given value is a `false`.
121
+ *
122
+ * @example
123
+ *
124
+ * ```ts
125
+ * import { isFalse } from '@hypernym/utils'
126
+ *
127
+ * isFalse(false) // => true
128
+ * ```
49
129
  */
50
130
  declare const isFalse: (v: any) => v is false;
51
131
  /**
52
132
  * Returns a boolean if the given value is a `number`.
133
+ *
134
+ * @example
135
+ *
136
+ * ```ts
137
+ * import { isNumber } from '@hypernym/utils'
138
+ *
139
+ * isNumber(33) // => true
140
+ * ```
53
141
  */
54
142
  declare const isNumber: (v: any) => v is number;
55
143
  /**
56
144
  * Returns a boolean if the given value is a `array`.
145
+ *
146
+ * @example
147
+ *
148
+ * ```ts
149
+ * import { isArray } from '@hypernym/utils'
150
+ *
151
+ * isArray([]) // => true
152
+ * ```
57
153
  */
58
154
  declare const isArray: (v: any) => v is any[];
59
155
  /**
60
156
  * Returns a boolean if the given value is an empty `array`.
157
+ *
158
+ * @example
159
+ *
160
+ * ```ts
161
+ * import { isArrayEmpty } from '@hypernym/utils'
162
+ *
163
+ * isArrayEmpty([]) // => true
164
+ * ```
61
165
  */
62
166
  declare const isArrayEmpty: (v: any) => v is any[];
63
167
  /**
64
168
  * Returns a boolean if the given value is a `object`.
169
+ *
170
+ * @example
171
+ *
172
+ * ```ts
173
+ * import { isObject } from '@hypernym/utils'
174
+ *
175
+ * isObject({}) // => true
176
+ * ```
65
177
  */
66
178
  declare const isObject: (v: any) => v is object;
67
179
  /**
68
180
  * Returns a boolean if the given value is an empty `object`.
181
+ *
182
+ * @example
183
+ *
184
+ * ```ts
185
+ * import { isObjectEmpty } from '@hypernym/utils'
186
+ *
187
+ * isObjectEmpty({}) // => true
188
+ * ```
69
189
  */
70
190
  declare const isObjectEmpty: (v: any) => v is object;
71
191
  /**
72
192
  * Returns a boolean if the given value is a `Function`.
193
+ *
194
+ * @example
195
+ *
196
+ * ```ts
197
+ * import { isFunction } from '@hypernym/utils'
198
+ *
199
+ * isFunction(() => {}) // => true
200
+ * ```
73
201
  */
74
202
  declare const isFunction: (v: any) => v is (...args: any[]) => unknown;
75
203
  /**
76
204
  * Returns a boolean if the given value is a `NaN`.
205
+ *
206
+ * @example
207
+ *
208
+ * ```ts
209
+ * import { isNaNValue } from '@hypernym/utils'
210
+ *
211
+ * isNaNValue(NaN) // => true
212
+ * ```
77
213
  */
78
- declare const isNaNValue: (v: any) => v is number;
214
+ declare const isNaNValue: (v: any) => v is typeof NaN;
79
215
  /**
80
216
  * Returns a boolean if the given value is a `RegExp`.
217
+ *
218
+ * @example
219
+ *
220
+ * ```ts
221
+ * import { isRegExp } from '@hypernym/utils'
222
+ *
223
+ * isRegExp(/^hypernym/) // => true
224
+ * ```
81
225
  */
82
226
  declare const isRegExp: (v: any) => v is RegExp;
83
227
  /**
84
228
  * Returns a boolean if the given value is a `Map`.
229
+ *
230
+ * @example
231
+ *
232
+ * ```ts
233
+ * import { isMap } from '@hypernym/utils'
234
+ *
235
+ * isMap(new Map()) // => true
236
+ * ```
85
237
  */
86
238
  declare const isMap: (v: any) => v is Map<any, any>;
87
239
  /**
88
240
  * Returns a boolean if the given value is a `WeakMap`.
241
+ *
242
+ * @example
243
+ *
244
+ * ```ts
245
+ * import { isWeakMap } from '@hypernym/utils'
246
+ *
247
+ * isWeakMap(new WeakMap()) // => true
248
+ * ```
89
249
  */
90
250
  declare const isWeakMap: (v: any) => v is WeakMap<any, any>;
91
251
  /**
92
252
  * Returns a boolean if the given value is a `Set`.
253
+ *
254
+ * @example
255
+ *
256
+ * ```ts
257
+ * import { isSet } from '@hypernym/utils'
258
+ *
259
+ * isSet(new Set()) // => true
260
+ * ```
93
261
  */
94
262
  declare const isSet: (v: any) => v is Set<any>;
95
263
  /**
96
264
  * Returns a boolean if the given value is a `WeakSet`.
265
+ *
266
+ * @example
267
+ *
268
+ * ```ts
269
+ * import { isWeakSet } from '@hypernym/utils'
270
+ *
271
+ * isWeakSet(new WeakSet()) // => true
272
+ * ```
97
273
  */
98
274
  declare const isWeakSet: (v: any) => v is WeakSet<any>;
99
275
  /**
100
276
  * Returns a boolean if the given value is a `symbol`.
277
+ *
278
+ * @example
279
+ *
280
+ * ```ts
281
+ * import { isSymbol } from '@hypernym/utils'
282
+ *
283
+ * isSymbol(Symboly('hypernym')) // => true
284
+ * ```
101
285
  */
102
286
  declare const isSymbol: (v: any) => v is symbol;
103
287
  /**
104
288
  * Returns a boolean if the given value is a `Date`.
289
+ *
290
+ * @example
291
+ *
292
+ * ```ts
293
+ * import { isDate } from '@hypernym/utils'
294
+ *
295
+ * isDate(new Date()) // => true
296
+ * ```
105
297
  */
106
298
  declare const isDate: (v: any) => v is Date;
107
299
  /**
108
300
  * Returns a boolean if the given value is a `bigint`.
301
+ *
302
+ * @example
303
+ *
304
+ * ```ts
305
+ * import { isBigInt } from '@hypernym/utils'
306
+ *
307
+ * isBigInt(1n) // => true
308
+ * ```
109
309
  */
110
- declare const isBigint: (v: any) => v is bigint;
310
+ declare const isBigInt: (v: any) => v is bigint;
111
311
  /**
112
312
  * Returns a boolean if the given value is a `Infinity`.
313
+ *
314
+ * @example
315
+ *
316
+ * ```ts
317
+ * import { isInfinity } from '@hypernym/utils'
318
+ *
319
+ * isInfinity(Infinity) // => true
320
+ * ```
113
321
  */
114
322
  declare const isInfinity: (v: any) => v is number;
115
323
  /**
116
324
  * Returns a boolean if the given value is a `URL`.
325
+ *
326
+ * @example
327
+ *
328
+ * ```ts
329
+ * import { isURL } from '@hypernym/utils'
330
+ *
331
+ * isURL(new URL('https://localhost:3000')) // => true
332
+ * ```
117
333
  */
118
334
  declare const isURL: (v: any) => v is URL;
119
335
  /**
120
336
  * Returns a boolean if the given value is a `Error`.
337
+ *
338
+ * @example
339
+ *
340
+ * ```ts
341
+ * import { isError } from '@hypernym/utils'
342
+ *
343
+ * isError(new Error()) // => true
344
+ * ```
121
345
  */
122
346
  declare const isError: (v: any) => v is Error;
123
347
  /**
124
348
  * Returns a boolean if the given value is a `Primitive`.
349
+ *
350
+ * @example
351
+ *
352
+ * ```ts
353
+ * import { isPrimitive } from '@hypernym/utils'
354
+ *
355
+ * isPrimitive(true) // => true
356
+ * ```
125
357
  */
126
358
  declare const isPrimitive: (v: any) => v is Primitive;
127
359
  /**
128
360
  * Returns a boolean if the given value is a `Element`.
361
+ *
362
+ * @example
363
+ *
364
+ * ```ts
365
+ * import { isElement } from '@hypernym/utils'
366
+ *
367
+ * isElement(el) // => true
368
+ * ```
129
369
  */
130
370
  declare const isElement: (v: any) => v is Element;
131
371
  /**
132
372
  * Returns a boolean if the given value is a `HTMLElement`.
373
+ *
374
+ * @example
375
+ *
376
+ * ```ts
377
+ * import { isHtmlElement } from '@hypernym/utils'
378
+ *
379
+ * isHtmlElement(htmlEl) // => true
380
+ * ```
133
381
  */
134
382
  declare const isHtmlElement: (v: any) => v is HTMLElement;
135
383
  /**
136
384
  * Returns a boolean if the given value is a `SVGElement`.
385
+ *
386
+ * @example
387
+ *
388
+ * ```ts
389
+ * import { isSvgElement } from '@hypernym/utils'
390
+ *
391
+ * isSvgElement(svgEl) // => true
392
+ * ```
137
393
  */
138
394
  declare const isSvgElement: (v: any) => v is SVGElement;
139
395
  /**
140
396
  * Returns a boolean if the given value is a `NodeList`.
397
+ *
398
+ * @example
399
+ *
400
+ * ```ts
401
+ * import { isNodeList } from '@hypernym/utils'
402
+ *
403
+ * isNodeList(document.querySelectorAll('div')) // => true
404
+ * ```
141
405
  */
142
406
  declare const isNodeList: (v: any) => v is NodeList;
143
407
  /**
144
408
  * Returns a boolean if the given value is an empty `NodeList`.
409
+ *
410
+ * @example
411
+ *
412
+ * ```ts
413
+ * import { isNodeListEmpty } from '@hypernym/utils'
414
+ *
415
+ * isNodeListEmpty(document.querySelectorAll('divs')) // => true
416
+ * ```
145
417
  */
146
418
  declare const isNodeListEmpty: (v: any) => v is NodeList;
147
419
  /**
148
420
  * Returns a boolean if the given value is a `HTMLCollection`.
421
+ *
422
+ * @example
423
+ *
424
+ * ```ts
425
+ * import { isHtmlCollection } from '@hypernym/utils'
426
+ *
427
+ * isHtmlCollection(document.getElementsByClassName('el')) // => true
428
+ * ```
149
429
  */
150
430
  declare const isHtmlCollection: (v: any) => v is HTMLCollection;
151
431
  /**
152
432
  * Returns a boolean if the given value is an empty `HTMLCollection`.
433
+ *
434
+ * ```ts
435
+ * import { isHtmlCollectionEmpty } from '@hypernym/utils'
436
+ *
437
+ * isHtmlCollectionEmpty(document.getElementsByClassName('els')) // => true
438
+ * ```
153
439
  */
154
440
  declare const isHtmlCollectionEmpty: (v: any) => v is HTMLCollection;
155
441
 
@@ -210,4 +496,4 @@ type RequiredObjectDeep<T extends object, Options extends RequiredOptions = {
210
496
  [K in keyof T]-?: RequiredDeep<T[K], Options>;
211
497
  };
212
498
 
213
- export { type BuiltIn, type IsAny, type IsNever, type IsNull, type PartialDeep, type Primitive, type RequiredDeep, isArray, isArrayEmpty, isBigint, isBoolean, isBrowser, isDate, isElement, isError, isFalse, isFunction, isHtmlCollection, isHtmlCollectionEmpty, isHtmlElement, isInfinity, isMap, isNaNValue, isNodeList, isNodeListEmpty, isNull, isNumber, isObject, isObjectEmpty, isPrimitive, isRegExp, isSet, isString, isStringEmpty, isSvgElement, isSymbol, isTrue, isURL, isUndefined, isWeakMap, isWeakSet, noop, toString };
499
+ export { type BuiltIn, type IsAny, type IsNever, type IsNull, type PartialDeep, type Primitive, type RequiredDeep, isArray, isArrayEmpty, isBigInt, isBoolean, isBrowser, isDate, isElement, isError, isFalse, isFunction, isHtmlCollection, isHtmlCollectionEmpty, isHtmlElement, isInfinity, isMap, isNaNValue, isNodeList, isNodeListEmpty, isNull, isNumber, isObject, isObjectEmpty, isPrimitive, isRegExp, isSet, isString, isStringEmpty, isSvgElement, isSymbol, isTrue, isURL, isUndefined, isWeakMap, isWeakSet, noop, toString };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypernym/utils",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "author": "Hypernym Studio",
5
5
  "description": "A collection of reusable utilities.",
6
6
  "license": "MIT",
@@ -36,17 +36,19 @@
36
36
  ],
37
37
  "scripts": {
38
38
  "dev:browser": "vite playgrounds/browser",
39
- "dev:node": "vite-node -w playgrounds/node/main.ts",
39
+ "dev:server": "bun --watch playgrounds/server/main.ts",
40
40
  "build": "hyperbundler",
41
- "test:types": "vitest -c .config/vitest.config.ts --typecheck.only",
42
- "lint": "eslint -c .config/eslint.config.js .",
43
- "lint:fix": "eslint -c .config/eslint.config.js --fix .",
44
- "format": "prettier --config .config/prettier.config.js --write .",
41
+ "test:types": "vitest --typecheck.only",
42
+ "lint": "eslint .",
43
+ "lint:fix": "eslint --fix .",
44
+ "format": "prettier --write .",
45
45
  "prepublishOnly": "npm run build"
46
46
  },
47
47
  "sideEffects": false,
48
+ "packageManager": "pnpm@9.9.0",
48
49
  "engines": {
49
- "node": ">=20.0.0"
50
+ "node": ">=20.0.0",
51
+ "pnpm": ">=9.0.0"
50
52
  },
51
53
  "peerDependencies": {
52
54
  "@types/node": ">=20.0.0",
@@ -61,14 +63,14 @@
61
63
  }
62
64
  },
63
65
  "devDependencies": {
64
- "@hypernym/bundler": "^0.8.1",
65
- "@hypernym/eslint-config": "^3.0.0",
66
- "@hypernym/prettier-config": "^3.0.0",
67
- "@hypernym/tsconfig": "^2.0.0",
68
- "@types/node": "^20.12.7",
69
- "eslint": "^9.0.0",
70
- "prettier": "^3.2.5",
71
- "typescript": "^5.4.4",
72
- "vitest": "^1.4.0"
66
+ "@hypernym/bundler": "^0.10.0",
67
+ "@hypernym/eslint-config": "^3.5.0",
68
+ "@hypernym/prettier-config": "^3.2.0",
69
+ "@hypernym/tsconfig": "^2.3.0",
70
+ "@types/node": "^20.16.5",
71
+ "eslint": "^9.10.0",
72
+ "prettier": "^3.3.3",
73
+ "typescript": "^5.5.4",
74
+ "vitest": "^2.0.5"
73
75
  }
74
76
  }