UNPKG

@quinck/collections

Version:

Allows extra operations on JavaScript collections: Array, Map and Set.

44 lines (43 loc) 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const array_index_out_of_bounds_error_1 = require("../errors/array-index-out-of-bounds-error"); const ARRAY_FIRST_ELEMENT_INDEX = 0; if (!Array.prototype.first) { Object.defineProperty(Array.prototype, 'first', { get: function () { const _self = this; const first = _self[ARRAY_FIRST_ELEMENT_INDEX]; if (first != undefined && first != null) return first; throw new array_index_out_of_bounds_error_1.ArrayIndexOutOfBoundsError(_self, ARRAY_FIRST_ELEMENT_INDEX); }, }); } if (!Array.prototype.firstOrDefault) { Object.defineProperty(Array.prototype, 'firstOrDefault', { get: function () { const _self = this; return _self[ARRAY_FIRST_ELEMENT_INDEX]; }, }); } if (!Array.prototype.last) { Object.defineProperty(Array.prototype, 'last', { get: function () { const _self = this; const arrayLastElementIndex = _self.length - 1; const last = _self[arrayLastElementIndex]; if (last != undefined && last != null) return last; throw new array_index_out_of_bounds_error_1.ArrayIndexOutOfBoundsError(_self, arrayLastElementIndex); }, }); } if (!Array.prototype.lastOrDefault) { Object.defineProperty(Array.prototype, 'lastOrDefault', { get: function () { const _self = this; return _self[_self.length - 1]; }, }); }