UNPKG

firebase-dates-util

Version:

A util package to transform dates string, numbers or Date Objects to firebase Timestamp and viceversa

27 lines (26 loc) 1.35 kB
import { Timestamp } from 'firebase/firestore'; declare type ToTimestamp = Timestamp | null; declare type Target = 'timestamp' | 'number' | 'date' | 'fieldDate'; interface TransformDateOptions { avoidUndefined?: boolean; includeFields?: string[]; avoidFields?: string[]; ignoreDefaultDateTypeField?: boolean; ignoreDefaultTimestampTypeField?: boolean; } declare class Dates { static errorLog(functionName: string, message: string, ...rest: unknown[]): void; static toTimestamp(date: unknown): ToTimestamp; static toDate: (date: unknown) => any; static toMiliseconds(date: any): any; static toFieldDate(date: any): string | null; static format: (date: string | number | Date, stringFormat?: string) => string; static fromNow: (date?: string | number | Date) => string; static transformDateTo(date: string | number | Date | Timestamp, target: Target, options?: TransformDateOptions): any; static formatObjectDates(object: object, target: Target, options?: TransformDateOptions): {}; static isLiteralObject(a: any): boolean; static formatComplexObjectDates(object: object, target: Target, options?: TransformDateOptions): object; static deepFormatObjectDates(object: object, target?: Target, options?: TransformDateOptions): object; static DATE_FIELDS: string[]; } export { Dates };