From 0b840ff00ddfa510f16f854f0b96e07ce619e3ee Mon Sep 17 00:00:00 2001 From: Jelle De Loecker Date: Sat, 27 Apr 2024 17:19:17 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20`Variables#get(key)`=20&=20`V?= =?UTF-8?q?ariables#setFromTemplate(key,=20value)`=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + lib/core/variables.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa5d12e..3736d89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * Use shorter compiled function body ids when not on development environment * Add basic `Optional` value-wrapper class support * Make sure variables are always cast to a `Variables` instance +* Add `Variables#get(key)` & `Variables#setFromTemplate(key, value)` method ## 2.3.19 (2024-04-13) diff --git a/lib/core/variables.js b/lib/core/variables.js index 682973a..90e414d 100644 --- a/lib/core/variables.js +++ b/lib/core/variables.js @@ -60,6 +60,28 @@ Variables.setProperty(function length() { return Object.keys(this).length; }); +/** + * Get a specific variable + * + * @author Jelle De Loecker + * @since 2.4.0 + * @version 2.4.0 + */ +Variables.setMethod(function get(key) { + return this[key]; +}); + +/** + * Set a specific variable from a template + * + * @author Jelle De Loecker + * @since 2.4.0 + * @version 2.4.0 + */ +Variables.setMethod(function setFromTemplate(key, value) { + return this[key] = value; +}); + /** * Get this instance's own key-values * (Skipping symbols)