'use strict' ; import { um } from './utilitymanager' ; export namespace transformutilities { export function upperCase ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utTransform , sp : um . TIXSelPolicy . Word , } , ( up ) : string => up . intext . toUpperCase ( ) ) ; } export function lowerCase ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utTransform , sp : um . TIXSelPolicy . Word , } , ( up ) : string => up . intext . toLowerCase ( ) ) ; } export function capitalize ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utInTransform , sp : um . TIXSelPolicy . Word , pat : /\b(_*\w)/g , repl : ( _match , p1 ) => p1 . toUpperCase ( ) , } ) ; } export function camelCase ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utInTransform , sp : um . TIXSelPolicy . Word , pat : /\b(_*\w)/g , repl : ( _match , p1 ) => p1 . toLowerCase ( ) , } ) ; } export function dashCase ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utInTransform , sp : um . TIXSelPolicy . Word , pat : /\b(\w+)\b/g , repl : ( _match , p1 ) => p1 . replace ( /([a-z])([A-Z])/g , '$1-$2' ) . toLowerCase ( ) . replace ( /_/g , '-' ) , } ) ; } export function cycleCase ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utInTransform , sp : um . TIXSelPolicy . Word , pat : /\b([\w\- ]+)\b/g , repl : ( _match , p1 ) => { if ( p1 === '' ) { return '' ; } const m6 = p1 . match ( /^(_*)([^ ])(.* .*)$/ ) ; if ( m6 !== null ) { return m6 [ 1 ] + m6 [ 2 ] . toUpperCase ( ) + m6 [ 3 ] . toLowerCase ( ) . replace ( / +([a-z])/g , ( _match , p2 ) => p2 . toUpperCase ( ) ) ; } if ( p1 . match ( /^_*[A-Z].*_/ ) !== null ) { return p1 . toLowerCase ( ) ; } const m4 = p1 . match ( /^(_*)([^_]+_.*)$/ ) ; if ( m4 !== null ) { return m4 [ 1 ] + m4 [ 2 ] . replace ( /_/g , '-' ) ; } const m5 = p1 . match ( /^(_*)([^\-].*-.*)$/ ) ; if ( m5 !== null ) { return m5 [ 1 ] + m5 [ 2 ] . replace ( /-/g , ' ' ) ; } const m1 = p1 . match ( /^(_*)([A-Z])([^A-Z].*)$/ ) ; if ( m1 !== null ) { return m1 [ 1 ] + m1 [ 2 ] . toLowerCase ( ) + m1 [ 3 ] ; } const m2 = p1 . match ( /^(_*)([^A-Z_]+[A-Z].*)$/ ) ; if ( m2 !== null ) { return m2 [ 1 ] + m2 [ 2 ] . replace ( /([A-Z]+)/g , ( _match , p2 ) => '_' + p2 ) . toUpperCase ( ) ; } return p1 ; } , } ) ; } export function spaceByUpper ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utInTransform , sp : um . TIXSelPolicy . Word , pat : /([A-Z])/g , repl : ( _match , p1 ) => ' ' + p1 , } ) ; } export function htmlEncode ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utTransform , sp : um . TIXSelPolicy . Line , } , ( up ) : string => { const d = document . createElement ( 'div' ) ; d . textContent = up . intext ; return d . innerHTML ; } ) ; } export function htmlDecode ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utTransform , sp : um . TIXSelPolicy . Line , } , ( up ) : string => { const d = document . createElement ( 'div' ) ; d . innerHTML = up . intext ; return d . textContent ; } ) ; } export function urlEncode ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utTransform , sp : um . TIXSelPolicy . Line , } , ( up ) : string => encodeURIComponent ( up . intext ) ) ; } export function urlDecode ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utTransform , sp : um . TIXSelPolicy . Line , } , ( up ) : string => decodeURIComponent ( up . intext ) ) ; } export function joinText ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utInTransform , sp : um . TIXSelPolicy . All , pat : /\n/g , repl : '' , } ) ; } export function reverseAssignment ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utInTransform , sp : um . TIXSelPolicy . Sentence , pat : /(\${0,1})\b(.+)(\s+)([=<>]=*|[!:]=+)(\s+)([^;]+)/ , repl : "$6$3$4$5$1$2" , } ) ; } export function unixToWinSlash ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utInTransform , sp : um . TIXSelPolicy . Line , pat : /\//g , repl : '\\' , } ) ; } export function winToUnixSlash ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utInTransform , sp : um . TIXSelPolicy . Line , pat : /\\/g , repl : '/' , } ) ; } export function singleToDoubleSlash ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utInTransform , sp : um . TIXSelPolicy . Line , pat : /\\/g , repl : '\\\\' , } ) ; } export function doubleToSingleSlash ( ) { um . utilityManager ( { utilType : um . TIXUtilityType . utInTransform , sp : um . TIXSelPolicy . Line , pat : /\\\\/g , repl : '\\' , } ) ; } }