Options
All
  • Public
  • Public/Protected
  • All
Menu

@distinction-dev/firebase-utils

Index

Functions

  • forFirestore(json: Record<string, any>, skipTimeOffset?: boolean): Record<string, any>
  • Prepare data before saving into firestore, does 3 important things

    • Converts undefined to null since undefined isn't allowed
    • Converts Date object to Timestamp
    • calls toJSON if available on the obj
    • supports multi level objects

    Parameters

    • json: Record<string, any>

      Data to save in firebase

    • skipTimeOffset: boolean = true

      Flag to prevent offsetting Date with timezone

    Returns Record<string, any>

    obj that can be safely saved in firestore

  • fromFirestore<T>(d: any, identifier?: keyof T, skipTimeOffset?: boolean): T
  • Parse Firestore Document into a TS interface passed as a generic

    • Converts Timestamp to Date():- Also applies timezone offset to the time
    • Can handle multi level objects
    • Also capable of parsing Arrays

    Type parameters

    • T: BaseObject

    Parameters

    • d: any

      Document from Firebase or any other obj that needs to be parsed

    • Optional identifier: keyof T

      field in interface to attach document id to

    • skipTimeOffset: boolean = true

      Flag used to disable timezone offsetting

    Returns T

    an object implementing the Generic that was passed

Generated using TypeDoc