New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

builder-ts

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

builder-ts

Small package that I use to create fixtures for my tests. Only works with classes for now.

latest
npmnpm
Version
0.2.3
Version published
Maintainers
1
Created
Source

Read Me

Small package that I use to create fixtures for my tests. Only works with classes for now.

Things I want to add whenever I am in the mood:

  • Add support to add methods to the Builder
    • Improve builder type so that custom methods do not get lost, more info below
  • Build from Types/Interfaces
  • Exclude methods that have been invoked already with a Strict Builder (e.g. after setTitle, setTitle is not available anymore)
import { ClassBuilderMixin } from "builder-ts"

export class Post {
  public readonly id: string
  public readonly name: string
  public readonly createdAt: Date

  // Also works with protected constructors
  public constructor(id: string, name: string, createdAt: Date) {
    this.id = id
    this.name = name
    this.createdAt = createdAt
  }

  public upvote() {}
}

class PostBuilder extends ClassBuilderMixin(Post) {
  public withTodaysDate() {
    this.setCreatedAt(Date.Today)
  }
}

const post = new PostBuilder()
  .withTodaysDate()
  .setId("id")
  .setName("myName")
  .build() // { id: "id", name: "myName", createdAt: Date, upvote: Function }

Rules

  • Properties should follow camelCase convention
  • Custom builder methods have to be used before the auto generated "set" methods (because of types)

FAQs

Package last updated on 17 Jun 2022

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