From 31df6a4542d8fc67da1f89322c83c1388f8c23ff Mon Sep 17 00:00:00 2001 From: Snowflake Date: Mon, 14 Dec 2020 14:35:02 +0545 Subject: [PATCH] reformat, linter --- src/utils/collection.ts | 48 ++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/utils/collection.ts b/src/utils/collection.ts index faf8590..1a5fc62 100644 --- a/src/utils/collection.ts +++ b/src/utils/collection.ts @@ -12,36 +12,36 @@ export class Collection extends Map { /** Get first value(s) in Collection */ first(): V | undefined; - first(amount: number): V[]; - first(amount?: number): V | V[] | undefined { - if (typeof amount === 'undefined') return this.values().next().value - if (amount < 0) return this.last(amount * -1) - amount = Math.min(this.size, amount) - const iter = this.values() - return Array.from({ length: amount }, (): V => iter.next().value) - } + first(amount: number): V[]; + first(amount?: number): V | V[] | undefined { + if (typeof amount === 'undefined') return this.values().next().value + if (amount < 0) return this.last(amount * -1) + amount = Math.min(this.size, amount) + const iter = this.values() + return Array.from({ length: amount }, (): V => iter.next().value) + } /** Get last value(s) in Collection */ last(): V | undefined; - last(amount: number): V[]; - last(amount?: number): V | V[] | undefined { - const arr = this.array() - if (typeof amount === 'undefined') return arr[arr.length - 1] - if (amount < 0) return this.first(amount * -1) - if (typeof amount !== 'number' && !amount) return [] - return arr.slice(-amount) - } + last(amount: number): V[]; + last(amount?: number): V | V[] | undefined { + const arr = this.array() + if (typeof amount === 'undefined') return arr[arr.length - 1] + if (amount < 0) return this.first(amount * -1) + if (!amount) return [] // eslint-disable-line + return arr.slice(-amount) + } /** Get random value(s) from Collection */ random(): V; - random(amount: number): V[]; - random(amount?: number): V | V[] { - let arr = this.array() - if (typeof amount === 'undefined') return arr[Math.floor(Math.random() * arr.length)] - if (arr.length === 0 || typeof amount !== 'number' && !amount) return [] - arr = arr.slice() - return Array.from({ length: amount }, (): V => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]) - } + random(amount: number): V[]; + random(amount?: number): V | V[] { + let arr = this.array() + if (typeof amount === 'undefined') return arr[Math.floor(Math.random() * arr.length)] + if (arr.length === 0 || !amount) return [] // eslint-disable-line + arr = arr.slice() + return Array.from({ length: amount }, (): V => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]) + } /** Find a value from Collection using callback */ find(callback: (value: V, key: K) => boolean): V | undefined {