esgarraet
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Esgarraet

Minimal Primitive utility class (483 bytes).

Install

npm i esgarraet

Use

import { Primitive } from "esgarraet";

class CheckoutAmount extends Primitive<number> {
   constructor(readonly initial_value: number) {
      super(initial_value);
   }

   public charge_taxes_from_percent(tax: number): CheckoutAmount {
      this.update(prev => prev + (prev * tax) / 100);

      return this;
   }

   public apply_discount_from_value(quantity: number): CheckoutAmount {
      this.update(prev => prev - quantity);

      return this;
   }

   public emit(): number {
      let value = this.currentValue();
      this.destroy();

      return value;
   }
}

let amount = new CheckoutAmount(1_000);

let amount_value = amount.charge_taxes_from_percent(21).apply_discount_from_value(100).emit();

console.log(amount_value);

License

Esgarraet is distributed under the MIT license

Readme

Keywords

none

Package Sidebar

Install

npm i esgarraet

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

6.02 kB

Total Files

7

Last publish

Collaborators

  • c_enguidanos