import bcrypt from 'bcrypt' ; import type { Optional } from '../types' ; param { string } password returns { string } export function generateHash ( password ) { return bcrypt . hashSync ( password , 10 ) ; } param { string } password param { string } hash returns { Promise < boolean > } export function validateHash ( password , hash ) { if ( ! password || ! hash ) { return Promise . resolve ( false ) ; } return bcrypt . compare ( password , hash ) ; } export function getVariableName < TResult > ( getVar ) { const m = /\(\)=>(.*)/ . exec ( getVar . toString ( ) . replace ( /(\r\n|\n|\r|\s)/gm , '' ) ) ; if ( ! m ) { throw new Error ( "The function does not contain a statement matching 'return variableName;'" ) ; } const fullMemberName = m [ 1 ] ; const memberParts = fullMemberName . split ( '.' ) ; return memberParts [ memberParts . length - 1 ] ; }