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

@fireflysemantics/validator

v4.0.24

Published

[![Build Status](https://travis-ci.org/fireflysemantics/validator.svg?branch=master)](https://travis-ci.org/fireflysemantics/validator)

Readme

Build Status

Validator

@fireflysemantics/validator

Introduction

Typescript Validation Decorators and Executor. Click API for the Validation API Typedoc.

If you like the @fireflysemantics/validator API please star our Github Repository.

Tutorials

Example

/**
 * Validate Todo Entities Example
 */
export class Todo {
  gid?: string;
  id?: string;

  @IsString()
  @IsDefined()
  public title!: string;

  @IsBoolean()
  @IsDefined()
  public completed!: boolean;

  constructor(todo?: any) {
    if (todo) {
      Object.assign(this, todo);
    }
  }
}

const todo = new Todo({ completed: 'yup' });
const todoEntities = [todo];
const errors: EntityError[] = validateEntities(todoEntities, 'gid');

Playground

https://stackblitz.com/edit/typescript-me2ddn

Install

npm i -S @fireflysemantics/validator @fireflysemantics/validatorts tslib

Typedoc

Typedoc Documentation

Use

The Typedoc for each decorator contains usage examples.

Use the Stackblitz Starter Demo for experimentation.

See the Tutorials and Typedoc for more detailed use API and use case examples.

import { ok } from 'assert';

import {
  validateProperty,
  IsNumber,
  IsGreaterThan,
  IfValid,
  validate,
  ObjectErrors,
  ValidationError,
} from '@fireflysemantics/validator';

class GreaterThanCheck {
  @IsNumber()
  firstNumber: any = null;

  @IsGreaterThan('firstNumber')
  @IsNumber()
  @IfValid('firstNumber')
  secondNumber: number = 22;
}

const GTC = new GreaterThanCheck();
const validFirstNumber: boolean = validateProperty(GTC, 'firstNumber');
ok(!validFirstNumber, 'The firstNumber property is not valid');
const OES: ObjectErrors = validate(GTC);
const errors: ValidationError[] = OES.errors;
ok(errors.length == 2, 'There should be 2 ValidationErrors created');

In this case the validation of secondNumber depends on the first number.

We minimize validation noise by triggering validation of secondNumber only if the firstNumber is valid (@IfValid('firstNumber')).

Features

  • Progressive validation (Only check if the date is valid if the property is non null)
  • Cross property validation (Does the start date come before the end date?)
  • Cross Property Conditional Validation with @IfValid stops cross property validation a dependent property is invalid.
  • Access to the entire ValidationContext enabling the customization of validation messages post validation
  • Executes the decorators is a predictable ordered sequence

The following decorators:

  • IfValid
  • IsAfterInstant
  • IsAlpha
  • IsAlphaNumeric
  • IsArray
  • IsArrayContainerOf
  • IsArrayIn
  • IsArrayNotEmpty
  • IsArrayNotIn
  • IsArraySizeGreaterThan
  • IsArraySizeLessThan
  • IsArrayUnique
  • IsAscii
  • IsBase64
  • IsBeforeInstant
  • IsBoolean
  • IsBooleanString
  • IsByteLength
  • IsCreditCard
  • IsCurrency
  • IsDate
  • IsDefined
  • IsDivisibleBy
  • IsEmail
  • IsEmpty
  • IsEnum
  • IsEqualTo
  • IsFQDN
  • IsFullWidth
  • IsGreaterThan
  • IsHalfWidth
  • IsHexColor
  • IsHexadecimal
  • IsIP
  • IsISBN
  • IsISIN
  • IsISODateString
  • IsInRange
  • IsInstanceOf
  • IsInt
  • IsJSON
  • IsLengthGreaterThan
  • IsLengthLessThan
  • IsLessThan
  • IsLowercase
  • IsMilitaryTime
  • IsMobilePhone
  • IsMongoID
  • IsMultibyte
  • IsNegative
  • IsNotEmpty
  • IsNotEqualTo
  • IsNotSubString
  • IsNotSuperString
  • IsNumber
  • IsNumberString
  • IsPatternMatch
  • IsPositive
  • IsSameInstant
  • IsString
  • IsSubString
  • IsSuperString
  • IsSurrogatePair
  • IsURL
  • IsUUID
  • IsUpperCase
  • IsValueIn
  • IsValueNotIn
  • IsVariableWidth

Pure Validation API

For the API used to implement the decorators or for pure functions that validate see @fireflysemantics/validatorts.

Runtime

This assumes a minimum ES2017 runtime environment. Use core.js if you think the code will run in non compliant runtimes. We use Object.values, which has an ES2017 a minimum runtime.

Build

Run npm run c to build the project. The build artifacts will be stored in the dist/ directory.

Publishing

After building your library with npm run p

Running unit tests

Run npm t to execute the unit tests via Jest.

Supported Package Formats

The library is built with the Angular Package Format. It therefore supports all these package formats (As can be seen in the provided package.json) and has integrated typescript definitions:

  • "main": "bundles/fireflysemantics-validatorts.umd.js",
  • "module": "fesm5/fireflysemantics-validatorts.js",
  • "es2015": "fesm2015/fireflysemantics-validatorts.js",
  • "esm5": "esm5/fireflysemantics-validatorts.js",
  • "esm2015": "esm2015/fireflysemantics-validatorts.js",
  • "fesm5": "fesm5/fireflysemantics-validatorts.js",
  • "fesm2015": "fesm2015/fireflysemantics-validatorts.js",
  • "typings": "fireflysemantics-validatorts.d.ts"