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 | const isStr = require( '../preds/isStr' ); const dict = { Z_OR_M: 'zeroOrMore', O_OR_M: 'oneOrMore', Z_OR_O: 'zeroOrOne', COLL_OF: 'collOf', MAP_OF: 'mapOf', }; function humanReadable( expr ) { if ( isStr( expr ) ) { return expr; } if ( expr.type ) { if ( dict[ expr.type ] ) { return dict[ expr.type ]; } else { return expr.type.toLowerCase(); } } else { return expr.toString(); } } module.exports = humanReadable; |