UNPKG

@yookue/ts-lang-utils

Version:

Common lang utilities for typescript

12 lines 439 B
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; export function fixLength(array, length, fillValue) { if (!array || !length) { return []; } if (array.length > length) { return array.slice(0, length); } else if (array.length < length) { return [].concat(_toConsumableArray(array), _toConsumableArray(Array(length - array.length).fill(fillValue))); } return _toConsumableArray(array); }