UNPKG

date-limits

Version:

Check if a date is before a flexible limit.

26 lines (25 loc) 738 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateSequence = void 0; function generateSequence(params, limit) { let { slope: a, offset: b = 0 } = params; if (Math.abs(a) === Infinity || Math.abs(b) === Infinity) { throw new Error(`Slope and offset cannot be set to Infinity`); } if (isNaN(a) || isNaN(b)) { return []; } const result = []; b %= a; let x = Math.max(0, Math.ceil(-b / a)); let value = a * x + b; while (value <= limit) { if (value > 0) { result.push(value); } x++; value = a * x + b; } return result; } exports.generateSequence = generateSequence;