vuilder
v0.0.0
Published
build type-safe builders
Downloads
4
Readme
🚀 Installation
yarn add vuilder
# or
npm install vuilder
🍿 Examples
type
pattern
import { createBuilder } from 'vuilder'
type Person = {
name: string
age: number
usingTwitter?: boolean
}
const builder = createBuilder<Person>()
const person = builder
.name('hoge')
.age(32)
.usingTwitter()
.build()
console.log(person)
class
pattern
import { createBuilder } from 'vuilder'
class Person {
constructor(
public name: string,
public age: number,
public usingTwitter: boolean
) {}
}
const builder = createBuilder<{
name: string
age: number
usingTwitter?: boolean
}, Person>((d) => new Person(d.name, d.age, d.usingTwitter ?? false))
const person = builder
.name('hoge')
.age(32)
.usingTwitter()
.build()
console.log(person)