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

nox-validation

v1.7.7

Published

validate dynamic schema

Downloads

1,728

Readme

Nox Validation

nox-validation is a powerful and flexible validation library for both client-side and server-side use. It supports nested fields, alias validation, and customizable rules, making it perfect for complex form data validation.

Installation

npm install nox-validation

Library Exports

Validation Functions:

  • validate - The core function for validating data.

Constants:

  • CONSTANTS - A collection of predefined constants (likely including data types, error messages, validation rules, etc.).

Helper Functions (HELPERS):

  • validateSingleField - Validates a single field against defined rules.
  • validateType - Performs type checks for data validation.
  • fieldsMapping - Groups fields by schemaId for structured access.
  • convertTree - Converts a flat structure into a nested tree format.
  • getValueByDynamicKey - Retrieves a value dynamically from an object using a key path.
  • setValueByDynamicKey - Sets a value dynamically in an object using a key path.

Usage

const { validate, helpers } = require("nox-validation");

const all_fields = []; 

const relations = []; 

const schema = [
  {
    _id: "67d2996955b853593b84a0c8",
    schema_id: "67d2993655b853593b84a086",
    field: "email",
    field_type: "Single",
    type: "String",
    path: "email",
    meta: {
      field: "email",
      interface: "input",
      hidden: false,
      sort: null,
      required: true,
      nullable: false,
      validations: {
        rules: [
          {
            rule: "matchesRegExp",
            matchesRegExp: {
              value: "/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$/",
            },
          },
        ],
      },
      readonly: false,
    },
    schema_definition: {
      name: "email",
      type: "String",
      default: null,
      unique: true,
    },
  },
  {
    _id: "67d2995955b853593b84a0bc",
    schema_id: "67d2993655b853593b84a086",
    field: "user_name",
    field_type: "Single",
    type: "String",
    path: "user_name",
    meta: {
      field: "user_name",
      interface: "input",
      hidden: false,
      sort: null,
      required: true,
      nullable: false,
      readonly: false,
    },
    schema_definition: {
      name: "user_name",
      type: "String",
      default: null,
    },
  },
];

When isSeparatedFields is true

const result = validate({
  formData: {
    user_name: "John Doe",
    email: "[email protected]",
  },
  isSeparatedFields: true,
  fields: schema,
  relationalFields: helpers.fieldsMapping(all_fields),
  relations: relations,
  formId: "67d2993655b853593b84a086",
  abortEarly: false,
  byPassKeys: [],
  apiVersion: "v1",
  language: "nl",
  maxLevel: 3,
  onlyFormFields: false,
  language_codes:[]
});

When isSeparatedFields is false

const result = validate({
  formData: {
    user_name: "John Doe",
    email: "[email protected]",
  },
  isSeparatedFields: false,
  fields: all_fields,
  relationalFields: {},
  relations: relations,
  formId: "67d2993655b853593b84a086",
  abortEarly: false,
  byPassKeys: [],
  apiVersion: "v1",
  language: "nl",
  maxLevel: 3,
  onlyFormFields: false, 
  language_codes:[]
});

Output Example:

{
  status: true, 
  error: {},    
  data: {}      
}

Parameters

Schema Parameter Descriptions:

formData (Object)

  • Represents the primary data structure for form submission.
  • Contains key-value pairs corresponding to form fields.

formId (ObjectId)

  • A unique identifier for the form schema.
  • Required when isSeparatedFields is true, indicating that only form-specific fields are provided.

isSeparatedFields (Boolean)

  • Determines how fields are structured in the request.
  • If true → Only form schema fields are included in fields.
  • If false → All fields for a specific tenant are included. Additionally, relationalFields will contain { schema_id: [related fields] }.

relations (Array of Objects)

  • Defines the relationships between different entities.
  • Contains objects specifying relation types and linked entities.

fields (Array of Objects)

  • Holds the form schema fields when isSeparatedFields is true.
  • If false, it contains all fields for the specific tenant.

relationalFields (Object)

  • Maps schema IDs to their related fields.
  • Used when isSeparatedFields is false to maintain relationships between schemas and related fields.

abortEarly (Boolean)

  • Determines validation behavior.
  • If true → Validation stops on the first error encountered.
  • If false → All validation errors are collected and returned.

byPassKeys (Array of Strings)

  • Contains field names that should be skipped during validation.
  • Allows exclusion of specific fields from validation checks.

apiVersion (String)

  • Specifies the API version ("v1" or "v2").
  • Helps in maintaining compatibility and version control.

language (String)

  • Specifies the locale language ("nl" or "en").
  • Determines the locale for validation messages.

maxLevel (Number)

  • Defines the level for generate tree structure.

onlyFormFields (Boolean)

Indicates the context in which the form is being used.

  • false: Used when creating new data (full form).
  • true: Used when editing or displaying only existing form fields.

language_codes (Array of IDs)

  • Represents the selected translation language IDs.
  • Each item in the array should be a valid language code or _id used for handling multilingual content.

Result

The validate function returns an object with two keys:

  • status (boolean): true if validation passed, false if there were errors.
  • error (object): Contains validation errors, with field paths as keys and error messages as values.