Spaces:
Paused
Paused
Download node_modules/@huggingface/hub/src/utils/chunk.ts from ken-q/opencode-home: direct link, hf CLI and curl.
- Browser
- Download file 629 Bytes
-
https://huggingface.co/spaces/ken-q/opencode-home/resolve/main/node_modules/%40huggingface/hub/src/utils/chunk.ts
- Command line
-
hf download hf://spaces/ken-q/opencode-home/node_modules/@huggingface/hub/src/utils/chunk.ts
-
curl -L -o chunk.ts https://huggingface.co/spaces/ken-q/opencode-home/resolve/main/node_modules/%40huggingface/hub/src/utils/chunk.ts
629 Bytes
| import { range } from "./range"; | |
| /** | |
| * Chunk array into arrays of length at most `chunkSize` | |
| * | |
| * @param chunkSize must be greater than or equal to 1 | |
| */ | |
| export function chunk<T extends unknown[] | string>(arr: T, chunkSize: number): T[] { | |
| if (isNaN(chunkSize) || chunkSize < 1) { | |
| throw new RangeError("Invalid chunk size: " + chunkSize); | |
| } | |
| if (!arr.length) { | |
| return []; | |
| } | |
| /// Small optimization to not chunk buffers unless needed | |
| if (arr.length <= chunkSize) { | |
| return [arr]; | |
| } | |
| return range(Math.ceil(arr.length / chunkSize)).map((i) => { | |
| return arr.slice(i * chunkSize, (i + 1) * chunkSize); | |
| }) as T[]; | |
| } | |