all files / src/ index.js

100% Statements 14/14
100% Branches 2/2
100% Functions 4/4
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20                
import { absolute } from 'ethical-utility-path'
import minimatch from 'minimatch'
 
const route = async (ctx, next, config) => {
    const { file: { path } } = ctx
    const { pattern } = config
    const resolvedPattern = absolute(pattern)
    const resolvedPath = absolute(path)
    if (minimatch(resolvedPath, resolvedPattern)) {
        await next()
    }
}
 
const routeInit = (pattern) => {
    const config = { pattern }
    return async (ctx, next) => await route(ctx, next, config)
}
 
export default routeInit