From 68114e5ac587a54ffcae0013812df4661af7541c Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 24 Apr 2015 11:17:31 -0400 Subject: [PATCH] feature(binom) add --- lib/server/binom.js | 27 +++++++++++++++++++++++++++ lib/server/rest.js | 6 +++--- 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 lib/server/binom.js diff --git a/lib/server/binom.js b/lib/server/binom.js new file mode 100644 index 00000000..ea71be70 --- /dev/null +++ b/lib/server/binom.js @@ -0,0 +1,27 @@ +(function() { + 'use strict'; + + module.exports = binom; + + function binom(name, array) { + var ret; + + if (typeof name !== 'string') + throw(Error('name should be string!')); + + if (!Array.isArray(array)) + throw(Error('array should be array!')); + + array.some(function(item) { + var is = item.name === name; + + if (is) + ret = item; + + return is; + }); + + return ret; + } + +})(); diff --git a/lib/server/rest.js b/lib/server/rest.js index 0679c7c1..38b33271 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -15,8 +15,8 @@ path = require('path'), root = require(DIR + 'root'), + binom = require(DIR + 'binom'), - Util = require(DIR_LIB + 'util'), CloudFunc = require(DIR_LIB + 'cloudfunc'), markdown = require(DIR + 'rest/markdown'), @@ -149,8 +149,8 @@ } function auth(code, callback) { - var storage = Util.findObjByNameInArr(Modules, 'storage'), - gh = Util.findObjByNameInArr(storage, 'GitHub'), + var storage = binom(Modules, 'storage'), + gh = binom(storage, 'GitHub'), env = process.env, key = env.github_key || gh.key,