Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

commons-validator-es

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commons-validator-es

Apache Commons Validator ported to TypeScript

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

commons-validator-es

npm npm bundle size Node.js CI CodeQL Coverage Status

Apache Commons Validator ported to TypeScript as a tree-shakable ES6 module

Usage

Install the library with npm install commons-validator-es

To use as an ES6 module:

import { isEmail } from 'commons-validator-es';

isEmail('test@test.com'); // => true
isEmail('test@test.con'); // => false!

It works as a CommonJS module too, for backwards compatibility

const validator = require('commons-validator-es');

validator.isEmail('test@test.com'); // => true
validator.isEmail('test@test.con'); // => false!

Supported validators

ValidatorDescription
isEmail(email, allowLocal?, allowTld?)Checks if email is a valid email address. Ensures fields like the TLD are valid (no .con!)
If allowLocal is true, emails like test@localhost are valid
If allowTld is true, emails like test@com are valid
isDomain(domain, allowLocal?)Checks if domain is a valid domain name
If allowLocal is true, domains like localhost.localdomain are valid, as are single name labels (like hostname)
isTld(tld, allowLocal?)Checks if tld is a valid tld (.com is allowed but .con is not, for example)
If allowLocal is true, tlds like localdomain are valid
isIpAddress(address)Checks if address is a valid IPv4 or IPv6 address
isIpv4Address(address)Checks if address is a valid IPv4 address
isIpv6Address(address)Checks if address is a valid IPv6 address
isCountryCodeTld(ccTld)Checks if ccTld is a valid country code TLD (like .au)
isGenericTld(gTld)Checks if gTld is a valid generic TLD (like .com)
isInfrastructureTld(iTld)Checks if iTld is a valid infrastructure TLD (only valid is .arpa)
isLocalTld(lTld)Checks if lTld is a valid local TLD (like .localdomain)

Inspiration

commons-validator-js hasn't been updated in a while and does not export an ES6 module. I'll be continuing to add more validators to this to bring it to parity with Apache Commons Validator

Keywords

FAQs

Package last updated on 12 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc