New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

common-id-validator

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

common-id-validator

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

latest
npmnpm
Version
1.5.0
Version published
Maintainers
0
Created
Source

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

Keywords

validator

FAQs

Package last updated on 24 Aug 2024

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