0.1.0 • Published 6 months ago

@stanfordspezi/spezi-firebase-utils v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Spezi Firebase Utils

Build and Test codecov

A collection of utility functions for Firebase projects, extracted from the Stanford ENGAGE-HF project. This package provides core utilities used by other Spezi Firebase packages.

Installation

npm install @stanfordspezi/spezi-firebase-utils

Features

  • Schema Converters: Type-safe data conversion with Zod
  • Localization: Easily handle multi-language text with fallbacks
  • Array Helpers: Functions for working with arrays (average, median, percentile, etc.)
  • Date Utilities: Simple date manipulation functions
  • Lazy Loading: Generic lazy initialization pattern

Usage Examples

Schema Converter

import { SchemaConverter } from '@stanfordspezi/spezi-firebase-utils'
import { z } from 'zod'

const userSchema = z.object({
  name: z.string(),
  email: z.string().email(),
  age: z.number().optional(),
})

const userConverter = new SchemaConverter({
  schema: userSchema,
  encode: (user) => ({
    name: user.name,
    email: user.email,
    age: user.age,
  }),
})

Localized Text

import { LocalizedText } from '@stanfordspezi/spezi-firebase-utils'

const greeting = new LocalizedText({
  en: 'Hello',
  es: 'Hola',
  fr: 'Bonjour',
})

console.log(greeting.localize('fr')) // 'Bonjour'
console.log(greeting.localize('de', 'en')) // 'Hello' (fallback)

License

This project is licensed under the MIT License. See Licenses for more information.

Contributors

This project is developed as part of the Stanford Byers Center for Biodesign at Stanford University. See CONTRIBUTORS.md for a full list of all Spezi Firebase contributors.

Stanford Byers Center for Biodesign Logo Stanford Byers Center for Biodesign Logo