You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
642 B
39 lines
642 B
2 years ago
|
'use strict';
|
||
|
|
||
|
const Promise = require('bluebird');
|
||
|
const { Pattern } = require('hexo-util');
|
||
|
|
||
|
class Processor {
|
||
|
constructor() {
|
||
|
this.store = [];
|
||
|
}
|
||
|
|
||
|
list() {
|
||
|
return this.store;
|
||
|
}
|
||
|
|
||
|
register(pattern, fn) {
|
||
|
if (!fn) {
|
||
|
if (typeof pattern === 'function') {
|
||
|
fn = pattern;
|
||
|
pattern = /(.*)/;
|
||
|
} else {
|
||
|
throw new TypeError('fn must be a function');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (fn.length > 1) {
|
||
|
fn = Promise.promisify(fn);
|
||
|
} else {
|
||
|
fn = Promise.method(fn);
|
||
|
}
|
||
|
|
||
|
this.store.push({
|
||
|
pattern: new Pattern(pattern),
|
||
|
process: fn
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = Processor;
|