3.0.2 • Published 2 years ago

@leyyo/builder v3.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Builder

Builder component for JavaScript/TypeScript

  • It generates virtual setter methods with returning existing object to use continuously
  • It takes care of types of properties

Install

npm i @leyyo/builder

Sample - Object

import {Builder} from "@leyyo/builder";

interface Person {
    name: string;
    age: number;
    married: boolean;
}

const person = Builder.build<Person>();
person
    .age(32)
    .name('foo bar')
    .married(true);
console.log(person);
// {age: 32, name: 'foo bar', married: true}

person.age('aaa'); // compile error
person.name(55); // compile error
person.married('yes'); // compile error

Sample - Class

type CarColor = 'white'|'black'|'red'|'blue'|'green'|'yellow';
class Car {
    brand: string;
    year: number;
    color: CarColor;
}

const car = Builder.build<Car>(Car);
car.brand('Toyota').year(2023).color('red');
console.log(car);
// {brand: 'Toyota', year: 2023, color: 'red'}

console.log(car.$return()); // it is casted to Car class
// Car {brand: 'Toyota', year: 2023, color: 'red'}

Standards

  • Language: TS
  • Eslint: Yes
  • Static Code Analysis: Yes IntelliJ Code Inspections
  • DDD - Document Driven: No No required
  • EDD - Exception Driven: No No required
  • TDD - Test Driven: No

Commands

  • npm run clear // clears "dist" folder
  • npm run lint // runs eslint for static code analysis
  • npm run build // builds JS files at "dist" folder
  • npm run test // runs test files in "test" folder
  • npm run test:watch *// runs test with watch option
  • npm run test:coverage *// runs test with coverage

Author

3.0.2

2 years ago

3.0.0

3 years ago