From 11c249c8f071d577a3756aa35b13060c3f653ba2 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 4 Apr 2018 18:03:12 +0300 Subject: [PATCH] feature(package) add for-each-key from npm --- bin/cloudcmd.js | 5 +-- client/modules/operation/set-listeners.js | 2 +- common/for-each-key.js | 11 ----- package.json | 1 + test/common/for-each-key.spec.js | 49 ----------------------- 5 files changed, 4 insertions(+), 64 deletions(-) delete mode 100644 common/for-each-key.js delete mode 100644 test/common/for-each-key.spec.js diff --git a/bin/cloudcmd.js b/bin/cloudcmd.js index 01c5e4ce..06464395 100755 --- a/bin/cloudcmd.js +++ b/bin/cloudcmd.js @@ -210,7 +210,7 @@ function readConfig(name) { const fs = require('fs'); const tryCatch = require('try-catch'); const jju = require('jju'); - const forEachKey = require('../common/for-each-key'); + const forEachKey = require('for-each-key'); const readjsonSync = (name) => jju.parse(fs.readFileSync(name, 'utf8'), { mode: 'json' @@ -228,7 +228,7 @@ function readConfig(name) { function help() { const bin = require('../json/help'); - const forEachKey = require('../common/for-each-key'); + const forEachKey = require('for-each-key'); const currify = require('currify/legacy'); const usage = 'Usage: cloudcmd [options]'; const url = Info.homepage; @@ -236,7 +236,6 @@ function help() { console.log(usage); console.log('Options:'); - forEachKey(log(' %s %s'), bin); console.log('\nGeneral help using Cloud Commander: <%s>', url); } diff --git a/client/modules/operation/set-listeners.js b/client/modules/operation/set-listeners.js index f05da81a..713536a1 100644 --- a/client/modules/operation/set-listeners.js +++ b/client/modules/operation/set-listeners.js @@ -8,7 +8,7 @@ const { Dialog, } = DOM; -const forEachKey = require('../../../common/for-each-key'); +const forEachKey = require('for-each-key/legacy'); const { TITLE, } = CloudCmd; diff --git a/common/for-each-key.js b/common/for-each-key.js deleted file mode 100644 index eaae90f2..00000000 --- a/common/for-each-key.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -const currify = require('currify/legacy'); -const setValue = currify((fn, obj, key) => fn(key, obj[key])); - -module.exports = (fn, obj) => { - Object - .keys(obj) - .forEach(setValue(fn, obj)); -}; - diff --git a/package.json b/package.json index 26de268c..ee7e16f7 100644 --- a/package.json +++ b/package.json @@ -127,6 +127,7 @@ "express": "^4.13.0", "files-io": "^1.2.0", "flop": "^4.0.0", + "for-each-key": "^1.0.0", "format-io": "^0.9.6", "fullstore": "^1.0.0", "http-auth": "^3.2.3", diff --git a/test/common/for-each-key.spec.js b/test/common/for-each-key.spec.js deleted file mode 100644 index 3a952e52..00000000 --- a/test/common/for-each-key.spec.js +++ /dev/null @@ -1,49 +0,0 @@ -'use strict'; - -const test = require('tape'); -const diff = require('sinon-called-with-diff'); -const sinon = diff(require('sinon')); - -const forEachKey = require('../../common/for-each-key'); - -test('forEachKey: on property', (t) => { - const obj = { - a: 'hello', - }; - - const fn = sinon.stub(); - - forEachKey(fn, obj); - - t.ok(fn.calledWith('a', 'hello'), 'should call fn'); - t.end(); -}); - -test('forEachKey: a couple properties', (t) => { - const obj = { - a: 'hello', - b: 'world', - }; - - const fn = sinon.stub(); - - forEachKey(fn, obj); - - t.ok(fn.calledWith('b', 'world'), 'should call fn'); - t.end(); -}); - -test('forEachKey: count', (t) => { - const obj = { - a: 'hello', - b: 'world', - c: 'some', - }; - - const fn = sinon.stub(); - - forEachKey(fn, obj); - - t.equal(fn.callCount, 3, 'should '); - t.end(); -});