@elyukai/utils 0.1.2 → 0.1.3

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +14 -0
  3. package/dist/array/filters.d.ts +4 -0
  4. package/dist/array/filters.js +4 -0
  5. package/dist/array/generators.d.ts +4 -0
  6. package/dist/array/generators.js +4 -0
  7. package/dist/array/groups.d.ts +4 -0
  8. package/dist/array/groups.js +4 -0
  9. package/dist/array/modify.d.ts +4 -0
  10. package/dist/array/modify.js +4 -0
  11. package/dist/array/nonEmpty.d.ts +1 -0
  12. package/dist/array/nonEmpty.js +1 -0
  13. package/dist/array/reductions.d.ts +4 -0
  14. package/dist/array/reductions.js +4 -0
  15. package/dist/array/sets.d.ts +4 -0
  16. package/dist/array/sets.js +4 -0
  17. package/dist/async.d.ts +4 -0
  18. package/dist/async.js +4 -0
  19. package/dist/classList.d.ts +4 -0
  20. package/dist/classList.js +4 -0
  21. package/dist/dictionary/native.d.ts +1 -0
  22. package/dist/dictionary/native.js +1 -0
  23. package/dist/dictionary.d.ts +2 -2
  24. package/dist/dictionary.js +2 -2
  25. package/dist/equality.d.ts +4 -0
  26. package/dist/equality.js +4 -0
  27. package/dist/function.d.ts +4 -0
  28. package/dist/function.js +4 -0
  29. package/dist/lazy.d.ts +4 -0
  30. package/dist/lazy.js +4 -0
  31. package/dist/maybe.d.ts +4 -0
  32. package/dist/maybe.js +4 -0
  33. package/dist/nullable.d.ts +4 -0
  34. package/dist/nullable.js +4 -0
  35. package/dist/number.d.ts +4 -0
  36. package/dist/number.js +4 -0
  37. package/dist/object.d.ts +4 -0
  38. package/dist/object.js +4 -0
  39. package/dist/ordering.d.ts +4 -0
  40. package/dist/ordering.js +4 -0
  41. package/dist/range.d.ts +4 -0
  42. package/dist/range.js +4 -0
  43. package/dist/result.d.ts +4 -0
  44. package/dist/result.js +4 -0
  45. package/dist/roman.d.ts +4 -0
  46. package/dist/roman.js +4 -0
  47. package/dist/string/number.d.ts +4 -0
  48. package/dist/string/number.js +4 -0
  49. package/dist/string/regex.d.ts +4 -0
  50. package/dist/string/regex.js +4 -0
  51. package/dist/string.d.ts +4 -0
  52. package/dist/string.js +4 -0
  53. package/dist/typeSafety.d.ts +4 -0
  54. package/dist/typeSafety.js +4 -0
  55. package/package.json +2 -1
  56. package/dist/array.d.ts +0 -4
  57. package/dist/array.js +0 -5
  58. package/dist/compare.d.ts +0 -44
  59. package/dist/compare.js +0 -73
  60. package/dist/date.d.ts +0 -5
  61. package/dist/date.js +0 -5
  62. package/dist/math.d.ts +0 -47
  63. package/dist/math.js +0 -56
  64. package/dist/regex.d.ts +0 -28
  65. package/dist/regex.js +0 -35
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [0.1.3](https://github.com/elyukai/ts-utils/compare/v0.1.2...v0.1.3) (2026-01-24)
6
+
5
7
  ## [0.1.2](https://github.com/elyukai/ts-utils/compare/v0.1.1...v0.1.2) (2026-01-24)
6
8
 
7
9
 
package/README.md CHANGED
@@ -1 +1,15 @@
1
1
  # General TypeScript Helpers
2
+
3
+ This package provides a range of utility functions that I personally often need, which is why I bundled them in a package.
4
+
5
+ ```ts
6
+ import { isNotEmpty } from "@elyukai/utils/array/nonEmpty"
7
+
8
+ const extractFirstNumberDoubled = (arr: number[]): number | undefined => {
9
+ if (isNotEmpty(arr)) {
10
+ return arr[0] * 2 // accessing index 0 is safe!
11
+ }
12
+
13
+ return undefined
14
+ }
15
+ ```
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for filtering arrays.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Filters out duplicate values from an array. Objects are not supported, since
3
7
  * they don’t provide value equality semantics.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for filtering arrays.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Filters out duplicate values from an array. Objects are not supported, since
3
7
  * they don’t provide value equality semantics.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for generating new arrays.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Returns the possibilities of all the combinations of nested array values.
3
7
  *
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for generating new arrays.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Returns the possibilities of all the combinations of nested array values.
3
7
  *
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for grouping values in arrays.
3
+ * @module
4
+ */
1
5
  import type { Equality } from "../equality.ts";
2
6
  /**
3
7
  * Partitions an array into two arrays based on a predicate.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for grouping values in arrays.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Partitions an array into two arrays based on a predicate.
3
7
  * @param arr The array to split.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for modifying arrays.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Moves an element from one position to another within the array.
3
7
  */
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for modifying arrays.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Moves an element from one position to another within the array.
3
7
  */
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Types and functions to check for non-empty arrays.
3
+ * @module
3
4
  */
4
5
  /**
5
6
  * The empty array type.
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Types and functions to check for non-empty arrays.
3
+ * @module
3
4
  */
4
5
  /**
5
6
  * Checks if the array is empty.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for building a single value from an array.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Reduces an array, but stops as soon as the predicate returns `true` for an
3
7
  * accumulated value (including the initial value) and returns the last
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for building a single value from an array.
3
+ * @module
4
+ */
1
5
  import { unique } from "./filters.js";
2
6
  /**
3
7
  * Reduces an array, but stops as soon as the predicate returns `true` for an
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for set-like operations on arrays.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Calculates the difference between two arrays, including duplicated values.
3
7
  * @param oldArr - The original array.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for set-like operations on arrays.
3
+ * @module
4
+ */
1
5
  import { removeAt } from "./modify.js";
2
6
  /**
3
7
  * Calculates the difference between two arrays, including duplicated values.
package/dist/async.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for asynchronous operations.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Returns a promise that resolves after a specified delay in milliseconds.
3
7
  * @param delay The delay in milliseconds.
package/dist/async.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for asynchronous operations.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Returns a promise that resolves after a specified delay in milliseconds.
3
7
  * @param delay The delay in milliseconds.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for HTML classes.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Returns a string of class names from the given arguments. Filters out
3
7
  * nullable values and keys with falsey values.
package/dist/classList.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for HTML classes.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Returns a string of class names from the given arguments. Filters out
3
7
  * nullable values and keys with falsey values.
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Introduces helper functions for a native dictionary, which is an index object.
3
+ * @module
3
4
  */
4
5
  import type { AnyNonNullish } from "../nullable.js";
5
6
  /**
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Introduces helper functions for a native dictionary, which is an index object.
3
+ * @module
3
4
  */
4
5
  import { omitKeys } from "../object.js";
5
6
  /**
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Introduces a Dictionary class that represents an immutable mapping from
3
- * strings to values.
2
+ * Introduces a Dictionary class that represents an immutable mapping from strings to values.
3
+ * @module
4
4
  */
5
5
  import type { AnyNonNullish } from "./nullable.js";
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Introduces a Dictionary class that represents an immutable mapping from
3
- * strings to values.
2
+ * Introduces a Dictionary class that represents an immutable mapping from strings to values.
3
+ * @module
4
4
  */
5
5
  import { omitKeys } from "./object.js";
6
6
  /**
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for testing for equality.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * A function that compares two values for equality.
3
7
  */
package/dist/equality.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for testing for equality.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Checks if the first number is less than the second number.
3
7
  */
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for combining functions.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Returns a function that always returns the given value.
3
7
  * @param value The value to return from the new function.
package/dist/function.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for combining functions.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Returns a function that always returns the given value.
3
7
  * @param value The value to return from the new function.
package/dist/lazy.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Implementation of lazy-evaluated values.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * A lazy value that is only evaluated when it is needed.
3
7
  */
package/dist/lazy.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Implementation of lazy-evaluated values.
3
+ * @module
4
+ */
1
5
  import { assertExhaustive } from "./typeSafety.js";
2
6
  /**
3
7
  * A lazy value that is only evaluated when it is needed.
package/dist/maybe.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Nullable values as a structure.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * A maybe can contain a value or nothing.
3
7
  */
package/dist/maybe.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Nullable values as a structure.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Creates a maybe that contains a value.
3
7
  */
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for working with values that might be `null` or `undefined`.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Extracts `null` and `undefined` from a type.
3
7
  */
package/dist/nullable.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for working with values that might be `null` or `undefined`.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Checks if a value is `null` or `undefined`.
3
7
  */
package/dist/number.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for numbers.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Returns a random integer between `0` and `max` (inclusive).
3
7
  */
package/dist/number.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for numbers.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Returns a random integer between `0` and `max` (inclusive).
3
7
  */
package/dist/object.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for objects.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Maps all own properties of an object to a new object. Returning `undefined`
3
7
  * from the mapping function will omit the property from the result.
package/dist/object.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for objects.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Maps all own properties of an object to a new object. Returning `undefined`
3
7
  * from the mapping function will omit the property from the result.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for ordering values.
3
+ * @module
4
+ */
1
5
  import { type AnyNonNullish } from "./nullable.js";
2
6
  /**
3
7
  * The type of a compare function that can be used to sort values.
package/dist/ordering.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for ordering values.
3
+ * @module
4
+ */
1
5
  import { isNullish } from "./nullable.js";
2
6
  /**
3
7
  * Build a compare function that nests multiple compare functions. The functions
package/dist/range.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for generating ranges and working with them.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * A pair that specifies the lower (including) and upper (including) bounds of a
3
7
  * contiguous subrange of integer values.
package/dist/range.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for generating ranges and working with them.
3
+ * @module
4
+ */
1
5
  const normalizeBounds = (bounds) => bounds.length === 1 ? bounds[0] : bounds;
2
6
  /**
3
7
  * The list of values in the subrange defined by a bounding pair.
package/dist/result.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Implementation of a `Result` type that can structurally represent success or failure.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * A result is either a value or an error.
3
7
  */
package/dist/result.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Implementation of a `Result` type that can structurally represent success or failure.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Creates a result that contains a value.
3
7
  */
package/dist/roman.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for roman numerals.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Converts a number to a roman numeral.
3
7
  */
package/dist/roman.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for roman numerals.
3
+ * @module
4
+ */
1
5
  import { minus } from "./string/number.js";
2
6
  const signPairs = [
3
7
  ["I", "V"],
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for converting numbers to and from strings.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * The minus sign.
3
7
  */
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for converting numbers to and from strings.
3
+ * @module
4
+ */
1
5
  import { isInteger, isNaturalNumber } from "./regex.js";
2
6
  /**
3
7
  * The minus sign.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Checks if strings match certain regular expressions.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Checks if the provided string is a string representation of a natural number.
3
7
  * @param test The string to test.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Checks if strings match certain regular expressions.
3
+ * @module
4
+ */
1
5
  const naturalNumberPattern = /^(?:0|[1-9][0-9]*)$/u;
2
6
  const integerPattern = /^(?:0|-?[1-9][0-9]*)$/u;
3
7
  const floatPattern = /^(?:(?:0|-?[1-9][0-9]*)(?:[.,][0-9]+)?)$/u;
package/dist/string.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for strings.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Checks if a value is a non-empty string.
3
7
  */
package/dist/string.js CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for strings.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * Checks if a value is a non-empty string.
3
7
  */
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for enhancing type-safety.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * This function is used to make sure that the `switch` is exhaustive. Place it
3
7
  * in the `default` case of the `switch`.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Utility functions for enhancing type-safety.
3
+ * @module
4
+ */
1
5
  /**
2
6
  * This function is used to make sure that the `switch` is exhaustive. Place it
3
7
  * in the `default` case of the `switch`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyukai/utils",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "A set of JavaScript helper functions.",
5
5
  "files": [
6
6
  "dist",
@@ -36,6 +36,7 @@
36
36
  "@types/node": "^25.0.10",
37
37
  "commit-and-tag-version": "^12.6.1",
38
38
  "eslint": "^9.39.2",
39
+ "eslint-plugin-jsdoc": "^62.4.1",
39
40
  "glob": "^13.0.0",
40
41
  "prettier": "^3.8.1",
41
42
  "tsx": "^4.21.0",
package/dist/array.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * Returns `true` if the two arrays are equal, `false` otherwise.
3
- */
4
- export declare const arrayEqual: <T extends number | boolean | string | symbol | null | undefined>(arr1: T[], arr2: T[]) => boolean;
package/dist/array.js DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * Returns `true` if the two arrays are equal, `false` otherwise.
3
- */
4
- export const arrayEqual = (arr1, arr2) => arr1.length === arr2.length &&
5
- arr1.every((value, index) => value === arr2[index]);
package/dist/compare.d.ts DELETED
@@ -1,44 +0,0 @@
1
- /**
2
- * The type of a compare function that can be used to sort values.
3
- * @returns A negative number if `a` should be sorted before `b`, a positive
4
- * number if `a` should be sorted after `b`, or zero if `a` and `b` are equal.
5
- */
6
- export type Compare<T> = (a: T, b: T) => number;
7
- /**
8
- * Build a compare function for values that are nested inside other values. The
9
- * nested value is getting extracted by the provided accessor function and then
10
- * compared using the provided compare function. An optional `reverse` parameter
11
- * can be used to reverse the sort order.
12
- */
13
- export declare const compareAt: <T, U>(accessor: (value: T) => U, compare: (a: U, b: U) => number, reverse?: boolean) => Compare<T>;
14
- /**
15
- * Build a compare function that nests multiple compare functions. The functions
16
- * are applied in order, so the first function is the primary sort key, the
17
- * second function is the secondary sort key, and so on.
18
- */
19
- export declare const reduceCompare: <T>(...compares: Compare<T>[]) => Compare<T>;
20
- /**
21
- * Compare function for numbers that sorts them in ascending order.
22
- */
23
- export declare const numAsc: Compare<number>;
24
- /**
25
- * Higher-order compare function that extends a compare function to also handle
26
- * `null` and `undefined` values. Nullish values are always sorted first.
27
- */
28
- export declare const compareNullish: <T extends NonNullable<unknown>>(compare: Compare<T>) => (a: T | null | undefined, b: T | null | undefined) => number;
29
- /**
30
- * A function that compares two values for equality.
31
- */
32
- export type Equality<T> = (a: T, b: T) => boolean;
33
- /**
34
- * Build an equality function for values that are nested inside other values.
35
- * The nested value is getting extracted by the provided accessor function and
36
- * then compared using the provided equality function.
37
- */
38
- export declare const equalityAt: <T, U>(accessor: (value: T) => U, equality: Equality<U>) => Equality<T>;
39
- /**
40
- * Checks two values for value equality. This is a deep equality check that
41
- * works for all types, including objects and arrays. For objects, it only
42
- * compares all enumerable keys, no other properties or the prototype chain.
43
- */
44
- export declare const deepEqual: <T>(a: T, b: T) => boolean;
package/dist/compare.js DELETED
@@ -1,73 +0,0 @@
1
- import { isNullish } from "./nullable.js";
2
- /**
3
- * Build a compare function for values that are nested inside other values. The
4
- * nested value is getting extracted by the provided accessor function and then
5
- * compared using the provided compare function. An optional `reverse` parameter
6
- * can be used to reverse the sort order.
7
- */
8
- export const compareAt = (accessor, compare, reverse = false) => (a, b) => {
9
- const result = compare(accessor(a), accessor(b));
10
- return reverse ? -result : result;
11
- };
12
- /**
13
- * Build a compare function that nests multiple compare functions. The functions
14
- * are applied in order, so the first function is the primary sort key, the
15
- * second function is the secondary sort key, and so on.
16
- */
17
- export const reduceCompare = (...compares) => (a, b) => {
18
- for (const compare of compares) {
19
- const result = compare(a, b);
20
- if (result !== 0) {
21
- return result;
22
- }
23
- }
24
- return 0;
25
- };
26
- /**
27
- * Compare function for numbers that sorts them in ascending order.
28
- */
29
- export const numAsc = (a, b) => a - b;
30
- /**
31
- * Higher-order compare function that extends a compare function to also handle
32
- * `null` and `undefined` values. Nullish values are always sorted first.
33
- */
34
- export const compareNullish = (compare) => (a, b) => {
35
- if (isNullish(a) && isNullish(b)) {
36
- return 0;
37
- }
38
- if (isNullish(a)) {
39
- return -1;
40
- }
41
- if (isNullish(b)) {
42
- return 1;
43
- }
44
- return compare(a, b);
45
- };
46
- /**
47
- * Build an equality function for values that are nested inside other values.
48
- * The nested value is getting extracted by the provided accessor function and
49
- * then compared using the provided equality function.
50
- */
51
- export const equalityAt = (accessor, equality) => (a, b) => equality(accessor(a), accessor(b));
52
- /**
53
- * Checks two values for value equality. This is a deep equality check that
54
- * works for all types, including objects and arrays. For objects, it only
55
- * compares all enumerable keys, no other properties or the prototype chain.
56
- */
57
- export const deepEqual = (a, b) => {
58
- if (a === b) {
59
- return true;
60
- }
61
- if (typeof a === "object" &&
62
- typeof b === "object" &&
63
- a !== null &&
64
- b !== null) {
65
- const keys = Object.keys(a);
66
- if (keys.length !== Object.keys(b).length) {
67
- return false;
68
- }
69
- return keys.every((key) => key in b &&
70
- deepEqual(a[key], b[key]));
71
- }
72
- return false;
73
- };
package/dist/date.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Compare } from "./compare.js";
2
- /**
3
- * A comparator function for {@link Date} objects in ascending order.
4
- */
5
- export declare const compareDate: Compare<Date>;
package/dist/date.js DELETED
@@ -1,5 +0,0 @@
1
- import { Compare } from "./compare.js";
2
- /**
3
- * A comparator function for {@link Date} objects in ascending order.
4
- */
5
- export const compareDate = (a, b) => a.getTime() - b.getTime();
package/dist/math.d.ts DELETED
@@ -1,47 +0,0 @@
1
- /**
2
- * The minus sign.
3
- */
4
- export declare const minus = "\u2212";
5
- /**
6
- * The plus/minus sign.
7
- */
8
- export declare const plusMinus = "\u00B1";
9
- /**
10
- * Forces signing on the given number, returning `undefined` on zero.
11
- */
12
- export declare const signIgnoreZero: (x: number) => string | undefined;
13
- /**
14
- * Forces signing on the given number.
15
- */
16
- export declare const sign: (x: number) => string;
17
- /**
18
- * Returns the sign of the given number. Returns `undefined` if the number is
19
- * zero.
20
- */
21
- export declare const signStr: (x: number) => string | undefined;
22
- /**
23
- * Converts a string to an integer. If the string is not a valid integer, it
24
- * returns `undefined`.
25
- */
26
- export declare const parseInt: (str: string) => number | undefined;
27
- /**
28
- * Converts a string to a natural number. If the string is not a valid natural
29
- * number, it returns `undefined`.
30
- */
31
- export declare const parseNat: (str: string) => number | undefined;
32
- /**
33
- * Returns a random integer between `0` and `max` (inclusive).
34
- */
35
- export declare const randomInt: (max: number) => number;
36
- /**
37
- * Returns a random integer between `min` and `max` (inclusive).
38
- */
39
- export declare const randomIntRange: (min: number, max: number) => number;
40
- /**
41
- * Returns if the given number is even.
42
- */
43
- export declare const even: (x: number) => boolean;
44
- /**
45
- * Returns if the given number is odd.
46
- */
47
- export declare const odd: (x: number) => boolean;
package/dist/math.js DELETED
@@ -1,56 +0,0 @@
1
- import { isInteger, isNaturalNumber } from "./regex.js";
2
- /**
3
- * The minus sign.
4
- */
5
- export const minus = "−";
6
- /**
7
- * The plus/minus sign.
8
- */
9
- export const plusMinus = "\xB1";
10
- /**
11
- * Forces signing on the given number, returning `undefined` on zero.
12
- */
13
- export const signIgnoreZero = (x) => x > 0
14
- ? `+${x.toString()}`
15
- : x < 0
16
- ? `${minus}\u2060${Math.abs(x).toString()}`
17
- : undefined;
18
- /**
19
- * Forces signing on the given number.
20
- */
21
- export const sign = (x) => x > 0
22
- ? `+${x.toString()}`
23
- : x < 0
24
- ? `${minus}\u2060${Math.abs(x).toString()}`
25
- : "0";
26
- /**
27
- * Returns the sign of the given number. Returns `undefined` if the number is
28
- * zero.
29
- */
30
- export const signStr = (x) => x > 0 ? "+" : x < 0 ? minus : undefined;
31
- /**
32
- * Converts a string to an integer. If the string is not a valid integer, it
33
- * returns `undefined`.
34
- */
35
- export const parseInt = (str) => str.length > 0 && isInteger(str) ? Number.parseInt(str, 10) : undefined;
36
- /**
37
- * Converts a string to a natural number. If the string is not a valid natural
38
- * number, it returns `undefined`.
39
- */
40
- export const parseNat = (str) => str.length > 0 && isNaturalNumber(str) ? Number.parseInt(str, 10) : undefined;
41
- /**
42
- * Returns a random integer between `0` and `max` (inclusive).
43
- */
44
- export const randomInt = (max) => Math.floor(Math.random() * (max + 1));
45
- /**
46
- * Returns a random integer between `min` and `max` (inclusive).
47
- */
48
- export const randomIntRange = (min, max) => Math.floor(Math.random() * (max + 1 - min)) + min;
49
- /**
50
- * Returns if the given number is even.
51
- */
52
- export const even = (x) => x % 2 === 0;
53
- /**
54
- * Returns if the given number is odd.
55
- */
56
- export const odd = (x) => x % 2 !== 0;
package/dist/regex.d.ts DELETED
@@ -1,28 +0,0 @@
1
- /**
2
- * Checks if the provided string is a string representation of a natural number.
3
- * @param test The string to test.
4
- */
5
- export declare const isNaturalNumber: (test: string) => boolean;
6
- /**
7
- * Checks if the provided string is a string representation of an integer.
8
- * @param test The string to test.
9
- */
10
- export declare const isInteger: (test: string) => boolean;
11
- /**
12
- * Checks if the provided string is a string representation of a floating-point
13
- * number. Both `.` and `,` are accepted as decimal separators.
14
- * @param test The string to test.
15
- */
16
- export declare const isFloat: (test: string) => boolean;
17
- /**
18
- * Checks if the provided string either is an empty string or passes the given
19
- * test function.
20
- * @param check The test function to apply if the string is not empty.
21
- * @param test The string to test.
22
- */
23
- export declare const isEmptyOr: (check: (test: string) => boolean, test: string) => boolean;
24
- /**
25
- * Checks if the provided string is a valid URL.
26
- * @param test The string to test.
27
- */
28
- export declare const isUrl: (test: string) => boolean;
package/dist/regex.js DELETED
@@ -1,35 +0,0 @@
1
- /**
2
- * Checks if the provided string is a string representation of a natural number.
3
- * @param test The string to test.
4
- */
5
- export const isNaturalNumber = (test) => /^(?:0|[1-9][0-9]*)$/u.test(test);
6
- /**
7
- * Checks if the provided string is a string representation of an integer.
8
- * @param test The string to test.
9
- */
10
- export const isInteger = (test) => /^(?:0|-?[1-9][0-9]*)$/u.test(test);
11
- /**
12
- * Checks if the provided string is a string representation of a floating-point
13
- * number. Both `.` and `,` are accepted as decimal separators.
14
- * @param test The string to test.
15
- */
16
- export const isFloat = (test) => /^(?:(?:0|-?[1-9][0-9]*)(?:[.,][0-9]+)?)$/u.test(test);
17
- /**
18
- * Checks if the provided string either is an empty string or passes the given
19
- * test function.
20
- * @param check The test function to apply if the string is not empty.
21
- * @param test The string to test.
22
- */
23
- export const isEmptyOr = (check, test) => test === "" || check(test);
24
- /**
25
- * Checks if the provided string is a valid URL.
26
- * @param test The string to test.
27
- */
28
- export const isUrl = (test) => {
29
- try {
30
- return typeof new URL(test) === "object";
31
- }
32
- catch {
33
- return false;
34
- }
35
- };