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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@padosoft/validator

v1.1.1

Published

Javascript validator.

Downloads

2

Readme

Padosoft Validator

Si tratta di un pacchetto javascript per la validazione dei dati.

Per installarlo:

npm i @padosoft/validator --save

Per utilizzarlo sono possibili i tre approcci commonJS, AMD, o con lo script:

CommonJs

const Validator = require("@padosoft/validator").Validator;
const isEmail = require("@padosoft/validator").isEmail;

AMD

import { Validator, isEmail } from "@padosoft/validator";

Per l'uso da script è consigliabile copiare il file dalla cartella node_modules in una a scelta. Una volta incluso sarà presente un oggetto globale 'padosoftValidator' con il quale richiamare le funzioni.

<script src="dist/padosoft-validator.js"></script>
[...]
<script>
    var validator = new padosoftValidator.Validator({
      rules: {
        recipient: {
          required: false,
          rule: (value) => {
            return padosoftValidator.isEmail(value);
          },
        },
      },
      messages: {
        recipient: "L'email non è valida.",
      },
    });
    validator.validate({
        recipient: "[email protected]",
      });
    if(!validator.hasValidData()){
        const errors = validator.getErrorsMessage();
        console.log("Errori", errors);
    }
</script>

Validator

Il Validator è la classe con la quale si possono effettuare le validazioni. Per istanziarla si deve passare, come parametro, un oggetto con le regole e i messaggi d'errore.


/*
 Questo è l'oggetto con le regole ed i messaggi d'errore. Le regole devono essere passate come oggetti con la proprietà required, che può avere valori true o false, e una funzione che verificherà la validità del dato. Come helpers ci sono delle funzioni che possono semplificare la validazione.
 Sia negli oggetti rulesm che nei messages, sono presenti proprietà che rappresentano il valore da vertificare. Il nome di quella proprietà è usato come riferimento ovunque: sia quando si passano i dati che quando si recuperano gli errori.
*/
const rules = {
  rules: {
    numero: {
      required: true,
      rule: (value) => {
        return isNumber(value);
      },
    },
    recipient: {
      required: false,
      rule: (value) => {
        return isEmail(value);
      },
    },
  },
  messages: {
    numero: "È obbligatorio e deve essere un numero.",
    recipient: "L'email non è valida.",
  },
};
// Istanziazione dell'oggetto
const validator = new Validator(rules);
// Passo i dati da validare alla funzione validate()
validator.validate({
    numero: 5,
    recipient: "[email protected]",
  });
// Verifico se i dati sono validi e se non lo sono recupero gli errori.
if(!validator.hasValidData()){
    const errors = validator.getErrorsMessage();
    console.log("Errori", errors);
}

Funzioni

isNumber(value)

Verifica che il valore sia di tipo numerico.

isInteger(value)

Verifica che il valore sia di tipo intero.

isEmail(value)

Verifica che il valore sia un'email.

isFunction(value)

Verifica che il valore sia una funzione.

isBoolean(value)

Verifica che il valore sia un booleano.

isObject(value)

Verifica che il valore sia un oggetto.

isDate(value)

Verifica che il valore sia una oggetto di tipo Date.

isDefined(value)

Verifica che il valore sia definito, cioè non 'undefined'.

isString(value)

Verifica che il valore sia di tipo stringa.

isArray(value)

Verifica che il valore sia un array.