import { mapValues , includes } from 'lodash' ; import { Arg } from './arg' ; export function Fn ( config ) { this . name = config . name ; this . type = config . type ; this . aliases = config . aliases || [ ] ; this . fn = ( ... args ) => Promise . resolve ( config . fn ( ... args ) ) ; this . help = config . help || '' ; this . args = mapValues ( config . args || { } , ( arg , name ) => new Arg ( { name , ... arg } ) ) ; this . context = config . context || { } ; this . accepts = ( type ) => { if ( ! this . context . types ) return true ; return includes ( this . context . types , type ) ; } ; }