export const _: PrivateVars; /** * ``` javascript * import { List } from 'hord'; * ``` * List maintains a sorted state internally, but doesn't observe changes to it's contents, so items manipulated externally can cause problems. If you must do this, the .sort() method is provided to resort the list. * * @class List * @classdesc Always sorted array. * * @param {...*|Array} values - Accepts an array of objects or multiple args of objects. */ declare class List { constructor(...values: any[]); /** * Used by .sort() and the binary search to determine equality. * * If you're setting this, you may want to call this before setting the values to prevent sorting twice, like this: * ``` javascript * import { List } from 'hord'; * * const list = new List().comparer(List.comparers.number.asc).values([1, 2, 3]); * ``` * * @memberOf List * @instance * * @param {Function} comparer - See the compare function for [Array.prototype.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Parameters) for details. A few simple comparer functions are provided via the static property [List.comparers](#List.comparers). * * @returns {Function | this} */ comparer(comparer: Function, ...args: any[]): Function | this; /** * Sort the items. * * @memberOf List * @instance * @chainable * * @returns {object} Returns `this`. */ sort(): object; /** * Add an item to the list. Uses binary search. * * @memberOf List * @instance * @chainable * * @param {unknown} item - Item is inserted into the list such that the items are still sorted. * * @returns {object} Returns `this`. */ add(item: unknown): object; /** * Add an item to the list if it isn't already included. Uses binary search. * * @memberOf List * @instance * @chainable * * @param {unknown} item - Item is inserted into the list such that the items are still sorted. * * @returns {object} Returns `this`. */ addUnique(item: unknown): object; /** * Get a new List of the unique (as determined by the comparer) values in this List. * * @memberOf List * @instance * * @returns {List} */ unique(): List; /** * Returns a shallow clone of this list with the contents of one or more arrays or lists appended. * * @memberOf List * @instance * @chainable * * @param {...Array|List} lists - One or more lists or arrays to concat to this list. * * @returns {List} */ concat(...lists: (any[] | List)[]): List; /** * Discard an item from the list. Uses binary search. * * @memberOf List * @instance * @chainable * * @param {unknown} item - Uses the comparer function to determine equality. * * @returns {object} Returns `this`. */ discard(item: unknown): object; /** * Discard an item from the list at a specified index. * * @memberOf List * @instance * @chainable * * @param {unknown} index - The index of the item to be discarded. * * @returns {object} Returns `this`. */ discardAt(index: unknown): object; /** * Discard all items from the list. * * @memberOf List * @instance * @chainable * * @returns {object} Returns `this`. */ discardAll(): object; /** * The current items in the list. * * @memberOf List * @instance * @chainable * * @param {Array} [values] - Replaces any previous values and immediately sorts them. * * @returns {Array} A shallow clone of the values. */ values(values?: any[]): any[]; /** * Gets the index of the first matching item. Uses a binary search. * * @memberOf List * @instance * * @param {unknown} item - Uses the comparer function to determine equality. * * @returns {number} The index of the item or -1. */ indexOf(item: unknown): number; /** * Gets the index of the last matching item. Uses a binary search. * * @memberOf List * @instance * * @param {unknown} item - Uses the comparer function to determine equality. * * @returns {number} The index of the item or -1. */ lastIndexOf(item: unknown): number; /** * Determines if an item exists in the list. Uses a binary search. * * @memberOf List * @instance * * @param {unknown} item - Uses the comparer function to determine equality. * * @returns {boolean} */ includes(item: unknown): boolean; /** * Gets the first matching item from the list. Uses a binary search. * * @memberOf List * @instance * * @param {unknown} item - Uses the comparer function to determine equality. * * @returns {unknown} The item or undefined. */ find(item: unknown): unknown; /** * Gets the last matching item from the list. Uses a binary search. * * @memberOf List * @instance * * @param {unknown} item - Uses the comparer function to determine equality. * * @returns {unknown} The item or undefined. */ findLast(item: unknown): unknown; /** * Gets all the matching items from the list. Uses a binary search. * * @memberOf List * @instance * * @param {unknown} item - Uses the comparer function to determine equality. * * @returns {List} */ findAll(item: unknown): List; /** * Gets the index of the first matching item. Uses a binary search (Identical to indexOf). * * @memberOf List * @instance * * @param {unknown} item - Uses the comparer function to determine equality. * * @returns {number} The index of the item or -1. */ findIndex(item: unknown): number; /** * Gets the index of the last matching item. Uses a binary search (Identical to lastIndexOf). * * @memberOf List * @instance * * @param {unknown} item - Uses the comparer function to determine equality. * * @returns {number} The index of the item or -1. */ findLastIndex(item: unknown): number; /** * Gets the first item in the list without removing it. * * @memberOf List * @instance * * @returns {unknown} */ first(): unknown; /** * Gets the last item in the list without removing it. * * @memberOf List * @instance * * @returns {unknown} */ last(): unknown; /** * Like .some(), but starts on the last (greatest index) item and progresses backwards. * * @memberOf List * @instance * * @param {Function} callback - Provides two arguments, the element and the index of the element. * @param {object} [thisArg=this] - A value to use as `this` when executing `callback`. * * @returns {List} */ someRight(callback: Function, thisArg?: object): List; /** * Gets the items that exist both in this list and in another list or array. Equality of items is determined by the comparer. * * @memberOf List * @instance * * @param {List|Array} array - Another list or array. * * @returns {List} */ intersection(array: List | any[]): List; /** * If the values in the list are Numbers, then this will return the median value. If there are an odd number of elements, then the value of the middle element is returned. If there are an even number of elements then the mean of the middle two elements is returned. To get the mean of a range of elements, low and high can be provided. * * @memberOf List * @instance * * @param {number} [low=0] - Index of a range to start at. * @param {number} [high=n] - Index of a range to end at. * * @returns {number} */ median(low?: number, high?: number): number; /** * If the values in the list are Numbers, then this will return the total value of all the elements added together. * * @memberOf List * @instance * * @returns {number} */ get total(): number; /** * If the values in the list are Numbers, then this will return the mean(average) of all the elements. * * @memberOf List * @instance * * @returns {number} */ mean(): number; /** * If the values in the list are Numbers, then this will return an object with a [quartile](https://en.wikipedia.org/wiki/Quartile) summary. * * @memberOf List * @instance * * @returns {{ min: number, Q1: number, median: number, Q3: number, max: number, outliers: Array }} Contains min, Q1, median, Q3, max, and outliers. All are numbers except outliers, which is an array of all outliers (low and high). */ quartiles(): { min: number; Q1: number; median: number; Q3: number; max: number; outliers: Array; }; /** * The number of items in the list. * * @memberOf List * @instance * @readonly * * @returns {number} */ readonly get length(): number; /** * See [Array.prototype.pop()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop) * * @method pop * @memberOf List * @instance * * @returns {unknown} */ pop(): unknown; /** * See [Array.prototype.shift()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift) * * @method shift * @memberOf List * @instance * * @returns {unknown} */ shift(): unknown; /** * See [Array.prototype.toString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString) * * @method toString * @memberOf List * @instance * * @returns {string} */ toString(): string; /** * See [Array.prototype.keys()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys) * * @method keys * @memberOf List * @instance * * @returns {object} */ keys(): object; /** * See [Array.prototype.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every) * * @method every * @memberOf List * @instance * * @param {Function} callback - Provides two arguments, the element and the index of the element. * @param {object} [thisArg=this] - A value to use as `this` when executing `callback`. * * @returns {boolean} */ every(...args: any[]): boolean; /** * See [Array.prototype.forEach()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) * * @method forEach * @memberOf List * @instance * * @param {Function} callback - Provides two arguments, the element and the index of the element. * @param {object} [thisArg=this] - A value to use as `this` when executing `callback`. * * @returns {undefined} */ forEach(...args: any[]): undefined; /** * See [Array.prototype.toLocaleString()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString) * * @method toLocaleString * @memberOf List * @instance * * @param {Array} [locales] * @param {object} [options] * * @returns {string} */ toLocaleString(...args: any[]): string; /** * See [Array.prototype.join()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join) * * @method join * @memberOf List * @instance * * @param {string} [separator=','] * * @returns {string} */ join(...args: any[]): string; /** * See [Array.prototype.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) * * @method map * @memberOf List * @instance * * @param {Function} callback - Provides two arguments, the element and the index of the element. * @param {object} [thisArg=this] - A value to use as `this` when executing `callback`. * * @returns {Array} */ map(...args: any[]): any[]; /** * See [Array.prototype.reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce) * * @method reduce * @memberOf List * @instance * * @param {Function} callback * @param {object} [thisArg=this] - A value to use as `this` when executing `callback`. * * @returns {unknown} */ reduce(...args: any[]): unknown; /** * See [Array.prototype.reduceRight()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduceRight) * * @method reduceRight * @memberOf List * @instance * * @param {Function} callback * @param {object} [thisArg=this] - A value to use as `this` when executing `callback`. * * @returns {unknown} */ reduceRight(...args: any[]): unknown; /** * See [Array.prototype.some()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) * * @method some * @memberOf List * @instance * * @param {Function} callback - Provides two arguments, the element and the index of the element. * @param {object} [thisArg=this] - A value to use as `this` when executing `callback`. * * @returns {boolean} */ some(...args: any[]): boolean; /** * See [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) * * @method filter * @memberOf List * @instance * * @param {Function} callback - Provides two arguments, the element and the index of the element. * @param {object} [thisArg=this] - A value to use as `this` when executing `callback`. * * @returns {List} */ filter(...args: any[]): List; /** * See [Array.prototype.slice()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) * * @method slice * @memberOf List * @instance * * @param {number} [begin=0] * @param {number} [end=array.length] * * @returns {List} */ slice(...args: any[]): List; } declare namespace List { export { comparers }; } export default List; import { PrivateVars } from 'type-enforcer'; declare const comparers: Readonly<{ default: import("./utility/compare.js").sortCompareFunction; string: { asc(a: any, b: any): any; desc(a: any, b: any): any; }; number: { asc(a: any, b: any): number; desc(a: any, b: any): number; }; id: { asc: import("./utility/compare.js").sortCompareFunction; desc: import("./utility/compare.js").sortCompareFunction; }; }>; //# sourceMappingURL=List.d.ts.map