import { generateUUID } from "./uuid" ; import { getSharedAppEnv } from "../env/appEnv" ; const ENCODED_STRING_PATTERN = /^utf8\+base64:(|[a-zA-Z0-9+\/=]+)$/ ; export const ENCODED_STRING_PREFIX = "utf8+base64:" ; param b64 returns export function base64ToBytes ( b64 ) { const decode = getSharedAppEnv ( ) . getProperty ( "encoding/v1/base64ToBytes" ) ; return decode ( b64 ) ; } param uint8Arr returns export function bytesToBase64 ( uint8Arr ) { const encode = getSharedAppEnv ( ) . getProperty ( "encoding/v1/bytesToBase64" ) ; return encode ( uint8Arr ) ; } param b64 returns export function decodeBase64String ( b64 ) { const decode = getSharedAppEnv ( ) . getProperty ( "encoding/v1/base64ToText" ) ; return decode ( b64 ) ; } param value returns export function decodeStringValue ( value ) { if ( isEncoded ( value ) !== true ) { throw new Error ( "Cannot decode: provided value is not encoded" ) ; } const newValue = value . substr ( ENCODED_STRING_PREFIX . length ) ; const decode = getSharedAppEnv ( ) . getProperty ( "encoding/v1/base64ToText" ) ; return decode ( newValue ) ; } param text returns export function encodeBase64String ( text ) { const encode = getSharedAppEnv ( ) . getProperty ( "encoding/v1/textToBase64" ) ; return encode ( text ) ; } param value returns export function encodeStringValue ( value ) { const encode = getSharedAppEnv ( ) . getProperty ( "encoding/v1/textToBase64" ) ; return `${ ENCODED_STRING_PREFIX }${ encode ( value ) }` ; } returns export function getUniqueID ( ) { return generateUUID ( ) ; } param text returns export function isEncoded ( text ) { return ENCODED_STRING_PATTERN . test ( text ) ; }