npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

flunt-notifications

v1.4.8

Published

Flunt is a fluent approach to using the Notification pattern with your TypeScript entities, centralizing all the changes you've made and making them easy to access when needed.

Downloads

5

Readme

Flunt

Flunt is a fluent approach to using the Notification pattern with your TypeScript entities, centralizing all the changes you've made and making them easy to access when needed. It is built on top of the https://github.com/andrebaltieri/Flunt repository and supports generic features. With Flunt, you can easily handle validation notifications, aggregating all relevant information in one place for more efficient handling of your data.

Models

When I install some library, I have difficulties in understanding the models/entities. So it was with that in mind that I decided to create this section especially to detail Flunt's main classes.

How to install

It's very simple, you just need to install the library with NPM

npm i flunt-validations

Examples

Validating a User with the Default Notification

import { Notification, Notifiable, Contract } from "flunt-validations";

class User extends Notifiable { // Class inheriting from "Notifiable"

  constructor(
      public name: string,
      public email: string,
      public password: string
  ) {
    super();

    // Creating the contract to configure the validation schemes.
    let contract = new Contract()

    // Validation scheme -> The "name" field must be more than 3 characters
    contract.minLength(name, 3, new Notification("name", "Name must have more than 3 chars"));
    // Validation scheme -> The "email" field must have the pattern of an email
    contract.isEmail(email, new Notification("email", "E-mail must be valid."));
    // Validation scheme -> The "password" field must be more than 8 characters
    contract.minLength(password, 8, new Notification("password", "Password must have more than 8 chars"));

    // Finally, sending all fields from the constructor to the Notifiable class,
    // which will apply the validation schemes.
    super.AddNotifications(contract)
  }
}



const user = new User("o", "gmail", "123") // creating an invalid user.
console.log(user.allFieldsValid()) // false
console.log(user.getNotifications()) // there will be an array with three notification,
                                     // because the three fields are invalid

const errors = user.getNotifications();
console.log(errors[0].property) // name
console.log(errors[1].property) // email
console.log(errors[2].message) // Password must have more than 8 chars


const user2 = new User("Matheus", "[email protected]", "12345678") // creating a valid user.
console.log(user2.allFieldsValid()) // true
console.log(user2.getNotifications()) // [] -> nothing, because all fields are valid.
import { Notification, Notifiable, Contract } from "flunt-validations";

class CustomNotification extends Notification {
  constructor(
      public customField: string // custom field
  ) {
    super();
  }

}

class User extends Notifiable<CustomNotification> { // Class inheriting from "Notifiable"

  constructor(
    public name: string,
    public email: string,
    public password: string
  ) {
    super();

    // Creating the contract to configure the validation schemes.
    let contract = new Contract<CustomNotification>()

    // Validation scheme -> The "name" field must be more than 3 characters
    contract.minLength(name, 3, new CustomNotification("name", "Name must have more than 3 chars", "notificationnnn"));
    // Validation scheme -> The "email" field must have the pattern of an email
    contract.isEmail(email, new CustomNotification("email", "E-mail must be valid.", "notificationnnn"));
    // Validation scheme -> The "password" field must be more than 8 characters
    contract.minLength(password, 8, new CustomNotification("password", "Password must have more than 8 chars", "notificationnnn"));

    // Finally, sending all fields from the constructor to the Notifiable class,
    // which will apply the validation schemes.
    super.AddNotifications(contract)
  }
}


const user = new User("o", "gmail", "123") // creating an invalid user.
console.log(user.allFieldsValid()) // false
console.log(user.getNotifications()) // there will be an array with three notification,
// because the three fields are invalid

const errors = user.getNotifications();
console.log(errors[0].property) // name
console.log(errors[1].customField) // notificationnnn
console.log(errors[2].message) // Password must have more than 8 chars


const user2 = new User("Matheus", "[email protected]", "12345678") // creating a valid user.
console.log(user2.allFieldsValid()) // true
console.log(user2.getNotifications()) // [] -> nothing, because all fields are valid.

Authors

Matheus Barichello Piccoli - https://github.com/ofmxtheuuz

License

This project is licensed under the MIT License.