Socket
Book a DemoInstallSign in
Socket

@jeppech/generic-builder-ts

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jeppech/generic-builder-ts

Generic builder for TypeScript

1.1.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Generic builder for TypeScript

This is small helper class for making buildable objects.

Usage

import { Builder } from '@jeppech/generic-builder-ts'

// Start by declaring an interface, describing your object

interface Person {
  name: string
  age: number
  dob?: Date
}

// Next create a class, with the same name of the interface. This is also known as Declaration Merging.

class Person {
  constructer(builder: Builder<Person> & Person) {
    Object.assign(this, builder)
  }
}

// Notice, that you get hints when calling the `with` method.

const person = new Builder(Person)
  .with('name', 'John')
  .with('age', 25)
  .with('dob', new Date('2005-10-13'))
  .build()

Acknowledgment

This was inspired by https://github.com/hanterlantant/ts-generic-builder

Keywords

typescript

FAQs

Package last updated on 22 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.