UNPKG

create-cf-planetscale-app

Version:

Create a Cloudflare workers app for building production ready RESTful APIs using Hono

16 lines (14 loc) 484 B
export abstract class BaseModel { abstract private_fields: string[] toJSON() { const properties = Object.getOwnPropertyNames(this) const publicProperties = properties.filter((property) => { return !this.private_fields.includes(property) && property !== 'private_fields' }) const json = publicProperties.reduce((obj: Record<string, unknown>, key: string) => { obj[key] = this[key as keyof typeof this] return obj }, {}) return json } }