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

common-id-validator

v1.5.0

Published

A light-weight low-dependency package to syntactically validate commonly used resource identifiers in databases and other systems.

Downloads

27

Readme

Common ID Validator

Introduction

A light-weight low-dependency package to syntactically validate commonly used resource identifiers in databases and other systems.

Installation

npm install common-id-validator

Usage

Example 1. Checking UUID

const { isUUID } = require("common-id-validator");
isUUID("21b7a7a8-cec5-4b67-9a55-74f800326045"); // true
isUUID("Hello World"); // false

isUUID("82ac7f18-e860-11ee-a5c4-325096b39f47", 4); // false
isUUID("000003e8-e861-21ee-b700-325096b39f47", 2); // true

Example 2. Checking ObjectId

const { isObjectId } = require("common-id-validator");
const { ObjectId } = require("bson"); // ObjectId wrapper used in mongoDB adapter

isObjectId(new ObjectId()); // true
isObjectId("5f92cbf10cf217478ba93561"); // true
isObjectId("000003e8-e861-21ee-b700-325096b39f47"); // false

Example 3. Checking TypeId (https://www.npmjs.com/package/typeid-js)

const { isTypeId } = require("common-id-validator");

isTypeId("user_2x4y6z8a0b1c2d3e4f5g6h7j8k"); // true
isTypeId("user2x4y6z8a0b1c2d3e4f5g6h7j8k"); // false

Example 4. Checking MAC addresses

const { isMacAddress } = require("common-id-validator");

isMacAddress("BC-50-D5-2C-5D-AC"); // true
isMacAddress("60:C1:9A:AE:A8:71"); // true
isMacAddress("3542.D272.908E"); // true

isMacAddress("BC-50-D5-2C-5D-AC-2C"); // false
isMacAddress("60:C1:9A-AE:A8:71"); // false

Example 5. Checking Snowflake ID (Twitter variant)

Snowflake ID should be either BigInt or String to be represented properly as unsigned 64-bit integers. Any other data type including Number will return false.

const { isTwitterSnowflakeId } = require("common-id-validator");

isTwitterSnowflakeId(BigInt("1771647565570244608")); // true
isTwitterSnowflakeId("7178357033781956611"); // true

isTwitterSnowflakeId("717835703378A956611"); // false
isTwitterSnowflakeId(1771647565570244608); // false

Example 6. Checking IMEI

IMEI should be provided as either a string or a number in these accepted formats. IMEISV is not accepted currently.

  • AA-BBBBBB-CCCCCC-D
  • AABBBBBBCCCCCCD
const { isIMEI } = require("common-id-validator");

isIMEI(356303483752836); // true
isIMEI("35-630348-375283-6"); // true

isIMEI("35-630-348-375283-6"); // false
isIMEI("35-630348-375283-7"); // incorrect check digit - false

GitHub

https://github.com/kkhtun/common-id-validator

License

MIT