import { asCodePointsArray } from "https://deno.land/x/codepoint_iterator@v1.1.1/mod.ts";
Converts an iterable of Uint8Array (byte arrays) into an array of Unicode code points. This is particularly useful for processing streams of text data, where each chunk is represented as a Uint8Array, and you want to work with the text's Unicode code points.
Similar to asCodePointsIterator, this function processes the input iterable to extract UTF-8 characters and calculate their corresponding Unicode code points. However, instead of yielding the code points one by one, it stores them in an array and returns the array once the processing is complete.
Examples
Convert an iterable of Uint8Array
chunks into an array of Unicode code points.
Convert an iterable of Uint8Array
chunks into an array of Unicode code points.
async function exampleArrayUsage() {
const utf8Chunks = [new Uint8Array([0x68, 0x65, 0x6C, 0x6C, 0x6F])]; // Represents the string 'hello'
const codePoints = await asCodePointsArray(utf8Chunks);
console.log(codePoints.map(cp => String.fromCodePoint(cp)).join('')); // Output: 'hello'
}
exampleArrayUsage();