builder-pattern-es6

Create a builder pattern from ES6 classes

Usage no npm install needed!

<script type="module">
  import builderPatternEs6 from 'https://cdn.skypack.dev/builder-pattern-es6';
</script>

README

builder-pattern-es6

Create a builder pattern for ES6 classes.

Installation

npm i builder-pattern-es6
yarn add builder-pattern-es6

Usage

const builderES6 = require("builder-pattern-es6");

class Pizza {
  get name() {
    return this._name;
  }

  set name(value) {
    this._name = value;
  }

  get meatQuantity() {
    return this._meatQuantity;
  }

  set meatQuantity(value) {
    this._meatQuantity = value;
  }

  get withOregano() {
    return this._withOregano;
  }

  set withOregano(value) {
    this._withOregano = value;
  }
}

builderES6(Pizza);

const pizza = Pizza.Builder()
  .name("Capricciosa")
  .meatQuantity(100)
  .withOregano(true)
  .build();
console.log(pizza);
// Pizza { _name: 'Capricciosa', _meatQuantity: 100, _withOregano: true }

License

This project is licensed under the MIT License - see the LICENSE file for details