import { protobuf } from "./protos" ; param micros description example export function fromMicros ( micros ) { return micros / 1000000 ; } param value description example export function toMicros ( value ) { return value * 1000000 ; } param query description example export function normaliseQuery ( query ) { return `${ query . replace ( /\s{2,}/g , " " ) }` ; } param str description example export function capitaliseFirstLetter < T extends string > ( str ) { return ( str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ) as Capitalize < T > ; } param str description example export function toCamelCase ( str ) { return str . replace ( /\s+/g , "_" ) . replace ( /(_)([A-Za-z])/g , ( pattern ) => pattern [ 1 ] . toUpperCase ( ) ) . replace ( /^([A-Z])/g , ( pattern ) => pattern . toLowerCase ( ) ) ; } param str description example export function toSnakeCase ( str ) { return str . replace ( /\s+/g , "_" ) . replace ( /(?<!(^|_))([A-Z])/g , ( pattern ) => "_" + pattern ) . toLowerCase ( ) ; } export function recursiveFieldMaskSearch ( data ) { const paths = [ ] ; for ( const key of Object . keys ( data ) ) { if ( key === "resourceName" ) { continue ; } const fieldKey = toSnakeCase ( key ) ; const value = data [ key ] ; if ( typeof value === "object" && ! Array . isArray ( value ) ) { const children = recursiveFieldMaskSearch ( value ) ; for ( const child of children ) { paths . push ( `${ fieldKey }.${ child }` ) ; } continue ; } paths . push ( fieldKey ) ; } return paths ; } export function getFieldMask ( data ) { const paths = recursiveFieldMaskSearch ( data ) ; return new protobuf . FieldMask ( { paths , } ) ; } export function createNextChunkArrivedPromise ( ) { let resolvePromise = ( ) : void => { return ; } ; let rejectPromise = ( error ) : void => { throw error ; } ; const newPromise = new Promise ( ( resolve , reject ) => { resolvePromise = resolve ; rejectPromise = reject ; } ) ; return { newPromise , resolve : resolvePromise , reject : rejectPromise } ; }