-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (45 loc) · 1.5 KB
/
index.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
44
45
46
47
48
49
const BSRunner = require('./libs')
module.exports = function (filename, dataSource, options = {}) {
typeof Object.isObject !== 'function' && (Object.isObject = function (obj) {
return Object.prototype.toString.call(obj) === '[object Object]'
})
typeof Array.prototype._orderBy !== 'function' &&
(Array.prototype._orderBy = function (delegate, direction) {
if (this.length <= 1) {
return this;
}
var isFunction = typeof delegate == 'function';
var tmp;
for (var i = 0; i < this.length - 1; i++) {
for (var j = i + 1; j < this.length; j++) {
var first = this[i];
var next = this[j];
var result;
if (direction == 'asc') {
result = isFunction
? delegate(first) > delegate(next)
: first > next;
} else {
result = isFunction
? delegate(first) < delegate(next)
: first < next;
}
if (result) {
tmp = this[i];
this[i] = this[j];
this[j] = tmp;
}
}
}
return this;
});
typeof Array.prototype.orderBy !== 'function' &&
(Array.prototype.orderBy = function (delegate) {
return this._orderBy(delegate, 'asc');
});
typeof Array.prototype.orderByDesc !== 'function' && (Array.prototype.orderByDesc = function (delegate) {
return this._orderBy(delegate, 'desc');
})
var runner = new BSRunner(filename, dataSource, options)
return runner.gen()
}