Skip to content

Instantly share code, notes, and snippets.

@zoonderkins
Forked from justjavac/unicode.js
Created February 19, 2019 05:45
Show Gist options
  • Save zoonderkins/dc499d7e9f88ee1058d8f5a6704bc2bf to your computer and use it in GitHub Desktop.
Save zoonderkins/dc499d7e9f88ee1058d8f5a6704bc2bf to your computer and use it in GitHub Desktop.
// JavaScript 字符串编码使用 UTF-16
"💩".length === 2;
"💩" === "\u{1F4A9}"; // es6
"💩" === "\uD83D\uDCA9"; // es5
// 同一个编码可能使用不同的码位
"ò" === "ò"; // ❎
"ò" === "\xF2"; // ✅
"ò" === "o\u0300"; // ✅
"o\u0300".normalize("NFC") === "\xF2"; // ✅ es6 提供了 normalize 函数
"👨‍👩‍👧‍👦".length === 11;
"👨‍👩‍👧‍👦" === "\u{1F468}\u200D\u{1F469}\u200D\u{1F467}\u200D\u{1F466}";
"👨" === "\u{1F468}";
"👩" === "\u{1F469}";
"👧" === "\u{1F467}";
"👦" === "\u{1F466}";
[..."👨‍👩‍👧‍👦"]; // [ "👨", "‍", "👩", "‍", "👧", "‍", "👦" ]
// 在 Unicode 支持不完善的系统上按退格键,能看到这些家庭成员一个接一个的消失。
// 一家人就是要齐齐整整
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment