From 771917a7a63a693a14437d59c8f8b3eb628c0a12 Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Tue, 3 Jan 2017 21:18:20 -0800 Subject: [PATCH] Clean up old unused code --- lib/common.coffee | 43 ------------------------------------------- lib/config.coffee | 5 +---- lib/db.coffee | 2 +- lib/query.coffee | 2 +- lib/session.coffee | 2 +- 5 files changed, 4 insertions(+), 50 deletions(-) diff --git a/lib/common.coffee b/lib/common.coffee index 1fe2fa0..f1e91e9 100644 --- a/lib/common.coffee +++ b/lib/common.coffee @@ -56,21 +56,6 @@ typeOf = (obj) -> Object.prototype.toString.call(obj) -exports.endsWith = (str, suffix) -> - str.indexOf(suffix, str.length - suffix.length) isnt -1 - - -exports.startsWith = (str, prefix) -> - str.substring(0, prefix.length) == prefix - - -exports.arrayToHash = (arr) -> - hash = {} - for i in arr - hash[i[0]] = i[1] - return hash - - exports.generateDeviceId = (deviceIdStruct) -> # Percent escaping function. Escapes everything except alphanumerics and underscore esc = (str) -> @@ -88,34 +73,6 @@ exports.generateDeviceId = (deviceIdStruct) -> return "#{esc(deviceIdStruct['OUI'])}-#{esc(deviceIdStruct['SerialNumber'])}" -exports.parseDeviceId = (deviceId) -> - parts = deviceId.split('-') - ret = {oui : querystring.unescape(parts[0])} - if parts.length == 3 - ret.productClass = querystring.unescape(parts[1]) - ret.serialNumber = querystring.unescape(parts[2]) - else - ret.serialNumber = querystring.unescape(parts[1]) - return ret - - -exports.extend = (obj, mixin) -> - obj[name] = method for name, method of mixin - obj - - -exports.flattenObject = (object) -> - newObj = {} - f = (obj, prefix) -> - for k, v of obj - if typeof(v) is 'object' - f(v, "#{prefix}#{k}.") - else - newObj["#{prefix}#{k}"] = v - f(object, '') - return newObj - - exports.getParamValueFromPath = (obj, path) -> pp = path.split('.') ref = obj diff --git a/lib/config.coffee b/lib/config.coffee index cae2e4b..230811e 100644 --- a/lib/config.coffee +++ b/lib/config.coffee @@ -62,7 +62,6 @@ options = { XML_IGNORE_NAMESPACE : {type : 'bool', default : false}, # Should probably never be changed - PRESETS_TIME_PADDING : {type : 'int', default : 1}, DEVICE_ONLINE_THRESHOLD : {type : 'int', default : 4000} } @@ -95,7 +94,7 @@ setConfig = (name, value, commandLineArgument) -> if name == n _value = cast(value, optionDetails.type) n = optionName - else if common.startsWith(name, "#{n}-") + else if name.startsWith("#{n}-") _value = cast(value, optionDetails.type) n = "#{optionName}-#{name[optionName.length+1..]}" @@ -163,5 +162,3 @@ try exports.auth = require(path.resolve(allConfig.CONFIG_DIR, 'auth')) exports.get = get - -exports.allConfig = allConfig diff --git a/lib/db.coffee b/lib/db.coffee index 5eac2d6..9cb4494 100644 --- a/lib/db.coffee +++ b/lib/db.coffee @@ -126,7 +126,7 @@ optimizeProjection = (obj) -> while i < keys.length a = keys[i-1] b = keys[i] - if common.startsWith(b, a) + if b.startsWith(a) if b.charAt(a.length) == '.' or b.charAt(a.length - 1) == '.' delete obj[b] keys.splice(i--, 1) diff --git a/lib/query.coffee b/lib/query.coffee index c82f493..ad93772 100644 --- a/lib/query.coffee +++ b/lib/query.coffee @@ -154,7 +154,7 @@ expand = (query) -> else new_query['$and'].push({'$or' : conditions}) else - common.extend(new_query, conditions[0]) + Object.assign(new_query, conditions[0]) return new_query diff --git a/lib/session.coffee b/lib/session.coffee index ca38c37..aa4bbcc 100644 --- a/lib/session.coffee +++ b/lib/session.coffee @@ -1356,7 +1356,7 @@ rpcResponse = (sessionData, id, rpcRes, callback) -> while (i = p[0].lastIndexOf('.', i - 1)) > rpcReq.parameterPath.length missing[p[0].slice(0, i)] |= 0 - if common.endsWith(p[0], '.') + if p[0].endsWith('.') missing[p[0][0...-1]] |= 1 path = common.parsePath(p[0][0...-1]) if not rpcReq.nextLevel