import { trimLeft , trimRight } from './polyfills' ; import type { EtaConfig } from './config' ; interface EscapeMap { '&' : '&amp;' ; '<' : '&lt;' ; '>' : '&gt;' ; '"' : '&quot;' ; "'" : '&#39;' ; [ index ] : string ; } export function hasOwnProp ( obj , prop ) { return Object . prototype . hasOwnProperty . call ( obj , prop ) ; } export function copyProps < T > ( toObj , fromObj ) { for ( const key in fromObj ) { if ( hasOwnProp ( ( fromObj as unknown ) as object , key ) ) { toObj [ key ] = fromObj [ key ] ; } } return toObj ; } /**
 * Takes a string within a template and trims it, based on the preceding tag's whitespace control and `config.autoTrim`
 */ function trimWS ( str , config , wsLeft , wsRight ? ) { let leftTrim ; let rightTrim ; if ( Array . isArray ( config . autoTrim ) ) { leftTrim = config . autoTrim [ 1 ] ; rightTrim = config . autoTrim [ 0 ] ; } else { leftTrim = rightTrim = config . autoTrim ; } if ( wsLeft || wsLeft === false ) { leftTrim = wsLeft ; } if ( wsRight || wsRight === false ) { rightTrim = wsRight ; } if ( ! rightTrim && ! leftTrim ) { return str ; } if ( leftTrim === 'slurp' && rightTrim === 'slurp' ) { return str . trim ( ) ; } if ( leftTrim === '_' || leftTrim === 'slurp' ) { str = trimLeft ( str ) ; } else if ( leftTrim === '-' || leftTrim === 'nl' ) { str = str . replace ( /^(?:\r\n|\n|\r)/ , '' ) ; } if ( rightTrim === '_' || rightTrim === 'slurp' ) { str = trimRight ( str ) ; } else if ( rightTrim === '-' || rightTrim === 'nl' ) { str = str . replace ( /(?:\r\n|\n|\r)$/ , '' ) ; } return str ; } /**
 * A map of special HTML characters to their XML-escaped equivalents
 */ const escMap = { '&' : '&amp;' , '<' : '&lt;' , '>' : '&gt;' , '"' : '&quot;' , "'" : '&#39;' } ; function replaceChar ( s ) { return escMap [ s ] ; } param str returns function XMLEscape ( str ) { const newStr = String ( str ) ; if ( /[&<>"']/ . test ( newStr ) ) { return newStr . replace ( /[&<>"']/g , replaceChar ) ; } else { return newStr ; } } export { trimWS , XMLEscape } ;