diff --git a/src/arr.ts b/src/arr.ts index 416aa22..7528145 100644 --- a/src/arr.ts +++ b/src/arr.ts @@ -15,10 +15,6 @@ export class Arr { /** * Create a new array instance providing chainable operations. This instance * shallow clones the original values and works with the clone. - * - * @param {T[]} values - * - * @returns {Arr} */ constructor (...values: Values) { this.values = [] @@ -28,8 +24,6 @@ export class Arr { /** * Creates an array from an iterable object. - * - * @param values An iterable object to convert to an array. */ static from (...values: Values): Arr { return new this(...values) @@ -37,8 +31,6 @@ export class Arr { /** * Determine whether the given `input` is an array. - * - * @param value - the `input` value to check whether it’s an array */ static isIterable (value?: any): value is Iterable { if (value == null) { @@ -50,8 +42,6 @@ export class Arr { /** * Determine whether the given `input` is an array. - * - * @param input - the `input` value to check whether it’s an array */ static isArray (input?: any): input is any[] { return Array.isArray(input) @@ -59,8 +49,6 @@ export class Arr { /** * Determine whether the given `input` is not an array. - * - * @param input - the `input` value to check whether it’s not an array */ static isNotArray (input?: any[] | T): input is T { return !this.isArray(input) @@ -75,8 +63,6 @@ export class Arr { /** * Returns the underlying, plain JavaScript array. - * - * @returns {T[]} */ all (): T[] { return this.values @@ -84,8 +70,6 @@ export class Arr { /** * Append the given `values` to the end of the array. This is an alias for `push`. - * - * @returns {this} */ append (...values: Values): this { return this.push(...values) @@ -93,10 +77,6 @@ export class Arr { /** * Returns the value at the given `index` or undefined if the index exceeds the array’s size. - * - * @param {Number} index - * - * @returns {T | undefined} */ at (index: number): T | undefined { index = Math.trunc(index) || 0 @@ -114,8 +94,6 @@ export class Arr { /** * Collapse a array of arrays into a single, flat array. - * - * @returns {Array} */ collapse (): Arr { return new Arr(...this.values) @@ -124,8 +102,6 @@ export class Arr { /** * Removes all falsy values from the given `array`. Falsy values * are `null`, `undefined`, `''`, `false`, `0`, `-0`, `0n`, `NaN`. - * - * @returns {Arr} */ compact (): Arr { return this.filter(Boolean) @@ -133,10 +109,6 @@ export class Arr { /** * Returns an array containing the concatenation of two or more values. - * - * @param {T[] | T[][]} values - * - * @returns {Arr} */ concat (...values: Array): Arr { return new Arr( @@ -145,12 +117,7 @@ export class Arr { } /** - * Breaks the array into multiple, smaller arrays - * of the given `size`. - * - * @param {Number} size - * - * @returns {Array} + * Breaks the array into multiple, smaller arrays of the given `size`. */ chunk (size: number): T[][] { const chunks = [] @@ -166,10 +133,6 @@ export class Arr { /** * Removes all values from the array that are present in the given array. - * - * @param {*} values - * - * @returns {Arr} */ diff (values: T[]): Arr { return this.filter((value: T) => { @@ -180,10 +143,6 @@ export class Arr { /** * Keeps the items in the array that meet the condition * specified in the given `predicate` callback function. - * - * @param {Function} predicate - * - * @returns {Arr} */ filter (predicate: (value: T, index: number, array: Arr) => unknown): Arr filter(predicate: (value: T, index: number, array: Arr) => value is S, thisArg?: any): Arr @@ -202,10 +161,6 @@ export class Arr { /** * Returns the first item in the array matching the given `predicate` * function, or `undefined` if no such item was found. - * - * @param {Function} predicate - * - * @returns {T | undefined} */ find (predicate: (item: T, index: number, array: Arr) => unknown): T | undefined find (predicate: (item: T, index: number, array: Arr) => item is S): S | undefined @@ -218,10 +173,6 @@ export class Arr { /** * Returns the index of the first element in the array where the * given `predicate` function is `true`. Returns -1 otherwise. - * - * @param {Function} predicate - * - * @returns {Number} */ findIndex (predicate: (item: T, index: number, array: Arr) => unknown): number findIndex (predicate: (item: T, index: number, array: Arr) => item is S): number @@ -234,10 +185,6 @@ export class Arr { /** * Returns the last item in the array matching the given `predicate` * function. Returns `undefined` if no item was found in the array. - * - * @param {Function} predicate - * - * @returns {T | undefined} */ findLast (predicate: (item: T, index: number, array: Arr) => item is S): S | undefined findLast (predicate: (item: T, index: number, array: Arr) => unknown): T | undefined @@ -251,10 +198,6 @@ export class Arr { * Returns a new array instance containing the results of applying the * given `transform` function to each item in the array. Ultimately, * it flattens the mapped results one level deep. - * - * @param {Function} transform - * - * @returns {Array} */ flatMap (transform: (item: T, index: number, arr: Arr) => R): Arr { return this.map((item, index) => { @@ -264,8 +207,6 @@ export class Arr { /** * Performs the given `action` for each item in the array. - * - * @param {Function} action */ forEach (action: (item: T, index: number, arr: Arr) => void): void { this.map(action) @@ -273,10 +214,6 @@ export class Arr { /** * Group the array items into arrays using the given `key`. - * - * @param {String} key - * - * @returns {Object} */ groupBy (key: keyof T | ((item: T) => any)): R { if (typeof key === 'string' && key.includes('.')) { @@ -300,10 +237,6 @@ export class Arr { /** * Create a value receiving callback. - * - * @param {*} value - * - * @returns {Function} */ private valueRetriever (value: keyof T | ((item: T) => any)): (item: any) => any { return typeof value === 'function' @@ -315,10 +248,6 @@ export class Arr { /** * Determine whether the array contains the given `value`. - * - * @param {*} value - * - * @returns {Boolean} */ has (valueOrPredicate: T | Predicate): boolean { const results = typeof valueOrPredicate === 'function' @@ -330,10 +259,6 @@ export class Arr { /** * Creates an array of unique values that are included in both given array. - * - * @param {Array} values - * - * @returns {Arr} */ intersect (values: T[]): Arr { return new Arr(...new Set( @@ -343,8 +268,6 @@ export class Arr { /** * Determine whether the array is empty. - * - * @returns {Boolean} */ isEmpty (): boolean { return this.length() === 0 @@ -352,10 +275,6 @@ export class Arr { /** * Determine whether the array does not contain the given `value`. - * - * @param {*} value - * - * @returns {Boolean} */ isMissing (value: T): boolean { return !this.has(value) @@ -363,8 +282,6 @@ export class Arr { /** * Determine whether the array is not empty. - * - * @returns {Boolean} */ isNotEmpty (): boolean { return !this.isEmpty() @@ -372,10 +289,6 @@ export class Arr { /** * Returns a new string by concatenating all of the elements in an array. - * - * @param {String} separator - * - * @returns {String} */ join (separator: string): string join (separator: string, finalGlue: string): string @@ -402,10 +315,6 @@ export class Arr { * Returns the last element of the array or returns the last item in the array matching * the given `predicate` function. Returns `undefined` if no matching item is found or * available. If no predicate is given then the last item in the array is returned. - * - * @param {Function} predicate - * - * @returns {T | undefined} */ last (predicate?: (item: T, index: number, array: Arr) => unknown): T | undefined { return predicate @@ -415,8 +324,6 @@ export class Arr { /** * Returns the number of items in the array. - * - * @returns {Number} */ length (): number { return this.values.length @@ -425,10 +332,6 @@ export class Arr { /** * Returns a new array instance containing the results after applying * the given `transform` function to each item in the array. - * - * @param {Function} transform - * - * @returns {Arr} */ map (transform: (item: T, index: number, arr: Arr) => R): Arr { return Arr.from( @@ -440,8 +343,6 @@ export class Arr { /** * Returns the max value in the array. - * - * @returns {Number} */ max (): number { return Math.max( @@ -451,10 +352,6 @@ export class Arr { /** * Returns median of the current array. - * - * @param {} - * - * @returns {Number} */ median (): number { const sorted: Arr = this.sort((a: T, b: T) => +a - +b) @@ -468,8 +365,6 @@ export class Arr { /** * Returns the min value in the array. - * - * @returns {Number} */ min (): number { return Math.min(...this.values.map((value: T) => +value)) @@ -477,8 +372,6 @@ export class Arr { /** * Removes and returns the last item from the array. - * - * @returns {T|undefined} */ pop (): T | undefined { return this.values.pop() @@ -486,8 +379,6 @@ export class Arr { /** * Prepend the given `values` to the beginning of the array. This is an alias for `unshift`. - * - * @returns {this} */ prepend (...values: T[]): this { return this.unshift(...values) @@ -495,8 +386,6 @@ export class Arr { /** * Add one or more items to the end of the array. - * - * @returns {Arr} */ push (...values: Values): this { this.values.push( @@ -508,10 +397,6 @@ export class Arr { /** * Returns a flat array of items removing `undefined` and `null` values. - * - * @param values - * - * @returns {T[]} */ private resolveValues (...values: Values): T[] { return values.flatMap(value => { @@ -538,10 +423,6 @@ export class Arr { /** * Returns a new array instance containing the results after applying * the given `transform` function to each item in the array. - * - * @param {Function} transform - * - * @returns {Arr} */ reduce (reducer: (previousValue: R, currentValue: T, currentIndex: number, array: Arr) => R, initialValue: R): R reduce (reducer: (previousValue: R, currentValue: T, currentIndex: number, array: Arr) => R, initialValue: R): R { @@ -553,10 +434,6 @@ export class Arr { /** * Inverse of the `filter` method, removing all items in the array satisfying * the condition specified in the given `predicate` callback function. - * - * @param {Function} predicate - * - * @returns {Arr} */ reject (predicate: (value: T, index: number, array: Arr) => unknown): Arr { return this.filter((item, index) => { @@ -566,8 +443,6 @@ export class Arr { /** * Removes `undefined` and `null` values from the array. - * - * @returns {Arr} */ removeNullish (): Arr { return this.filter(item => { @@ -577,8 +452,6 @@ export class Arr { /** * Returns reversed version of original array. - * - * @returns {Arr} */ reverse (): Arr { return new Arr( @@ -588,8 +461,6 @@ export class Arr { /** * Removes and returns the first item from the array. - * - * @returns {(T|undefined)} */ shift (): T | undefined { return this.values.shift() @@ -597,8 +468,6 @@ export class Arr { /** * Returns the number of items in the array. This method is an alias for `.length()`. - * - * @returns {Number} */ size (): number { return this.length() @@ -608,11 +477,6 @@ export class Arr { * Returns a chunk of items beginning at the `start` * index without removing them from the array. * You can `limit` the size of the slice. - * - * @param {Number} start - * @param {Number} limit - * - * @returns {Arr} */ slice (start: number, limit?: number): Arr { const chunk: T[] = this.values.slice(start) @@ -624,12 +488,6 @@ export class Arr { * Removes and returns a chunk of items beginning at the `start` * index from the array. You can `limit` the size of the * slice and replace the removed items with `inserts`. - * - * @param {Number} start - * @param {Number} limit - * @param {Array} inserts - * - * @returns {Arr} */ splice (start: number, limit?: number, ...inserts: T[]): Arr { const flattend: T[] = Array.prototype.concat(...inserts) @@ -640,24 +498,15 @@ export class Arr { /** * Returns a sorted array of items, with an optional comparator. - * - * @param {Function} comparator - * - * @returns {Arr} */ - sort (comparator: (a: T, b: T) => number): Arr { + sort (comparator?: (a: T, b: T) => number): Arr { return new Arr( ...this.values.slice(0).sort(comparator) ) } /** - * Take and remove `limit` items from the - * beginning or end of the array. - * - * @param {Integer} limit - * - * @returns {Arr} + * Take and remove `limit` items from the beginning or end of the array. */ takeAndRemove (limit: number): Arr { const cloned = new Arr(...this.values) @@ -675,8 +524,6 @@ export class Arr { /** * Transforms this array into a native JavaScript array. - * - * @returns {T[]} */ toArray (): T[] { return this.all() @@ -684,8 +531,6 @@ export class Arr { /** * Returns JSON representation of array. - * - * @returns {String} */ toJSON (): string { return JSON.stringify(this.values) @@ -693,8 +538,6 @@ export class Arr { /** * Keep only unique items in the array. - * - * @returns {Arr} */ unique (): Arr { return new Arr( @@ -704,10 +547,6 @@ export class Arr { /** * Keep only unique items in the array identified by the given `selector`. - * - * @param {Function} - * - * @returns {Array} */ uniqueBy (selector: (item: T, index: number, array: Arr) => unknown): Arr { const exists = new Set() @@ -725,10 +564,6 @@ export class Arr { /** * Add one or more items to the beginning of the array. - * - * @param {Array} values - * - * @returns {Arr} */ unshift (...values: T[]): this { this.values.unshift(...values)