import { create } from "https://deno.land/x/iter@v3.2.3/mod.ts";
const { fromCharCodes } = create;
Creates an iterable over a string's char codes.
Note that, in contrast to String.prototype[@@iterator]
,
this does not treat astral codepoints as single characters,
but rather as the constituent surrogate pair.
Each char code is therefore between 0x0000
and 0xffff = 2¹⁶ - 1
.
See the example below.
Examples
Example 1
Example 1
import * as iter from "https://deno.land/x/iter/mod.ts";
const str = "🦀💦🥱";
const chars = Uint16Array.from(iter.create.fromCharCodes(str));
console.log(chars.length); // -> 6
console.log(chars[0].toString(16)); // -> d83e
console.log(chars[1].toString(16)); // -> dd80
console.log(chars[2].toString(16)); // -> d83d
console.log(chars[3].toString(16)); // -> dca6
console.log(chars[4].toString(16)); // -> d83e
console.log(chars[5].tostring(16)); // -> dd71
console.log("\ud83e\udd80\ud83d\udca6\ud83e\udd71"); // -> 🦀💦🥱
Returns
IterableCircular<number>
An iterable over the char codes.