From 9c0b0c1d9e29af45b75a699ad70e5446ac184f0c Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 21 Oct 2017 18:11:42 +0200 Subject: [PATCH] Create utils --- Utils/ArrayUtils.js | 39 +++++++++++++++++++++++++++++++++++++++ Utils/oLib.js | 25 +++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 Utils/ArrayUtils.js diff --git a/Utils/ArrayUtils.js b/Utils/ArrayUtils.js new file mode 100644 index 0000000..70dff9b --- /dev/null +++ b/Utils/ArrayUtils.js @@ -0,0 +1,39 @@ +/** + * Standard library + * + * This library provides useful functionalities for the DOM and other manipulations. + * + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @since 1.0.0 + */ +(function (jsOMS) +{ + "use strict"; + + /** + * Trim char from string + * + * @param {string} path Array path + * @param {obj} data Object + * @param {string} delim Path delimiter + * + * @return {mixed} + * + * @function + * + * @since 1.0.0 + */ + jsOMS.getArray = function(path, data, delim) + { + const pathParts = path.split(delim); + let current = data; + + for(let key in pathParts) { + current = current[key]; + } + + return current; + }; +}(window.jsOMS = window.jsOMS || {})); diff --git a/Utils/oLib.js b/Utils/oLib.js index 9368d82..8af71fa 100644 --- a/Utils/oLib.js +++ b/Utils/oLib.js @@ -11,6 +11,31 @@ (function (jsOMS) { "use strict"; + + /** + * Trim char from string + * + * @param {string} path Array path + * @param {obj} data Object + * @param {string} delim Path delimiter + * + * @return {mixed} + * + * @function + * + * @since 1.0.0 + */ + jsOMS.getArray = function(path, data, delim) + { + const pathParts = path.split(delim); + let current = data; + + for(let key in pathParts) { + current = current[pathParts[key]]; + } + + return current; + }; /** * Trim char from string