/
githubmirror
/
hexo
Обзор
Документация
Войти
/
githubmirror
/
hexo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lib/extend/processor.ts
55 строк
1 KB
D-Sketon
refactor: refactor types & support warehouse6 (#5483)
22 янв 2025, 10:05
Не верифицирован
22 янв 2025, 10:05
70efca7
Код
Авторство
О чём код?
import Promise from 'bluebird'; import { Pattern } from 'hexo-util'; import type File from '../box/file'; interface StoreFunction { (file: File | string): any; } type Store = { pattern: Pattern; process: StoreFunction; }[]; type patternType = Exclude<ConstructorParameters<typeof Pattern>[0], (str: string) => string>; /** * A processor is used to process source files in the `source` folder. */ class Processor { public store: Store; constructor() { this.store = []; } list(): Store { return this.store; } register(fn: StoreFunction): void; register(pattern: patternType, fn: StoreFunction): void; register(pattern: patternType | StoreFunction, fn?: StoreFunction): void { 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 as patternType), process: fn }); } } export = Processor;