Skip to content

Latest commit

 

History

History
107 lines (72 loc) · 2.5 KB

README_zh.md

File metadata and controls

107 lines (72 loc) · 2.5 KB

ean-generator

为亚马逊随机生成ean13码

中文| English

Install

npm install --save ean-generator

Usage

import Ean from 'ean-generator';
let ean = new Ean(['030', '031', '039'])
const code = ean.create()
// 039544164511
const arr = ean.createMultiple({size: 3})
// ['0397442001659','0304437586565','0317191566247']

For commonJS

const Ean = require('ean-generator');

API

constructor(countryCodeArr)

countryCodeArr Type: string[]

设置要随机的前三位国家码

查看ean的前三位国家码

create(prop)

gen ean-13 code

const code = ean.create({countryCode: '123', vendorEan: '456789'})

// 1234567892870

prop?

Type: object

countryCode? Type: string | number Default: null, len is 3

设置要生成的EAN的前三位 不传就从构造函数里面设置的随机生成一个

vendorEan? Type: string | number Default: null, len is 6

设置ean的4-10为厂商编码

createMultiple(prop)

gen multiple ean-13 code, return array

code

const arr = ean.createMultiple({size: 3, countryCode: '123', vendorEan: '456789'})

prop?

size? Type: number Default: 1

isValid(code)

校验EAN是否合法

Type:: string

code

const valid = ean.isValid('1234567890123')
// false

const valid = ean.isValid('1234567892870')
// true

License

MIT License

Copyright (c) 2020 王珏