is-upc
v1.0.0
Published
Returns true or false, whether the value is a valid ITF-14 (GTIN-14) code.
Downloads
13
Maintainers
Readme
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