@leyyo/builder
v3.0.2
Published
Builder for classes and interfaces
Downloads
10
Readme
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
- [x] Language:
TS
- [x] Eslint:
Yes
- [x] Static Code Analysis:
Yes
IntelliJ Code Inspections - [x] DDD - Document Driven:
No
No required - [ ] EDD - Exception Driven:
No
No required - [x] TDD - Test Driven:
No
Commands
npm run clear
// clears "dist" foldernpm run lint
// runs eslint for static code analysisnpm run build
// builds JS files at "dist" foldernpm run test
// runs test files in "test" foldernpm run test:watch
*// runs test with watch optionnpm run test:coverage
*// runs test with coverage
Author
Date
2022-12-10Name
Mustafa YelmerRepo
github.com/leyyonet/builder