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

@neilscienceguy1/cosmo.js

v1.0.1

Published

A Schema validation library

Readme

Cosmo.js

Cosmo.js is a schema validation library that validates your data based on parameters set by you. It supports a variety of data types, from strings to dates.

Table of Contents

Installation

Install via NPM (Node Package Manager) or Yarn

npm install @neilscienceguy1/cosmo.js

Basic Usage

const { Cosmo, CosmoString } = require('@neilscienceguy1/cosmo.js');

const cosmo = new Cosmo();
const schema = cosmo.newSchema(new CosmoString().required().min(5).max(10));

schema.validate("Hello!!") // Output: Hello!!
schema.validate("Hi") // Output: Error: String must be at least 5 characters long
schema.validate(5) // Output: Error: Value must be a string
schema.validate() // Output: Error: Value is required

Get Started

const { Cosmo, CosmoString } = require('@neilscienceguy1/cosmo.js');

// Create a new Cosmo instance
const cosmo = new Cosmo();

// Create a new schema
const schema = cosmo.newSchema(new CosmoString().required().min(5).max(10)); 
// Mention your data type in schema, with the valid arguments
// Options - String, Number, Boolean, Date, Array, Object, Any

// Validate your data
schema.validate("Hello!!") // Output: Hello!!

Data Types

String

const { Cosmo, CosmoString } = require("@neilscienceguy1/cosmo.js");

const cosmo = new Cosmo();

// Initialize new CosmoString instance
let str = new CosmoString()

str.default("Hello World"); // Specify a default value
str.email() // Validate if the string is an email
str.ensure(true) // Trims the string (Space at the beginning and end)
str.length(5) // Specify the length of the string
str.lowercase(true) // Converts to lowercase
str.uppercase(true) // Converts to uppercase
str.matches() // Specify a regex to match the string
str.max(5) // Specify Maximum number of characters
str.min(5) // Specify Minimum number of characters
str.required(true) // Specify if a value is required
str.url() // Validate if the string is a URL
str.uuid() // Validate if the string is a UUID

const schema = cosmo.newSchema(str)

console.log(
	schema.validate("Hello World") 
    // Outputs validated string after all necessary checks and changes
);

Number

const { Cosmo, CosmoNumber } = require("@neilscienceguy1/cosmo.js");

const cosmo = new Cosmo();

let num = new CosmoNumber()

num.default(7) // Specify a default value
num.absolute(true) // Converts to positive number
num.float(true) // Converts to float
num.greater(5) // Checks if number is greater than specified value
num.integer(true) // Checks if number is integer
num.less(7) // Checks if number is less than specified value
num.max(7) // Specify Maximum value
num.min(5) // Specify Minimum value
num.multipleOf(3) // Checks if number is multiple of specified value
num.natural(true) // Checks if number is natural
num.negative(false) // Checks if number is negative
num.port(false) // Checks if number is a port
num.precision(2) // Trims the number to the specified value of decimal places
num.required(true) // Checks if value is required
num.round(10) // Rounds to the nearest specified value
num.whole(true) // Checks if number is whole

const schema = cosmo.newSchema(num)

console.log(
	schema.validate(6.7678)
    // Outputs validated number after all necessary checks and changes
);

Boolean

const { Cosmo, CosmoBoolean } = require("@neilscienceguy1/cosmo.js");

const cosmo = new Cosmo();

let bool = new CosmoBoolean()

bool.default(true) // Specify a default value

const schema = cosmo.newSchema(bool)

console.log(
	schema.validate(false)
);

Date

const { Cosmo, CosmoDate } = require("@neilscienceguy1/cosmo.js");

const cosmo = new Cosmo();

let date = new CosmoDate()

date.now() // Specifies the default value to be now (if no value is provided)
date.format("locale") // Specify the format of the date
// "string" | "date" | "ISO" | "JSON" | "localeDate" | "locale" | "localeTime"

const schema = cosmo.newSchema(date)

console.log(
	schema.validate()
    // Outputs date in the specified format
);

Array

const { Cosmo, CosmoArray, CosmoString } = require("@neilscienceguy1/cosmo.js");

const cosmo = new Cosmo();

let arr = new CosmoArray()

arr.length(2) // Specifies length of Array
arr.max(5) // Specifies max length of Array
arr.min(1) // Specifies min length of Array
arr.nonEmpty(true) // Specifies if Array can be empty
arr.of(new CosmoString().min(5))
// Specifies the type of elements in Array (Can be left empty or set to CosmoAny)

const schema = cosmo.newSchema(arr)

console.log(
	schema.validate(["Hello", "World"])
    // Outputs validated Array after all necessary checks and changes
);

Object

const { Cosmo, CosmoObject, CosmoString, CosmoNumber, CosmoArray } = require("@neilscienceguy1/cosmo.js");

const cosmo = new Cosmo();

// Put your object schema as an argument
// Specify type of each key in object using Cosmo Data Types
let obj = new CosmoObject({
	name: new CosmoString().required(),
	age: new CosmoNumber().min(18),
	friends: new CosmoArray().of(new CosmoString()).nonEmpty()
})

const schema = cosmo.newSchema(obj)

console.log(
	schema.validate({
        name: "John",
        age: 21,
        friends: ["Jack", "Fred"]
    })
    // Outputs validated Object after all necessary checks and changes
);

Any

const { Cosmo, CosmoAny } = require("@neilscienceguy1/cosmo.js");

const cosmo = new Cosmo();

// Allows for any type of value
let any = new CosmoAny()

const schema = cosmo.newSchema(any)

console.log(
	schema.validate(false)
    // Outputs input value
);

Authors

Support

For support, email me or contact me on Twitter.