Skip to content

Instantly share code, notes, and snippets.

@AmyShackles
Last active January 12, 2024 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AmyShackles/c59b13a88554736894ce8e5c978fccf6 to your computer and use it in GitHub Desktop.
Save AmyShackles/c59b13a88554736894ce8e5c978fccf6 to your computer and use it in GitHub Desktop.
Get Unicode codepoints associated with a particular property escape
const fs = require("fs");
const { unicode } = require("./Unicode");
const args = process.argv.slice(2);
const propertyEscape = args[0];
let ret = `const ${propertyEscape.toLowerCase()} = [`;
const regex = new RegExp(`\\p{${propertyEscape}}`, "gu");
for (let i = 0; i < unicode.length; i++) {
if (unicode[i].match(regex)) {
if (i <= 65535) {
if (ret[ret.length - 1] === "[") {
ret += `"\\\\u${i.toString(16).toUpperCase().padStart(4, "0")}"`;
} else {
ret += `, "\\\\u${i
.toString(16)
.toUpperCase()
.padStart(4, "0")}"`;
}
} else if (ret[ret.length - 1] === "[") {
ret += `"\\\\u{${i.toString(16).toUpperCase().padStart(5, "0")}}"`;
} else {
ret += `, "\\\\u{${i.toString(16).toUpperCase().padStart(5, "0")}}"`;
}
}
}
ret += `];
module.exports = { ${propertyEscape.toLowerCase()} };`;
fs.writeFile(`${propertyEscape}.js`, ret, (err) => {
if (err) throw err;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment