@ptolemy2002/list-object-utils 2.0.1 → 2.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/README.md +16 -10
- package/dist/index.d.ts +8 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,8 +11,14 @@ const { functionName } = require('@ptolemy2002/list-object-utils');
|
|
|
11
11
|
|
|
12
12
|
## Type Reference
|
|
13
13
|
```typescript
|
|
14
|
-
type ArrayOptional = any[] | null | undefined;
|
|
15
|
-
type ObjectOptional = Object | null | undefined;
|
|
14
|
+
type ArrayOptional<T = any> = T[] | null | undefined;
|
|
15
|
+
type ObjectOptional<T = Object> = T | null | undefined;
|
|
16
|
+
type ObjectDifferenceResult<T> = {
|
|
17
|
+
[P in keyof T]?:
|
|
18
|
+
T[P] extends any[] ? Record<number, ValueOf<T[P]>>
|
|
19
|
+
: T[P] extends Object ? Record<keyof T[P], ValueOf<T[P]>>
|
|
20
|
+
: T[P];
|
|
21
|
+
};
|
|
16
22
|
type SortCallback = (a: number, b: number) => number;
|
|
17
23
|
```
|
|
18
24
|
|
|
@@ -97,27 +103,27 @@ Checks if a list is a set, that is, it has no duplicate elements. Element identi
|
|
|
97
103
|
#### Returns
|
|
98
104
|
`boolean` - `true` if the list is a set, `false` otherwise.
|
|
99
105
|
|
|
100
|
-
### listDifference
|
|
106
|
+
### listDifference<T>
|
|
101
107
|
#### Description
|
|
102
108
|
Finds the difference between two lists, that is, the elements that do not match between the two lists. If one list has a different value at an index than the other list at the same index, the element from the second list will be included in the result. Uses recursion to check nested lists and the `objectDifference` function to check nested objects. If either of the operands is not a list, the function will return an empty object if the operands are equal and the second operand if they are not.
|
|
103
109
|
|
|
104
110
|
#### Parameters
|
|
105
|
-
- `a` (`ArrayOptional
|
|
106
|
-
- `b` (`ArrayOptional
|
|
111
|
+
- `a` (`ArrayOptional<T>`): The first list to be compared.
|
|
112
|
+
- `b` (`ArrayOptional<T>`): The second list to be compared.
|
|
107
113
|
|
|
108
114
|
#### Returns
|
|
109
|
-
`ObjectOptional
|
|
115
|
+
` ObjectOptional<Record<number, T>>` - If the operands are both lists, an object with a property for every index at which the two lists differ. The value for each property is the element from the second list. If the operands are not both lists and equal, an empty object. If the operands are not both lists and not equal, the second operand.
|
|
110
116
|
|
|
111
|
-
### objectDifference
|
|
117
|
+
### objectDifference<T>
|
|
112
118
|
#### Description
|
|
113
119
|
Finds the difference between two objects, that is, the properties that do not match between the two objects. If one object has a different value for a property than the other object for the same property, the value from the second object will be included in the result. Uses recursion to check nested objects and the `listDifference` function to check nested lists. If either of the operands is not an object, the function will return an empty object if the operands are equal and the second operand if they are not.
|
|
114
120
|
|
|
115
121
|
#### Parameters
|
|
116
|
-
- `a` (`ObjectOptional
|
|
117
|
-
- `b` (`ObjectOptional
|
|
122
|
+
- `a` (`ObjectOptional<T>`): The first object to be compared.
|
|
123
|
+
- `b` (`ObjectOptional<T>`): The second object to be compared.
|
|
118
124
|
|
|
119
125
|
#### Returns
|
|
120
|
-
`ObjectOptional
|
|
126
|
+
`ObjectOptional<T | ObjectDifferenceResult<T>>` - If the operands are both objects, an object with a property for every key at which the two objects differ. The value for each property is the value from the second object. If the operands are not both objects and equal, an empty object. If the operands are not both objects and not equal, the second operand.
|
|
121
127
|
|
|
122
128
|
### flattenKeys<T>
|
|
123
129
|
#### Description
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ValueOf } from "@ptolemy2002/ts-utils";
|
|
2
|
-
type ArrayOptional = any[] | null | undefined;
|
|
3
|
-
type ObjectOptional = Object | null | undefined;
|
|
2
|
+
export type ArrayOptional<T = any> = T[] | null | undefined;
|
|
3
|
+
export type ObjectOptional<T = Object> = T | null | undefined;
|
|
4
4
|
export declare function listsEqual(a: ArrayOptional, b: ArrayOptional): boolean;
|
|
5
5
|
export declare function objectsEqual(a: ObjectOptional, b: ObjectOptional): boolean;
|
|
6
6
|
export declare function listSwap<T>(list: T[], i: number, j: number): T[];
|
|
@@ -8,10 +8,12 @@ export declare function listRemove<T>(list: T[], i: number): T[];
|
|
|
8
8
|
export declare function listPush<T>(list: T[], item: T): T[];
|
|
9
9
|
export declare function listSet<T>(list: T[], i: number, item: T): T[];
|
|
10
10
|
export declare function isSet(list: any[]): boolean;
|
|
11
|
-
export declare function listDifference(a: ArrayOptional
|
|
12
|
-
export
|
|
11
|
+
export declare function listDifference<T>(a: ArrayOptional<T>, b: ArrayOptional<T>): ObjectOptional<Record<number, T>>;
|
|
12
|
+
export type ObjectDifferenceResult<T> = {
|
|
13
|
+
[P in keyof T]?: T[P] extends any[] ? Record<number, ValueOf<T[P]>> : T[P] extends Object ? Record<keyof T[P], ValueOf<T[P]>> : T[P];
|
|
14
|
+
};
|
|
15
|
+
export declare function objectDifference<T>(a: ObjectOptional<T>, b: ObjectOptional<T>): ObjectOptional<T | ObjectDifferenceResult<T>>;
|
|
13
16
|
export declare function flattenKeys<T>(obj: T, prefix?: string): Record<string, ValueOf<T>>;
|
|
14
|
-
type SortCallback = (a: number, b: number) => number;
|
|
17
|
+
export type SortCallback = (a: number, b: number) => number;
|
|
15
18
|
export declare function sortWithIndeces<T>(toSort: T[], sort?: SortCallback, descending?: boolean): T[];
|
|
16
19
|
export declare function objectToString(obj: Object): string;
|
|
17
|
-
export {};
|