moderndash 0.0.10 → 0.0.11

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.
@@ -1,5 +1,34 @@
1
1
  import { isEqual } from '@lang/isEqual';
2
2
 
3
- export function isEqualWith<T>(customizer: (value: T) => unknown, a: T, b: T): boolean {
3
+ /**
4
+ * This method is like `_.isEqual` except that it accepts `customizer` which
5
+ * is invoked to compare values. If `customizer` returns `undefined`, comparisons
6
+ * are handled by the method instead. The `customizer` is invoked with up to
7
+ * six arguments: (objValue, othValue [, index|key, object, other, stack]).
8
+ *
9
+ * @category Lang
10
+ * @param value1 - The value to compare.
11
+ * @param value2 - The other value to compare.
12
+ * @param customizer - The function to customize comparisons.
13
+ * @returns Returns `true` if the values are equivalent, else `false`.
14
+ * @example
15
+ * function isGreeting(value) {
16
+ * return /^h(?:i|ello)$/.test(value);
17
+ * }
18
+ *
19
+ * function customizer(objValue, othValue) {
20
+ * if (isGreeting(objValue) && isGreeting(othValue)) {
21
+ * return true;
22
+ * }
23
+ * }
24
+ *
25
+ * var array = ['hello', 'goodbye'];
26
+ * var other = ['hi', 'goodbye'];
27
+ *
28
+ * isEqualWith(array, other, customizer);
29
+ * // => true
30
+ */
31
+
32
+ export function isEqualWith<T>(a: T, b: T, customizer: (value: T) => unknown): boolean {
4
33
  return isEqual(customizer(a), customizer(b));
5
34
  }
package/src/types.ts CHANGED
@@ -1,9 +1,15 @@
1
- export type MinimumTwoArrays<T> = [T[], T[], ...T[][]];
1
+ export type MinimumTwoArrays<TInput> = [TInput[], TInput[], ...TInput[][]];
2
2
 
3
3
  export type IterateeFunction<T> = (value: T) => unknown;
4
4
  export type PropertyShorthand<T> = keyof T;
5
5
 
6
6
  export type RecordKey = string | number | symbol;
7
+ export type ArrayOrRecord<TInput> = TInput[] | Record<RecordKey, TInput>;
7
8
 
8
- export type ArrayOrRecord<T> = T[] | Record<RecordKey, T>;
9
- export type NoUnion<T, U = T> = T extends U ? [U] extends [T] ? T : never : never;
9
+ export type NoUnion<T, U = T> = T extends U ? [U] extends [T] ? T : never : never;
10
+
11
+ /**
12
+ * @description Generic function type, should fit any function
13
+ * @typeParam TFunc - The input function type
14
+ */
15
+ export type GenericFunction<TFunc extends (...args: Parameters<TFunc>) => ReturnType<TFunc>> = (...args: Parameters<TFunc>) => ReturnType<TFunc>;
@@ -1,16 +0,0 @@
1
- import type { MinimumTwoArrays } from '../types';
2
-
3
- /**
4
- * Creates an array of unique values, in order, from all given arrays using for equality comparisons.
5
- *
6
- * @category Array
7
- * @param arrays - The arrays to inspect.
8
- * @returns Returns the new array of combined values.
9
- * @example
10
- * union([2, 3], [1, 2])
11
- * // => [2, 3, 1]
12
- */
13
-
14
- export function union<TInput>(...arrays: MinimumTwoArrays<TInput>): TInput[] {
15
- return [...new Set(arrays.flat())];
16
- }
@@ -1,26 +0,0 @@
1
- import type { IterateeFunction, MinimumTwoArrays, PropertyShorthand } from '../types';
2
-
3
- import { unionWith } from '@array/unionWith';
4
- import { getIterateFunction } from '@helpers/shortHands';
5
- import { isEqualWith } from '@lang/isEqualWith';
6
-
7
- /**
8
- * This method is like `union` except that it accepts `iteratee` which is
9
- * invoked for each element of each `arrays` to generate the criterion by
10
- * which uniqueness is computed. Result values are chosen from the first
11
- * array in which the value occurs. The iteratee is invoked with one argument:
12
- * (value).
13
- *
14
- * @category Array
15
- * @param arrays - The arrays to inspect.
16
- * @param iteratee - The iteratee invoked per element. Or property shorthand.
17
- * @returns Returns the new array of combined values.
18
- * @example
19
- * unionBy(Math.floor, [2.1], [1.2, 2.3])
20
- * // => [2.1, 1.2]
21
- */
22
-
23
- export function unionBy<T>(iteratee: IterateeFunction<T> | PropertyShorthand<T>, ...arrays: MinimumTwoArrays<T>): T[] {
24
- const iterateeFunction = getIterateFunction(iteratee);
25
- return unionWith((a, b) => isEqualWith(iterateeFunction, a, b), ...arrays);
26
- }
@@ -1,31 +0,0 @@
1
- import type { MinimumTwoArrays } from '../types';
2
-
3
- /**
4
- * This method is like `union` except that it accepts `comparator` which
5
- * is invoked to compare elements of `arrays`. Result values are chosen from
6
- * the first array in which the value occurs. The comparator is invoked
7
- * with two arguments: (arrVal, othVal).
8
- *
9
- * @category Array
10
- * @param comparator - The comparator invoked per element.
11
- * @param arrays - The arrays to inspect.
12
- * @returns Returns the new array of combined values.
13
- * @example
14
- * const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
15
- * const others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]
16
- *
17
- * unionWith(isEqual, objects, others)
18
- * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
19
- */
20
-
21
- export function unionWith<TInput>(comparator: (a: TInput, b: TInput) => boolean, ...arrays: MinimumTwoArrays<TInput>): TInput[] {
22
- return arrays.reduce((acc, current) => {
23
- for (const item of current) {
24
- if (acc.some(x => comparator(x, item))) {
25
- continue;
26
- }
27
- acc.push(item);
28
- }
29
- return acc;
30
- }, []);
31
- }