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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mdaemon/validate

v1.2.2

Published

A validation library used by MDaemon Remote Administration

Downloads

74

Readme

Dynamic JSON Badge Static Badge install size Dynamic JSON Badge Node.js CI

@mdaemon/validate, A Dependency Free input validation library

[ @mdaemon/validate on npm ]

The "validate" utility provides several validation methods, from domains to ipv6, and email to LDAP.

Install

  $ npm install @mdaemon/validate --save  

Node CommonJS

    const validate = require("@mdaemon/validate/dist/validate.cjs");

Node Modules

    import validate from "@mdaemon/validate/dist/validate.mjs";  

Web

    <script type="text/javascript" src="/path_to_modules/dist/validate.umd.js">

Validate domain syntax

    let validDomain = validate.domain("mdaemon.com");
    console.log(validDomain); // true

    validDomain = validate.domain("mdaemon");
    console.log(validDomain); // false

    // use wild cards *
    validDomain = validate.domain("mdaemon.*", true);
    console.log(validDomain); // true  

Validate email address syntax

    let validEmail = validate.email("[email protected]");
    console.log(validEmail); // true

    validEmail = validate.email("tommy.com");
    console.log(validEmail); // false

    // use wild cards * or ?
    validEmail = validate.email("*@mdaemon???", true);
    console.log(validEmail); // true

Validate ipv4 and ipv6 address syntax

    let validIP = validate.ip("2001:0db8:85a3:0000:0000:8a2e:0370:7334");
    console.log(validIP); // true

    validIP = validate.ip("::");
    console.log(validIP); // true

    validIP = validate.ip("10");
    console.log(validIP); // false

    // use wild cards * or ? or #
    validIP = validate.ip("10.*.*.###", true); 
    console.log(validIP); // true

Validate LDAP DN syntax

    let validDN = validate.ldapDN("CN=test,OU=test,DC=test");
    console.log(validDN); // true

Validate windows file name

    let validFileName = validate.windowsFileName("test.txt");
    console.log(validFileName); // true

    validFileName = validate.windowsFileName("~test.txt");
    console.log(validFileName); // false

Validate windows path

    let validPath = validate.windowsPath("C:\\test\\this\\path");
    console.log(validPath); // true

    validPath = validate.windowsPath("C:\\test\n");
    console.log(validPath); // false

    // user wild cards
    validPath = validate.windowsPath("C:\\*", true);
    console.log(validPath); // true

Validate value is an int as opposed to a float

    let validInt = validate.int("1");
    console.log(validInt); // true

    validInt = validate.int("1.1");
    console.log(validInt); // false

Validate HTTP headers

    let validHeaderName = validate.headerName("X-Test-Name");
    console.log(validHeaderName); // true

    validHeaderName = validate.headerName("X=Test=Name");
    console.log(validHeaderName); // false

    let validHeaderValue = validate.headerValue("1");
    console.log(validHeaderValue); // true

    validHeaderValue = validate.headerValue("default-src 'self' example.com *.example.com");
    console.log(validHeaderValue); // true

    validHeaderValue = validate.headerValue("default-src 'self' \n");
    console.log(validHeaderValue); // false

    let validHeader = validate.header("Content-Security-Policy: default-src 'self'");
    console.log(validHeader); // true

    validHeader = validate.header("X-Frame-Options");
    console.log(validHeader); // false

Validate password requirements

    // do not require special characters
    let validPassword = validate.password("Test this Password1");
    console.log(validPassword); 
    /*
        {
            special: true,
            lower: true,
            upper: true,
            number: true,
            length: 19
        }
    */

   // require special characters
   validPassword = validate.password("test this one1", true);
   console.log(validPassword);
   /*
        {
            special: false,
            lower: true,
            upper: false,
            number: true,
            length: 13
        }
   */

  // validate each part individually
  validate.hasLowerCase("Test Password@1"); // true
  validate.hasLowerCase("TEST PASSWORD"); // false

  validate.hasUpperCase("Test Password@1"); // true
  validate.hasUpperCase("test password"); // false

  validate.hasNumber("Test Password@1"); // true
  validate.hasNumber("test password"); // false

  validate.hasSpecial("Test Password@1"); // true
  validate.hasSpecial("test password1"); // false

  // added for v1.2.0
  validate.isValidPassword("TestPassword1"); // true

  // include bRequireSpecial
  validate.isValidPassword("TestPassword1", true); // false

  // include min and max length of the password, or just min length
  validate.isValidPassword("TestPassword1*", true, 4, 20); // true
  
  // returns false if min >= max
  // numbers less than 1 min and max are ignored
  validate.setPasswordRequirements({ 
    upper: true, 
    lower: true, 
    number: false, 
    special: true, 
    min: 6, 
    max: 16 
  }); // true

  validate.isValidPassword("TestPassword*"); // true
  
  validate.setPasswordRequirements({ upper: false }); // true

  // you can override the requirements for special, min length, and max length
  validate.isValidPassword("testpassword", false); // true
  
  validate.resetPasswordRequirements();

  validate.isValidPassword("testpassword*"); // false

License

Published under the LGPL-2.1 license.

Published by MDaemon Technologies, Ltd. Simple Secure Email https://www.mdaemon.com