mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
refactor: use eslint-config-neon for packages. (#8579)
Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
/* eslint-disable unicorn/no-array-method-this-argument */
|
||||
/* eslint-disable id-length */
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { Collection } from '../src';
|
||||
import { Collection } from '../src/index.js';
|
||||
|
||||
type TestCollection = Collection<string, number>;
|
||||
|
||||
@@ -131,9 +133,9 @@ describe('each() tests', () => {
|
||||
const coll = createTestCollection();
|
||||
|
||||
test('throws if fn is not a function', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.each());
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.each(123), 123);
|
||||
});
|
||||
|
||||
@@ -152,7 +154,7 @@ describe('each() tests', () => {
|
||||
describe('ensure() tests', () => {
|
||||
test('throws if defaultValueGenerator is not a function', () => {
|
||||
const coll = createTestCollection();
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.ensure('d', 'abc'), 'abc');
|
||||
});
|
||||
|
||||
@@ -176,7 +178,7 @@ describe('equals() tests', () => {
|
||||
const coll2 = createTestCollection();
|
||||
|
||||
test('returns false if no collection is passed', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expect(coll1.equals()).toBeFalsy();
|
||||
});
|
||||
|
||||
@@ -198,9 +200,9 @@ describe('every() tests', () => {
|
||||
const coll = createTestCollection();
|
||||
|
||||
test('throws if fn is not a function', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.every());
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.every(123), 123);
|
||||
});
|
||||
|
||||
@@ -224,9 +226,9 @@ describe('filter() tests', () => {
|
||||
const coll = createTestCollection();
|
||||
|
||||
test('throws if fn is not a function', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.filter());
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.filter(123), 123);
|
||||
});
|
||||
|
||||
@@ -251,9 +253,9 @@ describe('find() tests', () => {
|
||||
const coll = createTestCollection();
|
||||
|
||||
test('throws if fn is not a function', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => createCollection().find());
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => createCollection().find(123), 123);
|
||||
});
|
||||
|
||||
@@ -275,9 +277,9 @@ describe('findKey() tests', () => {
|
||||
const coll = createTestCollection();
|
||||
|
||||
test('throws if fn is not a function', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.findKey());
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.findKey(123), 123);
|
||||
});
|
||||
|
||||
@@ -506,9 +508,9 @@ describe('map() tests', () => {
|
||||
const coll = createTestCollection();
|
||||
|
||||
test('throws if fn is not a function', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.map());
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.map(123), 123);
|
||||
});
|
||||
|
||||
@@ -529,9 +531,9 @@ describe('mapValues() tests', () => {
|
||||
const coll = createTestCollection();
|
||||
|
||||
test('throws if fn is not a function', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.mapValues());
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.mapValues(123), 123);
|
||||
});
|
||||
|
||||
@@ -606,9 +608,9 @@ describe('partition() tests', () => {
|
||||
const coll = createTestCollection();
|
||||
|
||||
test('throws if fn is not a function', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.partition());
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.partition(123), 123);
|
||||
});
|
||||
|
||||
@@ -690,9 +692,9 @@ describe('reduce() tests', () => {
|
||||
const coll = createTestCollection();
|
||||
|
||||
test('throws if fn is not a function', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.reduce());
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.reduce(123), 123);
|
||||
});
|
||||
|
||||
@@ -729,19 +731,15 @@ describe('some() tests', () => {
|
||||
const coll = createTestCollection();
|
||||
|
||||
test('throws if fn is not a function', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.some());
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.some(123), 123);
|
||||
});
|
||||
|
||||
test('returns false if no items pass the predicate', () => {
|
||||
expect(coll.some((v) => v > 3)).toBeFalsy();
|
||||
});
|
||||
|
||||
test('returns true if at least one item passes the predicate', () => {
|
||||
expect(coll.some((x) => x === 2)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('sort() tests', () => {
|
||||
@@ -777,9 +775,9 @@ describe('sweep() test', () => {
|
||||
const coll = createTestCollection();
|
||||
|
||||
test('throws if fn is not a function', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.sweep());
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.sweep(123), 123);
|
||||
});
|
||||
|
||||
@@ -804,9 +802,9 @@ describe('tap() tests', () => {
|
||||
const coll = createTestCollection();
|
||||
|
||||
test('throws if fn is not a function', () => {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.tap());
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error: invalid function
|
||||
expectInvalidFunctionError(() => coll.tap(123), 123);
|
||||
});
|
||||
|
||||
|
||||
@@ -54,16 +54,10 @@
|
||||
"@favware/cliff-jumper": "^1.8.7",
|
||||
"@microsoft/api-extractor": "^7.29.5",
|
||||
"@types/node": "^16.11.56",
|
||||
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
||||
"@typescript-eslint/parser": "^5.36.1",
|
||||
"@vitest/coverage-c8": "^0.22.1",
|
||||
"downlevel-dts": "^0.10.1",
|
||||
"eslint": "^8.23.0",
|
||||
"eslint-config-marine": "^9.4.1",
|
||||
"eslint-config-prettier": "^8.5.0",
|
||||
"eslint-import-resolver-typescript": "^3.5.0",
|
||||
"eslint-plugin-import": "^2.26.0",
|
||||
"eslint-plugin-tsdoc": "^0.2.16",
|
||||
"eslint-config-neon": "^0.1.23",
|
||||
"prettier": "^2.7.1",
|
||||
"rollup-plugin-typescript2": "^0.33.0",
|
||||
"typescript": "^4.8.2",
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
/* eslint-disable id-length */
|
||||
/* eslint-disable no-param-reassign */
|
||||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface CollectionConstructor {
|
||||
new (): Collection<unknown, unknown>;
|
||||
new <K, V>(entries?: ReadonlyArray<readonly [K, V]> | null): Collection<K, V>;
|
||||
new <K, V>(entries?: readonly (readonly [K, V])[] | null): Collection<K, V>;
|
||||
new <K, V>(iterable: Iterable<readonly [K, V]>): Collection<K, V>;
|
||||
readonly prototype: Collection<unknown, unknown>;
|
||||
readonly [Symbol.species]: CollectionConstructor;
|
||||
@@ -13,8 +15,11 @@ export interface CollectionConstructor {
|
||||
/**
|
||||
* Represents an immutable version of a collection
|
||||
*/
|
||||
export type ReadonlyCollection<K, V> = ReadonlyMap<K, V> &
|
||||
Omit<Collection<K, V>, 'forEach' | 'ensure' | 'reverse' | 'sweep' | 'sort' | 'get' | 'set' | 'delete'>;
|
||||
export type ReadonlyCollection<K, V> = Omit<
|
||||
Collection<K, V>,
|
||||
'delete' | 'ensure' | 'forEach' | 'get' | 'reverse' | 'set' | 'sort' | 'sweep'
|
||||
> &
|
||||
ReadonlyMap<K, V>;
|
||||
|
||||
/**
|
||||
* Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself
|
||||
@@ -38,7 +43,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param key - The key to get if it exists, or set otherwise
|
||||
* @param defaultValueGenerator - A function that generates the default value
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.ensure(guildId, () => defaultGuildConfig);
|
||||
@@ -56,7 +60,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
* Checks if all of the elements exist in the collection.
|
||||
*
|
||||
* @param keys - The keys of the elements to check for
|
||||
*
|
||||
* @returns `true` if all of the elements exist, `false` if at least one does not exist.
|
||||
*/
|
||||
public hasAll(...keys: K[]) {
|
||||
@@ -67,7 +70,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
* Checks if any of the elements exist in the collection.
|
||||
*
|
||||
* @param keys - The keys of the elements to check for
|
||||
*
|
||||
* @returns `true` if any of the elements exist, `false` if none exist.
|
||||
*/
|
||||
public hasAny(...keys: K[]) {
|
||||
@@ -78,7 +80,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
* Obtains the first value(s) in this collection.
|
||||
*
|
||||
* @param amount - Amount of values to obtain from the beginning
|
||||
*
|
||||
* @returns A single value if no amount is provided or an array of values, starting from the end if amount is negative
|
||||
*/
|
||||
public first(): V | undefined;
|
||||
@@ -97,7 +98,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
* Obtains the first key(s) in this collection.
|
||||
*
|
||||
* @param amount - Amount of keys to obtain from the beginning
|
||||
*
|
||||
* @returns A single key if no amount is provided or an array of keys, starting from the end if
|
||||
* amount is negative
|
||||
*/
|
||||
@@ -117,7 +117,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
* Obtains the last value(s) in this collection.
|
||||
*
|
||||
* @param amount - Amount of values to obtain from the end
|
||||
*
|
||||
* @returns A single value if no amount is provided or an array of values, starting from the start if
|
||||
* amount is negative
|
||||
*/
|
||||
@@ -135,7 +134,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
* Obtains the last key(s) in this collection.
|
||||
*
|
||||
* @param amount - Amount of keys to obtain from the end
|
||||
*
|
||||
* @returns A single key if no amount is provided or an array of keys, starting from the start if
|
||||
* amount is negative
|
||||
*/
|
||||
@@ -179,7 +177,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
* Obtains unique random value(s) from this collection.
|
||||
*
|
||||
* @param amount - Amount of values to obtain randomly
|
||||
*
|
||||
* @returns A single value if no amount is provided or an array of values
|
||||
*/
|
||||
public random(): V | undefined;
|
||||
@@ -198,7 +195,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
* Obtains unique random key(s) from this collection.
|
||||
*
|
||||
* @param amount - Amount of keys to obtain randomly
|
||||
*
|
||||
* @returns A single key if no amount is provided or an array
|
||||
*/
|
||||
public randomKey(): K | undefined;
|
||||
@@ -233,7 +229,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param fn - The function to test with (should return boolean)
|
||||
* @param thisArg - Value to use as `this` when executing function
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.find(user => user.username === 'Bob');
|
||||
@@ -252,6 +247,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this)) return val;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -262,7 +258,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param fn - The function to test with (should return boolean)
|
||||
* @param thisArg - Value to use as `this` when executing function
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.findKey(user => user.username === 'Bob');
|
||||
@@ -281,6 +276,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this)) return key;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -289,7 +285,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param fn - Function used to test (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing function
|
||||
*
|
||||
* @returns The number of removed entries
|
||||
*/
|
||||
public sweep(fn: (value: V, key: K, collection: this) => boolean): number;
|
||||
@@ -301,6 +296,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this)) this.delete(key);
|
||||
}
|
||||
|
||||
return previousSize - this.size;
|
||||
}
|
||||
|
||||
@@ -311,7 +307,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param fn - The function to test with (should return boolean)
|
||||
* @param thisArg - Value to use as `this` when executing function
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.filter(user => user.username === 'Bob');
|
||||
@@ -336,6 +331,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this)) results.set(key, val);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -345,7 +341,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param fn - Function used to test (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing function
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const [big, small] = collection.partition(guild => guild.memberCount > 250);
|
||||
@@ -387,6 +382,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
results[1].set(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -396,7 +392,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param fn - Function that produces a new Collection
|
||||
* @param thisArg - Value to use as `this` when executing function
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.flatMap(guild => guild.members.cache);
|
||||
@@ -408,6 +403,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
thisArg: This,
|
||||
): Collection<K, T>;
|
||||
public flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>, thisArg?: unknown): Collection<K, T> {
|
||||
// eslint-disable-next-line unicorn/no-array-method-this-argument
|
||||
const collections = this.map(fn, thisArg);
|
||||
return new this.constructor[Symbol.species]<K, T>().concat(...collections);
|
||||
}
|
||||
@@ -418,7 +414,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param fn - Function that produces an element of the new array, taking three arguments
|
||||
* @param thisArg - Value to use as `this` when executing function
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.map(user => user.tag);
|
||||
@@ -444,7 +439,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param fn - Function that produces an element of the new collection, taking three arguments
|
||||
* @param thisArg - Value to use as `this` when executing function
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.mapValues(user => user.tag);
|
||||
@@ -466,7 +460,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param fn - Function used to test (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing function
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.some(user => user.discriminator === '0000');
|
||||
@@ -480,6 +473,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
for (const [key, val] of this) {
|
||||
if (fn(val, key, this)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -489,7 +483,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param fn - Function used to test (should return a boolean)
|
||||
* @param thisArg - Value to use as `this` when executing function
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.every(user => !user.bot);
|
||||
@@ -513,6 +506,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
for (const [key, val] of this) {
|
||||
if (!fn(val, key, this)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -523,7 +517,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
* @param fn - Function used to reduce, taking four arguments; `accumulator`, `currentValue`, `currentKey`,
|
||||
* and `collection`
|
||||
* @param initialValue - Starting value for the accumulator
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.reduce((acc, guild) => acc + guild.memberCount, 0);
|
||||
@@ -538,6 +531,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
for (const [key, val] of this) accumulator = fn(accumulator, val, key, this);
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
let first = true;
|
||||
for (const [key, val] of this) {
|
||||
if (first) {
|
||||
@@ -545,6 +539,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
first = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
accumulator = fn(accumulator, val, key, this);
|
||||
}
|
||||
|
||||
@@ -563,7 +558,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param fn - Function to execute for each element
|
||||
* @param thisArg - Value to use as `this` when executing function
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection
|
||||
@@ -576,6 +570,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
public each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;
|
||||
public each(fn: (value: V, key: K, collection: this) => void, thisArg?: unknown): this {
|
||||
if (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);
|
||||
// eslint-disable-next-line unicorn/no-array-method-this-argument
|
||||
this.forEach(fn as (value: V, key: K, map: Map<K, V>) => void, thisArg);
|
||||
return this;
|
||||
}
|
||||
@@ -585,7 +580,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param fn - Function to execute
|
||||
* @param thisArg - Value to use as `this` when executing function
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection
|
||||
@@ -619,7 +613,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
* Combines this collection with others into a new collection. None of the source collections are modified.
|
||||
*
|
||||
* @param collections - Collections to merge
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
|
||||
@@ -630,6 +623,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
for (const coll of collections) {
|
||||
for (const [key, val] of coll) newColl.set(key, val);
|
||||
}
|
||||
|
||||
return newColl;
|
||||
}
|
||||
|
||||
@@ -639,7 +633,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
* the collections may be different objects, but contain the same data.
|
||||
*
|
||||
* @param collection - Collection to compare with
|
||||
*
|
||||
* @returns Whether the collections have identical contents
|
||||
*/
|
||||
public equals(collection: ReadonlyCollection<K, V>) {
|
||||
@@ -652,6 +645,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -662,7 +656,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param compareFunction - Specifies a function that defines the sort order.
|
||||
* If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||
@@ -679,6 +672,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
for (const [k, v] of entries) {
|
||||
super.set(k, v);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -694,6 +688,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
coll.set(k, v);
|
||||
}
|
||||
}
|
||||
|
||||
return coll;
|
||||
}
|
||||
|
||||
@@ -702,24 +697,26 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param other - The other Collection to filter against
|
||||
*/
|
||||
public difference<T>(other: ReadonlyCollection<K, T>): Collection<K, V | T> {
|
||||
const coll = new this.constructor[Symbol.species]<K, V | T>();
|
||||
public difference<T>(other: ReadonlyCollection<K, T>): Collection<K, T | V> {
|
||||
const coll = new this.constructor[Symbol.species]<K, T | V>();
|
||||
for (const [k, v] of other) {
|
||||
if (!this.has(k)) coll.set(k, v);
|
||||
}
|
||||
|
||||
for (const [k, v] of this) {
|
||||
if (!other.has(k)) coll.set(k, v);
|
||||
}
|
||||
|
||||
return coll;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges two Collections together into a new Collection.
|
||||
*
|
||||
* @param other - The other Collection to merge with
|
||||
* @param whenInSelf - Function getting the result if the entry only exists in this Collection
|
||||
* @param whenInOther - Function getting the result if the entry only exists in the other Collection
|
||||
* @param whenInBoth - Function getting the result if the entry exists in both Collections
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Sums up the entries in two collections.
|
||||
@@ -730,7 +727,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
* (x, y) => ({ keep: true, value: x + y }),
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // Intersects two collections in a left-biased manner.
|
||||
@@ -765,6 +761,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
if (r.keep) coll.set(k, r.value);
|
||||
}
|
||||
}
|
||||
|
||||
return coll;
|
||||
}
|
||||
|
||||
@@ -776,7 +773,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
* @param compareFunction - Specifies a function that defines the sort order.
|
||||
* If omitted, the collection is sorted according to each character's Unicode code point value,
|
||||
* according to the string conversion of each element.
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
|
||||
@@ -800,7 +796,6 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @param entries - The list of entries
|
||||
* @param combine - Function to combine an existing entry with a new one
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
|
||||
@@ -819,6 +814,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
coll.set(k, v);
|
||||
}
|
||||
}
|
||||
|
||||
return coll;
|
||||
}
|
||||
}
|
||||
@@ -826,7 +822,7 @@ export class Collection<K, V> extends Map<K, V> {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export type Keep<V> = { keep: true; value: V } | { keep: false };
|
||||
export type Keep<V> = { keep: false } | { keep: true; value: V };
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
||||
@@ -1 +1 @@
|
||||
export * from './collection';
|
||||
export * from './collection.js';
|
||||
|
||||
Reference in New Issue
Block a user