UNPKG

react-native-healthkit-bridge

Version:

A comprehensive React Native bridge for Apple HealthKit with TypeScript support, advanced authorization, and flexible data queries

60 lines (59 loc) 1.57 kB
export class HealthKitIdentifier { constructor(value) { this.value = value; this.validate(); } static create(identifier) { return new HealthKitIdentifier(identifier); } validate() { if (!this.value || this.value.trim().length === 0) { throw new Error('HealthKit identifier cannot be empty'); } if (!this.value.startsWith('HK')) { throw new Error('HealthKit identifier must start with "HK"'); } } toString() { return this.value; } equals(other) { return this.value === other.value; } } export class HealthKitUnit { constructor(value) { this.value = value; this.validate(); } static create(unit) { return new HealthKitUnit(unit); } validate() { if (!this.value || this.value.trim().length === 0) { throw new Error('HealthKit unit cannot be empty'); } } toString() { return this.value; } equals(other) { return this.value === other.value; } } export class DateRange { constructor(startDate, endDate) { this.startDate = startDate; this.endDate = endDate; this.validate(); } validate() { if (this.startDate >= this.endDate) { throw new Error('Start date must be before end date'); } } getDurationInDays() { const diffTime = Math.abs(this.endDate.getTime() - this.startDate.getTime()); return Math.ceil(diffTime / (1000 * 60 * 60 * 24)); } }