import { createHash , BinaryToTextEncoding } from 'crypto' ; import { primitiveToString } from '@terascope/utils' ; export function bufferEncode ( bufferEncoding ) { return function _bufferEncode ( input ) : string { return Buffer . from ( primitiveToString ( input ) ) . toString ( bufferEncoding ) ; } ; } export function cryptoEncode ( hash , digest ) { return function _cryptoEncode ( input ) : string { return createHash ( hash ) . update ( primitiveToString ( input ) ) . digest ( digest ) ; } ; } export function encodeURL ( input ) { return encodeURIComponent ( primitiveToString ( input ) ) ; } export function encodeAny ( algo , digest ? ) { if ( algo === 'url' ) return encodeURL ; if ( algo === 'base64' || algo === 'hex' ) return bufferEncode ( algo ) ; return cryptoEncode ( algo , digest ?? 'hex' ) ; }