-
Notifications
You must be signed in to change notification settings - Fork 1
/
all.js
43 lines (33 loc) · 815 Bytes
/
all.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*!
* callback-and-promise - all.js
* Copyright(c) 2014 dead_horse <[email protected]>
* MIT Licensed
*/
'use strict';
/**
* Module dependencies.
*/
var promisify = require('./')
module.exports = function (source, destination, methods) {
if (!destination) {
destination = {}
methods = Object.keys(source)
}
if (Array.isArray(destination)) {
methods = destination
destination = {}
}
if (!methods) {
methods = Object.keys(source)
}
methods.forEach(function (name) {
// promisify only if it's a function
if (typeof source[name] === 'function') destination[name] = promisify(source[name])
})
// proxy the rest
Object.keys(source).forEach(function (name) {
if (destination[name]) return
destination[name] = source[name]
})
return destination
}