import { hash } from 'bcrypt' ; import * as cheerio from 'cheerio' ; import _ from 'lodash' ; import { BCRYPT_ROUNDS } from 'common/enums' ; import { environment } from 'common/environment' ; export * from './makeContext' ; export * from './getFileName' ; export * from './getLanguage' ; export * from './getViewer' ; export * from './globalId' ; export * from './connections' ; export * from './validator' ; export * from './notice' ; export * from './getViewer' ; export * from './cookie' ; export * from './removeEmpty' ; export * from './xss' ; export * from './content' ; export * from './scope' ; export * from './payment' ; export * from './text' ; export * from './time' ; /**
 * Make a valid user name based on a given email address. It removes all special characters including _.
 * Also, leave 3 charateres for appending postfix when it's a duplicated user name.
 */ export const makeUserName = ( email ) : string => { const matched = email . split ( '@' ) [ 0 ] . match ( /[a-zA-Z0-9_]*/g ) ; if ( ! matched ) { return '' ; } return matched . join ( '' ) . substring ( 0 , 12 ) ; } ; export const extractAssetDataFromHtml = ( html , type ? ) => { const $ = cheerio . load ( html || '' , { decodeEntities : false } ) ; let selector = '[data-asset-id]' ; if ( type === 'image' ) { selector = 'figure.image [data-asset-id]' ; } else if ( type === 'audio' ) { selector = 'figure.audio [data-asset-id]' ; } return $ ( selector ) . map ( ( index , element ) => { const uuid = $ ( element ) . attr ( 'data-asset-id' ) ; if ( uuid ) { return uuid ; } } ) . get ( ) ; } ; export const generatePasswordhash = ( password ) => hash ( password , BCRYPT_ROUNDS ) ; /**
 * Generate redirect link for registeration
 */ export const generateRegisterRedirectUrl = ( { email , displayName , } ) => `${ environment . siteDomain }/signup?email=${ encodeURIComponent ( email ) }&displayName=${ encodeURIComponent ( displayName ) }` ; export const getFileName = ( disposition , url ) => { if ( disposition ) { const match = disposition . match ( /filename="(.*)"/ ) || [ ] ; if ( match . length >= 2 ) { return decodeURI ( match [ 1 ] ) ; } } if ( url ) { const fragment = url . split ( '/' ) . pop ( ) ; if ( fragment ) { return fragment . split ( '?' ) [ 0 ] ; } } } ;