import { DatabaseReference , FirebaseOperation , FirebaseOperationCases , PathReference } from './interfaces' ; import firebase from 'firebase/compat/app' ; export function isString ( value ) { return typeof value === 'string' ; } export function isFirebaseDataSnapshot ( value ) { return typeof value . exportVal === 'function' ; } export function isNil ( obj ) { return obj === undefined || obj === null ; } export function isFirebaseRef ( value ) { return typeof value . set === 'function' ; } param database param pathRef export function getRef ( database , pathRef ) { return isFirebaseRef ( pathRef ) ? pathRef as DatabaseReference : database . ref ( pathRef as string ) ; } export function checkOperationCases ( item , cases ) { if ( isString ( item ) ) { return cases . stringCase ( ) ; } else if ( isFirebaseRef ( item ) ) { return cases . firebaseCase ( ) ; } else if ( isFirebaseDataSnapshot ( item ) ) { return cases . snapshotCase ( ) ; } throw new Error ( `Expects a string, snapshot, or reference. Got: ${ typeof item }` ) ; }