import { Pipe , PipeTransform } from '@angular/core' ; @ Pipe ( { name : 'camelCase' } ) export class CamelCasePipe implements PipeTransform { transform ( value , mixed = false , ignore ? ) { let transformed = value || '' ; if ( mixed ) { if ( Array . isArray ( mixed ) ) { transformed = this . toCamelCaseMix ( value , mixed ) ; } else { transformed = this . toCamelCaseMix ( value ) ; } } else { transformed = this . toCamelCase ( value , ' ' ) ; } return transformed ; } param str param separator toCamelCase ( str , separator = '_' ) { return str . split ( separator ) . map ( ( word , index ) => { if ( index === 0 ) { let ind = word . lastIndexOf ( '.' ) ; if ( ind >= 0 ) { ind ++ ; } else { ind = 0 ; } const prefix = ind && ind > 0 ? word . slice ( 0 , ind ) : '' ; return `${ prefix }${ word . charAt ( ind ) . toLowerCase ( ) }${ word . slice ( ind + 1 ) }` ; } return word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) . toLowerCase ( ) ; } ) . join ( '' ) ; } param str param separators toCamelCaseMix ( str , separators = [ '_' , '-' , ' ' ] ) { let transformed = str ; separators . forEach ( separator => { transformed = this . toCamelCase ( transformed , separator ) ; } ) ; return transformed ; } }