import type Collection from './Support/Collection'; import type Paginator from './Support/Paginator'; import collect from './Support/initialiser/collect'; import paginate from './Support/initialiser/paginate'; import wrap from './Support/array/wrap'; declare global { /** * Globally available methods on Array.prototype. */ interface Array { /** * Create a collection from the array. * * @return {Collection} */ collect: () => Collection; /** * Construct a paginator instance. * * @return {Paginator} */ paginate: () => Paginator; } /** * Globally available methods on Array. */ interface ArrayConstructor { /** * Create a collection from the array. * * @param {any} items * * @return {Collection} */ collect: (items?: any[]) => ReturnType; /** * Ensure the given value is an array. * * @param {any} value * * @return {array}; */ wrap: (value?: any) => any[]; /** * Construct a paginator instance. * * @param {any} items * * @return {Paginator} */ paginate: (items: any[]) => ReturnType; } } if (!('collect' in Array.prototype)) { Object.defineProperty(Array.prototype, 'collect', { value: function (): ReturnType { return collect(this); } }); } if (!('collect' in Array)) { Object.defineProperty(Array, 'collect', { value: function (items?: any[]): ReturnType { return collect(items); } }); } if (!('paginate' in Array.prototype)) { Object.defineProperty(Array.prototype, 'paginate', { value: function (): ReturnType { return paginate(this as []); } }); } if (!('paginate' in Array)) { Object.defineProperty(Array, 'paginate', { value: function (items: any[]): ReturnType { return paginate(items); } }); } if (!('wrap' in Array)) { Object.defineProperty(Array, 'wrap', { value: function (value?: any) { return arguments.length ? wrap(value) : wrap(); } }); }