import Color = require ( "color" ) ; import { err } from "./log" ; import ColorProperties from "./color-pipes" ; /**
 * Match[2] : Function name
 * Match[4] : Parameter
 */ const pipeRegex = />((\w+)(\((.*?)\))?)/g ; export function parsePipe ( str , color ) { let match ; while ( true ) { match = pipeRegex . exec ( str ) ; if ( match == null ) break ; const fn = { name : match [ 2 ] , param : match [ 4 ] } ; let found = false ; for ( let [ alias , full , pipe , dparam ] of ColorProperties ) { if ( alias == fn . name || full == fn . name ) { if ( ! dparam && fn . param != undefined ) err ( `Pipe name ${ fn . name } didn't require any parameter. Write it as ">${ fn . name }" instead of "${ match [ 0 ] }"` ) ; if ( fn . param ) fn . param = Number ( fn . param ) ; color = pipe ( color , fn . param || dparam ) ; found = true ; break ; } } if ( ! found ) err ( `Pipe name ${ fn . name } not found` ) ; } return color ; }