Created
February 8, 2021 21:12
-
-
Save nnmrts/7f06da21729a7d495cdee147271847b5 to your computer and use it in GitHub Desktop.
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
import { | |
promises | |
} from "fs"; | |
const { | |
readFile, | |
writeFile | |
} = promises; | |
// https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry | |
const registryText = await readFile("./registry.txt", "utf8"); | |
const regex = /%%\n(Type): (.+?)\n(Subtag|Tag): (.+?)(?:\n(Description): ((?:.+?)(?:\n {2}(?:.+?))*)(?:\n\5: (?:(?:.+?)(?:\n {2}(?:.+?))*))*)*(?:\n(Added|Suppress-Script|Deprecated|Preferred-Value|Comments): (?:(?:.+?)(?:\n {2}(?:.+?))*)(?:\n\7: (?:(?:.+?)(?:\n {2}(?:.+?))*))*)*(?:\n(Prefix): ((?:.+?)(?:\n {2}(?:.+?))*)(?:\n\8: (?:(?:.+?)(?:\n {2}(?:.+?))*))*)*(?:\n\7: (?:(?:.+?)(?:\n {2}(?:.+?))*)(?:\n\7: (?:(?:.+?)(?:\n {2}(?:.+?))*))*)*(?:\n(Macrolanguage): ((?:.+?)(?:\n {2}(?:.+?))*)(?:\n\10: (?:(?:.+?)(?:\n {2}(?:.+?))*))*)*(?:\n\7: (?:(?:.+?)(?:\n {2}(?:.+?))*)(?:\n\7: (?:(?:.+?)(?:\n {2}(?:.+?))*))*)*(?:\n(Scope): ((?:.+?)(?:\n {2}(?:.+?))*)(?:\n\12: (?:(?:.+?)(?:\n {2}(?:.+?))*))*)*(?:\n(?:Added|Suppress-Script|Deprecated|Preferred-Value|Comments): (?:(?:.+?)(?:\n {2}(?:.+?))*)(?:\n\7: (?:(?:.+?)(?:\n {2}(?:.+?))*))*)*(?=\n%%|$)/g; | |
const replaceString = "\"$4\":{\"type\":\"$2\",\"tagType\":\"$3\",\"description\":\"$6\",\"prefix\":\"$9\",\"macrolanguage\":\"$11\",\"scope\":\"$13\"},"; | |
const processed = registryText | |
.replace(/^(.+?)\n/, "") | |
.replace(/"/g, "\\\"") | |
.replace(regex, replaceString) | |
.replace(/\n| {2,}/g, "") | |
.slice(0, -1); | |
const json = `{${processed}}`; | |
const registry = JSON.parse(json); | |
for (const tag in registry) { | |
for (const key in registry[tag]) { | |
if (registry[tag][key] === "") { | |
delete registry[tag][key]; | |
} | |
} | |
} | |
await writeFile("./registry.json", JSON.stringify(registry)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment