UNPKG

372 BJavaScriptView Raw
1'use strict'
2
3function promisfy (mod, fn) {
4 return function () {
5 var args = Array.prototype.slice.call(arguments)
6 return new Promise(function (resolve, reject) {
7 args.push(function (err, res) {
8 if (err) reject(err)
9 else resolve(res)
10 })
11 mod[fn].apply(mod, args)
12 })
13 }
14}
15
16module.exports = promisfy(require('fs'), 'readFile')