UNPKG

firebase-admin-ql

Version:

A powerful library that bridges Firebase Admin SDK with PostgreSQL, simplifies interaction with stored procedures, facilitates seamless third-party API calls using fetch, and provides utility functions to streamline backend operations.

43 lines 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PgFormData = void 0; exports.generateOTP = generateOTP; exports.formatAsMoney = formatAsMoney; function generateOTP(num) { if (num < 4 || !Number.isInteger(num)) { throw new Error("The length of the OTP must be a positive integer greater than or equal to 4."); } const digits = "0123456789"; let OTP = ""; for (let i = 0; i < num; i++) { OTP += digits[Math.floor(Math.random() * 10)]; } return OTP; } class PgFormData { constructor(data, order) { this.data = data; this.order = order; } get values() { return this.order.map((key) => { if (!(key in this.data)) { return null; } const value = this.data[key]; return value !== null && typeof value === "object" ? JSON.stringify(value) : value; }); } } exports.PgFormData = PgFormData; function formatAsMoney(input) { const number = Number(input); if (isNaN(number)) { throw new Error("Invalid input: Please provide a valid number or numeric string."); } return number.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); } //# sourceMappingURL=utility.js.map