summary refs log tree commit diff
path: root/resources/app/node_modules/pupa/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/app/node_modules/pupa/index.js')
-rw-r--r--resources/app/node_modules/pupa/index.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/resources/app/node_modules/pupa/index.js b/resources/app/node_modules/pupa/index.js
new file mode 100644
index 0000000..501fca5
--- /dev/null
+++ b/resources/app/node_modules/pupa/index.js
@@ -0,0 +1,22 @@
+'use strict';
+module.exports = (tpl, data) => {
+	if (typeof tpl !== 'string') {
+		throw new TypeError(`Expected a string in the first argument, got ${typeof tpl}`);
+	}
+
+	if (typeof data !== 'object') {
+		throw new TypeError(`Expected an Object/Array in the second argument, got ${typeof data}`);
+	}
+
+	const re = /{(.*?)}/g;
+
+	return tpl.replace(re, (_, key) => {
+		let ret = data;
+
+		for (const prop of key.split('.')) {
+			ret = ret ? ret[prop] : '';
+		}
+
+		return ret || '';
+	});
+};