UNPKG

@seasketch/geoprocessing

Version:

Geoprocessing and reporting framework for SeaSketch 2.0

33 lines 994 B
import { runes } from "runes2"; import stringLength from "string-length"; export default function fastChunkString(str, { size, unicodeAware = false, }) { str = str || ""; if (!unicodeAware) { return getChunks(str, size); } return getChunksUnicode(str, size); } function getChunks(str, size) { const strLength = str.length; const numChunks = Math.ceil(strLength / size); const chunks = new Array(numChunks); let i = 0; let o = 0; for (; i < numChunks; ++i, o += size) { chunks[i] = str.substr(o, size); } return chunks; } function getChunksUnicode(str, size) { const strLength = stringLength(str); const numChunks = Math.ceil(strLength / size); const chunks = new Array(numChunks); let i = 0; let o = 0; const runeChars = runes(str); for (; i < numChunks; ++i, o += size) { chunks[i] = runeChars.slice(o, o + size).join(""); } return chunks; } //# sourceMappingURL=fastChunkString.js.map