Check Firestore Function Type

Check Firestore Function Type

2 min read

Sometimes you want to check what kind of onWrite() function you are dealing with in Firestore: ```typescript functions.firestore .document('posts/{docId}') .onWrite(async (change: any, context: any) => { //... code } ``` So, I created some simple functions to find out. First install the package: ``` npm i adv-firestore-functions ``` Then import the functions you want: ```typescript import { createDoc, updateDoc, deleteDoc } from 'adv-firestore-functions'; ``` or for more complex checks like: writeDoc = createDoc || updateDoc shiftDoc = createDoc || deleteDoc popDoc = updateDoc || deleteDoc ```typescript import { writeDoc, shiftDoc, popDoc } from 'adv-firestore-functions'; ``` And use it like so: ```typescript if (createDoc(change)) { // a document is being created, so do something... } ``` Simple.
cloudfunction
helperfunction