UNPKG

typedash

Version:

modern, type-safe collection of utility functions

1 lines 1.96 kB
{"version":3,"sources":["../../src/functions/range/range.ts"],"names":[],"mappings":";AA8BO,SAAS,MAAM,YAAoB,KAAc,OAAO,GAAa;AAC1E,MAAI,QAAQ,GAAG;AACb,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,kBAAkB,OAAO,OAAO,IAAI;AAC1C,QAAM,gBAAgB,OAAO;AAE7B,QAAM,SAAS,CAAC;AAEhB,WAAS,QAAQ,iBAAiB,QAAQ,eAAe,SAAS,MAAM;AACtE,WAAO,KAAK,KAAK;AAAA,EACnB;AAEA,SAAO;AACT","sourcesContent":["/**\n * Returns an array of numbers from 0 to the specified end value (exclusive).\n * @param end The end value of the range.\n * @returns An array of numbers from 0 to the specified end value (exclusive).\n * @example\n * ```ts\n * range(5) // [0, 1, 2, 3, 4]\n * ```\n */\nexport function range(end: number): number[];\n/**\n * Returns an array of numbers from the specified start value to the specified end value (exclusive).\n * @param start The start value of the range.\n * @param end The end value of the range.\n * @param step The step between each value in the range.\n * @returns An array of numbers from the specified start value to the specified end value (exclusive).\n * @example\n * ```ts\n * range(2, 5) // [2, 3, 4]\n * range(2, 5, 2) // [2, 4]\n * ```\n */\nexport function range(start: number, end: number, step?: number): number[];\n/**\n * Implementation for all overloads.\n * @param startOrEnd The start value of the range, or the end value of the range if the `end` parameter is specified.\n * @param end The end value of the range.\n * @param step The step between each value in the range.\n * @returns An array of numbers from the specified start value to the specified end value (exclusive).\n */\nexport function range(startOrEnd: number, end?: number, step = 1): number[] {\n if (step <= 0) {\n return [];\n }\n\n const calculatedStart = end == null ? 0 : startOrEnd;\n const calculatedEnd = end ?? startOrEnd;\n\n const result = [];\n\n for (let index = calculatedStart; index < calculatedEnd; index += step) {\n result.push(index);\n }\n\n return result;\n}\n"]}