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

ptw-udi

v1.0.4

Published

Generate an unique device identification as speficied by HIBC.

Downloads

15

Readme

PTW UDI

Build Status Coverage Status npm version

Generates an unique device identification as specified by HIBC UDI (ANSI/HIBC 2.5 - 2015). You can find more information about the specification of the unique device identification on the HIBC website.

This library is very small (~6KB minified, no external dependencies) and its sole purpose is to generate a HIBC-conform data structure that uniquely identifies a product. It will automatically create a string with the correct order of information and check characters. The string can then be used by your favorite barcode generating library to generate a Bar-/QR-Code based on the generated string.

Install

$ npm install ptw-udi --save

Note: If you just want to embed the library in your website, use the file found in dist/udi.min.js.

Usage

The public API consists of 3 methods to create different types of data structures (primary, secondary and combined) and one method to transform the created data structure to a string that can be placed below the barcode.

Below are some examples that show how to create unique device identifications with ptw-udi. For an complete overview of the API, please check out the included declarations files lib/udi.d.ts. If you're using Typescript, you also can import PrimaryDataStructureConfig and SecondaryDataStructureConfig for additional help with the inevitable large method signature.

Primary Data Structure

import { createPrimaryDataStructure } from 'ptw-udi';

const udi = createPrimaryDataStructure({
    lic: 'BLUE',
    pcn: 'UNICORN',
    unitOfMeasure: 7
});
// udi = "+BLUEUNICORN7N"

Secondary Data Structure

import { createSecondaryDataStructure, DateFormat, QuantityFormat } from 'ptw-udi';

const lic = 'A123';
const pcn = 'BJC5D6E71G';
const unitOfMeasure = 1;

const lot = '3C001';
const sn = '0001';

let udi = createSecondaryDataStructure({
    lic, pcn, unitOfMeasure,
    lot, sn,
    expDate: {
        format: DateFormat.MMDDYY,
        value: '092805'
    },
    manufactureDate: '20000101'
});
// udi = "+$$20928053C001/S0001/16D20000101XQ"

udi = createSecondaryDataStructure({
    lic, pcn, unitOfMeasure,
    lot,
    quantity: {
        format: QuantityFormat.QQQQQ,
        value: '12345'
    },
    expDate: {
        format: DateFormat.YYYYMMDD,
        value: '20200101'
    },
    manufactureDate: '20160101'
})
// udi = "+$$91234573C001/16D20160101/14D20200101XX"

Combined Data Structure

import { createCombinedDataStructure, DateFormat } from 'ptw-udi';

const lic = 'A123';
const pcn = 'BJC5D6E71G';
const unitOfMeasure = 1;

const lot = '3C001';
const sn = '0001';

const udi = createCombinedDataStructure({
    lic, pcn, unitOfMeasure,
    lot, sn,
    expDate: {
        format: DateFormat.YYYYMMDD,
        value: '20200101'
    },
    manufactureDate: '20160101'
});
// udi = "+A123BJC5D6E71G1/$$73C001/S0001/16D20160101/14D20200101Y"

Errors

ptw-udi will throw errors if the input does not adhere the HIBC specification. For instance, if you pass a quantity to the library that does not has the required length, an Error will be thrown. We tried to make the errors helpful, so that you know how to fix the problematic input.

A quantity with the format QQQQQ and value of '100' will generate the following error message:

$ Expected "quantity.value" to be an numeric value with length of "5", but was "100".

Scripts

  • Build: npm run build
  • Test: npm test
  • Develop: npm run watch