export const EMAIL_FORMATING = { OPEN_TAG_AUTOCOMPLETE : '‹' , CLOSE_TAG_AUTOCOMPLETE : '›' , OPEN_TAG_AUTOCOMPLETE_RAW : '<' , CLOSE_TAG_AUTOCOMPLETE_RAW : '>' , } ; const { OPEN_TAG_AUTOCOMPLETE , CLOSE_TAG_AUTOCOMPLETE , OPEN_TAG_AUTOCOMPLETE_RAW , CLOSE_TAG_AUTOCOMPLETE_RAW } = EMAIL_FORMATING ; export const MAP_TAGS = { [ OPEN_TAG_AUTOCOMPLETE_RAW ] : OPEN_TAG_AUTOCOMPLETE , [ CLOSE_TAG_AUTOCOMPLETE_RAW ] : CLOSE_TAG_AUTOCOMPLETE , [ OPEN_TAG_AUTOCOMPLETE ] : OPEN_TAG_AUTOCOMPLETE_RAW , [ CLOSE_TAG_AUTOCOMPLETE ] : CLOSE_TAG_AUTOCOMPLETE_RAW , } ; /**
 * Replace custom unicode escape for chevrons by default
 * Replace <> (for a tag) via unicode or reverse it
 * mode undefined for toUnicode, reverse for unicode -> <|>
 */ export function unicodeTag ( input = '' , mode ) { if ( mode === 'reverse' ) { const matchTagUnicodeOpenClose = ( ) => new RegExp ( `${ OPEN_TAG_AUTOCOMPLETE }|${ CLOSE_TAG_AUTOCOMPLETE }` , 'ig' ) ; return input . replace ( matchTagUnicodeOpenClose ( ) , ( match ) => MAP_TAGS [ match ] || '' ) ; } const matchTagOpenClose = ( ) => new RegExp ( `${ OPEN_TAG_AUTOCOMPLETE_RAW }|${ CLOSE_TAG_AUTOCOMPLETE_RAW }` , 'ig' ) ; return input . replace ( matchTagOpenClose ( ) , ( match ) => MAP_TAGS [ match ] || '' ) ; } param val param bits export const toUnsignedString = ( val , bits ) => { const base = 1 << bits ; const wordCount = Math . ceil ( 32 / bits ) ; const bottomBits = ( wordCount - 1 ) * bits ; const bottom = val & ( ( 1 << bottomBits ) - 1 ) ; const top = val >>> bottomBits ; if ( top === 0 ) { return bottom . toString ( base ) ; } const topString = top . toString ( base ) ; const bottomString = bottom . toString ( base ) ; const padLength = wordCount - topString . length - bottomString . length ; const middleString = '0' . repeat ( padLength ) ; return topString + middleString + bottomString ; } ; export const ucFirst = ( input = '' ) => { return input . charAt ( 0 ) . toUpperCase ( ) + input . slice ( 1 ) ; } ; param str return export const extractChevrons = ( str = '' ) => { const CHEVRONS_REGEX = /<([^>]+)>/g ; const [ , match = '' ] = CHEVRONS_REGEX . exec ( str ) || [ ] ; return match ; } ; export const htmlEntities = ( str = '' ) => { return String ( str ) . replace ( /&/g , '&amp;' ) . replace ( /</g , '&lt;' ) . replace ( />/g , '&gt;' ) . replace ( /"/g , '&quot;' ) ; } ; export const uniqID = ( ) => { return `pt${ Math . random ( ) . toString ( 32 ) . slice ( 2 , 12 ) }-${ Date . now ( ) }` ; } ; export const replaceLineBreaks = ( content ) => { return content . replace ( /(?:\r\n|\r|\n)/g , '<br />' ) ; } ; /**
 * Generate a hash
 */ export const hash = ( str = '' ) => { return str . split ( '' ) . reduce ( ( prevHash , currVal ) => ( prevHash * 31 + currVal . charCodeAt ( 0 ) ) | 0 , 0 ) ; } ;