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

@fortress-validator/fortress

v1.0.20

Published

A powerful and flexible form validation library, built to validate inputs through method chaining, with support for custom plugins.

Downloads

163

Readme

Fortress Validator

A powerful and flexible form validation library, built to validate inputs through method chaining, with support for custom plugins.

Getting Started

Using with ES Modules

To get started with ES Modules, simply import the module and use it in your code:

import { FormValidator } from '@fortress-validator/fortress';

const validator = new FormValidator();

Using with UMD Modules

Alternatively, if you're using UMD modules, include the script in your HTML file and use it in your code:

<script src="https://unpkg.com/@fortress-validator/fortress/dist/index.umd.js"></script>
<script>
const validator = new window.Fortress.FormValidator();
</script>

Usage

Basic Validation

The defineField method sets up a field for validation, allowing you to chain validation rules like required and others to validate the input.

document.querySelector('input').addEventListener('input', (e) => {
  const result = validator
    .defineField('Input')
    .required()
    .alphaDash()
    .validate(e.target.value);

  console.log(result);
});

Conditional Validation

The when method allows you to conditionally apply validation rules like required and others based on specific conditions.

const result = validator
  .defineField('Input')
  .when({
    alphaDash: false,
  })
  .required()
  .alphaDash()
  .validate('@');

// Result:
// true

Available Rules

| Name | Description | | --- | --- | | accepted | Passes if the field's value is considered accepted (i.e., "y", "yes", "on", "1", "true"). | | after | Passes if the field's value is a date that occurs after the specified date. | | alpha | Passes if the field's value contains only letters. | | alphaDash | Passes if the field's value contains only letters, numbers, dashes and underscores. | | alphaDashDot | Passes if the field's value contains only letters, numbers, dashes, underscores and dots. | | alphaNum | Passes if the field's value contains only letters and numbers. | | array | Passes if the field's value is an array. | | arrayLength | Passes if the field's length matches the specified length. | | arrayLengthBetween | Passes if the field's length is between the specified minimum and maximum lengths. | | arrayLengthGt | Passes if the field's length is greater than the specified length. | | arrayLengthGte | Passes if the field's length is greater than or equal to the specified length. | | arrayLengthLt | Passes if the field's length is less than the specified length. | | arrayLengthLte | Passes if the field's length is less than or equal to the specified length. | | ascii | Passes if the field's value contains only ASCII characters and symbols. | | before | Passes if the field's value is a date that occurs before the specified date. | | between | Passes if the field's value is between the specified minimum and maximum values. | | boolean | Passes if the field's value is a boolean. | | contains | Passes if the field's value contains the specified value. | | containsAll | Passes if the field's value contains all of the specified values. | | containsAny | Passes if the field's value contains at least one of the specified values. | | date | Passes if the field's value matches the specified date format. | | declined | Passes if the field's value is considered declined (i.e., "n", "no", "off", "0", "false"). | | different | Passes if the field's value is different from the specified value in the given field. | | distinct | Passes if the field's value contains only unique items. | | domain | Passes if the field's value is a valid domain. | | email | Passes if the field's value is a valid email address. | | endsWith | Passes if the field's value ends with the specified value. | | equals | Passes if the field's value is equal to the specified value. | | file | Passes if the field's value is a file. | | fileSize | Passes if the field's file size matches the specified file size. | | fileSizeBetween | Passes if the field's file size is between the specified minimum and maximum file sizes. | | fileSizeGt | Passes if the field's file size is greater than the specified file size. | | fileSizeGte | Passes if the field's file size is greater than or equal to the specified file size. | | fileSizeLt | Passes if the field's file size is less than the specified file size. | | fileSizeLte | Passes if the field's file size is less than or equal to the specified file size. | | gt | Passes if the field's value is greater than the specified value. | | gte | Passes if the field's value is greater than or equal to the specified value. | | http | Passes if the field's value starts with the "http://" protocol. | | httpOrHttps | Passes if the field's value starts with the "http://" or "https://" protocols. | | https | Passes if the field's value starts with the "https://" protocol. | | integer | Passes if the field's value is an integer. | | ip | Passes if the field's value is a valid IP address. | | ipv4 | Passes if the field's value is a valid IPv4 address. | | ipv6 | Passes if the field's value is a valid IPv6 address. | | iso8601 | Passes if the field's value is a valid ISO 8601 date. | | json | Passes if the field's value is a valid JSON string. | | jsonSchema | Passes if the field's value matches the specified JSON schema. | | lowercase | Passes if the field's value contains only lowercase characters. | | lt | Passes if the field's value is less than the specified value. | | lte | Passes if the field's value is less than or equal to the specified value. | | notContains | Passes if the field's value does not contain the specified value. | | notContainsAll | Passes if the field's value does not contain all of the specified values together. | | notContainsAny | Passes if the field's value does not contain any of the specified values. | | notEndsWith | Passes if the field's value does not end with the specified value. | | notEquals | Passes if the field's value is not equal to the specified value. | | notOneOf | Passes if the field's value is not one of the specified values. | | notStartsWith | Passes if the field's value does not start with the specified value. | | notStartsWithNumber | Passes if the field's value does not start with a number. | | notSubsetOf | Passes if the field's value is not a subset of the specified values. | | number | Passes if the field's value is a number. | | numeric | Passes if the field's value contains only numeric characters. | | object | Passes if the field's value is an object. | | oneOf | Passes if the field's value is one of the specified values. | | protocol | Passes if the field's value starts with the specified protocol. | | regex | Passes if the field's value matches the specified regular expression. | | required | Passes if the field's value is not empty. | | requiredWhen | Passes if the field's value is not empty when the specified condition is true. | | same | Passes if the field's value is the same as the specified value in the given field. | | size | Passes if the field's value matches the specified size. | | startsWith | Passes if the field's value starts with the specified value. | | startsWithNumber | Passes if the field's value starts with a number. | | string | Passes if the field's value is a string. | | stringContains | Passes if the field's value contains the specified text. | | stringContainsAll | Passes if the field's value contains all of the specified text. | | stringContainsAny | Passes if the field's value contains at least one of the specified text. | | stringLength | Passes if the field's string length matches the specified string length. | | stringLengthBetween | Passes if the field's string length is between the specified minimum and maximum string lengths. | | stringLengthGt | Passes if the field's string length is greater than the specified string length. | | stringLengthGte | Passes if the field's string length is greater than or equal to the specified string length. | | stringLengthLt | Passes if the field's string length is less than the specified string length. | | stringLengthLte | Passes if the field's string length is less than or equal to the specified string length. | | stringNotContains | Passes if the field's value does not contain the specified text. | | stringNotContainsAll | Passes if the field's value does not contain all of the specified text together. | | stringNotContainsAny | Passes if the field's value does not contain any of the specified text. | | subsetOf | Passes if the field's value is a subset of the specified values. | | unique | Passes if the field's value does not exist in the provided values. | | uppercase | Passes if the field's value contains only uppercase characters. | | url | Passes if the field's value is a valid URL. |

Available Methods

| Name | Description | | --- | --- | | collect | Collects the rule functions. | | validate | Validates the field's value. | | apply | Applies the specified rule with the given arguments, useful for applying custom rules. | | when | Determines whether to apply or skip validation based on the provided conditions. |

Available Plugins

Custom Plugin

A custom plugin is composed of rules and locales, allowing you to define custom validation logic and locale-specific messages.

const validator = new FormValidator({
  plugins: [
    {
      rules: {
        multipleOf: (({ factor }: { factor: number }) => (input: unknown) => Number(input) % factor === 0) as Rule<unknown>,
      },
      locales: {
        en: {
          multipleOf: (field, args) => {
            const { factor } = args as { factor: number };
            return `The ${field} field must be a multiple of ${factor}.`;
          },
        },
      },
    },
  ],
});

const result = validator
  .defineField('Input')
  .apply('multipleOf', { factor: 2 })
  .validate(1);

// Result:
// The input field must be a multiple of 2.

Development

To start a local development server, run:

npm run dev

Testing

To run the tests for this package, run:

npm run test

Contributors