savaye-utils
v1.2.0
Published
Shared types and validation utilities for Savaye projects
Downloads
245
Maintainers
Readme
Savaye Utils
Shared TypeScript types and validation utilities for Savaye projects.
Installation
Local Development
# In your project
yarn add file:../savaye-utilsNPM (once published)
yarn add savaye-utilsUsage
Types
import { ProductData, PriceData, StrapiLifecycleEvent } from 'savaye-utils'
// Or import from specific module
import { ProductData } from 'savaye-utils/types'Validators
import {
validateDate,
validateDateRange,
validatePositiveNumber,
validateNumberRange,
validateInteger,
parseJsonArray,
isEmptyValue,
isDefined,
} from 'savaye-utils'
// Or import from specific module
import { validateDate, validatePositiveNumber } from 'savaye-utils/validators'
// Example usage
validateDate(someDate, 'EventDate')
validatePositiveNumber(price, 'BaseAmount')Available Types
ProductData
Interface for product data including:
- Product types: Product, Event, Resource
- Event-specific fields (dates, location, capacity, etc.)
- Media and email template fields
- Price relationships
PriceData
Interface for pricing data including:
- Payment types: Full, Discounted Full, Deposit Plan, Free
- Currency support (USD, NGN)
- Discount and installment options
- Payment provider integration (Stripe, Paystack)
- Product relationship
StrapiLifecycleEvent
Generic interface for Strapi lifecycle hooks.
Available Validators
validateDate(dateValue, fieldName)- Validates datesvalidateDateRange(startDate, endDate, startFieldName, endFieldName)- Validates date rangesvalidatePositiveNumber(value, fieldName)- Validates positive numbersvalidateNumberRange(value, min, max, fieldName)- Validates number rangesvalidateInteger(value, fieldName)- Validates integersparseJsonArray<T>(value, fieldName)- Parses JSON arrays safelyisEmptyValue(value)- Checks for empty valuesisDefined(value)- Checks if value is defined
Development
# Install dependencies
yarn install
# Build the package
yarn build
# Development mode
yarn devLicense
MIT
