npm.io
1.0.4 • Published 5 years ago

firestore-timestamp-formatter

Licence
ISC
Version
1.0.4
Deps
0
Size
2 kB
Vulns
0
Weekly
0
Stars
1

firestore-timestamp-converter

NPM version

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

Keywords