docs: fence examples in codeblocks

This commit is contained in:
iCrawl
2022-08-14 19:25:25 +02:00
parent bc06cc638d
commit 193b252672
3 changed files with 49 additions and 0 deletions

View File

@@ -37,7 +37,9 @@ export class Collection<K, V> extends Map<K, V> {
* @param defaultValueGenerator - A function that generates the default value * @param defaultValueGenerator - A function that generates the default value
* *
* @example * @example
* ```
* collection.ensure(guildId, () => defaultGuildConfig); * collection.ensure(guildId, () => defaultGuildConfig);
* ```
*/ */
public ensure(key: K, defaultValueGenerator: (key: K, collection: this) => V): V { public ensure(key: K, defaultValueGenerator: (key: K, collection: this) => V): V {
if (this.has(key)) return this.get(key)!; if (this.has(key)) return this.get(key)!;
@@ -230,7 +232,9 @@ export class Collection<K, V> extends Map<K, V> {
* @param thisArg - Value to use as `this` when executing function * @param thisArg - Value to use as `this` when executing function
* *
* @example * @example
* ```
* collection.find(user => user.username === 'Bob'); * collection.find(user => user.username === 'Bob');
* ```
*/ */
public find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined; public find<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): V2 | undefined;
public find(fn: (value: V, key: K, collection: this) => boolean): V | undefined; public find(fn: (value: V, key: K, collection: this) => boolean): V | undefined;
@@ -257,7 +261,9 @@ export class Collection<K, V> extends Map<K, V> {
* @param thisArg - Value to use as `this` when executing function * @param thisArg - Value to use as `this` when executing function
* *
* @example * @example
* ```
* collection.findKey(user => user.username === 'Bob'); * collection.findKey(user => user.username === 'Bob');
* ```
*/ */
public findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined; public findKey<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): K2 | undefined;
public findKey(fn: (value: V, key: K, collection: this) => boolean): K | undefined; public findKey(fn: (value: V, key: K, collection: this) => boolean): K | undefined;
@@ -304,7 +310,9 @@ export class Collection<K, V> extends Map<K, V> {
* @param thisArg - Value to use as `this` when executing function * @param thisArg - Value to use as `this` when executing function
* *
* @example * @example
* ```
* collection.filter(user => user.username === 'Bob'); * collection.filter(user => user.username === 'Bob');
* ```
*/ */
public filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>; public filter<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): Collection<K2, V>;
public filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>; public filter<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): Collection<K, V2>;
@@ -336,7 +344,9 @@ export class Collection<K, V> extends Map<K, V> {
* @param thisArg - Value to use as `this` when executing function * @param thisArg - Value to use as `this` when executing function
* *
* @example * @example
* ```
* const [big, small] = collection.partition(guild => guild.memberCount > 250); * const [big, small] = collection.partition(guild => guild.memberCount > 250);
* ```
*/ */
public partition<K2 extends K>( public partition<K2 extends K>(
fn: (value: V, key: K, collection: this) => key is K2, fn: (value: V, key: K, collection: this) => key is K2,
@@ -385,7 +395,9 @@ export class Collection<K, V> extends Map<K, V> {
* @param thisArg - Value to use as `this` when executing function * @param thisArg - Value to use as `this` when executing function
* *
* @example * @example
* ```
* collection.flatMap(guild => guild.members.cache); * collection.flatMap(guild => guild.members.cache);
* ```
*/ */
public flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>; public flatMap<T>(fn: (value: V, key: K, collection: this) => Collection<K, T>): Collection<K, T>;
public flatMap<T, This>( public flatMap<T, This>(
@@ -405,7 +417,9 @@ export class Collection<K, V> extends Map<K, V> {
* @param thisArg - Value to use as `this` when executing function * @param thisArg - Value to use as `this` when executing function
* *
* @example * @example
* ```
* collection.map(user => user.tag); * collection.map(user => user.tag);
* ```
*/ */
public map<T>(fn: (value: V, key: K, collection: this) => T): T[]; public map<T>(fn: (value: V, key: K, collection: this) => T): T[];
public map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[]; public map<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): T[];
@@ -429,7 +443,9 @@ export class Collection<K, V> extends Map<K, V> {
* @param thisArg - Value to use as `this` when executing function * @param thisArg - Value to use as `this` when executing function
* *
* @example * @example
* ```
* collection.mapValues(user => user.tag); * collection.mapValues(user => user.tag);
* ```
*/ */
public mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>; public mapValues<T>(fn: (value: V, key: K, collection: this) => T): Collection<K, T>;
public mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>; public mapValues<This, T>(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection<K, T>;
@@ -449,7 +465,9 @@ export class Collection<K, V> extends Map<K, V> {
* @param thisArg - Value to use as `this` when executing function * @param thisArg - Value to use as `this` when executing function
* *
* @example * @example
* ```
* collection.some(user => user.discriminator === '0000'); * collection.some(user => user.discriminator === '0000');
* ```
*/ */
public some(fn: (value: V, key: K, collection: this) => boolean): boolean; public some(fn: (value: V, key: K, collection: this) => boolean): boolean;
public some<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): boolean; public some<T>(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): boolean;
@@ -470,7 +488,9 @@ export class Collection<K, V> extends Map<K, V> {
* @param thisArg - Value to use as `this` when executing function * @param thisArg - Value to use as `this` when executing function
* *
* @example * @example
* ```
* collection.every(user => !user.bot); * collection.every(user => !user.bot);
* ```
*/ */
public every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>; public every<K2 extends K>(fn: (value: V, key: K, collection: this) => key is K2): this is Collection<K2, V>;
public every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>; public every<V2 extends V>(fn: (value: V, key: K, collection: this) => value is V2): this is Collection<K, V2>;
@@ -502,7 +522,9 @@ export class Collection<K, V> extends Map<K, V> {
* @param initialValue - Starting value for the accumulator * @param initialValue - Starting value for the accumulator
* *
* @example * @example
* ```
* collection.reduce((acc, guild) => acc + guild.memberCount, 0); * collection.reduce((acc, guild) => acc + guild.memberCount, 0);
* ```
*/ */
public reduce<T>(fn: (accumulator: T, value: V, key: K, collection: this) => T, initialValue?: T): T { public reduce<T>(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`); if (typeof fn !== 'function') throw new TypeError(`${fn} is not a function`);
@@ -540,10 +562,12 @@ export class Collection<K, V> extends Map<K, V> {
* @param thisArg - Value to use as `this` when executing function * @param thisArg - Value to use as `this` when executing function
* *
* @example * @example
* ```
* collection * collection
* .each(user => console.log(user.username)) * .each(user => console.log(user.username))
* .filter(user => user.bot) * .filter(user => user.bot)
* .each(user => console.log(user.username)); * .each(user => console.log(user.username));
* ```
*/ */
public each(fn: (value: V, key: K, collection: this) => void): this; public each(fn: (value: V, key: K, collection: this) => void): this;
public each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this; public each<T>(fn: (this: T, value: V, key: K, collection: this) => void, thisArg: T): this;
@@ -560,10 +584,12 @@ export class Collection<K, V> extends Map<K, V> {
* @param thisArg - Value to use as `this` when executing function * @param thisArg - Value to use as `this` when executing function
* *
* @example * @example
* ```
* collection * collection
* .tap(coll => console.log(coll.size)) * .tap(coll => console.log(coll.size))
* .filter(user => user.bot) * .filter(user => user.bot)
* .tap(coll => console.log(coll.size)) * .tap(coll => console.log(coll.size))
* ```
*/ */
public tap(fn: (collection: this) => void): this; public tap(fn: (collection: this) => void): this;
public tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this; public tap<T>(fn: (this: T, collection: this) => void, thisArg: T): this;
@@ -578,7 +604,9 @@ export class Collection<K, V> extends Map<K, V> {
* Creates an identical shallow copy of this collection. * Creates an identical shallow copy of this collection.
* *
* @example * @example
* ```
* const newColl = someColl.clone(); * const newColl = someColl.clone();
* ```
*/ */
public clone(): Collection<K, V> { public clone(): Collection<K, V> {
return new this.constructor[Symbol.species](this); return new this.constructor[Symbol.species](this);
@@ -590,7 +618,9 @@ export class Collection<K, V> extends Map<K, V> {
* @param collections - Collections to merge * @param collections - Collections to merge
* *
* @example * @example
* ```
* const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl); * const newColl = someColl.concat(someOtherColl, anotherColl, ohBoyAColl);
* ```
*/ */
public concat(...collections: ReadonlyCollection<K, V>[]) { public concat(...collections: ReadonlyCollection<K, V>[]) {
const newColl = this.clone(); const newColl = this.clone();
@@ -631,7 +661,9 @@ export class Collection<K, V> extends Map<K, V> {
* If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element. * If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each element.
* *
* @example * @example
* ```
* collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); * collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
* ```
*/ */
public sort(compareFunction: Comparator<K, V> = Collection.defaultSort) { public sort(compareFunction: Comparator<K, V> = Collection.defaultSort) {
const entries = [...this.entries()]; const entries = [...this.entries()];
@@ -686,6 +718,7 @@ export class Collection<K, V> extends Map<K, V> {
* @param whenInBoth - Function getting the result if the entry exists in both Collections * @param whenInBoth - Function getting the result if the entry exists in both Collections
* *
* @example * @example
* ```
* // Sums up the entries in two collections. * // Sums up the entries in two collections.
* coll.merge( * coll.merge(
* other, * other,
@@ -693,8 +726,10 @@ export class Collection<K, V> extends Map<K, V> {
* y => ({ keep: true, value: y }), * y => ({ keep: true, value: y }),
* (x, y) => ({ keep: true, value: x + y }), * (x, y) => ({ keep: true, value: x + y }),
* ); * );
* ```
* *
* @example * @example
* ```
* // Intersects two collections in a left-biased manner. * // Intersects two collections in a left-biased manner.
* coll.merge( * coll.merge(
* other, * other,
@@ -702,6 +737,7 @@ export class Collection<K, V> extends Map<K, V> {
* y => ({ keep: false }), * y => ({ keep: false }),
* (x, _) => ({ keep: true, value: x }), * (x, _) => ({ keep: true, value: x }),
* ); * );
* ```
*/ */
public merge<T, R>( public merge<T, R>(
other: ReadonlyCollection<K, T>, other: ReadonlyCollection<K, T>,
@@ -739,7 +775,9 @@ export class Collection<K, V> extends Map<K, V> {
* according to the string conversion of each element. * according to the string conversion of each element.
* *
* @example * @example
* ```
* collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); * collection.sorted((userA, userB) => userA.createdTimestamp - userB.createdTimestamp);
* ```
*/ */
public sorted(compareFunction: Comparator<K, V> = Collection.defaultSort) { public sorted(compareFunction: Comparator<K, V> = Collection.defaultSort) {
return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk)); return new this.constructor[Symbol.species](this).sort((av, bv, ak, bk) => compareFunction(av, bv, ak, bk));
@@ -761,8 +799,10 @@ export class Collection<K, V> extends Map<K, V> {
* @param combine - Function to combine an existing entry with a new one * @param combine - Function to combine an existing entry with a new one
* *
* @example * @example
* ```
* Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y); * Collection.combineEntries([["a", 1], ["b", 2], ["a", 2]], (x, y) => x + y);
* // returns Collection { "a" => 3, "b" => 2 } * // returns Collection { "a" => 3, "b" => 2 }
* ```
*/ */
public static combineEntries<K, V>( public static combineEntries<K, V>(
entries: Iterable<[K, V]>, entries: Iterable<[K, V]>,

View File

@@ -5,7 +5,9 @@ export type Awaitable<T> = T | Promise<T>;
/** /**
* Yields the numbers in the given range as an array * Yields the numbers in the given range as an array
* @example * @example
* ```
* range({ start: 3, end: 5 }); // [3, 4, 5] * range({ start: 3, end: 5 }); // [3, 4, 5]
* ```
*/ */
export function range({ start, end }: ShardRange): number[] { export function range({ start, end }: ShardRange): number[] {
return Array.from({ length: end - start + 1 }, (_, i) => i + start); return Array.from({ length: end - start + 1 }, (_, i) => i + start);

View File

@@ -80,16 +80,21 @@ export interface OptionalWebSocketManagerOptions {
* The ids of the shards this WebSocketManager should manage. * The ids of the shards this WebSocketManager should manage.
* Use `null` to simply spawn 0 through `shardCount - 1` * Use `null` to simply spawn 0 through `shardCount - 1`
* @example * @example
* ```
* const manager = new WebSocketManager({ * const manager = new WebSocketManager({
* shardIds: [1, 3, 7], // spawns shard 1, 3, and 7, nothing else * shardIds: [1, 3, 7], // spawns shard 1, 3, and 7, nothing else
* }); * });
* ```
*
* @example * @example
* ```
* const manager = new WebSocketManager({ * const manager = new WebSocketManager({
* shardIds: { * shardIds: {
* start: 3, * start: 3,
* end: 6, * end: 6,
* }, // spawns shards 3, 4, 5, and 6 * }, // spawns shards 3, 4, 5, and 6
* }); * });
* ```
*/ */
shardIds: number[] | ShardRange | null; 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 * Function used to retrieve session information (and attempt to resume) for a given shard
* @example * @example
* ```
* const manager = new WebSocketManager({ * const manager = new WebSocketManager({
* async retrieveSessionInfo(shardId): Awaitable<SessionInfo | null> { * async retrieveSessionInfo(shardId): Awaitable<SessionInfo | null> {
* // Fetch this info from redis or similar * // Fetch this info from redis or similar
@@ -129,6 +135,7 @@ export interface OptionalWebSocketManagerOptions {
* // Return null if no information is found * // Return null if no information is found
* }, * },
* }); * });
* ```
*/ */
retrieveSessionInfo: (shardId: number) => Awaitable<SessionInfo | null>; retrieveSessionInfo: (shardId: number) => Awaitable<SessionInfo | null>;
/** /**