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 🙏

© 2025 – Pkg Stats / Ryan Hefner

skymma

v1.0.4

Published

Simple client side form validation

Downloads

3

Readme

skymma

Simple client side object validation in javascript.

Install

Install skymma by running npm install --save skymma.

List of validation errors

By default skymma will create a list of validation errors. The list contains objects with the fields:

  • field [ String ] = name of the field being validated
  • name [ String ] = name of the validator
  • valid [ Boolean ] = true if valid, false otherwise
  • message [ String ] = an optionally specified message when manually setting the validity of a validator

Error object like in angular

Displaying errors when validating forms is conveniently handled in angular by specifying all error messages directly in the view. Skymma can create an error object similar to what you have in angular, but will make it possible to use with other single page app view libraries like react, ractive, vue, rivets etc. Just include the error object in the view and show different messages depending on which validation that failed.

To convert the validation list to an error object, just call the method asObject on the list.

Validate a form object

First we specify a rules method on the form object

const user = {
  username: '',
  email: '',
  rules: function(check) {
    check('username').required();
    check('email').email();
  }
};

Then import skymma and validate the object

import validate from 'skymma';
 
// as a list of errors
const errors = validate(user);
 
// or as an object
const errorsObj = errors.asObject();

the errorsObj object is then included in the view to manage errors shown in the client.

Separate rules function

At times it might be appropriate to specify the rules function outside of the model object. In those cases it is possible to supply the function at validation

const rules = function(check) {
  check('username').required();
  check('email').email();
};
 
const user = {
  username: '',
  email: ''
};
 
const errors = validate(user, rules).asObject();

Properties on the error object.

The errors object contains $valid and $invalid properties that says if the object has any errors or not.

For every field validated, a property with that name is added to errors, with an object where properties corresponds to the validators and with a value of true if the validation failed and false otherwise. The object also contains the properties $valid and $invalid, which is specific for that field.

expect(errors.$valid).toBe(false);
expect(errors.$invalid).toBe(true);
expect(errors.username.required).toBe(true);
expect(errors.username.$valid).toBe(false);
expect(errors.email.email).toBe(false);
expect(errors.email.$valid).toBe(true);

Changing the user input and validating again we get

user.username = 'Muppen';
user.email = '[email protected]';
 
const errors = validate(user);
 
expect(errors.$valid).toBe(true);
expect(errors.$invalid).toBe(false);
expect(errors.username.required).toBe(false);
expect(errors.email.email).toBe(false);

Included validators

By default the different validators available are

required

Check that a field is set to any value.

email

Check that the field is an email.

minLength

Check for a minimum length of a field.

maxLength

Check for a maximum length of a field.

min

Check for a minimum value of a numeric field.

max

Check for a maximum value of a numeric field.

Custom validators

A new validator is easily added

import {addValidator} from 'skymma';
 
const user = {
  username: '',
  rules: function(check) {
    check('username').mustBeBulle('a bulle');
  }
};
 
addValidator('mustBeBulle', function(bulle) {
  return this.value == bulle;
});
 
let errors = validate(user).asObject();
expect(errors.username.mustBeBulle).toBe(true);
 
user.username = 'a bulle';
errors = validate(user).asObject();
expect(errors.username.mustBeBulle).toBe(false);

Manually set validity on fields

In the rules method, manual validation can be performed. For instance to check that a "confirm password" field has the same value as the password.

const obj = {
    password: '',
    passwordConfirm: '',
    rules: function(check) {
        check('passwordConfirm').setValid('confirm', this.passwordConfirm == this.password);
    }
};
 
obj.password = "jubel och bullar";
let errors = validate(obj).asObject();
expect(errors.passwordConfirm.confirm).toBe(true);
 
obj.passwordConfirm = "jubel och bullar";
errors = validate(obj).asObject();
expect(errors.passwordConfirm.confirm).toBe(false);

The setValid method takes two arguments, the name of the validator and whether the field is valid or not. It can also take an optional third argument with a custom error message, retrievable from the object $messages.