typedash
Version:
modern, type-safe collection of utility functions
1 lines • 1.97 kB
Source Map (JSON)
{"version":3,"file":"range-fwApDQux.cjs","names":[],"sources":["../src/functions/range/range.ts"],"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"],"mappings":";;;;;;;;;AA8BA,SAAgB,MAAM,YAAoB,KAAc,OAAO,GAAa;AAC1E,KAAI,QAAQ,EACV,QAAO,EAAE;CAGX,MAAM,kBAAkB,OAAO,OAAO,IAAI;CAC1C,MAAM,gBAAgB,OAAO;CAE7B,MAAM,SAAS,EAAE;AAEjB,MAAK,IAAI,QAAQ,iBAAiB,QAAQ,eAAe,SAAS,KAChE,QAAO,KAAK,MAAM;AAGpB,QAAO"}