1.0.4 • Published 3 years ago
firestore-timestamp-formatter v1.0.4
firestore-timestamp-converter
Firestore WithConverter method to auto convert from default firestore timestamp to javascript date object
Description
While working on a firestore project, I figured I needed to manually convert the firestore timestamp response to actual javascript date object before they become usable, the problem with this is that even if I have an array of data, I need to always loop through and manually convert to javascript date object using the toDate
method. This can be time-consuming.
How To Use
import TimestampConverter from 'firestore-timestamp-formatter';
const response = await db
.collection("user")
.doc(id)
.withConverter(TimestampConverter))
.get();
The `response` will now contain a valid javascript date object instead of the default firestore timestamp.
Installation
Use your favourite package manager to add the package to your package.json
npm i firestore-timestamp-formatter