From 7f199593487f3fb0efe4c7598487a7f5af8d7ca9 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Tue, 13 Mar 2018 05:15:49 +1100 Subject: [PATCH] Added Object Utils --- common/Object.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 common/Object.js diff --git a/common/Object.js b/common/Object.js new file mode 100644 index 0000000..a2921e6 --- /dev/null +++ b/common/Object.js @@ -0,0 +1,37 @@ +'use strict'; + +Object.isUndefined = Object.isUndefined || function(v) { + return typeof v === typeof undefined; +} + +Object.isDefined = Object.isDefined || function(v) { + return !Object.isUndefined(v); +} + +Object.isBoolean = Object.isBoolean || function(v) { + return Object.isDefined(v) && typeof v === 'boolean'; +} + +Object.merge = Object.merge || function(left_most, right_most) { + let d = {}; + var left_keys = Object.keys(left_most); + for(var i = 0 ; i < left_keys.length; i++) { + var k = left_keys[i]; + if(typeof right_most[k] !== typeof undefined) continue; + d[k] = left_most[k]; + } + + var right_keys = Object.keys(right_most); + for(var i = 0; i < right_keys.length; i++) { + var k = right_keys[i]; + d[k] = right_most[k]; + } + + return d; +} + +Object.extendClass = Object.extendClass || function(super_class,new_methods) { + return Object.assign(Object.assign({}, super_class), new_methods); +} + +module.exports = Object;