From 1c382d6dc2c8e9a940b35344d2190388009c6dae Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Mon, 20 Jul 2020 13:52:56 +1200 Subject: [PATCH] Extract compile function to another file --- src/lang/en.js | 13 +------------ src/lang/utils/functions.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 src/lang/utils/functions.js diff --git a/src/lang/en.js b/src/lang/en.js index c93075d..5a3bf70 100644 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -1,16 +1,5 @@ -const compile = require("pug").compile const data = {...require("./base")} - -/** - * @param {string} text - */ -function pug(text) { - let lines = text.split("\n") - while (lines[0] === "") lines.shift() - const indentLevel = lines[0].match(/^\t*/)[0].length - lines = lines.map(l => l.replace(new RegExp(`^\\t{0,${indentLevel}}`), "")) - return compile(lines.join("\n")) -} +const {pug} = require("./utils/functions") ;(() => { data.go_to_profile = "Go to profile" diff --git a/src/lang/utils/functions.js b/src/lang/utils/functions.js new file mode 100644 index 0000000..56376cd --- /dev/null +++ b/src/lang/utils/functions.js @@ -0,0 +1,14 @@ +const compile = require("pug").compile + +/** + * @param {string} text + */ +function pug(text) { + let lines = text.split("\n") + while (lines[0] === "") lines.shift() + const indentLevel = lines[0].match(/^\t*/)[0].length + lines = lines.map(l => l.replace(new RegExp(`^\\t{0,${indentLevel}}`), "")) + return compile(lines.join("\n")) +} + +module.exports.pug = pug