is-upc

1.0.0 • Public • Published

is-upc

Returns true or false, whether the value is a valid UPC-A or UPC-E (GTIN-12) code.

import isUPC from 'is-upc'
 
// You can do strict comparisons on the returned falsy values
// to determine why it is not a valid code.
// undefined - Code is not a number or a string.
// null - Code does not fit the 12-digit format.
// false - Check digit validation failed.
 
isUPC({}) // undefined
isUPC('a') // null
isUPC('797662111151') // false
isUPC('797662111150') // true
isUPC(797662111150) // true
 
// Be careful when using numbers as the input:
isUPC(036702375177) // null
isUPC('036702375177') // true

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i is-upc

      Weekly Downloads

      2

      Version

      1.0.0

      License

      MIT

      Last publish

      Collaborators

      • str_t