UNPKG

hackmud-script-manager

Version:

Script manager for game hackmud, with minification, TypeScript support, and player script type definition generation.

21 lines (20 loc) 1.3 kB
const postprocess = (code, uniqueId) => code .replace(/^function\s*[\w$]+\(/, "function(") .replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$SC_DOLLAR\\$`, "g"), "S\\C$") .replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$DB_DOLLAR\\$`, "g"), "D\\B$") .replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$D\\$`, "g"), "_\\_D_S") .replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$FMCL\\$`, "g"), "_\\_FMCL_") .replace(RegExp(`\\$${uniqueId}\\$\\\\(?:\\\\)?\\$G\\$`, "g"), "_\\_G_") .replace(RegExp(`\\$${uniqueId}\\$(\\d)\\$SUBSCRIPT\\$(\\w+)\\$(\\w+)\\$`, "g"), "#$1s.$2.$3") .replace(RegExp(`\\$${uniqueId}\\$DEBUG\\$`, "g"), "#D") .replace(RegExp(`\\$${uniqueId}\\$FMCL\\$`, "g"), "#FMCL") .replace(RegExp(`\\$${uniqueId}\\$GLOBAL\\$`, "g"), "#G") .replace(RegExp(`\\$${uniqueId}\\$DB\\$(\\w+)\\$`, "g"), "#db.$1") .replace(RegExp(`\\$${uniqueId}\\$SLASH_SLASH\\$`, "g"), "/\\/") .replace(RegExp(`\\$${uniqueId}\\$NOT_A_SUBSCRIPT\\$(#[\\w\\.]+)\\(\\$`, "g"), "$1\\(") .replace(RegExp(`\\$${uniqueId}\\$NOT_A_DB_CALL\\$(\\w+)\\$`, "g"), "#db.$1\\(") .replace(RegExp(`\\$${uniqueId}\\$NOT_A_DEBUG_CALL\\$`, "g"), "#D\\(") .replace(RegExp(`\\$${uniqueId}\\$NOT_FMCL\\$`, "g"), "#\\FMCL") .replace(RegExp(`\\$${uniqueId}\\$NOT_G\\$`, "g"), "#\\G") export { postprocess }