11 Star 22 Fork 7

HeX / barcode.parser.js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

条码解析器配置说明

基本参数

以下几种匹配模式,如果都写,则必须满足所有匹配条件

属性 必填 说明 数据值
name 条码名称,可用于区分条码类型 字符串
size 长度匹配 数字
startWith 起始字符串匹配 字符串
endWith 结尾字符串匹配 字符串
regExp 正则表达式匹配 正则表达式
elements 解析元素集合 数组

Element参数

属性 必填 说明 数据值
name 解析后的名称 字符串
range 取值范围[起始位置,长度] 整形数组
unit 单位信息 数组或字符串

unit 如果是字符串,则会在数据结尾追加单位名称,如果位数组,如:["千克",1000],则先除以1000,再追加单位名称

栗子

var parserConfig = [
        {
            name:"条码1",
            regEx:/01\d{8}\d{6}3102\d{6}13\d{6}21\d{12}/g,//用正则匹配编码格式
            elements:[
                {
                    name:"国家", //产品编码
                    range:[2,8] //第2位开始,长度为8
                },{
                    name:"产品",
                    range:[10,6]
                },{
                    name:"重量",
                    range:[20,6],
                    unit:[
                        "千克",
                        100
                    ]
                },{
                    name:"日期",
                    range:[28,6]
                },{
                    name:"批次",
                    range:[36,12]
                }
            ]
        }
    ];
    parser.setConfig(parserConfig);
    console.log(parser.parse("010000000004553731020012101317020121006702013227"));

输出结果

{
    "name":"条码1",
    "国家":"00000000",
    "产品":"045537",
    "重量":"12.1千克",
    "日期":"170201",
    "批次":"006702013227"
}
The MIT License (MIT) Copyright (c) 2017 HexPang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

条形码解析,可自定解析规则 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/hexpang/barcode-parser-js.git
git@gitee.com:hexpang/barcode-parser-js.git
hexpang
barcode-parser-js
barcode.parser.js
master

搜索帮助