Last active
January 12, 2024 00:34
-
-
Save AmyShackles/c59b13a88554736894ce8e5c978fccf6 to your computer and use it in GitHub Desktop.
Get Unicode codepoints associated with a particular property escape
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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