import { PathItem } from '../types' ; param path returns export const documentPath = ( path ) : string => { if ( ! Array . isArray ( path ) ) { throw Error ( 'Not a valid path' ) ; } const pathArray = path . map ( ( item , index ) => { if ( path . length === index + 1 && item . type === 'document' ) { return item . key + '.json' ; } else { return item . key ; } } ) ; return pathArray . join ( '/' ) ; } ; export const documentPathKey = ( path ) : string => { const lastItem = path [ path . length - 1 ] ; if ( lastItem . type === 'document' ) { return lastItem . key ; } else { throw Error ( 'last Item in path is not a document' ) ; } } ; export const checkValidObject = ( obj ) => { if ( typeof obj === 'object' && obj instanceof Object && ! ( obj instanceof Array ) ) { return true ; } else { throw Error ( 'Not a valid object' ) ; } } ; const reservedKeyWords = { _meta : true , collection : true , doc : true , indices : true } ; param keyword returns export function isReservedKey ( keyword ) { return reservedKeyWords [ keyword ] ; } returns export function uuid ( ) { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' . replace ( /[xy]/g , ( c ) => { const r = ( Math . random ( ) * 16 ) | 0 ; const v = c === 'x' ? r : ( r & 0x3 ) | 0x8 ; return v . toString ( 16 ) ; } ) ; }