UNPKG

args-to-arr

Version:

converts arguments or any other array-like object into an array starting from specific index.

39 lines (28 loc) 816 B
'use strict'; var isArrayLike = require('is-array-like'); function toArray(args, start) { if (!isArrayLike(args) && args !== '') { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions throw new TypeError("".concat(args, " can't be converted to array.")); } if (start == null) { start = 0; } if (typeof start !== 'number' || !Number.isFinite(start)) { throw new TypeError("".concat(start, " is not a valid start point.")); } var len = args.length; if (start < 0) { start += len; } var argsObj = Object(args); var result = new Array(len - start); for (var i = start; i < len; i++) { if (i in argsObj) { result[i - start] = argsObj[i]; } } return result; } module.exports = toArray; //# sourceMappingURL=args-to-arr.js.map