1.0.3 • Published 2 years ago

@crowrvo/plume v1.0.3

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

FluntTS (Plume)

License: MIT

What is Flunt?

Inspired in Flunt, Every app has business rules and validations, and you probably will need to keep all the errors and notifications that happened and send it to somewhere, maybe to your UI.

Flunt implements the Notification Pattern and helps you to track everything that happend, consolidating your notifications and making it easy to access and manipulate.

Installation

$ npm install @crowrvo/plume --save

How to use

ES6

import { Notifiable, Contract } from "@crowrvo/plume";

// extends your class to Notifiable
class Customer extends Notifiable {
  constructor(name, lastname, age) {
    super();
    this.name = name;
    this.lastname = lastname;
    this.age = age;

    this.AddNotification(
      new Contract()
        .Equal(name.length > 0, true, "Name", "name is required")
        .Equal(lastname.length > 0, true, "Lastname", "Lastname is required")
        .Equal(age > 18, true, "Age", "You need more than 18 years")
    );
  }
}

// instance class
var customer = new Customer(null, "Goncalves", 10);

// take your messages

console.log(customer.GetMessages);

//take all notifications
console.log(customer.GetNotifications);

ES5

// i will improve imports soon
const { Notifiable, Contract } = require("@crowrvo/plume");

class Customer extends Notifiable {
  constructor(name, lastname, age) {
    super();
    this.name = name;
    this.lastname = lastname;
    this.age = age;

    this.AddNotification(
      new Contract()
        .Equal(name.length > 0, true, "Name", "name is required")
        .Equal(lastname.length > 0, true, "Lastname", "Lastname is required")
        .Equal(age > 18, true, "Age", "You need more than 18 years")
    );
  }

  // You can also add notifications in methods or gets/sets
  public newAge(newAge: number) {
        this.AddNotification(
            new Contract()
            .Equal(age > 18, true, "Age", "You need more than 18 years")
            .Equal(age < 200, true "Age", "You need to inform a valid age")
        );
        this.age = newAge;
    }
}

// To use class
module.exports = Customer;

// instance class
var customer = new Customer(null, "Goncalves", 10);

// take your messages

console.log(customer.GetMessages);

//take all notifications
console.log(customer.GetNotifications);

Methods

Follow the methods that the library provides.

Contract

Validations methods.

--

Example

Equal(value, comparer, property, message);
StrictEqual(value, comparer, property, message);
NotEqual(value, comparer, property, message);
StrictNotEqual(value, comparer, property, message);

//To get messages and notifications
GetNotifications();
GetMessages();

// To know if is valid
isValid();

Notifiable

Class turn another class notifiable and works with flunt.

--

Example

AddNotification(property, message);
AddNotification(Notification);
AddNotification(Notification[]);
AddNotification(contract);

// To get messages
GetMessages();

// To know if is valid
isValid();

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

Crowrvo
Crowrvo

See also the list of contributors who participated in this project.

License

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

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago