@ptolemy2002/ts-utils 3.4.0 → 3.5.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 +6 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -221,6 +221,12 @@ This function takes an object of type `T` and a list of keys `K` and returns a n
|
|
|
221
221
|
#### Returns
|
|
222
222
|
`Omit<T, K>` - The object with the keys omitted.
|
|
223
223
|
|
|
224
|
+
## Classes
|
|
225
|
+
This library exports the following classes:
|
|
226
|
+
|
|
227
|
+
### Collection<T>
|
|
228
|
+
An abstract class representing an object that can be treated as an array, but with some methods overwritten to use a collection of this type rather than a standard array. No methods are implemented here, so it is up to the extending class to do it all. This is just a template for the extending class to ensure that it has all the necessary methods and that they return the correct types.
|
|
229
|
+
|
|
224
230
|
## Peer Dependencies
|
|
225
231
|
- `is-callable^1.2.7`
|
|
226
232
|
- `@ptolemy2002/ts-brand-utils^1.0.0`
|
package/dist/index.d.ts
CHANGED
|
@@ -79,3 +79,36 @@ export type ValuesIntersection<T> = ValueOf<{
|
|
|
79
79
|
export type Contains<L extends unknown[], T> = L extends [...unknown[], T] ? true : L extends [T, ...unknown[]] ? true : L extends [T] ? true : false;
|
|
80
80
|
export declare function omit<T extends object, K extends keyof T>(obj: T, ...keys: K[]): Omit<T, K>;
|
|
81
81
|
export type ArrayWithOptional<AR extends unknown[], AO extends unknown[]> = AR | [...AR, ...AO];
|
|
82
|
+
export declare abstract class Collection<T> {
|
|
83
|
+
abstract get length(): number;
|
|
84
|
+
abstract at(index: number): T | undefined;
|
|
85
|
+
abstract find(predicate: (item: T, index: number, array: Collection<T>) => boolean): T | undefined;
|
|
86
|
+
abstract findIndex(predicate: (item: T, index: number, array: Collection<T>) => boolean): number;
|
|
87
|
+
abstract indexOf(item: T, fromIndex?: number): number;
|
|
88
|
+
abstract includes(item: T, fromIndex?: number): boolean;
|
|
89
|
+
abstract some(predicate: (item: T, index: number, array: Collection<T>) => boolean): boolean;
|
|
90
|
+
abstract every(predicate: (item: T, index: number, array: Collection<T>) => boolean): boolean;
|
|
91
|
+
abstract forEach(callback: (item: T, index: number, array: Collection<T>) => void): void;
|
|
92
|
+
abstract map<U>(callback: (item: T, index: number, array: Collection<T>) => U): U[];
|
|
93
|
+
abstract filter(predicate: (item: T, index: number, array: Collection<T>) => boolean): Collection<T>;
|
|
94
|
+
abstract flat(depth?: number): Collection<T>;
|
|
95
|
+
abstract flatMap<U>(callback: (item: T, index: number, array: Collection<T>) => U | U[], depth?: number): U[];
|
|
96
|
+
abstract slice(start?: number, end?: number): Collection<T>;
|
|
97
|
+
abstract concat(...others: (T | T[] | Collection<T>)[]): Collection<T>;
|
|
98
|
+
abstract push(...items: T[]): void;
|
|
99
|
+
abstract pop(): T | undefined;
|
|
100
|
+
abstract shift(): T | undefined;
|
|
101
|
+
abstract unshift(...items: T[]): number;
|
|
102
|
+
abstract splice(start: number, deleteCount?: number, ...items: T[]): Collection<T>;
|
|
103
|
+
abstract reverse(): Collection<T>;
|
|
104
|
+
abstract sort(compareFn?: (a: T, b: T) => number): Collection<T>;
|
|
105
|
+
abstract fill(value: T, start?: number, end?: number): Collection<T>;
|
|
106
|
+
abstract [Symbol.iterator](): Iterator<T>;
|
|
107
|
+
abstract entries(): IterableIterator<[number, T]>;
|
|
108
|
+
abstract keys(): IterableIterator<number>;
|
|
109
|
+
abstract values(): IterableIterator<T>;
|
|
110
|
+
abstract reduce<U>(accumulator: U, callback: (accumulator: U, item: T, index: number, array: Collection<T>) => U): U;
|
|
111
|
+
abstract reduce(callback: (accumulator: T, item: T, index: number, array: Collection<T>) => T): T;
|
|
112
|
+
abstract reduce<U>(callback: (accumulator: U | T, item: T, index: number, array: Collection<T>) => U | T, initialValue?: U): U | T;
|
|
113
|
+
abstract toArray(): T[];
|
|
114
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Collection = void 0;
|
|
6
7
|
exports.isAdvancedCondition = isAdvancedCondition;
|
|
7
8
|
exports.createAdvancedCondition = createAdvancedCondition;
|
|
8
9
|
exports.createSerializableAdvancedCondition = createSerializableAdvancedCondition;
|
|
@@ -111,3 +112,6 @@ function omit(obj, ...keys) {
|
|
|
111
112
|
keys.forEach((key) => delete _[key]);
|
|
112
113
|
return _;
|
|
113
114
|
}
|
|
115
|
+
class Collection {
|
|
116
|
+
}
|
|
117
|
+
exports.Collection = Collection;
|