From 193b252672440a860318d3c2968aedd9cb88e0ce Mon Sep 17 00:00:00 2001 From: iCrawl Date: Sun, 14 Aug 2022 19:25:25 +0200 Subject: [PATCH] docs: fence examples in codeblocks --- packages/collection/src/collection.ts | 40 ++++++++++++++++++++++++++ packages/ws/src/utils/utils.ts | 2 ++ packages/ws/src/ws/WebSocketManager.ts | 7 +++++ 3 files changed, 49 insertions(+) diff --git a/packages/collection/src/collection.ts b/packages/collection/src/collection.ts index d50ecfe34..7b33955ac 100644 --- a/packages/collection/src/collection.ts +++ b/packages/collection/src/collection.ts @@ -37,7 +37,9 @@ export class Collection extends Map { * @param defaultValueGenerator - A function that generates the default value * * @example + * ``` * collection.ensure(guildId, () => defaultGuildConfig); + * ``` */ public ensure(key: K, defaultValueGenerator: (key: K, collection: this) => V): V { if (this.has(key)) return this.get(key)!; @@ -230,7 +232,9 @@ export class Collection extends Map { * @param thisArg - Value to use as `this` when executing function * * @example + * ``` * collection.find(user => user.username === 'Bob'); + * ``` */ public find(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined; public find(fn: (value: V, key: K, collection: this) => boolean): V | undefined; @@ -257,7 +261,9 @@ export class Collection extends Map { * @param thisArg - Value to use as `this` when executing function * * @example + * ``` * collection.findKey(user => user.username === 'Bob'); + * ``` */ public findKey(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined; public findKey(fn: (value: V, key: K, collection: this) => boolean): K | undefined; @@ -304,7 +310,9 @@ export class Collection extends Map { * @param thisArg - Value to use as `this` when executing function * * @example + * ``` * collection.filter(user => user.username === 'Bob'); + * ``` */ public filter(fn: (value: V, key: K, collection: this) => key is K2): Collection; public filter(fn: (value: V, key: K, collection: this) => value is V2): Collection; @@ -336,7 +344,9 @@ export class Collection extends Map { * @param thisArg - Value to use as `this` when executing function * * @example + * ``` * const [big, small] = collection.partition(guild => guild.memberCount > 250); + * ``` */ public partition( fn: (value: V, key: K, collection: this) => key is K2, @@ -385,7 +395,9 @@ export class Collection extends Map { * @param thisArg - Value to use as `this` when executing function * * @example + * ``` * collection.flatMap(guild => guild.members.cache); + * ``` */ public flatMap(fn: (value: V, key: K, collection: this) => Collection): Collection; public flatMap( @@ -405,7 +417,9 @@ export class Collection extends Map { * @param thisArg - Value to use as `this` when executing function * * @example + * ``` * collection.map(user => user.tag); + * ``` */ public map(fn: (value: V, key: K, collection: this) => T): T[]; public map(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[]; @@ -429,7 +443,9 @@ export class Collection extends Map { * @param thisArg - Value to use as `this` when executing function * * @example + * ``` * collection.mapValues(user => user.tag); + * ``` */ public mapValues(fn: (value: V, key: K, collection: this) => T): Collection; public mapValues(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection; @@ -449,7 +465,9 @@ export class Collection extends Map { * @param thisArg - Value to use as `this` when executing function * * @example + * ``` * collection.some(user => user.discriminator === '0000'); + * ``` */ public some(fn: (value: V, key: K, collection: this) => boolean): boolean; public some(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): boolean; @@ -470,7 +488,9 @@ export class Collection extends Map { * @param thisArg - Value to use as `this` when executing function * * @example + * ``` * collection.every(user => !user.bot); + * ``` */ public every(fn: (value: V, key: K, collection: this) => key is K2): this is Collection; public every(fn: (value: V, key: K, collection: this) => value is V2): this is Collection; @@ -502,7 +522,9 @@ export class Collection extends Map { * @param initialValue - Starting value for the accumulator * * @example + * ``` * collection.reduce((acc, guild) => acc + guild.memberCount, 0); + * ``` */ public reduce(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T { if (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`); @@ -540,10 +562,12 @@ export class Collection extends Map { * @param thisArg - Value to use as `this` when executing function * * @example + * ``` * collection * .each(user => console.log(user.username)) * .filter(user => user.bot) * .each(user => console.log(user.username)); + * ``` */ public each(fn: (value: V, key: K, collection: this) => void): this; public each(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this; @@ -560,10 +584,12 @@ export class Collection extends Map { * @param thisArg - Value to use as `this` when executing function * * @example + * ``` * collection * .tap(coll => console.log(coll.size)) * .filter(user => user.bot) * .tap(coll => console.log(coll.size)) + * ``` */ public tap(fn: (collection: this) => void): this; public tap(fn: (this: T, collection: this) => void, thisArg: T): this; @@ -578,7 +604,9 @@ export class Collection extends Map { * Creates an identical shallow copy of this collection. * * @example + * ``` * const newColl = someColl.clone(); + * ``` */ public clone(): Collection { return new this.constructor[Symbol.species](this); @@ -590,7 +618,9 @@ export class Collection extends Map { * @param collections - Collections to merge * * @example + * ``` * const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl); + * ``` */ public concat(...collections: ReadonlyCollection[]) { const newColl = this.clone(); @@ -631,7 +661,9 @@ export class Collection extends Map { * If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element. * * @example + * ``` * collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); + * ``` */ public sort(compareFunction: Comparator = Collection.defaultSort) { const entries = [...this.entries()]; @@ -686,6 +718,7 @@ export class Collection extends Map { * @param whenInBoth - Function getting the result if the entry exists in both Collections * * @example + * ``` * // Sums up the entries in two collections. * coll.merge( * other, @@ -693,8 +726,10 @@ export class Collection extends Map { * y => ({ keep: true, value: y }), * (x, y) => ({ keep: true, value: x + y }), * ); + * ``` * * @example + * ``` * // Intersects two collections in a left-biased manner. * coll.merge( * other, @@ -702,6 +737,7 @@ export class Collection extends Map { * y => ({ keep: false }), * (x, _) => ({ keep: true, value: x }), * ); + * ``` */ public merge( other: ReadonlyCollection, @@ -739,7 +775,9 @@ export class Collection extends Map { * according to the string conversion of each element. * * @example + * ``` * collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); + * ``` */ public sorted(compareFunction: Comparator = Collection.defaultSort) { return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk)); @@ -761,8 +799,10 @@ export class Collection extends Map { * @param combine - Function to combine an existing entry with a new one * * @example + * ``` * Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y); * // returns Collection { "a" => 3, "b" => 2 } + * ``` */ public static combineEntries( entries: Iterable<[K, V]>, diff --git a/packages/ws/src/utils/utils.ts b/packages/ws/src/utils/utils.ts index 70c845d98..42bc1465c 100644 --- a/packages/ws/src/utils/utils.ts +++ b/packages/ws/src/utils/utils.ts @@ -5,7 +5,9 @@ export type Awaitable = T | Promise; /** * Yields the numbers in the given range as an array * @example + * ``` * range({ start: 3, end: 5 }); // [3, 4, 5] + * ``` */ export function range({ start, end }: ShardRange): number[] { return Array.from({ length: end - start + 1 }, (_, i) => i + start); diff --git a/packages/ws/src/ws/WebSocketManager.ts b/packages/ws/src/ws/WebSocketManager.ts index d4c649551..32fb4f136 100644 --- a/packages/ws/src/ws/WebSocketManager.ts +++ b/packages/ws/src/ws/WebSocketManager.ts @@ -80,16 +80,21 @@ export interface OptionalWebSocketManagerOptions { * The ids of the shards this WebSocketManager should manage. * Use `null` to simply spawn 0 through `shardCount - 1` * @example + * ``` * const manager = new WebSocketManager({ * shardIds: [1, 3, 7], // spawns shard 1, 3, and 7, nothing else * }); + * ``` + * * @example + * ``` * const manager = new WebSocketManager({ * shardIds: { * start: 3, * end: 6, * }, // spawns shards 3, 4, 5, and 6 * }); + * ``` */ shardIds: number[] | ShardRange | null; /** @@ -122,6 +127,7 @@ export interface OptionalWebSocketManagerOptions { /** * Function used to retrieve session information (and attempt to resume) for a given shard * @example + * ``` * const manager = new WebSocketManager({ * async retrieveSessionInfo(shardId): Awaitable { * // Fetch this info from redis or similar @@ -129,6 +135,7 @@ export interface OptionalWebSocketManagerOptions { * // Return null if no information is found * }, * }); + * ``` */ retrieveSessionInfo: (shardId: number) => Awaitable; /**