-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathengine.js
39 lines (31 loc) · 954 Bytes
/
engine.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
'use strict';
var pretty = require('pretty-hrtime');
function Engine (name, fn) {
if (!(this instanceof Engine)) {
return new Engine();
}
this.name = name;
this.func = fn;
var exports = this.func;
exports.version = this._getKey('version');
exports.url = this._getKey('homepage');
exports.toString = this.toString.bind(this);
exports.bench = function (css, precise) {
var start = process.hrtime();
return new Promise(function (resolve, reject) {
Promise.resolve(fn(css)).then(function () {
resolve(pretty(process.hrtime(start), {precise: precise}));
}, function (err) {
reject(err);
});
});
};
return exports;
}
Engine.prototype._getKey = function (key) {
return require(this.name + '/package.json')[key];
}
Engine.prototype.toString = function () {
return this.name;
}
module.exports = Engine;