UNPKG

@hangtime/grip-connect

Version:

Griptonite Motherboard, Tindeq Progressor, PitchSix Force Board, WHC-06, Entralpi, Climbro, mySmartBoard: Bluetooth API Force-Sensing strength analysis for climbers

27 lines (22 loc) 729 B
import type { IBase } from "../interfaces/base.interface.js" export abstract class BaseModel { id?: string createdAt?: Date updatedAt?: Date constructor(base: IBase) { this.id = base.id ?? globalThis.crypto?.randomUUID?.() ?? BaseModel.generateUUID() this.createdAt = base.createdAt ?? new Date() this.updatedAt = base.updatedAt ?? new Date() } /** * Generates a UUID using a simple algorithm. * @returns A string representing a UUID. */ private static generateUUID(): string { return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => { const r = Math.floor(Math.random() * 16) const v = c === "x" ? r : (r & 0x3) | 0x8 return v.toString(16) }) } }