mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-01-11 09:58:39 +00:00
90 lines
1.8 KiB
JavaScript
90 lines
1.8 KiB
JavaScript
/**
|
|
* 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";
|
|
|
|
/**
|
|
* Delayed watcher
|
|
*
|
|
* Used to fire event after delay
|
|
*
|
|
* @return {callback}
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
jsOMS.watcher = function ()
|
|
{
|
|
var timer = 0;
|
|
return function (callback, ms)
|
|
{
|
|
clearTimeout(timer);
|
|
timer = setTimeout(callback, ms);
|
|
};
|
|
}();
|
|
|
|
/**
|
|
* Merging two arrays recursively
|
|
*
|
|
* @param target Target array
|
|
* @param source Source array
|
|
*
|
|
* @return {Array}
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
jsOMS.merge = function (target, source)
|
|
{
|
|
const out = jsOMS.clone(target);
|
|
|
|
for (let p in source) {
|
|
if (source.hasOwnProperty(p)) {
|
|
// Property in destination object set; update its value.
|
|
if (typeof source[p] === 'object') {
|
|
out[p] = jsOMS.merge(out[p], source[p]);
|
|
|
|
} else {
|
|
out[p] = source[p];
|
|
|
|
}
|
|
} else {
|
|
out[p] = source[p];
|
|
}
|
|
}
|
|
|
|
return out;
|
|
};
|
|
|
|
/**
|
|
* todo: implement deep clone/copy
|
|
* @param obj
|
|
* @returns {*}
|
|
*/
|
|
jsOMS.clone = function (obj)
|
|
{
|
|
return obj;
|
|
};
|
|
|
|
/**
|
|
* Check if a value/variable is set
|
|
*
|
|
* @param variable Variable to check for existence.
|
|
*
|
|
* @return {boolean}
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
jsOMS.isset = function (variable)
|
|
{
|
|
return typeof variable !== 'undefined' && variable !== null;
|
|
};
|
|
}(window.jsOMS = window.jsOMS || {}));
|