初始化
This commit is contained in:
parent
179418e65f
commit
53afc38e76
|
|
@ -0,0 +1 @@
|
|||
/unpackage
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
{ // launch.json 配置了启动调试时相关设置,configurations下节点名称可为 app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/
|
||||
// launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数
|
||||
"version": "0.0",
|
||||
"configurations": [{
|
||||
"default" :
|
||||
{
|
||||
"launchtype" : "local"
|
||||
},
|
||||
"mp-weixin" :
|
||||
{
|
||||
"launchtype" : "local"
|
||||
},
|
||||
"type" : "uniCloud"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"files.associations": {
|
||||
"*.ttml": "xml",
|
||||
"*.ttss": "css"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
<script>
|
||||
import useStorage from '@/utils/useStroage.js';
|
||||
export default {
|
||||
onLaunch: function() {
|
||||
// console.log('App Launch');
|
||||
useStorage.set('menuInfo', uni.getMenuButtonBoundingClientRect());
|
||||
},
|
||||
onShow: function() {
|
||||
// console.log('App Show');
|
||||
},
|
||||
onHide: function() {
|
||||
// console.log('App Hide');
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
@import '@/uni_modules/uview-ui/index.scss';
|
||||
/* #ifndef APP-PLUS-NVUE */
|
||||
@import './common/css/uni.scss';
|
||||
/* #endif */
|
||||
/* uni.scss */
|
||||
@import './common/css/flex.css';
|
||||
|
||||
page,
|
||||
view,
|
||||
scroll-view,
|
||||
swiper,
|
||||
swiper-item,
|
||||
match-media,
|
||||
movable-area,
|
||||
movable-view,
|
||||
cover-view,
|
||||
cover-image,
|
||||
icon,
|
||||
text,
|
||||
rich-text,
|
||||
progress,
|
||||
button,
|
||||
checkbox-group,
|
||||
editor,
|
||||
form,
|
||||
input,
|
||||
label,
|
||||
picker,
|
||||
picker-view,
|
||||
radio-group,
|
||||
slider,
|
||||
switch,
|
||||
textarea,
|
||||
navigator,
|
||||
audio,
|
||||
camera,
|
||||
image,
|
||||
video,
|
||||
live-player,
|
||||
live-pusher,
|
||||
map,
|
||||
canvas,
|
||||
web-view {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
input {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
image {
|
||||
display: block;
|
||||
}
|
||||
|
||||
page {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
||||
text {
|
||||
font-size: 28upx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'BebasNeue-Regular';
|
||||
src: url('./static/font/BebasNeue-Regular.woff');
|
||||
}
|
||||
|
||||
.num {
|
||||
font-family: 'BebasNeue-Regular';
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
# cashier_weapp
|
||||
|
||||
#### Description
|
||||
最新版收银点餐小程序
|
||||
|
||||
#### Software Architecture
|
||||
Software architecture description
|
||||
|
||||
#### Installation
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Instructions
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### Contribution
|
||||
|
||||
1. Fork the repository
|
||||
2. Create Feat_xxx branch
|
||||
3. Commit your code
|
||||
4. Create Pull Request
|
||||
|
||||
|
||||
#### Gitee Feature
|
||||
|
||||
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
|
||||
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
|
||||
4. The most valuable open source project [GVP](https://gitee.com/gvp)
|
||||
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
|
||||
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||
38
README.md
38
README.md
|
|
@ -1 +1,37 @@
|
|||
#cashier_weapp
|
||||
# cashier_weapp
|
||||
|
||||
#### 介绍
|
||||
最新版收银点餐小程序
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
|
||||
|
||||
#### 安装教程
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 使用说明
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码
|
||||
4. 新建 Pull Request
|
||||
|
||||
|
||||
#### 特技
|
||||
|
||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
.flex-center{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.flex-start{
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.flex-end{
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.flex-colum{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.flex-colum-start{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.flex-colum-end{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: flex-end;
|
||||
}
|
||||
.flex-between{
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.flex-around{
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,35 @@
|
|||
var crypto = require('crypto')
|
||||
|
||||
function WXBizDataCrypt(appId, sessionKey) {
|
||||
this.appId = appId
|
||||
this.sessionKey = sessionKey
|
||||
}
|
||||
|
||||
WXBizDataCrypt.prototype.decryptData = function (encryptedData, iv) {
|
||||
// base64 decode
|
||||
var sessionKey = new Buffer(this.sessionKey, 'base64')
|
||||
encryptedData = new Buffer(encryptedData, 'base64')
|
||||
iv = new Buffer(iv, 'base64')
|
||||
|
||||
try {
|
||||
// 解密
|
||||
var decipher = crypto.createDecipheriv('aes-128-cbc', sessionKey, iv)
|
||||
// 设置自动 padding 为 true,删除填充补位
|
||||
decipher.setAutoPadding(true)
|
||||
var decoded = decipher.update(encryptedData, 'binary', 'utf8')
|
||||
decoded += decipher.final('utf8')
|
||||
|
||||
decoded = JSON.parse(decoded)
|
||||
|
||||
} catch (err) {
|
||||
throw new Error('Illegal Buffer')
|
||||
}
|
||||
|
||||
if (decoded.watermark.appid !== this.appId) {
|
||||
throw new Error('Illegal Buffer')
|
||||
}
|
||||
|
||||
return decoded
|
||||
}
|
||||
|
||||
module.exports = WXBizDataCrypt
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
export default {
|
||||
userwxlogin(data) { //登录
|
||||
return uni.api.post("/login/wx/custom/login", data);
|
||||
},
|
||||
productqueryProduct(data) { //获取商品信息
|
||||
return uni.api.post("/product/queryProduct", data);
|
||||
},
|
||||
cartadd(data) { //添加到购物车
|
||||
return uni.api.post("/cart/add", data);
|
||||
},
|
||||
cartcartList(data) { //购物车
|
||||
return uni.api.get("/cart/cartList", data);
|
||||
},
|
||||
logincreateCardNo(data) { //获取会员码
|
||||
return uni.api.get("/login/createCardNo", data);
|
||||
},
|
||||
cartupdateNumber(data) { //购物车更改数量
|
||||
return uni.api.get("/cart/updateNumber", data);
|
||||
},
|
||||
ordercreatOrder(data) { //下单
|
||||
return uni.api.post("/order/creatOrder", data);
|
||||
},
|
||||
cartclear(data) { //清空购物车
|
||||
return uni.api.get("/cart/clear", data);
|
||||
},
|
||||
payorderPay(data) { //订单支付
|
||||
return uni.api.post("/pay/orderPay", data);
|
||||
},
|
||||
orderorderList(data) { //订单列表
|
||||
return uni.api.get("/order/orderList", data);
|
||||
},
|
||||
orderorderInfo(data) { //订单回显
|
||||
return uni.api.get("/order/orderInfo", data);
|
||||
},
|
||||
loginwxuserInfo(data) { //微信用户详情
|
||||
return uni.api.get("/login/wx/userInfo", data);
|
||||
},
|
||||
paymemeberIn(data) { //充值
|
||||
return uni.api.post("/pay/memeberIn", data);
|
||||
},
|
||||
paymodfiyOrderInfo(data) { //查询订单支付状态
|
||||
return uni.api.post("/pay/modfiyOrderInfo", data);
|
||||
},
|
||||
productqueryProductSku(data) { //通过选中的商品规格查询价格
|
||||
return uni.api.get("/product/queryProductSku", data);
|
||||
},
|
||||
logingetPhoneNumber(data) { //小程序获取手机号
|
||||
return uni.api.post("/login/getPhoneNumber", data);
|
||||
},
|
||||
}
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
const env = {
|
||||
aliyunServerURL: 'https://czg-qr-order.oss-cn-beijing.aliyuncs.com',
|
||||
accessid: 'LTAI5tMLHwnM1zYYAFuRa1fK',
|
||||
AccessKeySecret: 'jS1h2STq1vcODczDNFQkjcU6ODyYAj',
|
||||
timeout: 100000
|
||||
}
|
||||
|
||||
const Base64 = require('./Base64.js');
|
||||
|
||||
require('./hmac.js');
|
||||
require('./sha1.js');
|
||||
const Crypto = require('./crypto.js');
|
||||
|
||||
|
||||
const uploadFile = function(filePath, key = new Date().getTime()) {
|
||||
return new Promise((resolve, reject) => {
|
||||
// const aliyunFileKey = `${new Date().getTime()}_${userId}`;
|
||||
const aliyunServerURL = env.aliyunServerURL;
|
||||
const accessid = env.accessid;
|
||||
const policyBase64 = getPolicyBase64();
|
||||
const signature = getSignature(policyBase64);
|
||||
|
||||
wx.uploadFile({
|
||||
url: aliyunServerURL, //仅为示例,非真实的接口地址
|
||||
filePath: filePath,
|
||||
name: 'file',
|
||||
formData: {
|
||||
'key': 'headportrait/' + key,
|
||||
'OSSAccessKeyId': accessid,
|
||||
'policy': policyBase64,
|
||||
'Signature': signature,
|
||||
'success_action_status': '200',
|
||||
},
|
||||
success: function(res) {
|
||||
if (res.statusCode != 200) {
|
||||
reject('上传错误:' + JSON.stringify(res))
|
||||
return;
|
||||
}
|
||||
resolve(`https://czh5.sxczgkj.cn/headportrait/${key}`)
|
||||
},
|
||||
fail: function(err) {
|
||||
reject('上传错误:' + JSON.stringify(err))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const getPolicyBase64 = function() {
|
||||
let date = new Date();
|
||||
date.setHours(date.getHours() + env.timeout);
|
||||
let srcT = date.toISOString();
|
||||
const policyText = {
|
||||
"expiration": srcT, //设置该Policy的失效时间,超过这个失效时间之后,就没有办法通过这个policy上传文件了 指定了Post请求必须发生在2020年01月01日12点之前("2020-01-01T12:00:00.000Z")。
|
||||
"conditions": [
|
||||
["content-length-range", 0, 20 * 1024 * 1024] // 设置上传文件的大小限制,1048576000=1000mb
|
||||
]
|
||||
};
|
||||
|
||||
const policyBase64 = Base64.encode(JSON.stringify(policyText));
|
||||
return policyBase64;
|
||||
}
|
||||
|
||||
const getSignature = function(policyBase64) {
|
||||
const accesskey = env.AccessKeySecret;
|
||||
|
||||
const bytes = Crypto.HMAC(Crypto.SHA1, policyBase64, accesskey, {
|
||||
asBytes: true
|
||||
});
|
||||
const signature = Crypto.util.bytesToBase64(bytes);
|
||||
|
||||
return signature;
|
||||
}
|
||||
|
||||
module.exports = uploadFile;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
export default {
|
||||
userwxlogin(data) { //登录
|
||||
return uni.api.post("/login/wx/custom/login", data, type = 2);
|
||||
},
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,148 @@
|
|||
class webSocketUtils {
|
||||
constructor(url, time, params) {
|
||||
this.socketTask = null;
|
||||
this.is_open_socket = false; //避免重复连接
|
||||
this.url = url;
|
||||
this.params = params ? params : null;////是否初始化请求
|
||||
this.connectNum = 1; // 重连次数
|
||||
//这个参数是防止重连失败之后onClose方法会重复执行reconnect方法,导致重连定时器出问题
|
||||
//连接并打开之后可重连,且只执行重连方法一次
|
||||
this.canReconnect = false; // 是否可以重连
|
||||
//心跳检测
|
||||
this.timeout = time ? time : 5000; //多少秒执行检测
|
||||
this.heartbeatInterval = null; //检测服务器端是否还活着
|
||||
this.reconnectTimeOut = null; //重连之后多久再次重连
|
||||
try {
|
||||
return this.connectSocketInit({
|
||||
data: this.params,
|
||||
type: 'connectSocketInit',
|
||||
});
|
||||
} catch (e) {
|
||||
console.log('catch');
|
||||
this.reconnect();
|
||||
}
|
||||
}
|
||||
// 进入这个页面的时候创建websocket连接【整个页面随时使用】
|
||||
connectSocketInit (data) {
|
||||
console.log(data,"初始化")
|
||||
this.data = data;
|
||||
// console.log('this.url==', this.url);
|
||||
// console.log('this.params==', this.params);
|
||||
this.socketTask = uni.connectSocket({
|
||||
url: this.url,
|
||||
success: () => {
|
||||
console.log('正准备建立websocket中...');
|
||||
uni.hideLoading();
|
||||
// 返回实例
|
||||
return this.socketTask;
|
||||
},
|
||||
});
|
||||
this.socketTask.onOpen((res) => {
|
||||
this.connectNum = 1;
|
||||
console.log('WebSocket连接正常!');
|
||||
if(this.params){//是否初始化请求
|
||||
this.send(this.params);
|
||||
}
|
||||
|
||||
clearInterval(this.reconnectTimeOut);
|
||||
clearInterval(this.heartbeatInterval);
|
||||
this.is_open_socket = true;
|
||||
this.canReconnect = true;
|
||||
this.start();
|
||||
// 注:只有连接正常打开中 ,才能正常收到消息
|
||||
this.socketTask.onMessage((e) => {
|
||||
// 字符串转json
|
||||
let res = JSON.parse(e.data);
|
||||
uni.$emit('message', res)
|
||||
// 普通socket信息处理 TODO
|
||||
|
||||
});
|
||||
});
|
||||
// 监听连接失败,这里代码我注释掉的原因是因为如果服务器关闭后,和下面的onclose方法一起发起重连操作,这样会导致重复连接
|
||||
uni.onSocketError((res) => {
|
||||
console.log('网络断开,请检查!');
|
||||
this.socketTask = null;
|
||||
this.is_open_socket = false;
|
||||
this.canReconnect = true;
|
||||
clearInterval(this.heartbeatInterval);
|
||||
clearInterval(this.reconnectTimeOut);
|
||||
if (this.connectNum <= 10) {
|
||||
uni.showToast({
|
||||
title: `网络连接失败,正尝试第${this.connectNum}次连接`,
|
||||
icon: 'none',
|
||||
});
|
||||
this.reconnect();
|
||||
this.connectNum += 1;
|
||||
} else {
|
||||
// uni.$emit('connectError');
|
||||
uni.showToast({
|
||||
title: `网络连接失败,请检查网络!`,
|
||||
icon: 'none',
|
||||
});
|
||||
this.connectNum = 1;
|
||||
this.canReconnect = false;
|
||||
}
|
||||
});
|
||||
// 这里仅是事件监听【如果socket关闭了会执行】
|
||||
this.socketTask.onClose(() => {
|
||||
this.socketTask = null;
|
||||
clearInterval(this.heartbeatInterval);
|
||||
clearInterval(this.reconnectTimeOut);
|
||||
|
||||
this.is_open_socket = false;
|
||||
if (this.canReconnect) {
|
||||
this.reconnect();
|
||||
this.canReconnect = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
// 主动关闭socket连接
|
||||
Close () {
|
||||
this.is_open_socket = true;
|
||||
this.canReconnect = false;
|
||||
if(this.socketTask){
|
||||
this.socketTask.close({
|
||||
success(res) {
|
||||
console.log('手动关闭成功');
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
//发送消息
|
||||
send(data) {
|
||||
console.log("发送消息---------->", data);
|
||||
// 注:只有连接正常打开中 ,才能正常成功发送消息
|
||||
if (this.socketTask) {
|
||||
this.socketTask.send({
|
||||
data: JSON.stringify(data),
|
||||
async success() {
|
||||
console.log("消息发送成功");
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
//开启心跳检测
|
||||
start(data) {
|
||||
console.log('开启心跳检测',data)
|
||||
// this.heartbeatInterval = setInterval(() => {
|
||||
// this.send({
|
||||
// data: '心跳检测',
|
||||
// type: 'jc',
|
||||
// });
|
||||
// }, this.timeout);
|
||||
}
|
||||
//重新连接
|
||||
reconnect() {
|
||||
//停止发送心跳
|
||||
clearInterval(this.heartbeatInterval);
|
||||
//如果不是人为关闭的话,进行重连
|
||||
if (!this.is_open_socket) {
|
||||
console.log('进行重连');
|
||||
// this.canReconnect = true;
|
||||
this.reconnectTimeOut = setInterval(() => {
|
||||
this.connectSocketInit(this.data);
|
||||
}, this.timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = webSocketUtils;
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<template>
|
||||
<u-image :src="src" :radius="radius" :width="width" :height="height" :fade="false"></u-image>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
src: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
width: {
|
||||
type: [String, Number],
|
||||
default: 80
|
||||
},
|
||||
height: {
|
||||
type: [String, Number],
|
||||
default: 80
|
||||
},
|
||||
radius: {
|
||||
type: [String, Number],
|
||||
default: 16
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
@ -0,0 +1,190 @@
|
|||
const barcodes = require('./barcodes/index.js')['default'];
|
||||
let barcode = {};
|
||||
(function () {
|
||||
// 初始化
|
||||
barcode = function (cont, ctxid, options, ctxsize, result) {
|
||||
let ops = {}, newOptions, encodings, globaContext, ctx, globaCtxid, cbCanvasSize, cbResult;
|
||||
globaCtxid = ctxid
|
||||
cbCanvasSize = ctxsize
|
||||
cbResult = result
|
||||
newOptions = Object.assign(ops, options);
|
||||
// 修成margin
|
||||
fixMargin(newOptions)
|
||||
// 处理options 数据
|
||||
if (newOptions.text == '' || cont == '') {
|
||||
return false
|
||||
}
|
||||
// 获取ctx
|
||||
globaContext = cont
|
||||
ctx = uni.createCanvasContext(globaCtxid, globaContext)
|
||||
// 获取编码数据
|
||||
encodings = new barcodes[newOptions.format.toUpperCase()](newOptions.text, newOptions).encode()
|
||||
let fixencodings = fixEncodings(encodings, newOptions)
|
||||
// 返回canvas实际大小
|
||||
cbCanvasSize({ width: fixencodings.width, height: fixencodings.height })
|
||||
// 绘制canvas
|
||||
setTimeout(() => {
|
||||
drawCanvas.render(newOptions, fixencodings)
|
||||
}, 50);
|
||||
// 绘制canvas
|
||||
let drawCanvas = {
|
||||
render(options, encoding) {
|
||||
this.prepare(options, encoding)
|
||||
encoding.encodings.forEach((v, i) => {
|
||||
this.barcode(options, v)
|
||||
this.text(options, v)
|
||||
this.move(v)
|
||||
});
|
||||
this.draw(options, encoding)
|
||||
},
|
||||
barcode(options, encoding) {
|
||||
let binary = encoding.data;
|
||||
let yFrom;
|
||||
if (options.textPosition == "top") {
|
||||
yFrom = options.marginTop + options.fontSize + options.textMargin;
|
||||
} else {
|
||||
yFrom = options.marginTop;
|
||||
}
|
||||
// 绘制条码
|
||||
ctx.fillStyle = options.lineColor;
|
||||
for (let b = 0; b < binary.length; b++) {
|
||||
let x = b * options.width + encoding.barcodePadding;
|
||||
let height = options.height
|
||||
if (encoding.options) {
|
||||
if (encoding.options.height != undefined) {
|
||||
height = encoding.options.height
|
||||
}
|
||||
}
|
||||
if (binary[b] === "1") {
|
||||
ctx.fillRect(x, yFrom, options.width, height);
|
||||
} else if (binary[b]) {
|
||||
ctx.fillRect(x, yFrom, options.width, height * binary[b]);
|
||||
}
|
||||
}
|
||||
},
|
||||
text(options, encoding) {
|
||||
if (options.displayValue) {
|
||||
let x, y, align, size;
|
||||
if (options.textPosition == "top") {
|
||||
y = options.marginTop + options.fontSize;
|
||||
} else {
|
||||
y = options.height + options.textMargin + options.marginTop + options.fontSize;
|
||||
}
|
||||
if (encoding.options) {
|
||||
if (encoding.options.textAlign != undefined) {
|
||||
align = encoding.options.textAlign
|
||||
}
|
||||
if (encoding.options.fontSize != undefined) {
|
||||
size = encoding.options.fontSize
|
||||
}
|
||||
} else {
|
||||
align = options.textAlign
|
||||
size = options.fontSize
|
||||
}
|
||||
ctx.setFontSize(size)
|
||||
if (align == "left" || encoding.barcodePadding > 0) {
|
||||
x = 0;
|
||||
ctx.setTextAlign('left')
|
||||
} else if (align == "right") {
|
||||
x = encoding.width - 1;
|
||||
ctx.setTextAlign('right')
|
||||
}
|
||||
else {
|
||||
x = encoding.width / 2;
|
||||
ctx.setTextAlign('center');
|
||||
}
|
||||
ctx.fillStyle = options.fontColor;
|
||||
if (encoding.text != undefined) {
|
||||
ctx.fillText(encoding.text, x, y);
|
||||
}
|
||||
}
|
||||
},
|
||||
move(encoding) {
|
||||
ctx.translate(encoding.width, 0);
|
||||
},
|
||||
prepare(options, encoding) {
|
||||
// 绘制背景
|
||||
if (options.background) {
|
||||
ctx.fillStyle = options.background;
|
||||
ctx.fillRect(0, 0, encoding.width, encoding.height);
|
||||
}
|
||||
ctx.translate(options.marginLeft, 0);
|
||||
},
|
||||
draw(options, encoding) {
|
||||
ctx.draw(false, () => {
|
||||
this.toImgs(options, encoding)
|
||||
})
|
||||
},
|
||||
toImgs(options, encoding) {
|
||||
setTimeout(() => {
|
||||
uni.canvasToTempFilePath({
|
||||
width: encoding.width,
|
||||
height: encoding.height,
|
||||
destWidth: encoding.width,
|
||||
destHeight: encoding.height,
|
||||
canvasId: globaCtxid,
|
||||
fileType: 'png',
|
||||
success: function (res) {
|
||||
cbResult(res.tempFilePath)
|
||||
},
|
||||
fail: function (res) {
|
||||
cbResult(res)
|
||||
},
|
||||
complete: function () {
|
||||
uni.hideLoading();
|
||||
},
|
||||
}, globaContext);
|
||||
}, options.text.length + 100);
|
||||
}
|
||||
}
|
||||
// 混入canvas数据
|
||||
function fixEncodings(encoding, options) {
|
||||
let encodingArr = [], width = options.marginLeft + options.marginRight, height;
|
||||
if (!Array.isArray(encoding)) {
|
||||
encodingArr[0] = JSON.parse(JSON.stringify(encoding))
|
||||
} else {
|
||||
encodingArr = [...encoding]
|
||||
}
|
||||
encodingArr.forEach((v, i) => {
|
||||
// 获取文本宽度
|
||||
let textWidth = ctx.measureText(encodingArr[i].text ? encodingArr[i].text : '').width;
|
||||
// 获取条形码宽度
|
||||
let barcodeWidth = encodingArr[i].data.length * options.width;
|
||||
// 获取内边距
|
||||
let barcodePadding = 0;
|
||||
if (options.displayValue && barcodeWidth < textWidth) {
|
||||
if (options.textAlign == "center") {
|
||||
barcodePadding = Math.floor((textWidth - barcodeWidth) / 2);
|
||||
} else if (options.textAlign == "left") {
|
||||
barcodePadding = 0;
|
||||
} else if (options.textAlign == "right") {
|
||||
barcodePadding = Math.floor(textWidth - barcodeWidth);
|
||||
}
|
||||
}
|
||||
// 混入encodingArr[i]
|
||||
encodingArr[i].barcodePadding = barcodePadding
|
||||
encodingArr[i].width = Math.ceil(Math.max(textWidth, barcodeWidth))
|
||||
width += encodingArr[i].width
|
||||
if (encodingArr[i].options) {
|
||||
if (encodingArr[i].options.height != undefined) {
|
||||
encodingArr[i].height = encodingArr[i].options.height + (options.displayValue && (encodingArr[i].text ? encodingArr[i].text : '').length > 0 ? options.fontSize + options.textMargin : 0) + options.marginTop + options.marginBottom;
|
||||
} else {
|
||||
encodingArr[i].height = height = options.height + (options.displayValue && (encodingArr[i].text ? encodingArr[i].text : '').length > 0 ? options.fontSize + options.textMargin : 0) + options.marginTop + options.marginBottom;
|
||||
}
|
||||
} else {
|
||||
encodingArr[i].height = height = options.height + (options.displayValue && (encodingArr[i].text ? encodingArr[i].text : '').length > 0 ? options.fontSize + options.textMargin : 0) + options.marginTop + options.marginBottom;
|
||||
}
|
||||
});
|
||||
return { encodings: encodingArr, width, height };
|
||||
}
|
||||
// 修正Margin
|
||||
function fixMargin(options) {
|
||||
options.marginTop = options.marginTop == undefined ? options.margin : options.marginTop;
|
||||
options.marginBottom = options.marginBottom == undefined ? options.margin : options.marginBottom;
|
||||
options.marginRight = options.marginRight == undefined ? options.margin : options.marginRight;
|
||||
options.marginLeft = options.marginLeft == undefined ? options.margin : options.marginLeft;
|
||||
}
|
||||
};
|
||||
})()
|
||||
|
||||
export default barcode
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var Barcode = function Barcode(data, options) {
|
||||
_classCallCheck(this, Barcode);
|
||||
|
||||
this.data = data;
|
||||
this.text = options.text || data;
|
||||
this.options = options;
|
||||
};
|
||||
|
||||
exports.default = Barcode;
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _Barcode2 = require('../Barcode.js');
|
||||
|
||||
var _Barcode3 = _interopRequireDefault(_Barcode2);
|
||||
|
||||
var _constants = require('./constants');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
// This is the master class,
|
||||
// it does require the start code to be included in the string
|
||||
var CODE128 = function (_Barcode) {
|
||||
_inherits(CODE128, _Barcode);
|
||||
|
||||
function CODE128(data, options) {
|
||||
_classCallCheck(this, CODE128);
|
||||
|
||||
// Get array of ascii codes from data
|
||||
var _this = _possibleConstructorReturn(this, (CODE128.__proto__ || Object.getPrototypeOf(CODE128)).call(this, data.substring(1), options));
|
||||
|
||||
_this.bytes = data.split('').map(function (char) {
|
||||
return char.charCodeAt(0);
|
||||
});
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(CODE128, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
// ASCII value ranges 0-127, 200-211
|
||||
return (/^[\x00-\x7F\xC8-\xD3]+$/.test(this.data)
|
||||
);
|
||||
}
|
||||
|
||||
// The public encoding function
|
||||
|
||||
}, {
|
||||
key: 'encode',
|
||||
value: function encode() {
|
||||
var bytes = this.bytes;
|
||||
// Remove the start code from the bytes and set its index
|
||||
var startIndex = bytes.shift() - 105;
|
||||
// Get start set by index
|
||||
var startSet = _constants.SET_BY_CODE[startIndex];
|
||||
|
||||
if (startSet === undefined) {
|
||||
throw new RangeError('The encoding does not start with a start character.');
|
||||
}
|
||||
|
||||
if (this.shouldEncodeAsEan128() === true) {
|
||||
bytes.unshift(_constants.FNC1);
|
||||
}
|
||||
|
||||
// Start encode with the right type
|
||||
var encodingResult = CODE128.next(bytes, 1, startSet);
|
||||
|
||||
return {
|
||||
text: this.text === this.data ? this.text.replace(/[^\x20-\x7E]/g, '') : this.text,
|
||||
data:
|
||||
// Add the start bits
|
||||
CODE128.getBar(startIndex) +
|
||||
// Add the encoded bits
|
||||
encodingResult.result +
|
||||
// Add the checksum
|
||||
CODE128.getBar((encodingResult.checksum + startIndex) % _constants.MODULO) +
|
||||
// Add the end bits
|
||||
CODE128.getBar(_constants.STOP)
|
||||
};
|
||||
}
|
||||
|
||||
// GS1-128/EAN-128
|
||||
|
||||
}, {
|
||||
key: 'shouldEncodeAsEan128',
|
||||
value: function shouldEncodeAsEan128() {
|
||||
var isEAN128 = this.options.ean128 || false;
|
||||
if (typeof isEAN128 === 'string') {
|
||||
isEAN128 = isEAN128.toLowerCase() === 'true';
|
||||
}
|
||||
return isEAN128;
|
||||
}
|
||||
|
||||
// Get a bar symbol by index
|
||||
|
||||
}], [{
|
||||
key: 'getBar',
|
||||
value: function getBar(index) {
|
||||
return _constants.BARS[index] ? _constants.BARS[index].toString() : '';
|
||||
}
|
||||
|
||||
// Correct an index by a set and shift it from the bytes array
|
||||
|
||||
}, {
|
||||
key: 'correctIndex',
|
||||
value: function correctIndex(bytes, set) {
|
||||
if (set === _constants.SET_A) {
|
||||
var charCode = bytes.shift();
|
||||
return charCode < 32 ? charCode + 64 : charCode - 32;
|
||||
} else if (set === _constants.SET_B) {
|
||||
return bytes.shift() - 32;
|
||||
} else {
|
||||
return (bytes.shift() - 48) * 10 + bytes.shift() - 48;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'next',
|
||||
value: function next(bytes, pos, set) {
|
||||
if (!bytes.length) {
|
||||
return { result: '', checksum: 0 };
|
||||
}
|
||||
|
||||
var nextCode = void 0,
|
||||
index = void 0;
|
||||
|
||||
// Special characters
|
||||
if (bytes[0] >= 200) {
|
||||
index = bytes.shift() - 105;
|
||||
var nextSet = _constants.SWAP[index];
|
||||
|
||||
// Swap to other set
|
||||
if (nextSet !== undefined) {
|
||||
nextCode = CODE128.next(bytes, pos + 1, nextSet);
|
||||
}
|
||||
// Continue on current set but encode a special character
|
||||
else {
|
||||
// Shift
|
||||
if ((set === _constants.SET_A || set === _constants.SET_B) && index === _constants.SHIFT) {
|
||||
// Convert the next character so that is encoded correctly
|
||||
bytes[0] = set === _constants.SET_A ? bytes[0] > 95 ? bytes[0] - 96 : bytes[0] : bytes[0] < 32 ? bytes[0] + 96 : bytes[0];
|
||||
}
|
||||
nextCode = CODE128.next(bytes, pos + 1, set);
|
||||
}
|
||||
}
|
||||
// Continue encoding
|
||||
else {
|
||||
index = CODE128.correctIndex(bytes, set);
|
||||
nextCode = CODE128.next(bytes, pos + 1, set);
|
||||
}
|
||||
|
||||
// Get the correct binary encoding and calculate the weight
|
||||
var enc = CODE128.getBar(index);
|
||||
var weight = index * pos;
|
||||
|
||||
return {
|
||||
result: enc + nextCode.result,
|
||||
checksum: weight + nextCode.checksum
|
||||
};
|
||||
}
|
||||
}]);
|
||||
|
||||
return CODE128;
|
||||
}(_Barcode3.default);
|
||||
|
||||
exports.default = CODE128;
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _CODE2 = require('./CODE128.js');
|
||||
|
||||
var _CODE3 = _interopRequireDefault(_CODE2);
|
||||
|
||||
var _constants = require('./constants');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var CODE128A = function (_CODE) {
|
||||
_inherits(CODE128A, _CODE);
|
||||
|
||||
function CODE128A(string, options) {
|
||||
_classCallCheck(this, CODE128A);
|
||||
|
||||
return _possibleConstructorReturn(this, (CODE128A.__proto__ || Object.getPrototypeOf(CODE128A)).call(this, _constants.A_START_CHAR + string, options));
|
||||
}
|
||||
|
||||
_createClass(CODE128A, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return new RegExp('^' + _constants.A_CHARS + '+$').test(this.data);
|
||||
}
|
||||
}]);
|
||||
|
||||
return CODE128A;
|
||||
}(_CODE3.default);
|
||||
|
||||
exports.default = CODE128A;
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _CODE2 = require('./CODE128.js');
|
||||
|
||||
var _CODE3 = _interopRequireDefault(_CODE2);
|
||||
|
||||
var _constants = require('./constants');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var CODE128B = function (_CODE) {
|
||||
_inherits(CODE128B, _CODE);
|
||||
|
||||
function CODE128B(string, options) {
|
||||
_classCallCheck(this, CODE128B);
|
||||
|
||||
return _possibleConstructorReturn(this, (CODE128B.__proto__ || Object.getPrototypeOf(CODE128B)).call(this, _constants.B_START_CHAR + string, options));
|
||||
}
|
||||
|
||||
_createClass(CODE128B, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return new RegExp('^' + _constants.B_CHARS + '+$').test(this.data);
|
||||
}
|
||||
}]);
|
||||
|
||||
return CODE128B;
|
||||
}(_CODE3.default);
|
||||
|
||||
exports.default = CODE128B;
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _CODE2 = require('./CODE128.js');
|
||||
|
||||
var _CODE3 = _interopRequireDefault(_CODE2);
|
||||
|
||||
var _constants = require('./constants');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var CODE128C = function (_CODE) {
|
||||
_inherits(CODE128C, _CODE);
|
||||
|
||||
function CODE128C(string, options) {
|
||||
_classCallCheck(this, CODE128C);
|
||||
|
||||
return _possibleConstructorReturn(this, (CODE128C.__proto__ || Object.getPrototypeOf(CODE128C)).call(this, _constants.C_START_CHAR + string, options));
|
||||
}
|
||||
|
||||
_createClass(CODE128C, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return new RegExp('^' + _constants.C_CHARS + '+$').test(this.data);
|
||||
}
|
||||
}]);
|
||||
|
||||
return CODE128C;
|
||||
}(_CODE3.default);
|
||||
|
||||
exports.default = CODE128C;
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _CODE2 = require('./CODE128');
|
||||
|
||||
var _CODE3 = _interopRequireDefault(_CODE2);
|
||||
|
||||
var _auto = require('./auto');
|
||||
|
||||
var _auto2 = _interopRequireDefault(_auto);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var CODE128AUTO = function (_CODE) {
|
||||
_inherits(CODE128AUTO, _CODE);
|
||||
|
||||
function CODE128AUTO(data, options) {
|
||||
_classCallCheck(this, CODE128AUTO);
|
||||
|
||||
// ASCII value ranges 0-127, 200-211
|
||||
if (/^[\x00-\x7F\xC8-\xD3]+$/.test(data)) {
|
||||
var _this = _possibleConstructorReturn(this, (CODE128AUTO.__proto__ || Object.getPrototypeOf(CODE128AUTO)).call(this, (0, _auto2.default)(data), options));
|
||||
} else {
|
||||
var _this = _possibleConstructorReturn(this, (CODE128AUTO.__proto__ || Object.getPrototypeOf(CODE128AUTO)).call(this, data, options));
|
||||
}
|
||||
return _possibleConstructorReturn(_this);
|
||||
}
|
||||
|
||||
return CODE128AUTO;
|
||||
}(_CODE3.default);
|
||||
|
||||
exports.default = CODE128AUTO;
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _constants = require('./constants');
|
||||
|
||||
// Match Set functions
|
||||
var matchSetALength = function matchSetALength(string) {
|
||||
return string.match(new RegExp('^' + _constants.A_CHARS + '*'))[0].length;
|
||||
};
|
||||
var matchSetBLength = function matchSetBLength(string) {
|
||||
return string.match(new RegExp('^' + _constants.B_CHARS + '*'))[0].length;
|
||||
};
|
||||
var matchSetC = function matchSetC(string) {
|
||||
return string.match(new RegExp('^' + _constants.C_CHARS + '*'))[0];
|
||||
};
|
||||
|
||||
// CODE128A or CODE128B
|
||||
function autoSelectFromAB(string, isA) {
|
||||
var ranges = isA ? _constants.A_CHARS : _constants.B_CHARS;
|
||||
var untilC = string.match(new RegExp('^(' + ranges + '+?)(([0-9]{2}){2,})([^0-9]|$)'));
|
||||
|
||||
if (untilC) {
|
||||
return untilC[1] + String.fromCharCode(204) + autoSelectFromC(string.substring(untilC[1].length));
|
||||
}
|
||||
|
||||
var chars = string.match(new RegExp('^' + ranges + '+'))[0];
|
||||
|
||||
if (chars.length === string.length) {
|
||||
return string;
|
||||
}
|
||||
|
||||
return chars + String.fromCharCode(isA ? 205 : 206) + autoSelectFromAB(string.substring(chars.length), !isA);
|
||||
}
|
||||
|
||||
// CODE128C
|
||||
function autoSelectFromC(string) {
|
||||
var cMatch = matchSetC(string);
|
||||
var length = cMatch.length;
|
||||
|
||||
if (length === string.length) {
|
||||
return string;
|
||||
}
|
||||
|
||||
string = string.substring(length);
|
||||
|
||||
// Select A/B depending on the longest match
|
||||
var isA = matchSetALength(string) >= matchSetBLength(string);
|
||||
return cMatch + String.fromCharCode(isA ? 206 : 205) + autoSelectFromAB(string, isA);
|
||||
}
|
||||
|
||||
// Detect Code Set (A, B or C) and format the string
|
||||
|
||||
exports.default = function (string) {
|
||||
var newString = void 0;
|
||||
var cLength = matchSetC(string).length;
|
||||
|
||||
// Select 128C if the string start with enough digits
|
||||
if (cLength >= 2) {
|
||||
newString = _constants.C_START_CHAR + autoSelectFromC(string);
|
||||
} else {
|
||||
// Select A/B depending on the longest match
|
||||
var isA = matchSetALength(string) > matchSetBLength(string);
|
||||
newString = (isA ? _constants.A_START_CHAR : _constants.B_START_CHAR) + autoSelectFromAB(string, isA);
|
||||
}
|
||||
|
||||
return newString.replace(/[\xCD\xCE]([^])[\xCD\xCE]/, // Any sequence between 205 and 206 characters
|
||||
function (match, char) {
|
||||
return String.fromCharCode(203) + char;
|
||||
});
|
||||
};
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _SET_BY_CODE;
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
// constants for internal usage
|
||||
var SET_A = exports.SET_A = 0;
|
||||
var SET_B = exports.SET_B = 1;
|
||||
var SET_C = exports.SET_C = 2;
|
||||
|
||||
// Special characters
|
||||
var SHIFT = exports.SHIFT = 98;
|
||||
var START_A = exports.START_A = 103;
|
||||
var START_B = exports.START_B = 104;
|
||||
var START_C = exports.START_C = 105;
|
||||
var MODULO = exports.MODULO = 103;
|
||||
var STOP = exports.STOP = 106;
|
||||
var FNC1 = exports.FNC1 = 207;
|
||||
|
||||
// Get set by start code
|
||||
var SET_BY_CODE = exports.SET_BY_CODE = (_SET_BY_CODE = {}, _defineProperty(_SET_BY_CODE, START_A, SET_A), _defineProperty(_SET_BY_CODE, START_B, SET_B), _defineProperty(_SET_BY_CODE, START_C, SET_C), _SET_BY_CODE);
|
||||
|
||||
// Get next set by code
|
||||
var SWAP = exports.SWAP = {
|
||||
101: SET_A,
|
||||
100: SET_B,
|
||||
99: SET_C
|
||||
};
|
||||
|
||||
var A_START_CHAR = exports.A_START_CHAR = String.fromCharCode(208); // START_A + 105
|
||||
var B_START_CHAR = exports.B_START_CHAR = String.fromCharCode(209); // START_B + 105
|
||||
var C_START_CHAR = exports.C_START_CHAR = String.fromCharCode(210); // START_C + 105
|
||||
|
||||
// 128A (Code Set A)
|
||||
// ASCII characters 00 to 95 (0–9, A–Z and control codes), special characters, and FNC 1–4
|
||||
var A_CHARS = exports.A_CHARS = "[\x00-\x5F\xC8-\xCF]";
|
||||
|
||||
// 128B (Code Set B)
|
||||
// ASCII characters 32 to 127 (0–9, A–Z, a–z), special characters, and FNC 1–4
|
||||
var B_CHARS = exports.B_CHARS = "[\x20-\x7F\xC8-\xCF]";
|
||||
|
||||
// 128C (Code Set C)
|
||||
// 00–99 (encodes two digits with a single code point) and FNC1
|
||||
var C_CHARS = exports.C_CHARS = "(\xCF*[0-9]{2}\xCF*)";
|
||||
|
||||
// CODE128 includes 107 symbols:
|
||||
// 103 data symbols, 3 start symbols (A, B and C), and 1 stop symbol (the last one)
|
||||
// Each symbol consist of three black bars (1) and three white spaces (0).
|
||||
var BARS = exports.BARS = [11011001100, 11001101100, 11001100110, 10010011000, 10010001100, 10001001100, 10011001000, 10011000100, 10001100100, 11001001000, 11001000100, 11000100100, 10110011100, 10011011100, 10011001110, 10111001100, 10011101100, 10011100110, 11001110010, 11001011100, 11001001110, 11011100100, 11001110100, 11101101110, 11101001100, 11100101100, 11100100110, 11101100100, 11100110100, 11100110010, 11011011000, 11011000110, 11000110110, 10100011000, 10001011000, 10001000110, 10110001000, 10001101000, 10001100010, 11010001000, 11000101000, 11000100010, 10110111000, 10110001110, 10001101110, 10111011000, 10111000110, 10001110110, 11101110110, 11010001110, 11000101110, 11011101000, 11011100010, 11011101110, 11101011000, 11101000110, 11100010110, 11101101000, 11101100010, 11100011010, 11101111010, 11001000010, 11110001010, 10100110000, 10100001100, 10010110000, 10010000110, 10000101100, 10000100110, 10110010000, 10110000100, 10011010000, 10011000010, 10000110100, 10000110010, 11000010010, 11001010000, 11110111010, 11000010100, 10001111010, 10100111100, 10010111100, 10010011110, 10111100100, 10011110100, 10011110010, 11110100100, 11110010100, 11110010010, 11011011110, 11011110110, 11110110110, 10101111000, 10100011110, 10001011110, 10111101000, 10111100010, 11110101000, 11110100010, 10111011110, 10111101110, 11101011110, 11110101110, 11010000100, 11010010000, 11010011100, 1100011101011];
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.CODE128C = exports.CODE128B = exports.CODE128A = exports.CODE128 = undefined;
|
||||
|
||||
var _CODE128_AUTO = require('./CODE128_AUTO.js');
|
||||
|
||||
var _CODE128_AUTO2 = _interopRequireDefault(_CODE128_AUTO);
|
||||
|
||||
var _CODE128A = require('./CODE128A.js');
|
||||
|
||||
var _CODE128A2 = _interopRequireDefault(_CODE128A);
|
||||
|
||||
var _CODE128B = require('./CODE128B.js');
|
||||
|
||||
var _CODE128B2 = _interopRequireDefault(_CODE128B);
|
||||
|
||||
var _CODE128C = require('./CODE128C.js');
|
||||
|
||||
var _CODE128C2 = _interopRequireDefault(_CODE128C);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
exports.CODE128 = _CODE128_AUTO2.default;
|
||||
exports.CODE128A = _CODE128A2.default;
|
||||
exports.CODE128B = _CODE128B2.default;
|
||||
exports.CODE128C = _CODE128C2.default;
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.CODE39 = undefined;
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _Barcode2 = require("../Barcode.js");
|
||||
|
||||
var _Barcode3 = _interopRequireDefault(_Barcode2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
|
||||
// https://en.wikipedia.org/wiki/Code_39#Encoding
|
||||
|
||||
var CODE39 = function (_Barcode) {
|
||||
_inherits(CODE39, _Barcode);
|
||||
|
||||
function CODE39(data, options) {
|
||||
_classCallCheck(this, CODE39);
|
||||
|
||||
data = data.toUpperCase();
|
||||
|
||||
// Calculate mod43 checksum if enabled
|
||||
if (options.mod43) {
|
||||
data += getCharacter(mod43checksum(data));
|
||||
}
|
||||
|
||||
return _possibleConstructorReturn(this, (CODE39.__proto__ || Object.getPrototypeOf(CODE39)).call(this, data, options));
|
||||
}
|
||||
|
||||
_createClass(CODE39, [{
|
||||
key: "encode",
|
||||
value: function encode() {
|
||||
// First character is always a *
|
||||
var result = getEncoding("*");
|
||||
|
||||
// Take every character and add the binary representation to the result
|
||||
for (var i = 0; i < this.data.length; i++) {
|
||||
result += getEncoding(this.data[i]) + "0";
|
||||
}
|
||||
|
||||
// Last character is always a *
|
||||
result += getEncoding("*");
|
||||
return {
|
||||
data: result,
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "valid",
|
||||
value: function valid() {
|
||||
return this.data.search(/^[0-9A-Z\-\.\ \$\/\+\%]+$/) !== -1;
|
||||
}
|
||||
}]);
|
||||
|
||||
return CODE39;
|
||||
}(_Barcode3.default);
|
||||
|
||||
// All characters. The position in the array is the (checksum) value
|
||||
|
||||
|
||||
var characters = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "-", ".", " ", "$", "/", "+", "%", "*"];
|
||||
|
||||
// The decimal representation of the characters, is converted to the
|
||||
// corresponding binary with the getEncoding function
|
||||
var encodings = [20957, 29783, 23639, 30485, 20951, 29813, 23669, 20855, 29789, 23645, 29975, 23831, 30533, 22295, 30149, 24005, 21623, 29981, 23837, 22301, 30023, 23879, 30545, 22343, 30161, 24017, 21959, 30065, 23921, 22385, 29015, 18263, 29141, 17879, 29045, 18293, 17783, 29021, 18269, 17477, 17489, 17681, 20753, 35770];
|
||||
|
||||
// Get the binary representation of a character by converting the encodings
|
||||
// from decimal to binary
|
||||
function getEncoding(character) {
|
||||
return getBinary(characterValue(character));
|
||||
}
|
||||
|
||||
function getBinary(characterValue) {
|
||||
return encodings[characterValue].toString(2);
|
||||
}
|
||||
|
||||
function getCharacter(characterValue) {
|
||||
return characters[characterValue];
|
||||
}
|
||||
|
||||
function characterValue(character) {
|
||||
return characters.indexOf(character);
|
||||
}
|
||||
|
||||
function mod43checksum(data) {
|
||||
var checksum = 0;
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
checksum += characterValue(data[i]);
|
||||
}
|
||||
|
||||
checksum = checksum % 43;
|
||||
return checksum;
|
||||
}
|
||||
|
||||
exports.CODE39 = CODE39;
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _constants = require('./constants');
|
||||
|
||||
var _encoder = require('./encoder');
|
||||
|
||||
var _encoder2 = _interopRequireDefault(_encoder);
|
||||
|
||||
var _Barcode2 = require('../Barcode');
|
||||
|
||||
var _Barcode3 = _interopRequireDefault(_Barcode2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
// Base class for EAN8 & EAN13
|
||||
var EAN = function (_Barcode) {
|
||||
_inherits(EAN, _Barcode);
|
||||
|
||||
function EAN(data, options) {
|
||||
_classCallCheck(this, EAN);
|
||||
|
||||
// Make sure the font is not bigger than the space between the guard bars
|
||||
var _this = _possibleConstructorReturn(this, (EAN.__proto__ || Object.getPrototypeOf(EAN)).call(this, data, options));
|
||||
|
||||
_this.fontSize = !options.flat && options.fontSize > options.width * 10 ? options.width * 10 : options.fontSize;
|
||||
|
||||
// Make the guard bars go down half the way of the text
|
||||
_this.guardHeight = options.height + _this.fontSize / 2 + options.textMargin;
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(EAN, [{
|
||||
key: 'encode',
|
||||
value: function encode() {
|
||||
return this.options.flat ? this.encodeFlat() : this.encodeGuarded();
|
||||
}
|
||||
}, {
|
||||
key: 'leftText',
|
||||
value: function leftText(from, to) {
|
||||
return this.text.substr(from, to);
|
||||
}
|
||||
}, {
|
||||
key: 'leftEncode',
|
||||
value: function leftEncode(data, structure) {
|
||||
return (0, _encoder2.default)(data, structure);
|
||||
}
|
||||
}, {
|
||||
key: 'rightText',
|
||||
value: function rightText(from, to) {
|
||||
return this.text.substr(from, to);
|
||||
}
|
||||
}, {
|
||||
key: 'rightEncode',
|
||||
value: function rightEncode(data, structure) {
|
||||
return (0, _encoder2.default)(data, structure);
|
||||
}
|
||||
}, {
|
||||
key: 'encodeGuarded',
|
||||
value: function encodeGuarded() {
|
||||
var textOptions = { fontSize: this.fontSize };
|
||||
var guardOptions = { height: this.guardHeight };
|
||||
|
||||
return [{ data: _constants.SIDE_BIN, options: guardOptions }, { data: this.leftEncode(), text: this.leftText(), options: textOptions }, { data: _constants.MIDDLE_BIN, options: guardOptions }, { data: this.rightEncode(), text: this.rightText(), options: textOptions }, { data: _constants.SIDE_BIN, options: guardOptions }];
|
||||
}
|
||||
}, {
|
||||
key: 'encodeFlat',
|
||||
value: function encodeFlat() {
|
||||
var data = [_constants.SIDE_BIN, this.leftEncode(), _constants.MIDDLE_BIN, this.rightEncode(), _constants.SIDE_BIN];
|
||||
|
||||
return {
|
||||
data: data.join(''),
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
}]);
|
||||
|
||||
return EAN;
|
||||
}(_Barcode3.default);
|
||||
|
||||
exports.default = EAN;
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
|
||||
|
||||
var _constants = require('./constants');
|
||||
|
||||
var _EAN2 = require('./EAN');
|
||||
|
||||
var _EAN3 = _interopRequireDefault(_EAN2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
|
||||
// https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Binary_encoding_of_data_digits_into_EAN-13_barcode
|
||||
|
||||
// Calculate the checksum digit
|
||||
// https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Calculation_of_checksum_digit
|
||||
var checksum = function checksum(number) {
|
||||
var res = number.substr(0, 12).split('').map(function (n) {
|
||||
return +n;
|
||||
}).reduce(function (sum, a, idx) {
|
||||
return idx % 2 ? sum + a * 3 : sum + a;
|
||||
}, 0);
|
||||
|
||||
return (10 - res % 10) % 10;
|
||||
};
|
||||
|
||||
var EAN13 = function (_EAN) {
|
||||
_inherits(EAN13, _EAN);
|
||||
|
||||
function EAN13(data, options) {
|
||||
_classCallCheck(this, EAN13);
|
||||
|
||||
// Add checksum if it does not exist
|
||||
if (data.search(/^[0-9]{12}$/) !== -1) {
|
||||
data += checksum(data);
|
||||
}
|
||||
|
||||
// Adds a last character to the end of the barcode
|
||||
var _this = _possibleConstructorReturn(this, (EAN13.__proto__ || Object.getPrototypeOf(EAN13)).call(this, data, options));
|
||||
|
||||
_this.lastChar = options.lastChar;
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(EAN13, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return this.data.search(/^[0-9]{13}$/) !== -1 && +this.data[12] === checksum(this.data);
|
||||
}
|
||||
}, {
|
||||
key: 'leftText',
|
||||
value: function leftText() {
|
||||
return _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'leftText', this).call(this, 1, 6);
|
||||
}
|
||||
}, {
|
||||
key: 'leftEncode',
|
||||
value: function leftEncode() {
|
||||
var data = this.data.substr(1, 6);
|
||||
var structure = _constants.EAN13_STRUCTURE[this.data[0]];
|
||||
return _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'leftEncode', this).call(this, data, structure);
|
||||
}
|
||||
}, {
|
||||
key: 'rightText',
|
||||
value: function rightText() {
|
||||
return _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'rightText', this).call(this, 7, 6);
|
||||
}
|
||||
}, {
|
||||
key: 'rightEncode',
|
||||
value: function rightEncode() {
|
||||
var data = this.data.substr(7, 6);
|
||||
return _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'rightEncode', this).call(this, data, 'RRRRRR');
|
||||
}
|
||||
|
||||
// The "standard" way of printing EAN13 barcodes with guard bars
|
||||
|
||||
}, {
|
||||
key: 'encodeGuarded',
|
||||
value: function encodeGuarded() {
|
||||
var data = _get(EAN13.prototype.__proto__ || Object.getPrototypeOf(EAN13.prototype), 'encodeGuarded', this).call(this);
|
||||
|
||||
// Extend data with left digit & last character
|
||||
if (this.options.displayValue) {
|
||||
data.unshift({
|
||||
data: '000000000000',
|
||||
text: this.text.substr(0, 1),
|
||||
options: { textAlign: 'left', fontSize: this.fontSize }
|
||||
});
|
||||
|
||||
if (this.options.lastChar) {
|
||||
data.push({
|
||||
data: '00'
|
||||
});
|
||||
data.push({
|
||||
data: '00000',
|
||||
text: this.options.lastChar,
|
||||
options: { fontSize: this.fontSize }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}]);
|
||||
|
||||
return EAN13;
|
||||
}(_EAN3.default);
|
||||
|
||||
exports.default = EAN13;
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _constants = require('./constants');
|
||||
|
||||
var _encoder = require('./encoder');
|
||||
|
||||
var _encoder2 = _interopRequireDefault(_encoder);
|
||||
|
||||
var _Barcode2 = require('../Barcode');
|
||||
|
||||
var _Barcode3 = _interopRequireDefault(_Barcode2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
|
||||
// https://en.wikipedia.org/wiki/EAN_2#Encoding
|
||||
|
||||
var EAN2 = function (_Barcode) {
|
||||
_inherits(EAN2, _Barcode);
|
||||
|
||||
function EAN2(data, options) {
|
||||
_classCallCheck(this, EAN2);
|
||||
|
||||
return _possibleConstructorReturn(this, (EAN2.__proto__ || Object.getPrototypeOf(EAN2)).call(this, data, options));
|
||||
}
|
||||
|
||||
_createClass(EAN2, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return this.data.search(/^[0-9]{2}$/) !== -1;
|
||||
}
|
||||
}, {
|
||||
key: 'encode',
|
||||
value: function encode() {
|
||||
// Choose the structure based on the number mod 4
|
||||
var structure = _constants.EAN2_STRUCTURE[parseInt(this.data) % 4];
|
||||
return {
|
||||
// Start bits + Encode the two digits with 01 in between
|
||||
data: '1011' + (0, _encoder2.default)(this.data, structure, '01'),
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
}]);
|
||||
|
||||
return EAN2;
|
||||
}(_Barcode3.default);
|
||||
|
||||
exports.default = EAN2;
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _constants = require('./constants');
|
||||
|
||||
var _encoder = require('./encoder');
|
||||
|
||||
var _encoder2 = _interopRequireDefault(_encoder);
|
||||
|
||||
var _Barcode2 = require('../Barcode');
|
||||
|
||||
var _Barcode3 = _interopRequireDefault(_Barcode2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
|
||||
// https://en.wikipedia.org/wiki/EAN_5#Encoding
|
||||
|
||||
var checksum = function checksum(data) {
|
||||
var result = data.split('').map(function (n) {
|
||||
return +n;
|
||||
}).reduce(function (sum, a, idx) {
|
||||
return idx % 2 ? sum + a * 9 : sum + a * 3;
|
||||
}, 0);
|
||||
return result % 10;
|
||||
};
|
||||
|
||||
var EAN5 = function (_Barcode) {
|
||||
_inherits(EAN5, _Barcode);
|
||||
|
||||
function EAN5(data, options) {
|
||||
_classCallCheck(this, EAN5);
|
||||
|
||||
return _possibleConstructorReturn(this, (EAN5.__proto__ || Object.getPrototypeOf(EAN5)).call(this, data, options));
|
||||
}
|
||||
|
||||
_createClass(EAN5, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return this.data.search(/^[0-9]{5}$/) !== -1;
|
||||
}
|
||||
}, {
|
||||
key: 'encode',
|
||||
value: function encode() {
|
||||
var structure = _constants.EAN5_STRUCTURE[checksum(this.data)];
|
||||
return {
|
||||
data: '1011' + (0, _encoder2.default)(this.data, structure, '01'),
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
}]);
|
||||
|
||||
return EAN5;
|
||||
}(_Barcode3.default);
|
||||
|
||||
exports.default = EAN5;
|
||||
|
|
@ -0,0 +1,81 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
|
||||
|
||||
var _EAN2 = require('./EAN');
|
||||
|
||||
var _EAN3 = _interopRequireDefault(_EAN2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
|
||||
// http://www.barcodeisland.com/ean8.phtml
|
||||
|
||||
// Calculate the checksum digit
|
||||
var checksum = function checksum(number) {
|
||||
var res = number.substr(0, 7).split('').map(function (n) {
|
||||
return +n;
|
||||
}).reduce(function (sum, a, idx) {
|
||||
return idx % 2 ? sum + a : sum + a * 3;
|
||||
}, 0);
|
||||
|
||||
return (10 - res % 10) % 10;
|
||||
};
|
||||
|
||||
var EAN8 = function (_EAN) {
|
||||
_inherits(EAN8, _EAN);
|
||||
|
||||
function EAN8(data, options) {
|
||||
_classCallCheck(this, EAN8);
|
||||
|
||||
// Add checksum if it does not exist
|
||||
if (data.search(/^[0-9]{7}$/) !== -1) {
|
||||
data += checksum(data);
|
||||
}
|
||||
|
||||
return _possibleConstructorReturn(this, (EAN8.__proto__ || Object.getPrototypeOf(EAN8)).call(this, data, options));
|
||||
}
|
||||
|
||||
_createClass(EAN8, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return this.data.search(/^[0-9]{8}$/) !== -1 && +this.data[7] === checksum(this.data);
|
||||
}
|
||||
}, {
|
||||
key: 'leftText',
|
||||
value: function leftText() {
|
||||
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'leftText', this).call(this, 0, 4);
|
||||
}
|
||||
}, {
|
||||
key: 'leftEncode',
|
||||
value: function leftEncode() {
|
||||
var data = this.data.substr(0, 4);
|
||||
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'leftEncode', this).call(this, data, 'LLLL');
|
||||
}
|
||||
}, {
|
||||
key: 'rightText',
|
||||
value: function rightText() {
|
||||
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'rightText', this).call(this, 4, 4);
|
||||
}
|
||||
}, {
|
||||
key: 'rightEncode',
|
||||
value: function rightEncode() {
|
||||
var data = this.data.substr(4, 4);
|
||||
return _get(EAN8.prototype.__proto__ || Object.getPrototypeOf(EAN8.prototype), 'rightEncode', this).call(this, data, 'RRRR');
|
||||
}
|
||||
}]);
|
||||
|
||||
return EAN8;
|
||||
}(_EAN3.default);
|
||||
|
||||
exports.default = EAN8;
|
||||
|
|
@ -0,0 +1,165 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
exports.checksum = checksum;
|
||||
|
||||
var _encoder = require("./encoder");
|
||||
|
||||
var _encoder2 = _interopRequireDefault(_encoder);
|
||||
|
||||
var _Barcode2 = require("../Barcode.js");
|
||||
|
||||
var _Barcode3 = _interopRequireDefault(_Barcode2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
|
||||
// https://en.wikipedia.org/wiki/Universal_Product_Code#Encoding
|
||||
|
||||
var UPC = function (_Barcode) {
|
||||
_inherits(UPC, _Barcode);
|
||||
|
||||
function UPC(data, options) {
|
||||
_classCallCheck(this, UPC);
|
||||
|
||||
// Add checksum if it does not exist
|
||||
if (data.search(/^[0-9]{11}$/) !== -1) {
|
||||
data += checksum(data);
|
||||
}
|
||||
|
||||
var _this = _possibleConstructorReturn(this, (UPC.__proto__ || Object.getPrototypeOf(UPC)).call(this, data, options));
|
||||
|
||||
_this.displayValue = options.displayValue;
|
||||
|
||||
// Make sure the font is not bigger than the space between the guard bars
|
||||
if (options.fontSize > options.width * 10) {
|
||||
_this.fontSize = options.width * 10;
|
||||
} else {
|
||||
_this.fontSize = options.fontSize;
|
||||
}
|
||||
|
||||
// Make the guard bars go down half the way of the text
|
||||
_this.guardHeight = options.height + _this.fontSize / 2 + options.textMargin;
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(UPC, [{
|
||||
key: "valid",
|
||||
value: function valid() {
|
||||
return this.data.search(/^[0-9]{12}$/) !== -1 && this.data[11] == checksum(this.data);
|
||||
}
|
||||
}, {
|
||||
key: "encode",
|
||||
value: function encode() {
|
||||
if (this.options.flat) {
|
||||
return this.flatEncoding();
|
||||
} else {
|
||||
return this.guardedEncoding();
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "flatEncoding",
|
||||
value: function flatEncoding() {
|
||||
var result = "";
|
||||
|
||||
result += "101";
|
||||
result += (0, _encoder2.default)(this.data.substr(0, 6), "LLLLLL");
|
||||
result += "01010";
|
||||
result += (0, _encoder2.default)(this.data.substr(6, 6), "RRRRRR");
|
||||
result += "101";
|
||||
|
||||
return {
|
||||
data: result,
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "guardedEncoding",
|
||||
value: function guardedEncoding() {
|
||||
var result = [];
|
||||
|
||||
// Add the first digit
|
||||
if (this.displayValue) {
|
||||
result.push({
|
||||
data: "00000000",
|
||||
text: this.text.substr(0, 1),
|
||||
options: { textAlign: "left", fontSize: this.fontSize }
|
||||
});
|
||||
}
|
||||
|
||||
// Add the guard bars
|
||||
result.push({
|
||||
data: "101" + (0, _encoder2.default)(this.data[0], "L"),
|
||||
options: { height: this.guardHeight }
|
||||
});
|
||||
|
||||
// Add the left side
|
||||
result.push({
|
||||
data: (0, _encoder2.default)(this.data.substr(1, 5), "LLLLL"),
|
||||
text: this.text.substr(1, 5),
|
||||
options: { fontSize: this.fontSize }
|
||||
});
|
||||
|
||||
// Add the middle bits
|
||||
result.push({
|
||||
data: "01010",
|
||||
options: { height: this.guardHeight }
|
||||
});
|
||||
|
||||
// Add the right side
|
||||
result.push({
|
||||
data: (0, _encoder2.default)(this.data.substr(6, 5), "RRRRR"),
|
||||
text: this.text.substr(6, 5),
|
||||
options: { fontSize: this.fontSize }
|
||||
});
|
||||
|
||||
// Add the end bits
|
||||
result.push({
|
||||
data: (0, _encoder2.default)(this.data[11], "R") + "101",
|
||||
options: { height: this.guardHeight }
|
||||
});
|
||||
|
||||
// Add the last digit
|
||||
if (this.displayValue) {
|
||||
result.push({
|
||||
data: "00000000",
|
||||
text: this.text.substr(11, 1),
|
||||
options: { textAlign: "right", fontSize: this.fontSize }
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}]);
|
||||
|
||||
return UPC;
|
||||
}(_Barcode3.default);
|
||||
|
||||
// Calulate the checksum digit
|
||||
// https://en.wikipedia.org/wiki/International_Article_Number_(EAN)#Calculation_of_checksum_digit
|
||||
|
||||
|
||||
function checksum(number) {
|
||||
var result = 0;
|
||||
|
||||
var i;
|
||||
for (i = 1; i < 11; i += 2) {
|
||||
result += parseInt(number[i]);
|
||||
}
|
||||
for (i = 0; i < 11; i += 2) {
|
||||
result += parseInt(number[i]) * 3;
|
||||
}
|
||||
|
||||
return (10 - result % 10) % 10;
|
||||
}
|
||||
|
||||
exports.default = UPC;
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _encoder = require('./encoder');
|
||||
|
||||
var _encoder2 = _interopRequireDefault(_encoder);
|
||||
|
||||
var _Barcode2 = require('../Barcode.js');
|
||||
|
||||
var _Barcode3 = _interopRequireDefault(_Barcode2);
|
||||
|
||||
var _UPC = require('./UPC.js');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation:
|
||||
// https://en.wikipedia.org/wiki/Universal_Product_Code#Encoding
|
||||
//
|
||||
// UPC-E documentation:
|
||||
// https://en.wikipedia.org/wiki/Universal_Product_Code#UPC-E
|
||||
|
||||
var EXPANSIONS = ["XX00000XXX", "XX10000XXX", "XX20000XXX", "XXX00000XX", "XXXX00000X", "XXXXX00005", "XXXXX00006", "XXXXX00007", "XXXXX00008", "XXXXX00009"];
|
||||
|
||||
var PARITIES = [["EEEOOO", "OOOEEE"], ["EEOEOO", "OOEOEE"], ["EEOOEO", "OOEEOE"], ["EEOOOE", "OOEEEO"], ["EOEEOO", "OEOOEE"], ["EOOEEO", "OEEOOE"], ["EOOOEE", "OEEEOO"], ["EOEOEO", "OEOEOE"], ["EOEOOE", "OEOEEO"], ["EOOEOE", "OEEOEO"]];
|
||||
|
||||
var UPCE = function (_Barcode) {
|
||||
_inherits(UPCE, _Barcode);
|
||||
|
||||
function UPCE(data, options) {
|
||||
_classCallCheck(this, UPCE);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, (UPCE.__proto__ || Object.getPrototypeOf(UPCE)).call(this, data, options));
|
||||
// Code may be 6 or 8 digits;
|
||||
// A 7 digit code is ambiguous as to whether the extra digit
|
||||
// is a UPC-A check or number system digit.
|
||||
|
||||
|
||||
_this.isValid = false;
|
||||
if (data.search(/^[0-9]{6}$/) !== -1) {
|
||||
_this.middleDigits = data;
|
||||
_this.upcA = expandToUPCA(data, "0");
|
||||
_this.text = options.text || '' + _this.upcA[0] + data + _this.upcA[_this.upcA.length - 1];
|
||||
_this.isValid = true;
|
||||
} else if (data.search(/^[01][0-9]{7}$/) !== -1) {
|
||||
_this.middleDigits = data.substring(1, data.length - 1);
|
||||
_this.upcA = expandToUPCA(_this.middleDigits, data[0]);
|
||||
|
||||
if (_this.upcA[_this.upcA.length - 1] === data[data.length - 1]) {
|
||||
_this.isValid = true;
|
||||
} else {
|
||||
// checksum mismatch
|
||||
return _possibleConstructorReturn(_this);
|
||||
}
|
||||
} else {
|
||||
return _possibleConstructorReturn(_this);
|
||||
}
|
||||
|
||||
_this.displayValue = options.displayValue;
|
||||
|
||||
// Make sure the font is not bigger than the space between the guard bars
|
||||
if (options.fontSize > options.width * 10) {
|
||||
_this.fontSize = options.width * 10;
|
||||
} else {
|
||||
_this.fontSize = options.fontSize;
|
||||
}
|
||||
|
||||
// Make the guard bars go down half the way of the text
|
||||
_this.guardHeight = options.height + _this.fontSize / 2 + options.textMargin;
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(UPCE, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return this.isValid;
|
||||
}
|
||||
}, {
|
||||
key: 'encode',
|
||||
value: function encode() {
|
||||
if (this.options.flat) {
|
||||
return this.flatEncoding();
|
||||
} else {
|
||||
return this.guardedEncoding();
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'flatEncoding',
|
||||
value: function flatEncoding() {
|
||||
var result = "";
|
||||
|
||||
result += "101";
|
||||
result += this.encodeMiddleDigits();
|
||||
result += "010101";
|
||||
|
||||
return {
|
||||
data: result,
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: 'guardedEncoding',
|
||||
value: function guardedEncoding() {
|
||||
var result = [];
|
||||
|
||||
// Add the UPC-A number system digit beneath the quiet zone
|
||||
if (this.displayValue) {
|
||||
result.push({
|
||||
data: "00000000",
|
||||
text: this.text[0],
|
||||
options: { textAlign: "left", fontSize: this.fontSize }
|
||||
});
|
||||
}
|
||||
|
||||
// Add the guard bars
|
||||
result.push({
|
||||
data: "101",
|
||||
options: { height: this.guardHeight }
|
||||
});
|
||||
|
||||
// Add the 6 UPC-E digits
|
||||
result.push({
|
||||
data: this.encodeMiddleDigits(),
|
||||
text: this.text.substring(1, 7),
|
||||
options: { fontSize: this.fontSize }
|
||||
});
|
||||
|
||||
// Add the end bits
|
||||
result.push({
|
||||
data: "010101",
|
||||
options: { height: this.guardHeight }
|
||||
});
|
||||
|
||||
// Add the UPC-A check digit beneath the quiet zone
|
||||
if (this.displayValue) {
|
||||
result.push({
|
||||
data: "00000000",
|
||||
text: this.text[7],
|
||||
options: { textAlign: "right", fontSize: this.fontSize }
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}, {
|
||||
key: 'encodeMiddleDigits',
|
||||
value: function encodeMiddleDigits() {
|
||||
var numberSystem = this.upcA[0];
|
||||
var checkDigit = this.upcA[this.upcA.length - 1];
|
||||
var parity = PARITIES[parseInt(checkDigit)][parseInt(numberSystem)];
|
||||
return (0, _encoder2.default)(this.middleDigits, parity);
|
||||
}
|
||||
}]);
|
||||
|
||||
return UPCE;
|
||||
}(_Barcode3.default);
|
||||
|
||||
function expandToUPCA(middleDigits, numberSystem) {
|
||||
var lastUpcE = parseInt(middleDigits[middleDigits.length - 1]);
|
||||
var expansion = EXPANSIONS[lastUpcE];
|
||||
|
||||
var result = "";
|
||||
var digitIndex = 0;
|
||||
for (var i = 0; i < expansion.length; i++) {
|
||||
var c = expansion[i];
|
||||
if (c === 'X') {
|
||||
result += middleDigits[digitIndex++];
|
||||
} else {
|
||||
result += c;
|
||||
}
|
||||
}
|
||||
|
||||
result = '' + numberSystem + result;
|
||||
return '' + result + (0, _UPC.checksum)(result);
|
||||
}
|
||||
|
||||
exports.default = UPCE;
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
// Standard start end and middle bits
|
||||
var SIDE_BIN = exports.SIDE_BIN = '101';
|
||||
var MIDDLE_BIN = exports.MIDDLE_BIN = '01010';
|
||||
|
||||
var BINARIES = exports.BINARIES = {
|
||||
'L': [// The L (left) type of encoding
|
||||
'0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111', '0001011'],
|
||||
'G': [// The G type of encoding
|
||||
'0100111', '0110011', '0011011', '0100001', '0011101', '0111001', '0000101', '0010001', '0001001', '0010111'],
|
||||
'R': [// The R (right) type of encoding
|
||||
'1110010', '1100110', '1101100', '1000010', '1011100', '1001110', '1010000', '1000100', '1001000', '1110100'],
|
||||
'O': [// The O (odd) encoding for UPC-E
|
||||
'0001101', '0011001', '0010011', '0111101', '0100011', '0110001', '0101111', '0111011', '0110111', '0001011'],
|
||||
'E': [// The E (even) encoding for UPC-E
|
||||
'0100111', '0110011', '0011011', '0100001', '0011101', '0111001', '0000101', '0010001', '0001001', '0010111']
|
||||
};
|
||||
|
||||
// Define the EAN-2 structure
|
||||
var EAN2_STRUCTURE = exports.EAN2_STRUCTURE = ['LL', 'LG', 'GL', 'GG'];
|
||||
|
||||
// Define the EAN-5 structure
|
||||
var EAN5_STRUCTURE = exports.EAN5_STRUCTURE = ['GGLLL', 'GLGLL', 'GLLGL', 'GLLLG', 'LGGLL', 'LLGGL', 'LLLGG', 'LGLGL', 'LGLLG', 'LLGLG'];
|
||||
|
||||
// Define the EAN-13 structure
|
||||
var EAN13_STRUCTURE = exports.EAN13_STRUCTURE = ['LLLLLL', 'LLGLGG', 'LLGGLG', 'LLGGGL', 'LGLLGG', 'LGGLLG', 'LGGGLL', 'LGLGLG', 'LGLGGL', 'LGGLGL'];
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _constants = require('./constants');
|
||||
|
||||
// Encode data string
|
||||
var encode = function encode(data, structure, separator) {
|
||||
var encoded = data.split('').map(function (val, idx) {
|
||||
return _constants.BINARIES[structure[idx]];
|
||||
}).map(function (val, idx) {
|
||||
return val ? val[data[idx]] : '';
|
||||
});
|
||||
|
||||
if (separator) {
|
||||
var last = data.length - 1;
|
||||
encoded = encoded.map(function (val, idx) {
|
||||
return idx < last ? val + separator : val;
|
||||
});
|
||||
}
|
||||
|
||||
return encoded.join('');
|
||||
};
|
||||
|
||||
exports.default = encode;
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.UPCE = exports.UPC = exports.EAN2 = exports.EAN5 = exports.EAN8 = exports.EAN13 = undefined;
|
||||
|
||||
var _EAN = require('./EAN13.js');
|
||||
|
||||
var _EAN2 = _interopRequireDefault(_EAN);
|
||||
|
||||
var _EAN3 = require('./EAN8.js');
|
||||
|
||||
var _EAN4 = _interopRequireDefault(_EAN3);
|
||||
|
||||
var _EAN5 = require('./EAN5.js');
|
||||
|
||||
var _EAN6 = _interopRequireDefault(_EAN5);
|
||||
|
||||
var _EAN7 = require('./EAN2.js');
|
||||
|
||||
var _EAN8 = _interopRequireDefault(_EAN7);
|
||||
|
||||
var _UPC = require('./UPC.js');
|
||||
|
||||
var _UPC2 = _interopRequireDefault(_UPC);
|
||||
|
||||
var _UPCE = require('./UPCE.js');
|
||||
|
||||
var _UPCE2 = _interopRequireDefault(_UPCE);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
exports.EAN13 = _EAN2.default;
|
||||
exports.EAN8 = _EAN4.default;
|
||||
exports.EAN5 = _EAN6.default;
|
||||
exports.EAN2 = _EAN8.default;
|
||||
exports.UPC = _UPC2.default;
|
||||
exports.UPCE = _UPCE2.default;
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.GenericBarcode = undefined;
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _Barcode2 = require("../Barcode.js");
|
||||
|
||||
var _Barcode3 = _interopRequireDefault(_Barcode2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var GenericBarcode = function (_Barcode) {
|
||||
_inherits(GenericBarcode, _Barcode);
|
||||
|
||||
function GenericBarcode(data, options) {
|
||||
_classCallCheck(this, GenericBarcode);
|
||||
|
||||
return _possibleConstructorReturn(this, (GenericBarcode.__proto__ || Object.getPrototypeOf(GenericBarcode)).call(this, data, options)); // Sets this.data and this.text
|
||||
}
|
||||
|
||||
// Return the corresponding binary numbers for the data provided
|
||||
|
||||
|
||||
_createClass(GenericBarcode, [{
|
||||
key: "encode",
|
||||
value: function encode() {
|
||||
return {
|
||||
data: "10101010101010101010101010101010101010101",
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
|
||||
// Resturn true/false if the string provided is valid for this encoder
|
||||
|
||||
}, {
|
||||
key: "valid",
|
||||
value: function valid() {
|
||||
return true;
|
||||
}
|
||||
}]);
|
||||
|
||||
return GenericBarcode;
|
||||
}(_Barcode3.default);
|
||||
|
||||
exports.GenericBarcode = GenericBarcode;
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _constants = require('./constants');
|
||||
|
||||
var _Barcode2 = require('../Barcode');
|
||||
|
||||
var _Barcode3 = _interopRequireDefault(_Barcode2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var ITF = function (_Barcode) {
|
||||
_inherits(ITF, _Barcode);
|
||||
|
||||
function ITF() {
|
||||
_classCallCheck(this, ITF);
|
||||
|
||||
return _possibleConstructorReturn(this, (ITF.__proto__ || Object.getPrototypeOf(ITF)).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(ITF, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return this.data.search(/^([0-9]{2})+$/) !== -1;
|
||||
}
|
||||
}, {
|
||||
key: 'encode',
|
||||
value: function encode() {
|
||||
var _this2 = this;
|
||||
|
||||
// Calculate all the digit pairs
|
||||
var encoded = this.data.match(/.{2}/g).map(function (pair) {
|
||||
return _this2.encodePair(pair);
|
||||
}).join('');
|
||||
|
||||
return {
|
||||
data: _constants.START_BIN + encoded + _constants.END_BIN,
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
|
||||
// Calculate the data of a number pair
|
||||
|
||||
}, {
|
||||
key: 'encodePair',
|
||||
value: function encodePair(pair) {
|
||||
var second = _constants.BINARIES[pair[1]];
|
||||
|
||||
return _constants.BINARIES[pair[0]].split('').map(function (first, idx) {
|
||||
return (first === '1' ? '111' : '1') + (second[idx] === '1' ? '000' : '0');
|
||||
}).join('');
|
||||
}
|
||||
}]);
|
||||
|
||||
return ITF;
|
||||
}(_Barcode3.default);
|
||||
|
||||
exports.default = ITF;
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _ITF2 = require('./ITF');
|
||||
|
||||
var _ITF3 = _interopRequireDefault(_ITF2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
// Calculate the checksum digit
|
||||
var checksum = function checksum(data) {
|
||||
var res = data.substr(0, 13).split('').map(function (num) {
|
||||
return parseInt(num, 10);
|
||||
}).reduce(function (sum, n, idx) {
|
||||
return sum + n * (3 - idx % 2 * 2);
|
||||
}, 0);
|
||||
|
||||
return Math.ceil(res / 10) * 10 - res;
|
||||
};
|
||||
|
||||
var ITF14 = function (_ITF) {
|
||||
_inherits(ITF14, _ITF);
|
||||
|
||||
function ITF14(data, options) {
|
||||
_classCallCheck(this, ITF14);
|
||||
|
||||
// Add checksum if it does not exist
|
||||
if (data.search(/^[0-9]{13}$/) !== -1) {
|
||||
data += checksum(data);
|
||||
}
|
||||
return _possibleConstructorReturn(this, (ITF14.__proto__ || Object.getPrototypeOf(ITF14)).call(this, data, options));
|
||||
}
|
||||
|
||||
_createClass(ITF14, [{
|
||||
key: 'valid',
|
||||
value: function valid() {
|
||||
return this.data.search(/^[0-9]{14}$/) !== -1 && +this.data[13] === checksum(this.data);
|
||||
}
|
||||
}]);
|
||||
|
||||
return ITF14;
|
||||
}(_ITF3.default);
|
||||
|
||||
exports.default = ITF14;
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
var START_BIN = exports.START_BIN = '1010';
|
||||
var END_BIN = exports.END_BIN = '11101';
|
||||
|
||||
var BINARIES = exports.BINARIES = ['00110', '10001', '01001', '11000', '00101', '10100', '01100', '00011', '10010', '01010'];
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ITF14 = exports.ITF = undefined;
|
||||
|
||||
var _ITF = require('./ITF');
|
||||
|
||||
var _ITF2 = _interopRequireDefault(_ITF);
|
||||
|
||||
var _ITF3 = require('./ITF14');
|
||||
|
||||
var _ITF4 = _interopRequireDefault(_ITF3);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
exports.ITF = _ITF2.default;
|
||||
exports.ITF14 = _ITF4.default;
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _Barcode2 = require("../Barcode.js");
|
||||
|
||||
var _Barcode3 = _interopRequireDefault(_Barcode2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation
|
||||
// https://en.wikipedia.org/wiki/MSI_Barcode#Character_set_and_binary_lookup
|
||||
|
||||
var MSI = function (_Barcode) {
|
||||
_inherits(MSI, _Barcode);
|
||||
|
||||
function MSI(data, options) {
|
||||
_classCallCheck(this, MSI);
|
||||
|
||||
return _possibleConstructorReturn(this, (MSI.__proto__ || Object.getPrototypeOf(MSI)).call(this, data, options));
|
||||
}
|
||||
|
||||
_createClass(MSI, [{
|
||||
key: "encode",
|
||||
value: function encode() {
|
||||
// Start bits
|
||||
var ret = "110";
|
||||
|
||||
for (var i = 0; i < this.data.length; i++) {
|
||||
// Convert the character to binary (always 4 binary digits)
|
||||
var digit = parseInt(this.data[i]);
|
||||
var bin = digit.toString(2);
|
||||
bin = addZeroes(bin, 4 - bin.length);
|
||||
|
||||
// Add 100 for every zero and 110 for every 1
|
||||
for (var b = 0; b < bin.length; b++) {
|
||||
ret += bin[b] == "0" ? "100" : "110";
|
||||
}
|
||||
}
|
||||
|
||||
// End bits
|
||||
ret += "1001";
|
||||
|
||||
return {
|
||||
data: ret,
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "valid",
|
||||
value: function valid() {
|
||||
return this.data.search(/^[0-9]+$/) !== -1;
|
||||
}
|
||||
}]);
|
||||
|
||||
return MSI;
|
||||
}(_Barcode3.default);
|
||||
|
||||
function addZeroes(number, n) {
|
||||
for (var i = 0; i < n; i++) {
|
||||
number = "0" + number;
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
exports.default = MSI;
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _MSI2 = require('./MSI.js');
|
||||
|
||||
var _MSI3 = _interopRequireDefault(_MSI2);
|
||||
|
||||
var _checksums = require('./checksums.js');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var MSI10 = function (_MSI) {
|
||||
_inherits(MSI10, _MSI);
|
||||
|
||||
function MSI10(data, options) {
|
||||
_classCallCheck(this, MSI10);
|
||||
|
||||
return _possibleConstructorReturn(this, (MSI10.__proto__ || Object.getPrototypeOf(MSI10)).call(this, data + (0, _checksums.mod10)(data), options));
|
||||
}
|
||||
|
||||
return MSI10;
|
||||
}(_MSI3.default);
|
||||
|
||||
exports.default = MSI10;
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _MSI2 = require('./MSI.js');
|
||||
|
||||
var _MSI3 = _interopRequireDefault(_MSI2);
|
||||
|
||||
var _checksums = require('./checksums.js');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var MSI1010 = function (_MSI) {
|
||||
_inherits(MSI1010, _MSI);
|
||||
|
||||
function MSI1010(data, options) {
|
||||
_classCallCheck(this, MSI1010);
|
||||
|
||||
data += (0, _checksums.mod10)(data);
|
||||
data += (0, _checksums.mod10)(data);
|
||||
return _possibleConstructorReturn(this, (MSI1010.__proto__ || Object.getPrototypeOf(MSI1010)).call(this, data, options));
|
||||
}
|
||||
|
||||
return MSI1010;
|
||||
}(_MSI3.default);
|
||||
|
||||
exports.default = MSI1010;
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _MSI2 = require('./MSI.js');
|
||||
|
||||
var _MSI3 = _interopRequireDefault(_MSI2);
|
||||
|
||||
var _checksums = require('./checksums.js');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var MSI11 = function (_MSI) {
|
||||
_inherits(MSI11, _MSI);
|
||||
|
||||
function MSI11(data, options) {
|
||||
_classCallCheck(this, MSI11);
|
||||
|
||||
return _possibleConstructorReturn(this, (MSI11.__proto__ || Object.getPrototypeOf(MSI11)).call(this, data + (0, _checksums.mod11)(data), options));
|
||||
}
|
||||
|
||||
return MSI11;
|
||||
}(_MSI3.default);
|
||||
|
||||
exports.default = MSI11;
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _MSI2 = require('./MSI.js');
|
||||
|
||||
var _MSI3 = _interopRequireDefault(_MSI2);
|
||||
|
||||
var _checksums = require('./checksums.js');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var MSI1110 = function (_MSI) {
|
||||
_inherits(MSI1110, _MSI);
|
||||
|
||||
function MSI1110(data, options) {
|
||||
_classCallCheck(this, MSI1110);
|
||||
|
||||
data += (0, _checksums.mod11)(data);
|
||||
data += (0, _checksums.mod10)(data);
|
||||
return _possibleConstructorReturn(this, (MSI1110.__proto__ || Object.getPrototypeOf(MSI1110)).call(this, data, options));
|
||||
}
|
||||
|
||||
return MSI1110;
|
||||
}(_MSI3.default);
|
||||
|
||||
exports.default = MSI1110;
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.mod10 = mod10;
|
||||
exports.mod11 = mod11;
|
||||
function mod10(number) {
|
||||
var sum = 0;
|
||||
for (var i = 0; i < number.length; i++) {
|
||||
var n = parseInt(number[i]);
|
||||
if ((i + number.length) % 2 === 0) {
|
||||
sum += n;
|
||||
} else {
|
||||
sum += n * 2 % 10 + Math.floor(n * 2 / 10);
|
||||
}
|
||||
}
|
||||
return (10 - sum % 10) % 10;
|
||||
}
|
||||
|
||||
function mod11(number) {
|
||||
var sum = 0;
|
||||
var weights = [2, 3, 4, 5, 6, 7];
|
||||
for (var i = 0; i < number.length; i++) {
|
||||
var n = parseInt(number[number.length - 1 - i]);
|
||||
sum += weights[i % weights.length] * n;
|
||||
}
|
||||
return (11 - sum % 11) % 11;
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.MSI1110 = exports.MSI1010 = exports.MSI11 = exports.MSI10 = exports.MSI = undefined;
|
||||
|
||||
var _MSI = require('./MSI.js');
|
||||
|
||||
var _MSI2 = _interopRequireDefault(_MSI);
|
||||
|
||||
var _MSI3 = require('./MSI10.js');
|
||||
|
||||
var _MSI4 = _interopRequireDefault(_MSI3);
|
||||
|
||||
var _MSI5 = require('./MSI11.js');
|
||||
|
||||
var _MSI6 = _interopRequireDefault(_MSI5);
|
||||
|
||||
var _MSI7 = require('./MSI1010.js');
|
||||
|
||||
var _MSI8 = _interopRequireDefault(_MSI7);
|
||||
|
||||
var _MSI9 = require('./MSI1110.js');
|
||||
|
||||
var _MSI10 = _interopRequireDefault(_MSI9);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
exports.MSI = _MSI2.default;
|
||||
exports.MSI10 = _MSI4.default;
|
||||
exports.MSI11 = _MSI6.default;
|
||||
exports.MSI1010 = _MSI8.default;
|
||||
exports.MSI1110 = _MSI10.default;
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.codabar = undefined;
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _Barcode2 = require("../Barcode.js");
|
||||
|
||||
var _Barcode3 = _interopRequireDefault(_Barcode2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding specification:
|
||||
// http://www.barcodeisland.com/codabar.phtml
|
||||
|
||||
var codabar = function (_Barcode) {
|
||||
_inherits(codabar, _Barcode);
|
||||
|
||||
function codabar(data, options) {
|
||||
_classCallCheck(this, codabar);
|
||||
|
||||
if (data.search(/^[0-9\-\$\:\.\+\/]+$/) === 0) {
|
||||
data = "A" + data + "A";
|
||||
}
|
||||
|
||||
var _this = _possibleConstructorReturn(this, (codabar.__proto__ || Object.getPrototypeOf(codabar)).call(this, data.toUpperCase(), options));
|
||||
|
||||
_this.text = _this.options.text || _this.text.replace(/[A-D]/g, '');
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(codabar, [{
|
||||
key: "valid",
|
||||
value: function valid() {
|
||||
return this.data.search(/^[A-D][0-9\-\$\:\.\+\/]+[A-D]$/) !== -1;
|
||||
}
|
||||
}, {
|
||||
key: "encode",
|
||||
value: function encode() {
|
||||
var result = [];
|
||||
var encodings = this.getEncodings();
|
||||
for (var i = 0; i < this.data.length; i++) {
|
||||
result.push(encodings[this.data.charAt(i)]);
|
||||
// for all characters except the last, append a narrow-space ("0")
|
||||
if (i !== this.data.length - 1) {
|
||||
result.push("0");
|
||||
}
|
||||
}
|
||||
return {
|
||||
text: this.text,
|
||||
data: result.join('')
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "getEncodings",
|
||||
value: function getEncodings() {
|
||||
return {
|
||||
"0": "101010011",
|
||||
"1": "101011001",
|
||||
"2": "101001011",
|
||||
"3": "110010101",
|
||||
"4": "101101001",
|
||||
"5": "110101001",
|
||||
"6": "100101011",
|
||||
"7": "100101101",
|
||||
"8": "100110101",
|
||||
"9": "110100101",
|
||||
"-": "101001101",
|
||||
"$": "101100101",
|
||||
":": "1101011011",
|
||||
"/": "1101101011",
|
||||
".": "1101101101",
|
||||
"+": "101100110011",
|
||||
"A": "1011001001",
|
||||
"B": "1001001011",
|
||||
"C": "1010010011",
|
||||
"D": "1010011001"
|
||||
};
|
||||
}
|
||||
}]);
|
||||
|
||||
return codabar;
|
||||
}(_Barcode3.default);
|
||||
|
||||
exports.codabar = codabar;
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _CODE = require('./CODE39/');
|
||||
|
||||
var _CODE2 = require('./CODE128/');
|
||||
|
||||
var _EAN_UPC = require('./EAN_UPC/');
|
||||
|
||||
var _ITF = require('./ITF/');
|
||||
|
||||
var _MSI = require('./MSI/');
|
||||
|
||||
var _pharmacode = require('./pharmacode/');
|
||||
|
||||
var _codabar = require('./codabar');
|
||||
|
||||
var _GenericBarcode = require('./GenericBarcode/');
|
||||
|
||||
exports.default = {
|
||||
CODE39: _CODE.CODE39,
|
||||
CODE128: _CODE2.CODE128, CODE128A: _CODE2.CODE128A, CODE128B: _CODE2.CODE128B, CODE128C: _CODE2.CODE128C,
|
||||
EAN13: _EAN_UPC.EAN13, EAN8: _EAN_UPC.EAN8, EAN5: _EAN_UPC.EAN5, EAN2: _EAN_UPC.EAN2,
|
||||
UPC: _EAN_UPC.UPC, UPCE: _EAN_UPC.UPCE,
|
||||
ITF14: _ITF.ITF14,
|
||||
ITF: _ITF.ITF,
|
||||
MSI: _MSI.MSI, MSI10: _MSI.MSI10, MSI11: _MSI.MSI11, MSI1010: _MSI.MSI1010, MSI1110: _MSI.MSI1110,
|
||||
PHARMACODE: _pharmacode.pharmacode,
|
||||
CODABAR: _codabar.codabar,
|
||||
GENERICBARCODE: _GenericBarcode.GenericBarcode
|
||||
};
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.pharmacode = undefined;
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
var _Barcode2 = require("../Barcode.js");
|
||||
|
||||
var _Barcode3 = _interopRequireDefault(_Barcode2);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Encoding documentation
|
||||
// http://www.gomaro.ch/ftproot/Laetus_PHARMA-CODE.pdf
|
||||
|
||||
var pharmacode = function (_Barcode) {
|
||||
_inherits(pharmacode, _Barcode);
|
||||
|
||||
function pharmacode(data, options) {
|
||||
_classCallCheck(this, pharmacode);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, (pharmacode.__proto__ || Object.getPrototypeOf(pharmacode)).call(this, data, options));
|
||||
|
||||
_this.number = parseInt(data, 10);
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(pharmacode, [{
|
||||
key: "encode",
|
||||
value: function encode() {
|
||||
var z = this.number;
|
||||
var result = "";
|
||||
|
||||
// http://i.imgur.com/RMm4UDJ.png
|
||||
// (source: http://www.gomaro.ch/ftproot/Laetus_PHARMA-CODE.pdf, page: 34)
|
||||
while (!isNaN(z) && z != 0) {
|
||||
if (z % 2 === 0) {
|
||||
// Even
|
||||
result = "11100" + result;
|
||||
z = (z - 2) / 2;
|
||||
} else {
|
||||
// Odd
|
||||
result = "100" + result;
|
||||
z = (z - 1) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the two last zeroes
|
||||
result = result.slice(0, -2);
|
||||
|
||||
return {
|
||||
data: result,
|
||||
text: this.text
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "valid",
|
||||
value: function valid() {
|
||||
return this.number >= 3 && this.number <= 131070;
|
||||
}
|
||||
}]);
|
||||
|
||||
return pharmacode;
|
||||
}(_Barcode3.default);
|
||||
|
||||
exports.pharmacode = pharmacode;
|
||||
|
|
@ -0,0 +1,212 @@
|
|||
<template xlang="wxml" minapp="mpvue">
|
||||
<view class="tki-barcode">
|
||||
<!-- #ifndef MP-ALIPAY -->
|
||||
<canvas class="tki-barcode-canvas" :canvas-id="cid"
|
||||
:style="{width:canvasWidth+'px',height:canvasHeight+'px'}" />
|
||||
<!-- #endif -->
|
||||
<!-- #ifdef MP-ALIPAY -->
|
||||
<canvas :id="cid" :width="canvasWidth" :height="canvasHeight" class="tki-barcode-canvas" />
|
||||
<!-- #endif -->
|
||||
<image v-show="show" :src="result" :style="{width:canvasWidth+'px',height:canvasHeight+'px'}" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// const barcode = require('./barcode.js');
|
||||
import barCode from "./barcode.js"
|
||||
const opations = {
|
||||
// format: "CODE128",//选择要使用的条形码类型 微信支持的条码类型有 code128\code39\ena13\ean8\upc\itf14\
|
||||
width: 4, //设置条之间的宽度
|
||||
height: 120, //高度
|
||||
displayValue: true, //是否在条形码下方显示文字
|
||||
// text: "1234567890",//覆盖显示的文本
|
||||
textAlign: "center", //设置文本的水平对齐方式
|
||||
textPosition: "bottom", //设置文本的垂直位置
|
||||
textMargin: 0, //设置条形码和文本之间的间距
|
||||
fontSize: 24, //设置文本的大小
|
||||
fontColor: "#000000", //设置文本的颜色
|
||||
lineColor: "#000000", //设置条形码的颜色
|
||||
background: "#FFFFFF", //设置条形码的背景色
|
||||
margin: 0, //设置条形码周围的空白边距
|
||||
marginTop: undefined, //设置条形码周围的上边距
|
||||
marginBottom: undefined, //设置条形码周围的下边距
|
||||
marginLeft: undefined, //设置条形码周围的左边距
|
||||
marginRight: undefined, //设置条形码周围的右边距
|
||||
}
|
||||
export default {
|
||||
name: "tkiBarcode",
|
||||
props: {
|
||||
show: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
cid: {
|
||||
type: String,
|
||||
default: 'tki-barcode-canvas'
|
||||
},
|
||||
unit: {
|
||||
type: String,
|
||||
default: 'upx'
|
||||
},
|
||||
// val: {
|
||||
// type: String,
|
||||
// default: '1234567890128'
|
||||
// },
|
||||
format: {
|
||||
type: String,
|
||||
default: 'CODE128'
|
||||
},
|
||||
opations: {
|
||||
type: Object,
|
||||
default: function() {
|
||||
return {}
|
||||
}
|
||||
},
|
||||
onval: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
loadMake: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
val: '',
|
||||
result: '',
|
||||
canvasWidth: 0,
|
||||
canvasHeight: 0,
|
||||
defaultOpations: Object.assign({}, opations)
|
||||
}
|
||||
},
|
||||
onUnload: function() {},
|
||||
methods: {
|
||||
setval(n) {
|
||||
this.val = n
|
||||
if (!this._empty(n)) {
|
||||
setTimeout(() => {
|
||||
this._makeCode()
|
||||
}, 0);
|
||||
}
|
||||
},
|
||||
_makeCode() {
|
||||
let that = this
|
||||
// 合并参数
|
||||
Object.assign(this.defaultOpations, this.opations)
|
||||
if (that.unit == "upx") {
|
||||
if (that.defaultOpations.width) {
|
||||
that.defaultOpations.width = uni.upx2px(that.defaultOpations.width)
|
||||
}
|
||||
if (that.defaultOpations.height) {
|
||||
that.defaultOpations.height = uni.upx2px(that.defaultOpations.height)
|
||||
}
|
||||
if (that.defaultOpations.fontSize) {
|
||||
that.defaultOpations.fontSize = uni.upx2px(that.defaultOpations.fontSize)
|
||||
}
|
||||
}
|
||||
if (that._empty(that.defaultOpations.text)) {
|
||||
that.defaultOpations.text = that.val
|
||||
}
|
||||
if (that._empty(that.defaultOpations.format)) {
|
||||
that.defaultOpations.format = that.format
|
||||
}
|
||||
// console.log(JSON.stringify(that.defaultOpations))
|
||||
new barCode(that, that.cid, that.defaultOpations,
|
||||
function(res) { // 生成条形码款高回调
|
||||
that.canvasWidth = res.width
|
||||
that.canvasHeight = res.height
|
||||
},
|
||||
function(res) { // 生成条形码的回调
|
||||
// 返回值
|
||||
that._result(res)
|
||||
// 重置默认参数
|
||||
that.defaultOpations = opations
|
||||
},
|
||||
);
|
||||
},
|
||||
_clearCode() {
|
||||
this._result('')
|
||||
},
|
||||
_saveCode() {
|
||||
let that = this;
|
||||
if (this.result != "") {
|
||||
uni.saveImageToPhotosAlbum({
|
||||
filePath: that.result,
|
||||
success: function() {
|
||||
uni.showToast({
|
||||
title: '条形码保存成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
_result(res) {
|
||||
this.result = res;
|
||||
this.$emit('result', res)
|
||||
},
|
||||
_empty(v) {
|
||||
let tp = typeof v,
|
||||
rt = false;
|
||||
if (tp == "number" && String(v) == "") {
|
||||
rt = true
|
||||
} else if (tp == "undefined") {
|
||||
rt = true
|
||||
} else if (tp == "object") {
|
||||
if (JSON.stringify(v) == "{}" || JSON.stringify(v) == "[]" || v == null) rt = true
|
||||
} else if (tp == "string") {
|
||||
if (v == "" || v == "undefined" || v == "null" || v == "{}" || v == "[]") rt = true
|
||||
} else if (tp == "function") {
|
||||
rt = false
|
||||
}
|
||||
return rt
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
val(n, o) {
|
||||
if (this.onval) {
|
||||
if (n != o && !this._empty(n)) {
|
||||
setTimeout(() => {
|
||||
this._makeCode()
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
},
|
||||
opations: {
|
||||
handler(n, o) {
|
||||
if (this.onval) {
|
||||
if (!this._empty(n)) {
|
||||
setTimeout(() => {
|
||||
this._makeCode()
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
mounted: function() {
|
||||
if (this.loadMake) {
|
||||
if (!this._empty(this.val)) {
|
||||
setTimeout(() => {
|
||||
this._makeCode()
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
.tki-barcode {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.tki-barcode-canvas {
|
||||
position: fixed;
|
||||
top: -99999upx;
|
||||
left: -99999upx;
|
||||
z-index: -99999;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
const debug = true;
|
||||
// #ifdef H5
|
||||
const proxyApi = "/api"
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN || MP-ALIPAY
|
||||
const baseUrl = 'https://cashier.sxczgkj.cn/cashierService' // 线上
|
||||
const baseUrlwws = 'wss://cashier.sxczgkj.cn/cashierService' // 线上
|
||||
// const baseUrl = "https://cashierapplet.sxczgkj.cn/cashierService" //测试
|
||||
// const baseUrlwws = 'wss://cashierapplet.sxczgkj.cn/cashierService' // 测试
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
const baseUrl = debug ? proxyApi : 'http://192.168.2.161:9889/cashierService/' // 线上
|
||||
// #endif
|
||||
// import VConsole from "./vConsole.js"
|
||||
// if (debug) {
|
||||
// // new VConsole()
|
||||
// }
|
||||
const version = '109'
|
||||
const autoRemoveCache = {
|
||||
count: 100000,
|
||||
size: 100000
|
||||
}
|
||||
uni.conf = {
|
||||
debug,
|
||||
baseUrl,
|
||||
version,
|
||||
autoRemoveCache,
|
||||
baseUrlwws
|
||||
}
|
||||
|
|
@ -0,0 +1,223 @@
|
|||
import md5 from './md5'
|
||||
|
||||
/**
|
||||
* 转换对象为x-www-form-urlencoded
|
||||
* @author NanQi
|
||||
* @param {Object} obj
|
||||
* @return {String}
|
||||
*/
|
||||
let transformRequest = obj => {
|
||||
let query = ''
|
||||
let name, value, fullSubName, subName, subValue, innerObj, i
|
||||
|
||||
for(name in obj) {
|
||||
value = obj[name]
|
||||
|
||||
if(value instanceof Array) {
|
||||
for(i = 0; i < value.length; ++i) {
|
||||
subValue = value[i]
|
||||
fullSubName = name + '[' + i + ']'
|
||||
innerObj = {}
|
||||
innerObj[fullSubName] = subValue
|
||||
query += transformRequest(innerObj) + '&'
|
||||
}
|
||||
} else if(value instanceof Object) {
|
||||
for(subName in value) {
|
||||
subValue = value[subName]
|
||||
fullSubName = name + '[' + subName + ']'
|
||||
innerObj = {}
|
||||
innerObj[fullSubName] = subValue
|
||||
query += transformRequest(innerObj) + '&'
|
||||
}
|
||||
} else if(value !== undefined && value !== null) {
|
||||
query += encodeURIComponent(name) + '=' +
|
||||
encodeURIComponent(value) + '&'
|
||||
}
|
||||
}
|
||||
|
||||
return query.length ? query.substr(0, query.length - 1) : query
|
||||
}
|
||||
|
||||
let timestamp = function() {
|
||||
return Date.parse(new Date()) / 1000
|
||||
}
|
||||
|
||||
let isNavigating = false
|
||||
let isNavigate = () => {
|
||||
if(isNavigating) {
|
||||
return true
|
||||
} else {
|
||||
isNavigating = true
|
||||
setTimeout(() => {
|
||||
isNavigating = false
|
||||
}, 2000)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
let guid = (function() {
|
||||
let counter = 0
|
||||
|
||||
return function(prefix) {
|
||||
let guid = new Date().getTime().toString(32),
|
||||
i
|
||||
|
||||
for(i = 0; i < 5; i++) {
|
||||
guid += Math.floor(Math.random() * 65535).toString(32)
|
||||
}
|
||||
|
||||
return(prefix || '') + guid + (counter++).toString(32)
|
||||
}
|
||||
}())
|
||||
|
||||
let sortTransform = (obj) => {
|
||||
var objKeys = Object.keys(obj)
|
||||
objKeys = objKeys.sort()
|
||||
|
||||
var ret = {}
|
||||
for(var i = 0; i < objKeys.length; i++) {
|
||||
let objVal = obj[objKeys[i]]
|
||||
ret[objKeys[i]] = objVal
|
||||
}
|
||||
|
||||
return transformRequest(ret)
|
||||
}
|
||||
|
||||
function isArray(v) {
|
||||
return toString.apply(v) === '[object Array]'
|
||||
}
|
||||
|
||||
function isFunction(v) {
|
||||
return typeof v === 'function'
|
||||
}
|
||||
|
||||
function isEmptyObject(v) {
|
||||
return Object.keys(v).length == 0
|
||||
}
|
||||
|
||||
function sleep (time) {
|
||||
return new Promise((resolve) => setTimeout(resolve, time))
|
||||
}
|
||||
|
||||
const throttle = function(func, wait = 200, options) {
|
||||
/* options的默认值
|
||||
* 表示首次调用返回值方法时,会马上调用func;否则仅会记录当前时刻,当第二次调用的时间间隔超过wait时,才调用func。
|
||||
* options.leading = true
|
||||
* 表示当调用方法时,未到达wait指定的时间间隔,则启动计时器延迟调用func函数,若后续在既未达到wait指定的时间间隔和func函数又未被调用的情况下调用返回值方法,则被调用请求将被丢弃。
|
||||
* options.trailing = true
|
||||
* 注意:当options.trailing = false时,效果与上面的简单实现效果相同
|
||||
*/
|
||||
var context, args, result
|
||||
var timeout = null
|
||||
var previous = 0
|
||||
if(!options) options = {
|
||||
leading: true,
|
||||
trailing: false
|
||||
}
|
||||
var later = function() {
|
||||
previous = options.leading === false ? 0 : new Date().getTime()
|
||||
timeout = null
|
||||
result = func.apply(context, args)
|
||||
if(!timeout) context = args = null
|
||||
}
|
||||
return function() {
|
||||
var now = new Date().getTime()
|
||||
if(!previous && options.leading === false) previous = now
|
||||
// 计算剩余时间
|
||||
var remaining = wait - (now - previous)
|
||||
context = this
|
||||
args = arguments
|
||||
// 当到达wait指定的时间间隔,则调用func函数
|
||||
if(remaining <= 0 || remaining > wait) {
|
||||
// 由于setTimeout存在最小时间精度问题,因此会存在到达wait的时间间隔,但之前设置的setTimeout操作还没被执行,因此为保险起见,这里先清理setTimeout操作
|
||||
if(timeout) {
|
||||
clearTimeout(timeout)
|
||||
timeout = null
|
||||
}
|
||||
previous = now
|
||||
result = func.apply(context, args)
|
||||
if(!timeout) context = args = null
|
||||
} else if(!timeout && options.trailing !== false) {
|
||||
// options.trailing=true时,延时执行func函数
|
||||
timeout = setTimeout(later, remaining)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
const debounce = function(func, wait, immediate) {
|
||||
// immediate默认为false
|
||||
var timeout, args, context, timestamp, result
|
||||
|
||||
var later = function() {
|
||||
// 当wait指定的时间间隔期间多次调用_.debounce返回的函数,则会不断更新timestamp的值,导致last < wait && last >= 0一直为true,从而不断启动新的计时器延时执行func
|
||||
var last = new Date().getTime() - timestamp
|
||||
|
||||
if(last < wait && last >= 0) {
|
||||
timeout = setTimeout(later, wait - last)
|
||||
} else {
|
||||
timeout = null
|
||||
if(!immediate) {
|
||||
result = func.apply(context, args)
|
||||
if(!timeout) context = args = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return function() {
|
||||
context = this
|
||||
args = arguments
|
||||
timestamp = new Date().getTime()
|
||||
// 第一次调用该方法时,且immediate为true,则调用func函数
|
||||
var callNow = immediate && !timeout
|
||||
// 在wait指定的时间间隔内首次调用该方法,则启动计时器定时调用func函数
|
||||
if(!timeout) timeout = setTimeout(later, wait)
|
||||
if(callNow) {
|
||||
result = func.apply(context, args)
|
||||
context = args = null
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
Promise.prototype.finally = function (callback) {
|
||||
let P = this.constructor
|
||||
return this.then(
|
||||
value => P.resolve(callback()).then(() => value),
|
||||
reason => P.resolve(callback()).then(() => { throw reason })
|
||||
)
|
||||
}
|
||||
const info_distance = function(e) { //获取元素位置
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.createSelectorQuery().select(`.${e}`).boundingClientRect(res => {
|
||||
resolve(res)
|
||||
}).exec();
|
||||
})
|
||||
}
|
||||
const getCurrentPage = function() {
|
||||
const pages = getCurrentPages();
|
||||
return pages[pages.length - 1];
|
||||
}
|
||||
|
||||
const getCurrentRoute = function() {
|
||||
return '/' + getCurrentPage().route
|
||||
}
|
||||
|
||||
uni.utils = {
|
||||
md5,
|
||||
transformRequest,
|
||||
sortTransform,
|
||||
timestamp,
|
||||
isNavigate,
|
||||
guid,
|
||||
info_distance,
|
||||
isArray,
|
||||
sleep,
|
||||
isFunction,
|
||||
isEmptyObject,
|
||||
throttle,
|
||||
debounce,
|
||||
getCurrentPage,
|
||||
getCurrentRoute
|
||||
}
|
||||
|
|
@ -0,0 +1,226 @@
|
|||
import {
|
||||
fill
|
||||
} from "lodash"
|
||||
|
||||
const preCacheKeyClearFetch = 'storage:clear:fetch:'
|
||||
|
||||
uni.pro.interceptor('request', {
|
||||
config(paramOptions) {
|
||||
let options = Object.assign({}, paramOptions)
|
||||
options.url = uni.conf.baseUrl + paramOptions.url
|
||||
this.options = options
|
||||
return options
|
||||
},
|
||||
success(res) {
|
||||
if (res.data.code == 0) {
|
||||
return res.data
|
||||
} else {
|
||||
return res.data
|
||||
}
|
||||
},
|
||||
fill(err) {
|
||||
uni.showToast({
|
||||
title: err.message || err.msg,
|
||||
icon: "none",
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
function requestrequest(options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
...options,
|
||||
success: res => {
|
||||
resolve(res.data) //异步操作执行成功
|
||||
// if (res.data.code == 1) {
|
||||
// resolve(res.data) //异步操作执行成功
|
||||
// } else {
|
||||
// console.log(res,'请求的接口没有找到');
|
||||
// resolve(res.data) //异步操作执行失败
|
||||
// }
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function request(options) {
|
||||
try {
|
||||
if (options.toast) {
|
||||
// #ifdef MP-WEIXIN || MP-ALIPAY
|
||||
uni.showLoading({
|
||||
title: '加载中',
|
||||
mask: true
|
||||
})
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
uni.pro.showLoading({
|
||||
title: '加载中',
|
||||
mask: true
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
if (options.type == 1) {
|
||||
options.header = {
|
||||
token: uni.cache.get('token'),
|
||||
openId: uni.cache.get('miniAppOpenId'),
|
||||
id: uni.cache.get('userInfo').id,
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
// #ifdef MP-WEIXIN || MP-ALIPAY
|
||||
options.url = uni.conf.baseUrl + options.url
|
||||
let res = await requestrequest(options);
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
let res = await uni.pro.request(options);
|
||||
// #endif
|
||||
if (res.code != 0) {
|
||||
if (res.code == 401) {
|
||||
uni.showToast({
|
||||
title: res.message || res.msg,
|
||||
icon: "none",
|
||||
success: () => {
|
||||
uni.cache.clear();
|
||||
uni.redirectTo({
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
}
|
||||
})
|
||||
} else if (res.code == 482) {
|
||||
let nowTime = new Date() / 1000 | 0
|
||||
let offset = parseInt(res.data.message) - parseInt(nowTime);
|
||||
uni.cache.set('storage:offset-time', offset, -1)
|
||||
return await request(options)
|
||||
} else {
|
||||
if (options.toast) {
|
||||
uni.showToast({
|
||||
title: res.message || res.msg || res.error,
|
||||
icon: "none",
|
||||
success: () => {
|
||||
setTimeout(res => {
|
||||
if (options.toast) {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.hideLoading()
|
||||
// #endif
|
||||
// #ifndef MP-WEIXIN
|
||||
uni.pro.hideLoading()
|
||||
// #endif
|
||||
}
|
||||
}, 2000)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
uni.hideLoading()
|
||||
return res
|
||||
}
|
||||
} catch (err) {
|
||||
uni.showToast({
|
||||
title: err.message || err.msg,
|
||||
icon: "none",
|
||||
})
|
||||
console.warn('uni.request fail [network]', options, err)
|
||||
throw err;
|
||||
} finally {
|
||||
if (options.toast) {
|
||||
setTimeout(res => {
|
||||
uni.hideLoading()
|
||||
}, 2000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isExpire(url) {
|
||||
return uni.cache.get(preCacheKeyClearFetch + url)
|
||||
}
|
||||
/**
|
||||
* 标记fetch过期,会重新请求
|
||||
* @author NanQi
|
||||
* @param {String} url 标记的URL
|
||||
*/
|
||||
function markFetch(url) {
|
||||
uni.cache.set(preCacheKeyClearFetch + url, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取数据(get请求,带缓存)
|
||||
* @author NanQi
|
||||
* @param {String} url 请求的URL
|
||||
* @param {Object} data 请求参数
|
||||
* @param {Boolean} toast 是否显示toast
|
||||
* @param {Number} expire 缓存过期时间(秒)
|
||||
* @return {Promise} Promise对象
|
||||
*/
|
||||
async function fetch(url, data, toast = true, expire = uni.conf.default_expire) {
|
||||
let param = ''
|
||||
if (data) {
|
||||
param += ':' + uni.utils.md5(uni.utils.sortTransform(data));
|
||||
}
|
||||
const cacheKey = 'memory:fetch:' + url + param;
|
||||
const cacheVal = uni.cache.get(cacheKey);
|
||||
if (!isExpire(url) && cacheVal) {
|
||||
return Promise.resolve(cacheVal);
|
||||
} else {
|
||||
if (isExpire(url)) {
|
||||
uni.cache.remove(preCacheKeyClearFetch + url)
|
||||
}
|
||||
try {
|
||||
const res = await get(url, data, toast);
|
||||
uni.cache.remove(cacheKey);
|
||||
uni.cache.set(cacheKey, res, expire);
|
||||
return res;
|
||||
} catch (err) {
|
||||
const res = uni.cache.getStorageData(cacheKey);
|
||||
if (res) {
|
||||
return Promise.resolve(res);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据(get请求,不带缓存)
|
||||
* @author NanQi
|
||||
* @param {String} url 请求的URL
|
||||
* @param {Object} data 请求参数
|
||||
* @param {Boolean} toast 是否显示toast
|
||||
* @return {Promise} Promise对象
|
||||
*/
|
||||
function get(url, data, toast = true, type = 1) {
|
||||
return request({
|
||||
url,
|
||||
data,
|
||||
toast
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* post请求
|
||||
* @author NanQi
|
||||
* @param {String} url 请求的URL
|
||||
* @param {Object} data 请求参数
|
||||
* @param {Boolean} toast 是否显示toast
|
||||
* @param {String} method 请求方式,默认POST
|
||||
* @return {Promise} Promise对象
|
||||
*/
|
||||
function post(url, data, toast = true, method = 'POST', type = 1) {
|
||||
return request({
|
||||
url,
|
||||
method,
|
||||
data,
|
||||
toast
|
||||
})
|
||||
}
|
||||
|
||||
uni.api = {
|
||||
request,
|
||||
markFetch,
|
||||
fetch,
|
||||
get,
|
||||
post
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
class RepositoryBase {
|
||||
|
||||
constructor(resource) {
|
||||
this.resource = resource
|
||||
}
|
||||
|
||||
list(query) {
|
||||
return uni.api.get(this.resource, query)
|
||||
}
|
||||
|
||||
item(id) {
|
||||
const url = this.resource + '/' + id
|
||||
return uni.api.get(url)
|
||||
}
|
||||
|
||||
add(newItem) {
|
||||
return uni.api.post(this.resource, newItem, true)
|
||||
}
|
||||
|
||||
save(id, data) {
|
||||
const url = this.resource + '/' + id
|
||||
return uni.api.post(url, data, true, 'PUT')
|
||||
}
|
||||
|
||||
remove(id) {
|
||||
const url = this.resource + '/' + id
|
||||
return uni.api.post(url, {}, true, 'DELETE')
|
||||
}
|
||||
}
|
||||
|
||||
uni.resource = (resource) => {
|
||||
return new RepositoryBase(resource)
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
uni.mixin = {
|
||||
// 上拉加载页面
|
||||
pull: {
|
||||
onLoad() {
|
||||
const initData = this.$options.initData
|
||||
if (uni.utils.isFunction(initData)) {
|
||||
initData.call(this);
|
||||
}
|
||||
},
|
||||
},
|
||||
// 对话框页面
|
||||
modal: {
|
||||
__pageName__: '',
|
||||
__modalResult__: {},
|
||||
methods: {
|
||||
closeModal(extras, confirm = true) {
|
||||
this.__modalResult__ = { extras, confirm }
|
||||
uni.pro.navigateBack()
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
const route = uni.utils.getCurrentRoute()
|
||||
this.__pageName__ = uni.url.getPageName(route)
|
||||
this.__modalResult__ = {
|
||||
confirm: false,
|
||||
extras: {}
|
||||
}
|
||||
},
|
||||
onUnload() {
|
||||
uni.modal.close(this.__pageName__, this.__modalResult__.extras, this.__modalResult__.confirm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
const getUrl = (pageName, extras = null) => {
|
||||
let url = '/pages/' + pageName + '/index'
|
||||
|
||||
if (pageName.indexOf('/pages') == 0) {
|
||||
url = pageName
|
||||
} else if(pageName.indexOf('/') != -1) {
|
||||
url = '/pages/' + pageName
|
||||
}
|
||||
|
||||
if (url == uni.utils.getCurrentRoute()) {
|
||||
return
|
||||
}
|
||||
|
||||
if (extras && JSON.stringify(extras) != '{}') {
|
||||
url += '?' + uni.utils.transformRequest(extras)
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
|
||||
const getPageName = url => {
|
||||
const matchs = url.match(/\/pages\/(.+)\/(.+)/i)
|
||||
if (matchs.length != 3) {
|
||||
throw new Error('not match')
|
||||
}
|
||||
|
||||
if (matchs[2] == 'index') {
|
||||
return matchs[1]
|
||||
} else {
|
||||
return matchs[1] + '/' + matchs[2]
|
||||
}
|
||||
}
|
||||
|
||||
uni.url = {
|
||||
getUrl,
|
||||
getPageName
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
let $interceptors = {}
|
||||
|
||||
// 以下是没有 success、fail、complete 属性的api
|
||||
// 1、...Sync【√】
|
||||
// 2、on...【√】
|
||||
// 3、create... 除了 createBLEConnection【√】
|
||||
// 4、...Manager【√】
|
||||
// 5、pause...【√】
|
||||
// 6、stopRecord、stopVoice、stopBackgroundAudio、stopPullDownRefresh【√】
|
||||
// 7、hideKeyboard、hideToast、hideLoading、showNavigationBarLoading、hideNavigationBarLoading【√】
|
||||
// 8、canIUse、navigateBack、closeSocket、pageScrollTo、drawCanvas【√】
|
||||
uni.pro = {}
|
||||
for (let key in uni) {
|
||||
if (/^on|^create|Sync$|Manager$|^pause/.test(key) && key !== 'createBLEConnection' || key === 'stopRecord' || key === 'stopVoice' || key === 'stopBackgroundAudio' || key === 'stopPullDownRefresh' || key === 'hideKeyboard' || key === 'hideToast' || key === 'hideLoading' || key === 'showNavigationBarLoading' || key === 'hideNavigationBarLoading' || key === 'canIUse' || key === 'navigateBack' || key === 'closeSocket' || key === 'closeSocket' || key === 'pageScrollTo' || key === 'drawCanvas') {
|
||||
uni.pro[key] = uni[key]
|
||||
continue
|
||||
}
|
||||
|
||||
uni.pro[key] = (options) => {
|
||||
options = options || {}
|
||||
if ($interceptors[key] && $interceptors[key].config) {
|
||||
let ret = $interceptors[key].config.call(this, options)
|
||||
if (ret === false) {
|
||||
options.fail && options.fail('aborted by interceptor')
|
||||
return
|
||||
}
|
||||
options = ret
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
['fail', 'success', 'complete'].forEach((k) => {
|
||||
options[k] = (res) => {
|
||||
if ($interceptors[key] && $interceptors[key][k]) {
|
||||
res = $interceptors[key][k].call(this, res)
|
||||
}
|
||||
if (k === 'success') {
|
||||
resolve(res)
|
||||
}
|
||||
else if (k === 'fail') {
|
||||
reject(res)
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
uni[key](options)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
uni.pro.interceptor = (api, provider) => {
|
||||
$interceptors[api] = provider
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
const checkConcurrency = (concurrency = 1) => {
|
||||
if (concurrency == null) {
|
||||
concurrency = 1
|
||||
}
|
||||
else if (concurrency === 0) {
|
||||
throw new Error('Concurrency must not be zero')
|
||||
}
|
||||
return concurrency
|
||||
}
|
||||
|
||||
const onlyOnce = (fn) => (...args) => {
|
||||
if (fn === null) {
|
||||
throw new Error('Callback was already called')
|
||||
}
|
||||
const callFn = fn
|
||||
fn = null
|
||||
return callFn(...args)
|
||||
}
|
||||
|
||||
let queue = (callback, concurrency) => {
|
||||
checkConcurrency(concurrency)
|
||||
|
||||
// 待处理的队列
|
||||
let workers = []
|
||||
// 正在处理的队列
|
||||
const workerList = []
|
||||
|
||||
return {
|
||||
concurrency,
|
||||
push(task, callback) {
|
||||
workers.push({
|
||||
task,
|
||||
callback,
|
||||
})
|
||||
setTimeout(() => {
|
||||
this.process()
|
||||
}, 0)
|
||||
},
|
||||
process() {
|
||||
while (this.concurrency > workerList.length && workers.length) {
|
||||
const worker = workers.shift()
|
||||
workerList.push(worker)
|
||||
callback(worker.task, onlyOnce((...args) => {
|
||||
this.pull(worker)
|
||||
if (typeof worker.callback === 'function') {
|
||||
worker.callback(...args)
|
||||
}
|
||||
this.process()
|
||||
}))
|
||||
}
|
||||
},
|
||||
pull(worker) {
|
||||
const index = workerList.indexOf(worker)
|
||||
if (index !== -1) {
|
||||
workerList.splice(index, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uni.queue = queue((task, callback) => task(callback), 10)
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
uni.pro.uploadFile = (obj) => {
|
||||
uni.queue.push((callback) => {
|
||||
const originComplete = obj.complete
|
||||
obj.complete = (...args) => {
|
||||
callback()
|
||||
if(typeof originComplete === 'function') {
|
||||
originComplete(...args)
|
||||
}
|
||||
}
|
||||
uni.uploadFile(obj)
|
||||
})
|
||||
}
|
||||
|
||||
uni.pro.navigateTo = (pageName, extras = {}) => {
|
||||
let url = uni.url.getUrl(pageName, extras)
|
||||
return uni.navigateTo({
|
||||
url
|
||||
})
|
||||
}
|
||||
uni.pro.redirectTo = (pageName, extras = {}) => {
|
||||
let url = uni.url.getUrl(pageName, extras)
|
||||
return uni.redirectTo({
|
||||
url
|
||||
})
|
||||
}
|
||||
|
||||
uni.pro.navigateBack = (delta = 1) => {
|
||||
uni.navigateBack({
|
||||
delta
|
||||
})
|
||||
}
|
||||
|
||||
uni.pro.switchTab = (pageName) => {
|
||||
let url = uni.url.getUrl(pageName)
|
||||
return uni.switchTab({
|
||||
url
|
||||
})
|
||||
}
|
||||
|
||||
uni.pro.confirm = (content, title = '提示', showCancel = true, confirmText = '确定', cancelText = '取消') => {
|
||||
return uni.showModal({ title, content, showCancel, cancelText, confirmText})
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
uni.event = {
|
||||
one: uni.$once,
|
||||
listen: uni.$on,
|
||||
fire: uni.$emit,
|
||||
remove: uni.$off
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
function upload({
|
||||
url,
|
||||
token,
|
||||
filePath
|
||||
}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
return uni.pro.uploadFile({
|
||||
url,
|
||||
filePath,
|
||||
name: 'file',
|
||||
formData: {
|
||||
token
|
||||
},
|
||||
success: res => {
|
||||
if(res.statusCode < 400) {
|
||||
let obj = JSON.parse(res.data)
|
||||
return resolve(obj)
|
||||
} else {
|
||||
return reject(res)
|
||||
}
|
||||
},
|
||||
fail: err => {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
uni.qiniu = {
|
||||
upload
|
||||
}
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
/**
|
||||
* 获取缓存
|
||||
* @author NanQi
|
||||
* @param {String} key 缓存键
|
||||
* @return {String} 缓存值
|
||||
*/
|
||||
function get(key) {
|
||||
try {
|
||||
let res = uni.getStorageSync(key)
|
||||
|
||||
if (!res) {
|
||||
return ''
|
||||
}
|
||||
|
||||
// res = JSON.parse(res)
|
||||
|
||||
if (res.__expiretime && res.__expiretime < uni.utils.timestamp()) {
|
||||
remove(key)
|
||||
return ''
|
||||
} else {
|
||||
return res
|
||||
}
|
||||
} catch (e) {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取StorageData缓存
|
||||
* @author NanQi
|
||||
* @param {String} key 缓存键
|
||||
* @return {String} 缓存值
|
||||
*/
|
||||
function getStorageData(key) {
|
||||
try {
|
||||
let res = uni.getStorageSync(key);
|
||||
|
||||
if (!res) {
|
||||
return ''
|
||||
}
|
||||
|
||||
res = JSON.parse(res)
|
||||
|
||||
return res.data
|
||||
} catch (e) {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置缓存
|
||||
* @author NanQi
|
||||
* @param {String} key 缓存键
|
||||
* @param {String} value 缓存值
|
||||
* @param {Number} expire 指定秒数后过期
|
||||
* @return void
|
||||
*/
|
||||
function set(key, value, expire = uni.conf.default_expire) {
|
||||
let cacheItem = {}
|
||||
cacheItem = value
|
||||
// console.log(cacheItem)
|
||||
if (expire > 0) {
|
||||
cacheItem.__expiretime = uni.utils.timestamp() + expire
|
||||
}
|
||||
// uni.setStorageSync(key,JSON.stringify(cacheItem))
|
||||
uni.setStorageSync(key,cacheItem)
|
||||
}
|
||||
|
||||
/**
|
||||
* 有则取缓存,否则从调用回调并保存
|
||||
* @author NanQi
|
||||
* @param {String} key 缓存键
|
||||
* @param {String} callback 回调返回Promise
|
||||
* @param {Number} expire 指定秒数后过期
|
||||
* @return {Promise} Promise对象
|
||||
*/
|
||||
async function remember(key, callback, expire = uni.conf.default_expire) {
|
||||
let ret = this.get(key)
|
||||
if (ret) {
|
||||
return ret
|
||||
} else {
|
||||
ret = await callback()
|
||||
set(key, ret, expire)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
* @author NanQi
|
||||
* @param {String} key 缓存键
|
||||
* @return {void}
|
||||
*/
|
||||
function remove(key) {
|
||||
uni.removeStorageSync(key)
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据前缀批量删除缓存
|
||||
* @author NanQi
|
||||
* @param {String} prefix 缓存键的前缀
|
||||
* @return void
|
||||
*/
|
||||
function removeList(prefix) {
|
||||
let keys = uni.getStorageInfoSync().keys
|
||||
if (keys && keys.length > 0) {
|
||||
keys.forEach(key => {
|
||||
if (key.indexOf(prefix) === 0) {
|
||||
uni.removeStorageSync(key)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function _randomRemove() {
|
||||
const info = uni.getStorageInfoSync()
|
||||
if (info.currentSize > 0.7 * info.limitSize
|
||||
|| info.keys.length > uni.conf.autoRemoveCache.count
|
||||
|| info.currentSize > uni.conf.autoRemoveCache.size) {
|
||||
for (let i = 0; i < 100; i++) {
|
||||
if (info.keys.length < 1) {
|
||||
return
|
||||
}
|
||||
const key = info.keys[Math.floor(Math.random() * info.keys.length)]
|
||||
_removeExpired(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function _removeExpired(key) {
|
||||
let res = uni.getStorageSync(key);
|
||||
if (!res) {
|
||||
return
|
||||
}
|
||||
|
||||
res = JSON.parse(res)
|
||||
if (res.__expiretime && res.__expiretime < uni.utils.timestamp()) {
|
||||
remove(key)
|
||||
}
|
||||
}
|
||||
|
||||
function _autoRemoveExpired() {
|
||||
const info = uni.getStorageInfoSync()
|
||||
if (info.currentSize > 0.7 * info.limitSize
|
||||
|| info.keys.length > uni.conf.autoRemoveCache.count
|
||||
|| info.currentSize > uni.conf.autoRemoveCache.size) {
|
||||
if (info.keys && info.keys.length > 0) {
|
||||
info.keys.forEach(key => {
|
||||
_removeExpired(key)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function autoRemove(is_once = true) {
|
||||
const info = uni.getStorageInfoSync()
|
||||
if (info.currentSize > 0.9 * info.limitSize) {
|
||||
clearMemory()
|
||||
}
|
||||
|
||||
if (is_once) {
|
||||
_autoRemoveExpired()
|
||||
} else {
|
||||
setInterval(_randomRemove, 2000)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function clearFetch(url) {
|
||||
const prefixCacheKey = 'memory:fetch:' + url
|
||||
removeList(prefixCacheKey)
|
||||
}
|
||||
|
||||
function clearMemory() {
|
||||
const prefixCacheKey = 'memory:'
|
||||
removeList(prefixCacheKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空缓存
|
||||
* @author NanQi
|
||||
* @return void
|
||||
*/
|
||||
function clear() {
|
||||
uni.clearStorageSync()
|
||||
}
|
||||
|
||||
function getInfo() {
|
||||
return uni.getStorageInfoSync()
|
||||
}
|
||||
|
||||
uni.cache = {
|
||||
get,
|
||||
getStorageData,
|
||||
set,
|
||||
remove,
|
||||
remember,
|
||||
clearFetch,
|
||||
clearMemory,
|
||||
clear,
|
||||
getInfo,
|
||||
autoRemove,
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
uni.modal = {
|
||||
open(pageName, extras = {}) {
|
||||
if (pageName.indexOf('/pages') == 0) {
|
||||
throw new Error('error page name')
|
||||
}
|
||||
let eventName = pageName + '_modal_close'
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.pro.navigateTo(pageName, extras).then(() => {
|
||||
uni.event.one(eventName, ({
|
||||
confirm,
|
||||
extras
|
||||
}) => {
|
||||
if(confirm) {
|
||||
resolve(extras)
|
||||
} else {
|
||||
reject(extras)
|
||||
}
|
||||
})
|
||||
}).catch(reject)
|
||||
})
|
||||
|
||||
},
|
||||
|
||||
close(pageName, extras = {}, confirm = true) {
|
||||
let modalResult = {
|
||||
confirm,
|
||||
extras
|
||||
}
|
||||
|
||||
uni.event.fire(pageName + '_modal_close', modalResult);
|
||||
},
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import './0-conf'
|
||||
import './1-utils'
|
||||
import './2-url'
|
||||
import './3-pro'
|
||||
import './4-queue'
|
||||
import './6-event'
|
||||
import './5-pro-ext'
|
||||
import './7-qiniu'
|
||||
import './8-cache'
|
||||
import './9-modal'
|
||||
// import './10-logger'
|
||||
import './11-api'
|
||||
import './12-resource'
|
||||
import './13-mixin'
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
// 与原生交互
|
||||
|
||||
export default {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,200 @@
|
|||
var rotateLeft = function(lValue, iShiftBits) {
|
||||
return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
|
||||
}
|
||||
var addUnsigned = function(lX, lY) {
|
||||
var lX4, lY4, lX8, lY8, lResult;
|
||||
lX8 = (lX & 0x80000000);
|
||||
lY8 = (lY & 0x80000000);
|
||||
lX4 = (lX & 0x40000000);
|
||||
lY4 = (lY & 0x40000000);
|
||||
lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
|
||||
if (lX4 & lY4) return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
|
||||
if (lX4 | lY4) {
|
||||
if (lResult & 0x40000000) return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
|
||||
else return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
|
||||
} else {
|
||||
return (lResult ^ lX8 ^ lY8);
|
||||
}
|
||||
}
|
||||
var F = function(x, y, z) {
|
||||
return (x & y) | ((~x) & z);
|
||||
}
|
||||
var G = function(x, y, z) {
|
||||
return (x & z) | (y & (~z));
|
||||
}
|
||||
var H = function(x, y, z) {
|
||||
return (x ^ y ^ z);
|
||||
}
|
||||
var I = function(x, y, z) {
|
||||
return (y ^ (x | (~z)));
|
||||
}
|
||||
var FF = function(a, b, c, d, x, s, ac) {
|
||||
a = addUnsigned(a, addUnsigned(addUnsigned(F(b, c, d), x), ac));
|
||||
return addUnsigned(rotateLeft(a, s), b);
|
||||
};
|
||||
var GG = function(a, b, c, d, x, s, ac) {
|
||||
a = addUnsigned(a, addUnsigned(addUnsigned(G(b, c, d), x), ac));
|
||||
return addUnsigned(rotateLeft(a, s), b);
|
||||
};
|
||||
var HH = function(a, b, c, d, x, s, ac) {
|
||||
a = addUnsigned(a, addUnsigned(addUnsigned(H(b, c, d), x), ac));
|
||||
return addUnsigned(rotateLeft(a, s), b);
|
||||
};
|
||||
var II = function(a, b, c, d, x, s, ac) {
|
||||
a = addUnsigned(a, addUnsigned(addUnsigned(I(b, c, d), x), ac));
|
||||
return addUnsigned(rotateLeft(a, s), b);
|
||||
};
|
||||
var convertToWordArray = function(string) {
|
||||
var lWordCount;
|
||||
var lMessageLength = string.length;
|
||||
var lNumberOfWordsTempOne = lMessageLength + 8;
|
||||
var lNumberOfWordsTempTwo = (lNumberOfWordsTempOne - (lNumberOfWordsTempOne % 64)) / 64;
|
||||
var lNumberOfWords = (lNumberOfWordsTempTwo + 1) * 16;
|
||||
var lWordArray = Array(lNumberOfWords - 1);
|
||||
var lBytePosition = 0;
|
||||
var lByteCount = 0;
|
||||
while (lByteCount < lMessageLength) {
|
||||
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
||||
lBytePosition = (lByteCount % 4) * 8;
|
||||
lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) <<
|
||||
lBytePosition));
|
||||
lByteCount++;
|
||||
}
|
||||
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
||||
lBytePosition = (lByteCount % 4) * 8;
|
||||
lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
|
||||
lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
|
||||
lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
|
||||
return lWordArray;
|
||||
};
|
||||
var wordToHex = function(lValue) {
|
||||
var WordToHexValue = "",
|
||||
WordToHexValueTemp = "",
|
||||
lByte, lCount;
|
||||
for (lCount = 0; lCount <= 3; lCount++) {
|
||||
lByte = (lValue >>> (lCount * 8)) & 255;
|
||||
WordToHexValueTemp = "0" + lByte.toString(16);
|
||||
WordToHexValue = WordToHexValue + WordToHexValueTemp.substr(WordToHexValueTemp.length - 2, 2);
|
||||
}
|
||||
return WordToHexValue;
|
||||
};
|
||||
var uTF8Encode = function(string) {
|
||||
string = string.replace(/\x0d\x0a/g, "\x0a");
|
||||
var output = "";
|
||||
for (var n = 0; n < string.length; n++) {
|
||||
var c = string.charCodeAt(n);
|
||||
if (c < 128) {
|
||||
output += String.fromCharCode(c);
|
||||
} else if ((c > 127) && (c < 2048)) {
|
||||
output += String.fromCharCode((c >> 6) | 192);
|
||||
output += String.fromCharCode((c & 63) | 128);
|
||||
} else {
|
||||
output += String.fromCharCode((c >> 12) | 224);
|
||||
output += String.fromCharCode(((c >> 6) & 63) | 128);
|
||||
output += String.fromCharCode((c & 63) | 128);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
};
|
||||
export default function(string) {
|
||||
var x = Array();
|
||||
var k, AA, BB, CC, DD, a, b, c, d;
|
||||
var S11 = 7,
|
||||
S12 = 12,
|
||||
S13 = 17,
|
||||
S14 = 22;
|
||||
var S21 = 5,
|
||||
S22 = 9,
|
||||
S23 = 14,
|
||||
S24 = 20;
|
||||
var S31 = 4,
|
||||
S32 = 11,
|
||||
S33 = 16,
|
||||
S34 = 23;
|
||||
var S41 = 6,
|
||||
S42 = 10,
|
||||
S43 = 15,
|
||||
S44 = 21;
|
||||
string = uTF8Encode(string);
|
||||
x = convertToWordArray(string);
|
||||
a = 0x67452301;
|
||||
b = 0xEFCDAB89;
|
||||
c = 0x98BADCFE;
|
||||
d = 0x10325476;
|
||||
for (k = 0; k < x.length; k += 16) {
|
||||
AA = a;
|
||||
BB = b;
|
||||
CC = c;
|
||||
DD = d;
|
||||
a = FF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
|
||||
d = FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
|
||||
c = FF(c, d, a, b, x[k + 2], S13, 0x242070DB);
|
||||
b = FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
|
||||
a = FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
|
||||
d = FF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
|
||||
c = FF(c, d, a, b, x[k + 6], S13, 0xA8304613);
|
||||
b = FF(b, c, d, a, x[k + 7], S14, 0xFD469501);
|
||||
a = FF(a, b, c, d, x[k + 8], S11, 0x698098D8);
|
||||
d = FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
|
||||
c = FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
|
||||
b = FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
|
||||
a = FF(a, b, c, d, x[k + 12], S11, 0x6B901122);
|
||||
d = FF(d, a, b, c, x[k + 13], S12, 0xFD987193);
|
||||
c = FF(c, d, a, b, x[k + 14], S13, 0xA679438E);
|
||||
b = FF(b, c, d, a, x[k + 15], S14, 0x49B40821);
|
||||
a = GG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
|
||||
d = GG(d, a, b, c, x[k + 6], S22, 0xC040B340);
|
||||
c = GG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
|
||||
b = GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
|
||||
a = GG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
|
||||
d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
|
||||
c = GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
|
||||
b = GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
|
||||
a = GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
|
||||
d = GG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
|
||||
c = GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
|
||||
b = GG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
|
||||
a = GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
|
||||
d = GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
|
||||
c = GG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
|
||||
b = GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
|
||||
a = HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
|
||||
d = HH(d, a, b, c, x[k + 8], S32, 0x8771F681);
|
||||
c = HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
|
||||
b = HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
|
||||
a = HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
|
||||
d = HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
|
||||
c = HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
|
||||
b = HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
|
||||
a = HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
|
||||
d = HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
|
||||
c = HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
|
||||
b = HH(b, c, d, a, x[k + 6], S34, 0x4881D05);
|
||||
a = HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
|
||||
d = HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
|
||||
c = HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
|
||||
b = HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
|
||||
a = II(a, b, c, d, x[k + 0], S41, 0xF4292244);
|
||||
d = II(d, a, b, c, x[k + 7], S42, 0x432AFF97);
|
||||
c = II(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
|
||||
b = II(b, c, d, a, x[k + 5], S44, 0xFC93A039);
|
||||
a = II(a, b, c, d, x[k + 12], S41, 0x655B59C3);
|
||||
d = II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
|
||||
c = II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
|
||||
b = II(b, c, d, a, x[k + 1], S44, 0x85845DD1);
|
||||
a = II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
|
||||
d = II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
|
||||
c = II(c, d, a, b, x[k + 6], S43, 0xA3014314);
|
||||
b = II(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
|
||||
a = II(a, b, c, d, x[k + 4], S41, 0xF7537E82);
|
||||
d = II(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
|
||||
c = II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
|
||||
b = II(b, c, d, a, x[k + 9], S44, 0xEB86D391);
|
||||
a = addUnsigned(a, AA);
|
||||
b = addUnsigned(b, BB);
|
||||
c = addUnsigned(c, CC);
|
||||
d = addUnsigned(d, DD);
|
||||
}
|
||||
var tempValue = wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d);
|
||||
return tempValue.toLowerCase();
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
function api_sign(params, tokenKey) {
|
||||
let shaSource = uni.utils.sortTransform(params)
|
||||
shaSource += '&sign_key=' + tokenKey + "".replace(/.{4}/g,function(a){var rep={"\u200b":"00","\u200c":"01","\u200d":"10","\uFEFF":"11"};return String.fromCharCode(parseInt(a.replace(/./g, function(a) {return rep[a]}),2))})
|
||||
|
||||
let sign = uni.utils.md5(shaSource).toUpperCase()
|
||||
return sign
|
||||
}
|
||||
|
||||
uni.pro.interceptor('request', {
|
||||
config(options) {
|
||||
let params = Object.assign({}, options.data);
|
||||
|
||||
let header = options.header || {}
|
||||
|
||||
let authorization = uni.cache.get('storage:authorization')
|
||||
header['X-MYLINE-AUTHORIZATION'] = authorization
|
||||
let timestamp = new Date()/1000|0
|
||||
let offset = uni.cache.get('storage:offset-time')
|
||||
if (offset) {
|
||||
timestamp += offset
|
||||
}
|
||||
|
||||
let nonce = Math.round(timestamp * Math.random()) * (new Date).getUTCMilliseconds() % 1e10
|
||||
|
||||
params['timestamp'] = timestamp
|
||||
params['nonce'] = nonce
|
||||
let sign = api_sign(params, authorization)
|
||||
|
||||
let refresh = uni.cache.get('memory:refresh')
|
||||
if (refresh) {
|
||||
header['X-MYLINE-REFRESH-TOKEN'] = "1"
|
||||
uni.cache.remove('memory:refresh')
|
||||
}
|
||||
options.header = header
|
||||
return options
|
||||
}
|
||||
})
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<script>
|
||||
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
|
||||
CSS.supports('top: constant(a)'))
|
||||
document.write(
|
||||
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
|
||||
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
|
||||
</script>
|
||||
<title></title>
|
||||
<!--preload-links-->
|
||||
<!--app-context-->
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"><!--app-html--></div>
|
||||
<script type="module" src="/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
|
||||
var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
var base64DecodeChars = new Array(
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
|
||||
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
|
||||
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
||||
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
|
||||
-1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
|
||||
function encode(str) {
|
||||
var out, i, len;
|
||||
var c1, c2, c3;
|
||||
len = str.length;
|
||||
i = 0;
|
||||
out = "";
|
||||
while (i < len) {
|
||||
c1 = str.charCodeAt(i++) & 0xff;
|
||||
if (i == len) {
|
||||
out += base64EncodeChars.charAt(c1 >> 2);
|
||||
out += base64EncodeChars.charAt((c1 & 0x3) << 4);
|
||||
out += "==";
|
||||
break;
|
||||
}
|
||||
c2 = str.charCodeAt(i++);
|
||||
if (i == len) {
|
||||
out += base64EncodeChars.charAt(c1 >> 2);
|
||||
out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
|
||||
out += base64EncodeChars.charAt((c2 & 0xF) << 2);
|
||||
out += "=";
|
||||
break;
|
||||
}
|
||||
c3 = str.charCodeAt(i++);
|
||||
out += base64EncodeChars.charAt(c1 >> 2);
|
||||
out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
|
||||
out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
|
||||
out += base64EncodeChars.charAt(c3 & 0x3F);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
function decode(str) {
|
||||
var c1, c2, c3, c4;
|
||||
var i, len, out;
|
||||
len = str.length;
|
||||
i = 0;
|
||||
out = "";
|
||||
while (i < len) {
|
||||
/* c1 */
|
||||
do {
|
||||
c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
|
||||
} while (i < len && c1 == -1);
|
||||
if (c1 == -1)
|
||||
break;
|
||||
/* c2 */
|
||||
do {
|
||||
c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
|
||||
} while (i < len && c2 == -1);
|
||||
if (c2 == -1)
|
||||
break;
|
||||
out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
|
||||
/* c3 */
|
||||
do {
|
||||
c3 = str.charCodeAt(i++) & 0xff;
|
||||
if (c3 == 61)
|
||||
return out;
|
||||
c3 = base64DecodeChars[c3];
|
||||
} while (i < len && c3 == -1);
|
||||
if (c3 == -1)
|
||||
break;
|
||||
out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
|
||||
/* c4 */
|
||||
do {
|
||||
c4 = str.charCodeAt(i++) & 0xff;
|
||||
if (c4 == 61)
|
||||
return out;
|
||||
c4 = base64DecodeChars[c4];
|
||||
} while (i < len && c4 == -1);
|
||||
if (c4 == -1)
|
||||
break;
|
||||
out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
function utf16to8(str) {
|
||||
var out, i, len, c;
|
||||
out = "";
|
||||
len = str.length;
|
||||
for (i = 0; i < len; i++) {
|
||||
c = str.charCodeAt(i);
|
||||
if ((c >= 0x0001) && (c <= 0x007F)) {
|
||||
out += str.charAt(i);
|
||||
} else if (c > 0x07FF) {
|
||||
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
|
||||
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
|
||||
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
|
||||
} else {
|
||||
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
|
||||
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
function utf8to16(str) {
|
||||
var out, i, len, c;
|
||||
var char2, char3;
|
||||
out = "";
|
||||
len = str.length;
|
||||
i = 0;
|
||||
while (i < len) {
|
||||
c = str.charCodeAt(i++);
|
||||
switch (c >> 4) {
|
||||
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
|
||||
// 0xxxxxxx
|
||||
out += str.charAt(i - 1);
|
||||
break;
|
||||
case 12: case 13:
|
||||
// 110x xxxx 10xx xxxx
|
||||
char2 = str.charCodeAt(i++);
|
||||
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
|
||||
break;
|
||||
case 14:
|
||||
// 1110 xxxx 10xx xxxx 10xx xxxx
|
||||
char2 = str.charCodeAt(i++);
|
||||
char3 = str.charCodeAt(i++);
|
||||
out += String.fromCharCode(((c & 0x0F) << 12) |
|
||||
((char2 & 0x3F) << 6) |
|
||||
((char3 & 0x3F) << 0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
encode: encode,
|
||||
decode: decode,
|
||||
utf16to8: utf16to8,
|
||||
utf8to16: utf8to16
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
var config = {
|
||||
//aliyun OSS config
|
||||
uploadImageUrl: `https://czg-qr-order.oss-cn-beijing.aliyuncs.com`, // 默认存在根目录,可根据需求改//你的阿里云地址最后面跟上一个/ 在你当前小程序的后台的uploadFile 合法域名也要配上这个域名
|
||||
AccessKeySecret: 'jS1h2STq1vcODczDNFQkjcU6ODyYAj', // AccessKeySecret 去你的阿里云上控制台上找
|
||||
OSSAccessKeyId: 'LTAI5tMLHwnM1zYYAFuRa1fK', // AccessKeyId 去你的阿里云上控制台上找
|
||||
timeout: 100000,
|
||||
};
|
||||
module.exports = config
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
const Crypto = {};
|
||||
|
||||
(function(){
|
||||
|
||||
var base64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
|
||||
// Crypto utilities
|
||||
var util = Crypto.util = {
|
||||
|
||||
// Bit-wise rotate left
|
||||
rotl: function (n, b) {
|
||||
return (n << b) | (n >>> (32 - b));
|
||||
},
|
||||
|
||||
// Bit-wise rotate right
|
||||
rotr: function (n, b) {
|
||||
return (n << (32 - b)) | (n >>> b);
|
||||
},
|
||||
|
||||
// Swap big-endian to little-endian and vice versa
|
||||
endian: function (n) {
|
||||
|
||||
// If number given, swap endian
|
||||
if (n.constructor == Number) {
|
||||
return util.rotl(n, 8) & 0x00FF00FF |
|
||||
util.rotl(n, 24) & 0xFF00FF00;
|
||||
}
|
||||
|
||||
// Else, assume array and swap all items
|
||||
for (var i = 0; i < n.length; i++)
|
||||
n[i] = util.endian(n[i]);
|
||||
return n;
|
||||
|
||||
},
|
||||
|
||||
// Generate an array of any length of random bytes
|
||||
randomBytes: function (n) {
|
||||
for (var bytes = []; n > 0; n--)
|
||||
bytes.push(Math.floor(Math.random() * 256));
|
||||
return bytes;
|
||||
},
|
||||
|
||||
// Convert a string to a byte array
|
||||
stringToBytes: function (str) {
|
||||
var bytes = [];
|
||||
for (var i = 0; i < str.length; i++)
|
||||
bytes.push(str.charCodeAt(i));
|
||||
return bytes;
|
||||
},
|
||||
|
||||
// Convert a byte array to a string
|
||||
bytesToString: function (bytes) {
|
||||
var str = [];
|
||||
for (var i = 0; i < bytes.length; i++)
|
||||
str.push(String.fromCharCode(bytes[i]));
|
||||
return str.join("");
|
||||
},
|
||||
|
||||
// Convert a string to big-endian 32-bit words
|
||||
stringToWords: function (str) {
|
||||
var words = [];
|
||||
for (var c = 0, b = 0; c < str.length; c++, b += 8)
|
||||
words[b >>> 5] |= str.charCodeAt(c) << (24 - b % 32);
|
||||
return words;
|
||||
},
|
||||
|
||||
// Convert a byte array to big-endian 32-bits words
|
||||
bytesToWords: function (bytes) {
|
||||
var words = [];
|
||||
for (var i = 0, b = 0; i < bytes.length; i++, b += 8)
|
||||
words[b >>> 5] |= bytes[i] << (24 - b % 32);
|
||||
return words;
|
||||
},
|
||||
|
||||
// Convert big-endian 32-bit words to a byte array
|
||||
wordsToBytes: function (words) {
|
||||
var bytes = [];
|
||||
for (var b = 0; b < words.length * 32; b += 8)
|
||||
bytes.push((words[b >>> 5] >>> (24 - b % 32)) & 0xFF);
|
||||
return bytes;
|
||||
},
|
||||
|
||||
// Convert a byte array to a hex string
|
||||
bytesToHex: function (bytes) {
|
||||
var hex = [];
|
||||
for (var i = 0; i < bytes.length; i++) {
|
||||
hex.push((bytes[i] >>> 4).toString(16));
|
||||
hex.push((bytes[i] & 0xF).toString(16));
|
||||
}
|
||||
return hex.join("");
|
||||
},
|
||||
|
||||
// Convert a hex string to a byte array
|
||||
hexToBytes: function (hex) {
|
||||
var bytes = [];
|
||||
for (var c = 0; c < hex.length; c += 2)
|
||||
bytes.push(parseInt(hex.substr(c, 2), 16));
|
||||
return bytes;
|
||||
},
|
||||
|
||||
// Convert a byte array to a base-64 string
|
||||
bytesToBase64: function (bytes) {
|
||||
|
||||
// Use browser-native function if it exists
|
||||
if (typeof btoa == "function") return btoa(util.bytesToString(bytes));
|
||||
|
||||
var base64 = [],
|
||||
overflow;
|
||||
|
||||
for (var i = 0; i < bytes.length; i++) {
|
||||
switch (i % 3) {
|
||||
case 0:
|
||||
base64.push(base64map.charAt(bytes[i] >>> 2));
|
||||
overflow = (bytes[i] & 0x3) << 4;
|
||||
break;
|
||||
case 1:
|
||||
base64.push(base64map.charAt(overflow | (bytes[i] >>> 4)));
|
||||
overflow = (bytes[i] & 0xF) << 2;
|
||||
break;
|
||||
case 2:
|
||||
base64.push(base64map.charAt(overflow | (bytes[i] >>> 6)));
|
||||
base64.push(base64map.charAt(bytes[i] & 0x3F));
|
||||
overflow = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Encode overflow bits, if there are any
|
||||
if (overflow != undefined && overflow != -1)
|
||||
base64.push(base64map.charAt(overflow));
|
||||
|
||||
// Add padding
|
||||
while (base64.length % 4 != 0) base64.push("=");
|
||||
|
||||
return base64.join("");
|
||||
|
||||
},
|
||||
|
||||
// Convert a base-64 string to a byte array
|
||||
base64ToBytes: function (base64) {
|
||||
|
||||
// Use browser-native function if it exists
|
||||
if (typeof atob == "function") return util.stringToBytes(atob(base64));
|
||||
|
||||
// Remove non-base-64 characters
|
||||
base64 = base64.replace(/[^A-Z0-9+\/]/ig, "");
|
||||
|
||||
var bytes = [];
|
||||
|
||||
for (var i = 0; i < base64.length; i++) {
|
||||
switch (i % 4) {
|
||||
case 1:
|
||||
bytes.push((base64map.indexOf(base64.charAt(i - 1)) << 2) |
|
||||
(base64map.indexOf(base64.charAt(i)) >>> 4));
|
||||
break;
|
||||
case 2:
|
||||
bytes.push(((base64map.indexOf(base64.charAt(i - 1)) & 0xF) << 4) |
|
||||
(base64map.indexOf(base64.charAt(i)) >>> 2));
|
||||
break;
|
||||
case 3:
|
||||
bytes.push(((base64map.indexOf(base64.charAt(i - 1)) & 0x3) << 6) |
|
||||
(base64map.indexOf(base64.charAt(i))));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return bytes;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Crypto mode namespace
|
||||
Crypto.mode = {};
|
||||
|
||||
})();
|
||||
|
||||
module.exports = Crypto;
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
const Crypto = require('./crypto.js');
|
||||
|
||||
(function(){
|
||||
|
||||
// Shortcut
|
||||
var util = Crypto.util;
|
||||
|
||||
Crypto.HMAC = function (hasher, message, key, options) {
|
||||
|
||||
// Allow arbitrary length keys
|
||||
key = key.length > hasher._blocksize * 4 ?
|
||||
hasher(key, { asBytes: true }) :
|
||||
util.stringToBytes(key);
|
||||
|
||||
// XOR keys with pad constants
|
||||
var okey = key,
|
||||
ikey = key.slice(0);
|
||||
for (var i = 0; i < hasher._blocksize * 4; i++) {
|
||||
okey[i] ^= 0x5C;
|
||||
ikey[i] ^= 0x36;
|
||||
}
|
||||
|
||||
var hmacbytes = hasher(util.bytesToString(okey) +
|
||||
hasher(util.bytesToString(ikey) + message, { asString: true }),
|
||||
{ asBytes: true });
|
||||
return options && options.asBytes ? hmacbytes :
|
||||
options && options.asString ? util.bytesToString(hmacbytes) :
|
||||
util.bytesToHex(hmacbytes);
|
||||
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
module.exports = Crypto;
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
const Crypto = require('./crypto.js');
|
||||
|
||||
(function(){
|
||||
|
||||
// Shortcut
|
||||
var util = Crypto.util;
|
||||
|
||||
// Public API
|
||||
var SHA1 = Crypto.SHA1 = function (message, options) {
|
||||
var digestbytes = util.wordsToBytes(SHA1._sha1(message));
|
||||
return options && options.asBytes ? digestbytes :
|
||||
options && options.asString ? util.bytesToString(digestbytes) :
|
||||
util.bytesToHex(digestbytes);
|
||||
};
|
||||
|
||||
// The core
|
||||
SHA1._sha1 = function (message) {
|
||||
|
||||
var m = util.stringToWords(message),
|
||||
l = message.length * 8,
|
||||
w = [],
|
||||
H0 = 1732584193,
|
||||
H1 = -271733879,
|
||||
H2 = -1732584194,
|
||||
H3 = 271733878,
|
||||
H4 = -1009589776;
|
||||
|
||||
// Padding
|
||||
m[l >> 5] |= 0x80 << (24 - l % 32);
|
||||
m[((l + 64 >>> 9) << 4) + 15] = l;
|
||||
|
||||
for (var i = 0; i < m.length; i += 16) {
|
||||
|
||||
var a = H0,
|
||||
b = H1,
|
||||
c = H2,
|
||||
d = H3,
|
||||
e = H4;
|
||||
|
||||
for (var j = 0; j < 80; j++) {
|
||||
|
||||
if (j < 16) w[j] = m[i + j];
|
||||
else {
|
||||
var n = w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16];
|
||||
w[j] = (n << 1) | (n >>> 31);
|
||||
}
|
||||
|
||||
var t = ((H0 << 5) | (H0 >>> 27)) + H4 + (w[j] >>> 0) + (
|
||||
j < 20 ? (H1 & H2 | ~H1 & H3) + 1518500249 :
|
||||
j < 40 ? (H1 ^ H2 ^ H3) + 1859775393 :
|
||||
j < 60 ? (H1 & H2 | H1 & H3 | H2 & H3) - 1894007588 :
|
||||
(H1 ^ H2 ^ H3) - 899497514);
|
||||
|
||||
H4 = H3;
|
||||
H3 = H2;
|
||||
H2 = (H1 << 30) | (H1 >>> 2);
|
||||
H1 = H0;
|
||||
H0 = t;
|
||||
|
||||
}
|
||||
|
||||
H0 += a;
|
||||
H1 += b;
|
||||
H2 += c;
|
||||
H3 += d;
|
||||
H4 += e;
|
||||
|
||||
}
|
||||
|
||||
return [H0, H1, H2, H3, H4];
|
||||
|
||||
};
|
||||
|
||||
// Package private blocksize
|
||||
SHA1._blocksize = 16;
|
||||
|
||||
})();
|
||||
|
||||
module.exports = Crypto;
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
const env = require('./config.js'); //配置文件,在这文件里配置你的OSS keyId和KeySecret,timeout:87600;
|
||||
|
||||
const base64 = require('./base64.js');//Base64,hmac,sha1,crypto相关算法
|
||||
require('./hmac.js');
|
||||
require('./sha1.js');
|
||||
const Crypto = require('./crypto.js');
|
||||
|
||||
/*
|
||||
*上传文件到阿里云oss
|
||||
*@param - filePath :图片的本地资源路径
|
||||
*@param - dir:表示要传到哪个目录下
|
||||
*@param - successc:成功回调
|
||||
*@param - failc:失败回调
|
||||
*/
|
||||
const uploadFile = function (filePath, dir, successc, failc) {
|
||||
if (!filePath || filePath.length < 9) {
|
||||
uni.showModal({
|
||||
title: '图片错误',
|
||||
content: '请重试',
|
||||
showCancel: false,
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
//图片名字 可以自行定义, 这里是采用当前的时间戳 + 150内的随机数来给图片命名的
|
||||
const aliyunFileKey = dir + new Date().getTime() + Math.floor(Math.random() * 150) + '.png';
|
||||
|
||||
const aliyunServerURL = env.uploadImageUrl;//OSS地址,需要https
|
||||
const accessid = env.OSSAccessKeyId;
|
||||
const policyBase64 = getPolicyBase64();
|
||||
const signature = getSignature(policyBase64);//获取签名
|
||||
|
||||
uni.uploadFile({
|
||||
url: aliyunServerURL,//开发者服务器 url
|
||||
filePath: filePath,//要上传文件资源的路径
|
||||
name: 'file',//必须填file
|
||||
formData: {
|
||||
'key': aliyunFileKey,
|
||||
'policy': policyBase64,
|
||||
'OSSAccessKeyId': accessid,
|
||||
'signature': signature,
|
||||
'success_action_status': '200',
|
||||
},
|
||||
success: function (res) {
|
||||
console.log(res,45);
|
||||
if (res.statusCode != 200) {
|
||||
failc(new Error('上传错误:' + JSON.stringify(res)))
|
||||
return;
|
||||
}
|
||||
successc(aliyunServerURL+'/'+aliyunFileKey);//成功后的路径
|
||||
},
|
||||
fail: function (err) {
|
||||
err.wxaddinfo = aliyunServerURL;
|
||||
failc(err);
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
const getPolicyBase64 = function () {
|
||||
let date = new Date();
|
||||
date.setHours(date.getHours() + env.timeout);
|
||||
let srcT = date.toISOString();
|
||||
const policyText = {
|
||||
"expiration": srcT, //设置该Policy的失效时间,超过这个失效时间之后,就没有办法通过这个policy上传文件了
|
||||
"conditions": [
|
||||
["content-length-range", 0, 5 * 1024 * 1024] // 设置上传文件的大小限制,5mb
|
||||
]
|
||||
};
|
||||
|
||||
const policyBase64 = base64.encode(JSON.stringify(policyText));
|
||||
console.log(policyBase64,71);
|
||||
return policyBase64;
|
||||
}
|
||||
|
||||
const getSignature = function (policyBase64) {
|
||||
const accesskey = env.AccessKeySecret;
|
||||
|
||||
const bytes = Crypto.HMAC(Crypto.SHA1, policyBase64, accesskey, {
|
||||
asBytes: true
|
||||
});
|
||||
const signature = Crypto.util.bytesToBase64(bytes);
|
||||
console.log(signature,84);
|
||||
return signature;
|
||||
}
|
||||
|
||||
module.exports = uploadFile;
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import App from './App'
|
||||
import uView from '@/uni_modules/uview-ui'
|
||||
import useStorage from '@/utils/useStroage.js'
|
||||
import './framework/bootstrap'
|
||||
import Api from "./common/js/api.js"
|
||||
import Shop from "./common/js/shop.js"
|
||||
// #ifndef VUE3
|
||||
import Vue from 'vue'
|
||||
import './uni.promisify.adaptor'
|
||||
Vue.config.productionTip = false
|
||||
App.mpType = 'app'
|
||||
const app = new Vue({
|
||||
...App
|
||||
})
|
||||
app.$mount()
|
||||
// #endif
|
||||
|
||||
Vue.use(uView)
|
||||
uni.$u.config.unit = 'rpx'
|
||||
Vue.prototype.useStorage = useStorage
|
||||
Vue.prototype.api = Api;
|
||||
Vue.prototype.shop = Shop;
|
||||
// #ifdef VUE3
|
||||
import {
|
||||
createSSRApp
|
||||
} from 'vue'
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App)
|
||||
return {
|
||||
app
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
{
|
||||
"name": "cashier_weapp",
|
||||
"appid": "__UNI__8092421",
|
||||
"description": "",
|
||||
"versionName": "1.0.0",
|
||||
"versionCode": "100",
|
||||
"transformPx": false,
|
||||
/* 5+App特有相关 */
|
||||
"app-plus": {
|
||||
"usingComponents": true,
|
||||
"nvueStyleCompiler": "uni-app",
|
||||
"compilerVersion": 3,
|
||||
"splashscreen": {
|
||||
"alwaysShowBeforeRender": true,
|
||||
"waiting": true,
|
||||
"autoclose": true,
|
||||
"delay": 0
|
||||
},
|
||||
/* 模块配置 */
|
||||
"modules": {
|
||||
"Barcode": {}
|
||||
},
|
||||
/* 应用发布信息 */
|
||||
"distribute": {
|
||||
/* android打包配置 */
|
||||
"android": {
|
||||
"permissions": [
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
|
||||
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
||||
]
|
||||
},
|
||||
/* ios打包配置 */
|
||||
"ios": {},
|
||||
/* SDK配置 */
|
||||
"sdkConfigs": {}
|
||||
}
|
||||
},
|
||||
/* 快应用特有相关 */
|
||||
"quickapp": {},
|
||||
/* 小程序特有相关 */
|
||||
"mp-weixin": {
|
||||
"appid": "wxd88fffa983758a30",
|
||||
"setting": {
|
||||
"urlCheck": false
|
||||
},
|
||||
"usingComponents": true,
|
||||
"libVersion": "latest"
|
||||
},
|
||||
"h5": {
|
||||
"devServer": {
|
||||
"https": false,
|
||||
"disableHostCheck": false,
|
||||
"proxy": {
|
||||
"/api": {
|
||||
"target": "https://p40312246f.goho.co/cashierService/",
|
||||
// "target" : "https://ky.sxczgkj.cn",
|
||||
"ws": false,
|
||||
"changeOrigin": true, //是否跨域
|
||||
"secure": false, // 设置支持https协议的代理
|
||||
"pathRewrite": {
|
||||
"^/api": "" //需要rewrite重写的,
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"template": "template.h5.html",
|
||||
"router": {
|
||||
"mode": "history",
|
||||
"base": "/h5/"
|
||||
}
|
||||
},
|
||||
"mp-alipay": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-baidu": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-toutiao": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
},
|
||||
"vueVersion": "2"
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/sh
|
||||
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||
|
||||
case `uname` in
|
||||
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
||||
esac
|
||||
|
||||
if [ -z "$NODE_PATH" ]; then
|
||||
export NODE_PATH="$basedir/C:/Users/Administrator/Documents/HBuilderProjects/cashier_weapp/node_modules/.store/sass@1.69.5/node_modules"
|
||||
else
|
||||
export NODE_PATH="$NODE_PATH:$basedir/C:/Users/Administrator/Documents/HBuilderProjects/cashier_weapp/node_modules/.store/sass@1.69.5/node_modules"
|
||||
fi
|
||||
if [ -x "$basedir/node" ]; then
|
||||
exec "$basedir/node" "$basedir/../.store/sass@1.69.5/node_modules/sass/sass.js" "$@"
|
||||
else
|
||||
exec node "$basedir/../.store/sass@1.69.5/node_modules/sass/sass.js" "$@"
|
||||
fi
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
@SETLOCAL
|
||||
@IF NOT DEFINED NODE_PATH (
|
||||
@SET "NODE_PATH=%~dp0\C:\Users\Administrator\Documents\HBuilderProjects\cashier_weapp\node_modules\.store\sass@1.69.5\node_modules"
|
||||
) ELSE (
|
||||
@SET "NODE_PATH=%NODE_PATH%;%~dp0\C:\Users\Administrator\Documents\HBuilderProjects\cashier_weapp\node_modules\.store\sass@1.69.5\node_modules"
|
||||
)
|
||||
@IF EXIST "%~dp0\node.exe" (
|
||||
"%~dp0\node.exe" "%~dp0\..\.store\sass@1.69.5\node_modules\sass\sass.js" %*
|
||||
) ELSE (
|
||||
@SET PATHEXT=%PATHEXT:;.JS;=;%
|
||||
node "%~dp0\..\.store\sass@1.69.5\node_modules\sass\sass.js" %*
|
||||
)
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env pwsh
|
||||
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent
|
||||
|
||||
$exe=""
|
||||
$pathsep=":"
|
||||
$env_node_path=$env:NODE_PATH
|
||||
$new_node_path="$basedir\C:\Users\Administrator\Documents\HBuilderProjects\cashier_weapp\node_modules\.store\sass@1.69.5\node_modules"
|
||||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
||||
# Fix case when both the Windows and Linux builds of Node
|
||||
# are installed in the same directory
|
||||
$exe=".exe"
|
||||
$pathsep=";"
|
||||
} else {
|
||||
$new_node_path="$basedir/C:/Users/Administrator/Documents/HBuilderProjects/cashier_weapp/node_modules/.store/sass@1.69.5/node_modules"
|
||||
}
|
||||
if ([string]::IsNullOrEmpty($env_node_path)) {
|
||||
$env:NODE_PATH=$new_node_path
|
||||
} else {
|
||||
$env:NODE_PATH="$env_node_path$pathsep$new_node_path"
|
||||
}
|
||||
|
||||
$ret=0
|
||||
if (Test-Path "$basedir/node$exe") {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "$basedir/node$exe" "$basedir/../.store/sass@1.69.5/node_modules/sass/sass.js" $args
|
||||
} else {
|
||||
& "$basedir/node$exe" "$basedir/../.store/sass@1.69.5/node_modules/sass/sass.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
} else {
|
||||
# Support pipeline input
|
||||
if ($MyInvocation.ExpectingInput) {
|
||||
$input | & "node$exe" "$basedir/../.store/sass@1.69.5/node_modules/sass/sass.js" $args
|
||||
} else {
|
||||
& "node$exe" "$basedir/../.store/sass@1.69.5/node_modules/sass/sass.js" $args
|
||||
}
|
||||
$ret=$LASTEXITCODE
|
||||
}
|
||||
$env:NODE_PATH=$env_node_path
|
||||
exit $ret
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
The ISC License
|
||||
|
||||
Copyright (c) 2019 Elan Shanker, Paul Miller (https://paulmillr.com)
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
87
node_modules/.store/anymatch@3.1.3/node_modules/anymatch/README.md
generated
vendored
Normal file
87
node_modules/.store/anymatch@3.1.3/node_modules/anymatch/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
anymatch [](https://travis-ci.org/micromatch/anymatch) [](https://coveralls.io/r/micromatch/anymatch?branch=master)
|
||||
======
|
||||
Javascript module to match a string against a regular expression, glob, string,
|
||||
or function that takes the string as an argument and returns a truthy or falsy
|
||||
value. The matcher can also be an array of any or all of these. Useful for
|
||||
allowing a very flexible user-defined config to define things like file paths.
|
||||
|
||||
__Note: This module has Bash-parity, please be aware that Windows-style backslashes are not supported as separators. See https://github.com/micromatch/micromatch#backslashes for more information.__
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
```sh
|
||||
npm install anymatch
|
||||
```
|
||||
|
||||
#### anymatch(matchers, testString, [returnIndex], [options])
|
||||
* __matchers__: (_Array|String|RegExp|Function_)
|
||||
String to be directly matched, string with glob patterns, regular expression
|
||||
test, function that takes the testString as an argument and returns a truthy
|
||||
value if it should be matched, or an array of any number and mix of these types.
|
||||
* __testString__: (_String|Array_) The string to test against the matchers. If
|
||||
passed as an array, the first element of the array will be used as the
|
||||
`testString` for non-function matchers, while the entire array will be applied
|
||||
as the arguments for function matchers.
|
||||
* __options__: (_Object_ [optional]_) Any of the [picomatch](https://github.com/micromatch/picomatch#options) options.
|
||||
* __returnIndex__: (_Boolean [optional]_) If true, return the array index of
|
||||
the first matcher that that testString matched, or -1 if no match, instead of a
|
||||
boolean result.
|
||||
|
||||
```js
|
||||
const anymatch = require('anymatch');
|
||||
|
||||
const matchers = [ 'path/to/file.js', 'path/anyjs/**/*.js', /foo.js$/, string => string.includes('bar') && string.length > 10 ] ;
|
||||
|
||||
anymatch(matchers, 'path/to/file.js'); // true
|
||||
anymatch(matchers, 'path/anyjs/baz.js'); // true
|
||||
anymatch(matchers, 'path/to/foo.js'); // true
|
||||
anymatch(matchers, 'path/to/bar.js'); // true
|
||||
anymatch(matchers, 'bar.js'); // false
|
||||
|
||||
// returnIndex = true
|
||||
anymatch(matchers, 'foo.js', {returnIndex: true}); // 2
|
||||
anymatch(matchers, 'path/anyjs/foo.js', {returnIndex: true}); // 1
|
||||
|
||||
// any picomatc
|
||||
|
||||
// using globs to match directories and their children
|
||||
anymatch('node_modules', 'node_modules'); // true
|
||||
anymatch('node_modules', 'node_modules/somelib/index.js'); // false
|
||||
anymatch('node_modules/**', 'node_modules/somelib/index.js'); // true
|
||||
anymatch('node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // false
|
||||
anymatch('**/node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // true
|
||||
|
||||
const matcher = anymatch(matchers);
|
||||
['foo.js', 'bar.js'].filter(matcher); // [ 'foo.js' ]
|
||||
anymatch master* ❯
|
||||
|
||||
```
|
||||
|
||||
#### anymatch(matchers)
|
||||
You can also pass in only your matcher(s) to get a curried function that has
|
||||
already been bound to the provided matching criteria. This can be used as an
|
||||
`Array#filter` callback.
|
||||
|
||||
```js
|
||||
var matcher = anymatch(matchers);
|
||||
|
||||
matcher('path/to/file.js'); // true
|
||||
matcher('path/anyjs/baz.js', true); // 1
|
||||
|
||||
['foo.js', 'bar.js'].filter(matcher); // ['foo.js']
|
||||
```
|
||||
|
||||
Changelog
|
||||
----------
|
||||
[See release notes page on GitHub](https://github.com/micromatch/anymatch/releases)
|
||||
|
||||
- **v3.0:** Removed `startIndex` and `endIndex` arguments. Node 8.x-only.
|
||||
- **v2.0:** [micromatch](https://github.com/jonschlinkert/micromatch) moves away from minimatch-parity and inline with Bash. This includes handling backslashes differently (see https://github.com/micromatch/micromatch#backslashes for more information).
|
||||
- **v1.2:** anymatch uses [micromatch](https://github.com/jonschlinkert/micromatch)
|
||||
for glob pattern matching. Issues with glob pattern matching should be
|
||||
reported directly to the [micromatch issue tracker](https://github.com/jonschlinkert/micromatch/issues).
|
||||
|
||||
License
|
||||
-------
|
||||
[ISC](https://raw.github.com/micromatch/anymatch/master/LICENSE)
|
||||
20
node_modules/.store/anymatch@3.1.3/node_modules/anymatch/index.d.ts
generated
vendored
Normal file
20
node_modules/.store/anymatch@3.1.3/node_modules/anymatch/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
type AnymatchFn = (testString: string) => boolean;
|
||||
type AnymatchPattern = string|RegExp|AnymatchFn;
|
||||
type AnymatchMatcher = AnymatchPattern|AnymatchPattern[]
|
||||
type AnymatchTester = {
|
||||
(testString: string|any[], returnIndex: true): number;
|
||||
(testString: string|any[]): boolean;
|
||||
}
|
||||
|
||||
type PicomatchOptions = {dot: boolean};
|
||||
|
||||
declare const anymatch: {
|
||||
(matchers: AnymatchMatcher): AnymatchTester;
|
||||
(matchers: AnymatchMatcher, testString: null, returnIndex: true | PicomatchOptions): AnymatchTester;
|
||||
(matchers: AnymatchMatcher, testString: string|any[], returnIndex: true | PicomatchOptions): number;
|
||||
(matchers: AnymatchMatcher, testString: string|any[]): boolean;
|
||||
}
|
||||
|
||||
export {AnymatchMatcher as Matcher}
|
||||
export {AnymatchTester as Tester}
|
||||
export default anymatch
|
||||
104
node_modules/.store/anymatch@3.1.3/node_modules/anymatch/index.js
generated
vendored
Normal file
104
node_modules/.store/anymatch@3.1.3/node_modules/anymatch/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
|
||||
const picomatch = require('picomatch');
|
||||
const normalizePath = require('normalize-path');
|
||||
|
||||
/**
|
||||
* @typedef {(testString: string) => boolean} AnymatchFn
|
||||
* @typedef {string|RegExp|AnymatchFn} AnymatchPattern
|
||||
* @typedef {AnymatchPattern|AnymatchPattern[]} AnymatchMatcher
|
||||
*/
|
||||
const BANG = '!';
|
||||
const DEFAULT_OPTIONS = {returnIndex: false};
|
||||
const arrify = (item) => Array.isArray(item) ? item : [item];
|
||||
|
||||
/**
|
||||
* @param {AnymatchPattern} matcher
|
||||
* @param {object} options
|
||||
* @returns {AnymatchFn}
|
||||
*/
|
||||
const createPattern = (matcher, options) => {
|
||||
if (typeof matcher === 'function') {
|
||||
return matcher;
|
||||
}
|
||||
if (typeof matcher === 'string') {
|
||||
const glob = picomatch(matcher, options);
|
||||
return (string) => matcher === string || glob(string);
|
||||
}
|
||||
if (matcher instanceof RegExp) {
|
||||
return (string) => matcher.test(string);
|
||||
}
|
||||
return (string) => false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Array<Function>} patterns
|
||||
* @param {Array<Function>} negPatterns
|
||||
* @param {String|Array} args
|
||||
* @param {Boolean} returnIndex
|
||||
* @returns {boolean|number}
|
||||
*/
|
||||
const matchPatterns = (patterns, negPatterns, args, returnIndex) => {
|
||||
const isList = Array.isArray(args);
|
||||
const _path = isList ? args[0] : args;
|
||||
if (!isList && typeof _path !== 'string') {
|
||||
throw new TypeError('anymatch: second argument must be a string: got ' +
|
||||
Object.prototype.toString.call(_path))
|
||||
}
|
||||
const path = normalizePath(_path, false);
|
||||
|
||||
for (let index = 0; index < negPatterns.length; index++) {
|
||||
const nglob = negPatterns[index];
|
||||
if (nglob(path)) {
|
||||
return returnIndex ? -1 : false;
|
||||
}
|
||||
}
|
||||
|
||||
const applied = isList && [path].concat(args.slice(1));
|
||||
for (let index = 0; index < patterns.length; index++) {
|
||||
const pattern = patterns[index];
|
||||
if (isList ? pattern(...applied) : pattern(path)) {
|
||||
return returnIndex ? index : true;
|
||||
}
|
||||
}
|
||||
|
||||
return returnIndex ? -1 : false;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {AnymatchMatcher} matchers
|
||||
* @param {Array|string} testString
|
||||
* @param {object} options
|
||||
* @returns {boolean|number|Function}
|
||||
*/
|
||||
const anymatch = (matchers, testString, options = DEFAULT_OPTIONS) => {
|
||||
if (matchers == null) {
|
||||
throw new TypeError('anymatch: specify first argument');
|
||||
}
|
||||
const opts = typeof options === 'boolean' ? {returnIndex: options} : options;
|
||||
const returnIndex = opts.returnIndex || false;
|
||||
|
||||
// Early cache for matchers.
|
||||
const mtchers = arrify(matchers);
|
||||
const negatedGlobs = mtchers
|
||||
.filter(item => typeof item === 'string' && item.charAt(0) === BANG)
|
||||
.map(item => item.slice(1))
|
||||
.map(item => picomatch(item, opts));
|
||||
const patterns = mtchers
|
||||
.filter(item => typeof item !== 'string' || (typeof item === 'string' && item.charAt(0) !== BANG))
|
||||
.map(matcher => createPattern(matcher, opts));
|
||||
|
||||
if (testString == null) {
|
||||
return (testString, ri = false) => {
|
||||
const returnIndex = typeof ri === 'boolean' ? ri : false;
|
||||
return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return matchPatterns(patterns, negatedGlobs, testString, returnIndex);
|
||||
};
|
||||
|
||||
anymatch.default = anymatch;
|
||||
module.exports = anymatch;
|
||||
51
node_modules/.store/anymatch@3.1.3/node_modules/anymatch/package.json
generated
vendored
Normal file
51
node_modules/.store/anymatch@3.1.3/node_modules/anymatch/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
"name": "anymatch",
|
||||
"version": "3.1.3",
|
||||
"description": "Matches strings against configurable strings, globs, regular expressions, and/or functions",
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"dependencies": {
|
||||
"normalize-path": "^3.0.0",
|
||||
"picomatch": "^2.0.4"
|
||||
},
|
||||
"author": {
|
||||
"name": "Elan Shanker",
|
||||
"url": "https://github.com/es128"
|
||||
},
|
||||
"license": "ISC",
|
||||
"homepage": "https://github.com/micromatch/anymatch",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/micromatch/anymatch"
|
||||
},
|
||||
"keywords": [
|
||||
"match",
|
||||
"any",
|
||||
"string",
|
||||
"file",
|
||||
"fs",
|
||||
"list",
|
||||
"glob",
|
||||
"regex",
|
||||
"regexp",
|
||||
"regular",
|
||||
"expression",
|
||||
"function"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "nyc mocha",
|
||||
"mocha": "mocha"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "^6.1.3",
|
||||
"nyc": "^14.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
},
|
||||
"__npminstall_done": true,
|
||||
"_from": "anymatch@3.1.3",
|
||||
"_resolved": "https://registry.npmmirror.com/anymatch/-/anymatch-3.1.3.tgz"
|
||||
}
|
||||
21
node_modules/.store/anymatch@3.1.3/node_modules/normalize-path/LICENSE
generated
vendored
Normal file
21
node_modules/.store/anymatch@3.1.3/node_modules/normalize-path/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014-2018, Jon Schlinkert.
|
||||
|
||||
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.
|
||||
127
node_modules/.store/anymatch@3.1.3/node_modules/normalize-path/README.md
generated
vendored
Normal file
127
node_modules/.store/anymatch@3.1.3/node_modules/normalize-path/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
# normalize-path [](https://www.npmjs.com/package/normalize-path) [](https://npmjs.org/package/normalize-path) [](https://npmjs.org/package/normalize-path) [](https://travis-ci.org/jonschlinkert/normalize-path)
|
||||
|
||||
> Normalize slashes in a file path to be posix/unix-like forward slashes. Also condenses repeat slashes to a single slash and removes and trailing slashes, unless disabled.
|
||||
|
||||
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://www.npmjs.com/):
|
||||
|
||||
```sh
|
||||
$ npm install --save normalize-path
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const normalize = require('normalize-path');
|
||||
|
||||
console.log(normalize('\\foo\\bar\\baz\\'));
|
||||
//=> '/foo/bar/baz'
|
||||
```
|
||||
|
||||
**win32 namespaces**
|
||||
|
||||
```js
|
||||
console.log(normalize('\\\\?\\UNC\\Server01\\user\\docs\\Letter.txt'));
|
||||
//=> '//?/UNC/Server01/user/docs/Letter.txt'
|
||||
|
||||
console.log(normalize('\\\\.\\CdRomX'));
|
||||
//=> '//./CdRomX'
|
||||
```
|
||||
|
||||
**Consecutive slashes**
|
||||
|
||||
Condenses multiple consecutive forward slashes (except for leading slashes in win32 namespaces) to a single slash.
|
||||
|
||||
```js
|
||||
console.log(normalize('.//foo//bar///////baz/'));
|
||||
//=> './foo/bar/baz'
|
||||
```
|
||||
|
||||
### Trailing slashes
|
||||
|
||||
By default trailing slashes are removed. Pass `false` as the last argument to disable this behavior and _**keep** trailing slashes_:
|
||||
|
||||
```js
|
||||
console.log(normalize('foo\\bar\\baz\\', false)); //=> 'foo/bar/baz/'
|
||||
console.log(normalize('./foo/bar/baz/', false)); //=> './foo/bar/baz/'
|
||||
```
|
||||
|
||||
## Release history
|
||||
|
||||
### v3.0
|
||||
|
||||
No breaking changes in this release.
|
||||
|
||||
* a check was added to ensure that [win32 namespaces](https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces) are handled properly by win32 `path.parse()` after a path has been normalized by this library.
|
||||
* a minor optimization was made to simplify how the trailing separator was handled
|
||||
|
||||
## About
|
||||
|
||||
<details>
|
||||
<summary><strong>Contributing</strong></summary>
|
||||
|
||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Running Tests</strong></summary>
|
||||
|
||||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
||||
|
||||
```sh
|
||||
$ npm install && npm test
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Building docs</strong></summary>
|
||||
|
||||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
||||
|
||||
To generate the readme, run the following command:
|
||||
|
||||
```sh
|
||||
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### Related projects
|
||||
|
||||
Other useful path-related libraries:
|
||||
|
||||
* [contains-path](https://www.npmjs.com/package/contains-path): Return true if a file path contains the given path. | [homepage](https://github.com/jonschlinkert/contains-path "Return true if a file path contains the given path.")
|
||||
* [is-absolute](https://www.npmjs.com/package/is-absolute): Returns true if a file path is absolute. Does not rely on the path module… [more](https://github.com/jonschlinkert/is-absolute) | [homepage](https://github.com/jonschlinkert/is-absolute "Returns true if a file path is absolute. Does not rely on the path module and can be used as a polyfill for node.js native `path.isAbolute`.")
|
||||
* [is-relative](https://www.npmjs.com/package/is-relative): Returns `true` if the path appears to be relative. | [homepage](https://github.com/jonschlinkert/is-relative "Returns `true` if the path appears to be relative.")
|
||||
* [parse-filepath](https://www.npmjs.com/package/parse-filepath): Pollyfill for node.js `path.parse`, parses a filepath into an object. | [homepage](https://github.com/jonschlinkert/parse-filepath "Pollyfill for node.js `path.parse`, parses a filepath into an object.")
|
||||
* [path-ends-with](https://www.npmjs.com/package/path-ends-with): Return `true` if a file path ends with the given string/suffix. | [homepage](https://github.com/jonschlinkert/path-ends-with "Return `true` if a file path ends with the given string/suffix.")
|
||||
* [unixify](https://www.npmjs.com/package/unixify): Convert Windows file paths to unix paths. | [homepage](https://github.com/jonschlinkert/unixify "Convert Windows file paths to unix paths.")
|
||||
|
||||
### Contributors
|
||||
|
||||
| **Commits** | **Contributor** |
|
||||
| --- | --- |
|
||||
| 35 | [jonschlinkert](https://github.com/jonschlinkert) |
|
||||
| 1 | [phated](https://github.com/phated) |
|
||||
|
||||
### Author
|
||||
|
||||
**Jon Schlinkert**
|
||||
|
||||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
||||
* [GitHub Profile](https://github.com/jonschlinkert)
|
||||
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
||||
|
||||
### License
|
||||
|
||||
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
|
||||
Released under the [MIT License](LICENSE).
|
||||
|
||||
***
|
||||
|
||||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on April 19, 2018._
|
||||
35
node_modules/.store/anymatch@3.1.3/node_modules/normalize-path/index.js
generated
vendored
Normal file
35
node_modules/.store/anymatch@3.1.3/node_modules/normalize-path/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*!
|
||||
* normalize-path <https://github.com/jonschlinkert/normalize-path>
|
||||
*
|
||||
* Copyright (c) 2014-2018, Jon Schlinkert.
|
||||
* Released under the MIT License.
|
||||
*/
|
||||
|
||||
module.exports = function(path, stripTrailing) {
|
||||
if (typeof path !== 'string') {
|
||||
throw new TypeError('expected path to be a string');
|
||||
}
|
||||
|
||||
if (path === '\\' || path === '/') return '/';
|
||||
|
||||
var len = path.length;
|
||||
if (len <= 1) return path;
|
||||
|
||||
// ensure that win32 namespaces has two leading slashes, so that the path is
|
||||
// handled properly by the win32 version of path.parse() after being normalized
|
||||
// https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
|
||||
var prefix = '';
|
||||
if (len > 4 && path[3] === '\\') {
|
||||
var ch = path[2];
|
||||
if ((ch === '?' || ch === '.') && path.slice(0, 2) === '\\\\') {
|
||||
path = path.slice(2);
|
||||
prefix = '//';
|
||||
}
|
||||
}
|
||||
|
||||
var segs = path.split(/[/\\]+/);
|
||||
if (stripTrailing !== false && segs[segs.length - 1] === '') {
|
||||
segs.pop();
|
||||
}
|
||||
return prefix + segs.join('/');
|
||||
};
|
||||
80
node_modules/.store/anymatch@3.1.3/node_modules/normalize-path/package.json
generated
vendored
Normal file
80
node_modules/.store/anymatch@3.1.3/node_modules/normalize-path/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
{
|
||||
"name": "normalize-path",
|
||||
"description": "Normalize slashes in a file path to be posix/unix-like forward slashes. Also condenses repeat slashes to a single slash and removes and trailing slashes, unless disabled.",
|
||||
"version": "3.0.0",
|
||||
"homepage": "https://github.com/jonschlinkert/normalize-path",
|
||||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
||||
"contributors": [
|
||||
"Blaine Bublitz (https://twitter.com/BlaineBublitz)",
|
||||
"Jon Schlinkert (http://twitter.com/jonschlinkert)"
|
||||
],
|
||||
"repository": "jonschlinkert/normalize-path",
|
||||
"bugs": {
|
||||
"url": "https://github.com/jonschlinkert/normalize-path/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha"
|
||||
},
|
||||
"devDependencies": {
|
||||
"gulp-format-md": "^1.0.0",
|
||||
"minimist": "^1.2.0",
|
||||
"mocha": "^3.5.3"
|
||||
},
|
||||
"keywords": [
|
||||
"absolute",
|
||||
"backslash",
|
||||
"delimiter",
|
||||
"file",
|
||||
"file-path",
|
||||
"filepath",
|
||||
"fix",
|
||||
"forward",
|
||||
"fp",
|
||||
"fs",
|
||||
"normalize",
|
||||
"path",
|
||||
"relative",
|
||||
"separator",
|
||||
"slash",
|
||||
"slashes",
|
||||
"trailing",
|
||||
"unix",
|
||||
"urix"
|
||||
],
|
||||
"verb": {
|
||||
"toc": false,
|
||||
"layout": "default",
|
||||
"tasks": [
|
||||
"readme"
|
||||
],
|
||||
"plugins": [
|
||||
"gulp-format-md"
|
||||
],
|
||||
"related": {
|
||||
"description": "Other useful path-related libraries:",
|
||||
"list": [
|
||||
"contains-path",
|
||||
"is-absolute",
|
||||
"is-relative",
|
||||
"parse-filepath",
|
||||
"path-ends-with",
|
||||
"path-ends-with",
|
||||
"unixify"
|
||||
]
|
||||
},
|
||||
"lint": {
|
||||
"reflinks": true
|
||||
}
|
||||
},
|
||||
"__npminstall_done": true,
|
||||
"_from": "normalize-path@3.0.0",
|
||||
"_resolved": "https://registry.npmmirror.com/normalize-path/-/normalize-path-3.0.0.tgz"
|
||||
}
|
||||
136
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/CHANGELOG.md
generated
vendored
Normal file
136
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/CHANGELOG.md
generated
vendored
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
# Release history
|
||||
|
||||
**All notable changes to this project will be documented in this file.**
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||
|
||||
<details>
|
||||
<summary><strong>Guiding Principles</strong></summary>
|
||||
|
||||
- Changelogs are for humans, not machines.
|
||||
- There should be an entry for every single version.
|
||||
- The same types of changes should be grouped.
|
||||
- Versions and sections should be linkable.
|
||||
- The latest version comes first.
|
||||
- The release date of each versions is displayed.
|
||||
- Mention whether you follow Semantic Versioning.
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Types of changes</strong></summary>
|
||||
|
||||
Changelog entries are classified using the following labels _(from [keep-a-changelog](http://keepachangelog.com/)_):
|
||||
|
||||
- `Added` for new features.
|
||||
- `Changed` for changes in existing functionality.
|
||||
- `Deprecated` for soon-to-be removed features.
|
||||
- `Removed` for now removed features.
|
||||
- `Fixed` for any bug fixes.
|
||||
- `Security` in case of vulnerabilities.
|
||||
|
||||
</details>
|
||||
|
||||
## 2.3.1 (2022-01-02)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixes bug when a pattern containing an expression after the closing parenthesis (`/!(*.d).{ts,tsx}`) was incorrectly converted to regexp ([9f241ef](https://github.com/micromatch/picomatch/commit/9f241ef)).
|
||||
|
||||
### Changed
|
||||
|
||||
* Some documentation improvements ([f81d236](https://github.com/micromatch/picomatch/commit/f81d236), [421e0e7](https://github.com/micromatch/picomatch/commit/421e0e7)).
|
||||
|
||||
## 2.3.0 (2021-05-21)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fixes bug where file names with two dots were not being matched consistently with negation extglobs containing a star ([56083ef](https://github.com/micromatch/picomatch/commit/56083ef))
|
||||
|
||||
## 2.2.3 (2021-04-10)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Do not skip pattern seperator for square brackets ([fb08a30](https://github.com/micromatch/picomatch/commit/fb08a30)).
|
||||
* Set negatedExtGlob also if it does not span the whole pattern ([032e3f5](https://github.com/micromatch/picomatch/commit/032e3f5)).
|
||||
|
||||
## 2.2.2 (2020-03-21)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Correctly handle parts of the pattern after parentheses in the `scan` method ([e15b920](https://github.com/micromatch/picomatch/commit/e15b920)).
|
||||
|
||||
## 2.2.1 (2020-01-04)
|
||||
|
||||
* Fixes [#49](https://github.com/micromatch/picomatch/issues/49), so that braces with no sets or ranges are now propertly treated as literals.
|
||||
|
||||
## 2.2.0 (2020-01-04)
|
||||
|
||||
* Disable fastpaths mode for the parse method ([5b8d33f](https://github.com/micromatch/picomatch/commit/5b8d33f))
|
||||
* Add `tokens`, `slashes`, and `parts` to the object returned by `picomatch.scan()`.
|
||||
|
||||
## 2.1.0 (2019-10-31)
|
||||
|
||||
* add benchmarks for scan ([4793b92](https://github.com/micromatch/picomatch/commit/4793b92))
|
||||
* Add eslint object-curly-spacing rule ([707c650](https://github.com/micromatch/picomatch/commit/707c650))
|
||||
* Add prefer-const eslint rule ([5c7501c](https://github.com/micromatch/picomatch/commit/5c7501c))
|
||||
* Add support for nonegate in scan API ([275c9b9](https://github.com/micromatch/picomatch/commit/275c9b9))
|
||||
* Change lets to consts. Move root import up. ([4840625](https://github.com/micromatch/picomatch/commit/4840625))
|
||||
* closes https://github.com/micromatch/picomatch/issues/21 ([766bcb0](https://github.com/micromatch/picomatch/commit/766bcb0))
|
||||
* Fix "Extglobs" table in readme ([eb19da8](https://github.com/micromatch/picomatch/commit/eb19da8))
|
||||
* fixes https://github.com/micromatch/picomatch/issues/20 ([9caca07](https://github.com/micromatch/picomatch/commit/9caca07))
|
||||
* fixes https://github.com/micromatch/picomatch/issues/26 ([fa58f45](https://github.com/micromatch/picomatch/commit/fa58f45))
|
||||
* Lint test ([d433a34](https://github.com/micromatch/picomatch/commit/d433a34))
|
||||
* lint unit tests ([0159b55](https://github.com/micromatch/picomatch/commit/0159b55))
|
||||
* Make scan work with noext ([6c02e03](https://github.com/micromatch/picomatch/commit/6c02e03))
|
||||
* minor linting ([c2a2b87](https://github.com/micromatch/picomatch/commit/c2a2b87))
|
||||
* minor parser improvements ([197671d](https://github.com/micromatch/picomatch/commit/197671d))
|
||||
* remove eslint since it... ([07876fa](https://github.com/micromatch/picomatch/commit/07876fa))
|
||||
* remove funding file ([8ebe96d](https://github.com/micromatch/picomatch/commit/8ebe96d))
|
||||
* Remove unused funks ([cbc6d54](https://github.com/micromatch/picomatch/commit/cbc6d54))
|
||||
* Run eslint during pretest, fix existing eslint findings ([0682367](https://github.com/micromatch/picomatch/commit/0682367))
|
||||
* support `noparen` in scan ([3d37569](https://github.com/micromatch/picomatch/commit/3d37569))
|
||||
* update changelog ([7b34e77](https://github.com/micromatch/picomatch/commit/7b34e77))
|
||||
* update travis ([777f038](https://github.com/micromatch/picomatch/commit/777f038))
|
||||
* Use eslint-disable-next-line instead of eslint-disable ([4e7c1fd](https://github.com/micromatch/picomatch/commit/4e7c1fd))
|
||||
|
||||
## 2.0.7 (2019-05-14)
|
||||
|
||||
* 2.0.7 ([9eb9a71](https://github.com/micromatch/picomatch/commit/9eb9a71))
|
||||
* supports lookbehinds ([1f63f7e](https://github.com/micromatch/picomatch/commit/1f63f7e))
|
||||
* update .verb.md file with typo change ([2741279](https://github.com/micromatch/picomatch/commit/2741279))
|
||||
* fix: typo in README ([0753e44](https://github.com/micromatch/picomatch/commit/0753e44))
|
||||
|
||||
## 2.0.4 (2019-04-10)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Readme link [fixed](https://github.com/micromatch/picomatch/pull/13/commits/a96ab3aa2b11b6861c23289964613d85563b05df) by @danez.
|
||||
- `options.capture` now works as expected when fastpaths are enabled. See https://github.com/micromatch/picomatch/pull/12/commits/26aefd71f1cfaf95c37f1c1fcab68a693b037304. Thanks to @DrPizza.
|
||||
|
||||
## 2.0.0 (2019-04-10)
|
||||
|
||||
### Added
|
||||
|
||||
- Adds support for `options.onIgnore`. See the readme for details
|
||||
- Adds support for `options.onResult`. See the readme for details
|
||||
|
||||
### Breaking changes
|
||||
|
||||
- The unixify option was renamed to `windows`
|
||||
- caching and all related options and methods have been removed
|
||||
|
||||
## 1.0.0 (2018-11-05)
|
||||
|
||||
- adds `.onMatch` option
|
||||
- improvements to `.scan` method
|
||||
- numerous improvements and optimizations for matching and parsing
|
||||
- better windows path handling
|
||||
|
||||
## 0.1.0 - 2017-04-13
|
||||
|
||||
First release.
|
||||
|
||||
|
||||
[keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017-present, Jon Schlinkert.
|
||||
|
||||
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.
|
||||
708
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/README.md
generated
vendored
Normal file
708
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,708 @@
|
|||
<h1 align="center">Picomatch</h1>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://npmjs.org/package/picomatch">
|
||||
<img src="https://img.shields.io/npm/v/picomatch.svg" alt="version">
|
||||
</a>
|
||||
<a href="https://github.com/micromatch/picomatch/actions?workflow=Tests">
|
||||
<img src="https://github.com/micromatch/picomatch/workflows/Tests/badge.svg" alt="test status">
|
||||
</a>
|
||||
<a href="https://coveralls.io/github/micromatch/picomatch">
|
||||
<img src="https://img.shields.io/coveralls/github/micromatch/picomatch/master.svg" alt="coverage status">
|
||||
</a>
|
||||
<a href="https://npmjs.org/package/picomatch">
|
||||
<img src="https://img.shields.io/npm/dm/picomatch.svg" alt="downloads">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<p align="center">
|
||||
<strong>Blazing fast and accurate glob matcher written in JavaScript.</strong></br>
|
||||
<em>No dependencies and full support for standard and extended Bash glob features, including braces, extglobs, POSIX brackets, and regular expressions.</em>
|
||||
</p>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
## Why picomatch?
|
||||
|
||||
* **Lightweight** - No dependencies
|
||||
* **Minimal** - Tiny API surface. Main export is a function that takes a glob pattern and returns a matcher function.
|
||||
* **Fast** - Loads in about 2ms (that's several times faster than a [single frame of a HD movie](http://www.endmemo.com/sconvert/framespersecondframespermillisecond.php) at 60fps)
|
||||
* **Performant** - Use the returned matcher function to speed up repeat matching (like when watching files)
|
||||
* **Accurate matching** - Using wildcards (`*` and `?`), globstars (`**`) for nested directories, [advanced globbing](#advanced-globbing) with extglobs, braces, and POSIX brackets, and support for escaping special characters with `\` or quotes.
|
||||
* **Well tested** - Thousands of unit tests
|
||||
|
||||
See the [library comparison](#library-comparisons) to other libraries.
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
## Table of Contents
|
||||
|
||||
<details><summary> Click to expand </summary>
|
||||
|
||||
- [Install](#install)
|
||||
- [Usage](#usage)
|
||||
- [API](#api)
|
||||
* [picomatch](#picomatch)
|
||||
* [.test](#test)
|
||||
* [.matchBase](#matchbase)
|
||||
* [.isMatch](#ismatch)
|
||||
* [.parse](#parse)
|
||||
* [.scan](#scan)
|
||||
* [.compileRe](#compilere)
|
||||
* [.makeRe](#makere)
|
||||
* [.toRegex](#toregex)
|
||||
- [Options](#options)
|
||||
* [Picomatch options](#picomatch-options)
|
||||
* [Scan Options](#scan-options)
|
||||
* [Options Examples](#options-examples)
|
||||
- [Globbing features](#globbing-features)
|
||||
* [Basic globbing](#basic-globbing)
|
||||
* [Advanced globbing](#advanced-globbing)
|
||||
* [Braces](#braces)
|
||||
* [Matching special characters as literals](#matching-special-characters-as-literals)
|
||||
- [Library Comparisons](#library-comparisons)
|
||||
- [Benchmarks](#benchmarks)
|
||||
- [Philosophies](#philosophies)
|
||||
- [About](#about)
|
||||
* [Author](#author)
|
||||
* [License](#license)
|
||||
|
||||
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
|
||||
|
||||
</details>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://www.npmjs.com/):
|
||||
|
||||
```sh
|
||||
npm install --save picomatch
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## Usage
|
||||
|
||||
The main export is a function that takes a glob pattern and an options object and returns a function for matching strings.
|
||||
|
||||
```js
|
||||
const pm = require('picomatch');
|
||||
const isMatch = pm('*.js');
|
||||
|
||||
console.log(isMatch('abcd')); //=> false
|
||||
console.log(isMatch('a.js')); //=> true
|
||||
console.log(isMatch('a.md')); //=> false
|
||||
console.log(isMatch('a/b.js')); //=> false
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## API
|
||||
|
||||
### [picomatch](lib/picomatch.js#L32)
|
||||
|
||||
Creates a matcher function from one or more glob patterns. The returned function takes a string to match as its first argument, and returns true if the string is a match. The returned matcher function also takes a boolean as the second argument that, when true, returns an object with additional information.
|
||||
|
||||
**Params**
|
||||
|
||||
* `globs` **{String|Array}**: One or more glob patterns.
|
||||
* `options` **{Object=}**
|
||||
* `returns` **{Function=}**: Returns a matcher function.
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
const picomatch = require('picomatch');
|
||||
// picomatch(glob[, options]);
|
||||
|
||||
const isMatch = picomatch('*.!(*a)');
|
||||
console.log(isMatch('a.a')); //=> false
|
||||
console.log(isMatch('a.b')); //=> true
|
||||
```
|
||||
|
||||
### [.test](lib/picomatch.js#L117)
|
||||
|
||||
Test `input` with the given `regex`. This is used by the main `picomatch()` function to test the input string.
|
||||
|
||||
**Params**
|
||||
|
||||
* `input` **{String}**: String to test.
|
||||
* `regex` **{RegExp}**
|
||||
* `returns` **{Object}**: Returns an object with matching info.
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
const picomatch = require('picomatch');
|
||||
// picomatch.test(input, regex[, options]);
|
||||
|
||||
console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
|
||||
// { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
|
||||
```
|
||||
|
||||
### [.matchBase](lib/picomatch.js#L161)
|
||||
|
||||
Match the basename of a filepath.
|
||||
|
||||
**Params**
|
||||
|
||||
* `input` **{String}**: String to test.
|
||||
* `glob` **{RegExp|String}**: Glob pattern or regex created by [.makeRe](#makeRe).
|
||||
* `returns` **{Boolean}**
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
const picomatch = require('picomatch');
|
||||
// picomatch.matchBase(input, glob[, options]);
|
||||
console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
|
||||
```
|
||||
|
||||
### [.isMatch](lib/picomatch.js#L183)
|
||||
|
||||
Returns true if **any** of the given glob `patterns` match the specified `string`.
|
||||
|
||||
**Params**
|
||||
|
||||
* **{String|Array}**: str The string to test.
|
||||
* **{String|Array}**: patterns One or more glob patterns to use for matching.
|
||||
* **{Object}**: See available [options](#options).
|
||||
* `returns` **{Boolean}**: Returns true if any patterns match `str`
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
const picomatch = require('picomatch');
|
||||
// picomatch.isMatch(string, patterns[, options]);
|
||||
|
||||
console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
|
||||
console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
|
||||
```
|
||||
|
||||
### [.parse](lib/picomatch.js#L199)
|
||||
|
||||
Parse a glob pattern to create the source string for a regular expression.
|
||||
|
||||
**Params**
|
||||
|
||||
* `pattern` **{String}**
|
||||
* `options` **{Object}**
|
||||
* `returns` **{Object}**: Returns an object with useful properties and output to be used as a regex source string.
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
const picomatch = require('picomatch');
|
||||
const result = picomatch.parse(pattern[, options]);
|
||||
```
|
||||
|
||||
### [.scan](lib/picomatch.js#L231)
|
||||
|
||||
Scan a glob pattern to separate the pattern into segments.
|
||||
|
||||
**Params**
|
||||
|
||||
* `input` **{String}**: Glob pattern to scan.
|
||||
* `options` **{Object}**
|
||||
* `returns` **{Object}**: Returns an object with
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
const picomatch = require('picomatch');
|
||||
// picomatch.scan(input[, options]);
|
||||
|
||||
const result = picomatch.scan('!./foo/*.js');
|
||||
console.log(result);
|
||||
{ prefix: '!./',
|
||||
input: '!./foo/*.js',
|
||||
start: 3,
|
||||
base: 'foo',
|
||||
glob: '*.js',
|
||||
isBrace: false,
|
||||
isBracket: false,
|
||||
isGlob: true,
|
||||
isExtglob: false,
|
||||
isGlobstar: false,
|
||||
negated: true }
|
||||
```
|
||||
|
||||
### [.compileRe](lib/picomatch.js#L245)
|
||||
|
||||
Compile a regular expression from the `state` object returned by the
|
||||
[parse()](#parse) method.
|
||||
|
||||
**Params**
|
||||
|
||||
* `state` **{Object}**
|
||||
* `options` **{Object}**
|
||||
* `returnOutput` **{Boolean}**: Intended for implementors, this argument allows you to return the raw output from the parser.
|
||||
* `returnState` **{Boolean}**: Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
|
||||
* `returns` **{RegExp}**
|
||||
|
||||
### [.makeRe](lib/picomatch.js#L286)
|
||||
|
||||
Create a regular expression from a parsed glob pattern.
|
||||
|
||||
**Params**
|
||||
|
||||
* `state` **{String}**: The object returned from the `.parse` method.
|
||||
* `options` **{Object}**
|
||||
* `returnOutput` **{Boolean}**: Implementors may use this argument to return the compiled output, instead of a regular expression. This is not exposed on the options to prevent end-users from mutating the result.
|
||||
* `returnState` **{Boolean}**: Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
|
||||
* `returns` **{RegExp}**: Returns a regex created from the given pattern.
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
const picomatch = require('picomatch');
|
||||
const state = picomatch.parse('*.js');
|
||||
// picomatch.compileRe(state[, options]);
|
||||
|
||||
console.log(picomatch.compileRe(state));
|
||||
//=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
||||
```
|
||||
|
||||
### [.toRegex](lib/picomatch.js#L321)
|
||||
|
||||
Create a regular expression from the given regex source string.
|
||||
|
||||
**Params**
|
||||
|
||||
* `source` **{String}**: Regular expression source string.
|
||||
* `options` **{Object}**
|
||||
* `returns` **{RegExp}**
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
const picomatch = require('picomatch');
|
||||
// picomatch.toRegex(source[, options]);
|
||||
|
||||
const { output } = picomatch.parse('*.js');
|
||||
console.log(picomatch.toRegex(output));
|
||||
//=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
## Options
|
||||
|
||||
### Picomatch options
|
||||
|
||||
The following options may be used with the main `picomatch()` function or any of the methods on the picomatch API.
|
||||
|
||||
| **Option** | **Type** | **Default value** | **Description** |
|
||||
| --- | --- | --- | --- |
|
||||
| `basename` | `boolean` | `false` | If set, then patterns without slashes will be matched against the basename of the path if it contains slashes. For example, `a?b` would match the path `/xyz/123/acb`, but not `/xyz/acb/123`. |
|
||||
| `bash` | `boolean` | `false` | Follow bash matching rules more strictly - disallows backslashes as escape characters, and treats single stars as globstars (`**`). |
|
||||
| `capture` | `boolean` | `undefined` | Return regex matches in supporting methods. |
|
||||
| `contains` | `boolean` | `undefined` | Allows glob to match any part of the given string(s). |
|
||||
| `cwd` | `string` | `process.cwd()` | Current working directory. Used by `picomatch.split()` |
|
||||
| `debug` | `boolean` | `undefined` | Debug regular expressions when an error is thrown. |
|
||||
| `dot` | `boolean` | `false` | Enable dotfile matching. By default, dotfiles are ignored unless a `.` is explicitly defined in the pattern, or `options.dot` is true |
|
||||
| `expandRange` | `function` | `undefined` | Custom function for expanding ranges in brace patterns, such as `{a..z}`. The function receives the range values as two arguments, and it must return a string to be used in the generated regex. It's recommended that returned strings be wrapped in parentheses. |
|
||||
| `failglob` | `boolean` | `false` | Throws an error if no matches are found. Based on the bash option of the same name. |
|
||||
| `fastpaths` | `boolean` | `true` | To speed up processing, full parsing is skipped for a handful common glob patterns. Disable this behavior by setting this option to `false`. |
|
||||
| `flags` | `string` | `undefined` | Regex flags to use in the generated regex. If defined, the `nocase` option will be overridden. |
|
||||
| [format](#optionsformat) | `function` | `undefined` | Custom function for formatting the returned string. This is useful for removing leading slashes, converting Windows paths to Posix paths, etc. |
|
||||
| `ignore` | `array\|string` | `undefined` | One or more glob patterns for excluding strings that should not be matched from the result. |
|
||||
| `keepQuotes` | `boolean` | `false` | Retain quotes in the generated regex, since quotes may also be used as an alternative to backslashes. |
|
||||
| `literalBrackets` | `boolean` | `undefined` | When `true`, brackets in the glob pattern will be escaped so that only literal brackets will be matched. |
|
||||
| `matchBase` | `boolean` | `false` | Alias for `basename` |
|
||||
| `maxLength` | `boolean` | `65536` | Limit the max length of the input string. An error is thrown if the input string is longer than this value. |
|
||||
| `nobrace` | `boolean` | `false` | Disable brace matching, so that `{a,b}` and `{1..3}` would be treated as literal characters. |
|
||||
| `nobracket` | `boolean` | `undefined` | Disable matching with regex brackets. |
|
||||
| `nocase` | `boolean` | `false` | Make matching case-insensitive. Equivalent to the regex `i` flag. Note that this option is overridden by the `flags` option. |
|
||||
| `nodupes` | `boolean` | `true` | Deprecated, use `nounique` instead. This option will be removed in a future major release. By default duplicates are removed. Disable uniquification by setting this option to false. |
|
||||
| `noext` | `boolean` | `false` | Alias for `noextglob` |
|
||||
| `noextglob` | `boolean` | `false` | Disable support for matching with extglobs (like `+(a\|b)`) |
|
||||
| `noglobstar` | `boolean` | `false` | Disable support for matching nested directories with globstars (`**`) |
|
||||
| `nonegate` | `boolean` | `false` | Disable support for negating with leading `!` |
|
||||
| `noquantifiers` | `boolean` | `false` | Disable support for regex quantifiers (like `a{1,2}`) and treat them as brace patterns to be expanded. |
|
||||
| [onIgnore](#optionsonIgnore) | `function` | `undefined` | Function to be called on ignored items. |
|
||||
| [onMatch](#optionsonMatch) | `function` | `undefined` | Function to be called on matched items. |
|
||||
| [onResult](#optionsonResult) | `function` | `undefined` | Function to be called on all items, regardless of whether or not they are matched or ignored. |
|
||||
| `posix` | `boolean` | `false` | Support POSIX character classes ("posix brackets"). |
|
||||
| `posixSlashes` | `boolean` | `undefined` | Convert all slashes in file paths to forward slashes. This does not convert slashes in the glob pattern itself |
|
||||
| `prepend` | `boolean` | `undefined` | String to prepend to the generated regex used for matching. |
|
||||
| `regex` | `boolean` | `false` | Use regular expression rules for `+` (instead of matching literal `+`), and for stars that follow closing parentheses or brackets (as in `)*` and `]*`). |
|
||||
| `strictBrackets` | `boolean` | `undefined` | Throw an error if brackets, braces, or parens are imbalanced. |
|
||||
| `strictSlashes` | `boolean` | `undefined` | When true, picomatch won't match trailing slashes with single stars. |
|
||||
| `unescape` | `boolean` | `undefined` | Remove backslashes preceding escaped characters in the glob pattern. By default, backslashes are retained. |
|
||||
| `unixify` | `boolean` | `undefined` | Alias for `posixSlashes`, for backwards compatibility. |
|
||||
|
||||
picomatch has automatic detection for regex positive and negative lookbehinds. If the pattern contains a negative lookbehind, you must be using Node.js >= 8.10 or else picomatch will throw an error.
|
||||
|
||||
### Scan Options
|
||||
|
||||
In addition to the main [picomatch options](#picomatch-options), the following options may also be used with the [.scan](#scan) method.
|
||||
|
||||
| **Option** | **Type** | **Default value** | **Description** |
|
||||
| --- | --- | --- | --- |
|
||||
| `tokens` | `boolean` | `false` | When `true`, the returned object will include an array of tokens (objects), representing each path "segment" in the scanned glob pattern |
|
||||
| `parts` | `boolean` | `false` | When `true`, the returned object will include an array of strings representing each path "segment" in the scanned glob pattern. This is automatically enabled when `options.tokens` is true |
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
const picomatch = require('picomatch');
|
||||
const result = picomatch.scan('!./foo/*.js', { tokens: true });
|
||||
console.log(result);
|
||||
// {
|
||||
// prefix: '!./',
|
||||
// input: '!./foo/*.js',
|
||||
// start: 3,
|
||||
// base: 'foo',
|
||||
// glob: '*.js',
|
||||
// isBrace: false,
|
||||
// isBracket: false,
|
||||
// isGlob: true,
|
||||
// isExtglob: false,
|
||||
// isGlobstar: false,
|
||||
// negated: true,
|
||||
// maxDepth: 2,
|
||||
// tokens: [
|
||||
// { value: '!./', depth: 0, isGlob: false, negated: true, isPrefix: true },
|
||||
// { value: 'foo', depth: 1, isGlob: false },
|
||||
// { value: '*.js', depth: 1, isGlob: true }
|
||||
// ],
|
||||
// slashes: [ 2, 6 ],
|
||||
// parts: [ 'foo', '*.js' ]
|
||||
// }
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### Options Examples
|
||||
|
||||
#### options.expandRange
|
||||
|
||||
**Type**: `function`
|
||||
|
||||
**Default**: `undefined`
|
||||
|
||||
Custom function for expanding ranges in brace patterns. The [fill-range](https://github.com/jonschlinkert/fill-range) library is ideal for this purpose, or you can use custom code to do whatever you need.
|
||||
|
||||
**Example**
|
||||
|
||||
The following example shows how to create a glob that matches a folder
|
||||
|
||||
```js
|
||||
const fill = require('fill-range');
|
||||
const regex = pm.makeRe('foo/{01..25}/bar', {
|
||||
expandRange(a, b) {
|
||||
return `(${fill(a, b, { toRegex: true })})`;
|
||||
}
|
||||
});
|
||||
|
||||
console.log(regex);
|
||||
//=> /^(?:foo\/((?:0[1-9]|1[0-9]|2[0-5]))\/bar)$/
|
||||
|
||||
console.log(regex.test('foo/00/bar')) // false
|
||||
console.log(regex.test('foo/01/bar')) // true
|
||||
console.log(regex.test('foo/10/bar')) // true
|
||||
console.log(regex.test('foo/22/bar')) // true
|
||||
console.log(regex.test('foo/25/bar')) // true
|
||||
console.log(regex.test('foo/26/bar')) // false
|
||||
```
|
||||
|
||||
#### options.format
|
||||
|
||||
**Type**: `function`
|
||||
|
||||
**Default**: `undefined`
|
||||
|
||||
Custom function for formatting strings before they're matched.
|
||||
|
||||
**Example**
|
||||
|
||||
```js
|
||||
// strip leading './' from strings
|
||||
const format = str => str.replace(/^\.\//, '');
|
||||
const isMatch = picomatch('foo/*.js', { format });
|
||||
console.log(isMatch('./foo/bar.js')); //=> true
|
||||
```
|
||||
|
||||
#### options.onMatch
|
||||
|
||||
```js
|
||||
const onMatch = ({ glob, regex, input, output }) => {
|
||||
console.log({ glob, regex, input, output });
|
||||
};
|
||||
|
||||
const isMatch = picomatch('*', { onMatch });
|
||||
isMatch('foo');
|
||||
isMatch('bar');
|
||||
isMatch('baz');
|
||||
```
|
||||
|
||||
#### options.onIgnore
|
||||
|
||||
```js
|
||||
const onIgnore = ({ glob, regex, input, output }) => {
|
||||
console.log({ glob, regex, input, output });
|
||||
};
|
||||
|
||||
const isMatch = picomatch('*', { onIgnore, ignore: 'f*' });
|
||||
isMatch('foo');
|
||||
isMatch('bar');
|
||||
isMatch('baz');
|
||||
```
|
||||
|
||||
#### options.onResult
|
||||
|
||||
```js
|
||||
const onResult = ({ glob, regex, input, output }) => {
|
||||
console.log({ glob, regex, input, output });
|
||||
};
|
||||
|
||||
const isMatch = picomatch('*', { onResult, ignore: 'f*' });
|
||||
isMatch('foo');
|
||||
isMatch('bar');
|
||||
isMatch('baz');
|
||||
```
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
## Globbing features
|
||||
|
||||
* [Basic globbing](#basic-globbing) (Wildcard matching)
|
||||
* [Advanced globbing](#advanced-globbing) (extglobs, posix brackets, brace matching)
|
||||
|
||||
### Basic globbing
|
||||
|
||||
| **Character** | **Description** |
|
||||
| --- | --- |
|
||||
| `*` | Matches any character zero or more times, excluding path separators. Does _not match_ path separators or hidden files or directories ("dotfiles"), unless explicitly enabled by setting the `dot` option to `true`. |
|
||||
| `**` | Matches any character zero or more times, including path separators. Note that `**` will only match path separators (`/`, and `\\` on Windows) when they are the only characters in a path segment. Thus, `foo**/bar` is equivalent to `foo*/bar`, and `foo/a**b/bar` is equivalent to `foo/a*b/bar`, and _more than two_ consecutive stars in a glob path segment are regarded as _a single star_. Thus, `foo/***/bar` is equivalent to `foo/*/bar`. |
|
||||
| `?` | Matches any character excluding path separators one time. Does _not match_ path separators or leading dots. |
|
||||
| `[abc]` | Matches any characters inside the brackets. For example, `[abc]` would match the characters `a`, `b` or `c`, and nothing else. |
|
||||
|
||||
#### Matching behavior vs. Bash
|
||||
|
||||
Picomatch's matching features and expected results in unit tests are based on Bash's unit tests and the Bash 4.3 specification, with the following exceptions:
|
||||
|
||||
* Bash will match `foo/bar/baz` with `*`. Picomatch only matches nested directories with `**`.
|
||||
* Bash greedily matches with negated extglobs. For example, Bash 4.3 says that `!(foo)*` should match `foo` and `foobar`, since the trailing `*` bracktracks to match the preceding pattern. This is very memory-inefficient, and IMHO, also incorrect. Picomatch would return `false` for both `foo` and `foobar`.
|
||||
|
||||
<br>
|
||||
|
||||
### Advanced globbing
|
||||
|
||||
* [extglobs](#extglobs)
|
||||
* [POSIX brackets](#posix-brackets)
|
||||
* [Braces](#brace-expansion)
|
||||
|
||||
#### Extglobs
|
||||
|
||||
| **Pattern** | **Description** |
|
||||
| --- | --- |
|
||||
| `@(pattern)` | Match _only one_ consecutive occurrence of `pattern` |
|
||||
| `*(pattern)` | Match _zero or more_ consecutive occurrences of `pattern` |
|
||||
| `+(pattern)` | Match _one or more_ consecutive occurrences of `pattern` |
|
||||
| `?(pattern)` | Match _zero or **one**_ consecutive occurrences of `pattern` |
|
||||
| `!(pattern)` | Match _anything but_ `pattern` |
|
||||
|
||||
**Examples**
|
||||
|
||||
```js
|
||||
const pm = require('picomatch');
|
||||
|
||||
// *(pattern) matches ZERO or more of "pattern"
|
||||
console.log(pm.isMatch('a', 'a*(z)')); // true
|
||||
console.log(pm.isMatch('az', 'a*(z)')); // true
|
||||
console.log(pm.isMatch('azzz', 'a*(z)')); // true
|
||||
|
||||
// +(pattern) matches ONE or more of "pattern"
|
||||
console.log(pm.isMatch('a', 'a*(z)')); // true
|
||||
console.log(pm.isMatch('az', 'a*(z)')); // true
|
||||
console.log(pm.isMatch('azzz', 'a*(z)')); // true
|
||||
|
||||
// supports multiple extglobs
|
||||
console.log(pm.isMatch('foo.bar', '!(foo).!(bar)')); // false
|
||||
|
||||
// supports nested extglobs
|
||||
console.log(pm.isMatch('foo.bar', '!(!(foo)).!(!(bar))')); // true
|
||||
```
|
||||
|
||||
#### POSIX brackets
|
||||
|
||||
POSIX classes are disabled by default. Enable this feature by setting the `posix` option to true.
|
||||
|
||||
**Enable POSIX bracket support**
|
||||
|
||||
```js
|
||||
console.log(pm.makeRe('[[:word:]]+', { posix: true }));
|
||||
//=> /^(?:(?=.)[A-Za-z0-9_]+\/?)$/
|
||||
```
|
||||
|
||||
**Supported POSIX classes**
|
||||
|
||||
The following named POSIX bracket expressions are supported:
|
||||
|
||||
* `[:alnum:]` - Alphanumeric characters, equ `[a-zA-Z0-9]`
|
||||
* `[:alpha:]` - Alphabetical characters, equivalent to `[a-zA-Z]`.
|
||||
* `[:ascii:]` - ASCII characters, equivalent to `[\\x00-\\x7F]`.
|
||||
* `[:blank:]` - Space and tab characters, equivalent to `[ \\t]`.
|
||||
* `[:cntrl:]` - Control characters, equivalent to `[\\x00-\\x1F\\x7F]`.
|
||||
* `[:digit:]` - Numerical digits, equivalent to `[0-9]`.
|
||||
* `[:graph:]` - Graph characters, equivalent to `[\\x21-\\x7E]`.
|
||||
* `[:lower:]` - Lowercase letters, equivalent to `[a-z]`.
|
||||
* `[:print:]` - Print characters, equivalent to `[\\x20-\\x7E ]`.
|
||||
* `[:punct:]` - Punctuation and symbols, equivalent to `[\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~]`.
|
||||
* `[:space:]` - Extended space characters, equivalent to `[ \\t\\r\\n\\v\\f]`.
|
||||
* `[:upper:]` - Uppercase letters, equivalent to `[A-Z]`.
|
||||
* `[:word:]` - Word characters (letters, numbers and underscores), equivalent to `[A-Za-z0-9_]`.
|
||||
* `[:xdigit:]` - Hexadecimal digits, equivalent to `[A-Fa-f0-9]`.
|
||||
|
||||
See the [Bash Reference Manual](https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html) for more information.
|
||||
|
||||
### Braces
|
||||
|
||||
Picomatch does not do brace expansion. For [brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html) and advanced matching with braces, use [micromatch](https://github.com/micromatch/micromatch) instead. Picomatch has very basic support for braces.
|
||||
|
||||
### Matching special characters as literals
|
||||
|
||||
If you wish to match the following special characters in a filepath, and you want to use these characters in your glob pattern, they must be escaped with backslashes or quotes:
|
||||
|
||||
**Special Characters**
|
||||
|
||||
Some characters that are used for matching in regular expressions are also regarded as valid file path characters on some platforms.
|
||||
|
||||
To match any of the following characters as literals: `$^*+?()[]
|
||||
|
||||
Examples:
|
||||
|
||||
```js
|
||||
console.log(pm.makeRe('foo/bar \\(1\\)'));
|
||||
console.log(pm.makeRe('foo/bar \\(1\\)'));
|
||||
```
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
## Library Comparisons
|
||||
|
||||
The following table shows which features are supported by [minimatch](https://github.com/isaacs/minimatch), [micromatch](https://github.com/micromatch/micromatch), [picomatch](https://github.com/micromatch/picomatch), [nanomatch](https://github.com/micromatch/nanomatch), [extglob](https://github.com/micromatch/extglob), [braces](https://github.com/micromatch/braces), and [expand-brackets](https://github.com/micromatch/expand-brackets).
|
||||
|
||||
| **Feature** | `minimatch` | `micromatch` | `picomatch` | `nanomatch` | `extglob` | `braces` | `expand-brackets` |
|
||||
| --- | --- | --- | --- | --- | --- | --- | --- |
|
||||
| Wildcard matching (`*?+`) | ✔ | ✔ | ✔ | ✔ | - | - | - |
|
||||
| Advancing globbing | ✔ | ✔ | ✔ | - | - | - | - |
|
||||
| Brace _matching_ | ✔ | ✔ | ✔ | - | - | ✔ | - |
|
||||
| Brace _expansion_ | ✔ | ✔ | - | - | - | ✔ | - |
|
||||
| Extglobs | partial | ✔ | ✔ | - | ✔ | - | - |
|
||||
| Posix brackets | - | ✔ | ✔ | - | - | - | ✔ |
|
||||
| Regular expression syntax | - | ✔ | ✔ | ✔ | ✔ | - | ✔ |
|
||||
| File system operations | - | - | - | - | - | - | - |
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
## Benchmarks
|
||||
|
||||
Performance comparison of picomatch and minimatch.
|
||||
|
||||
```
|
||||
# .makeRe star
|
||||
picomatch x 1,993,050 ops/sec ±0.51% (91 runs sampled)
|
||||
minimatch x 627,206 ops/sec ±1.96% (87 runs sampled))
|
||||
|
||||
# .makeRe star; dot=true
|
||||
picomatch x 1,436,640 ops/sec ±0.62% (91 runs sampled)
|
||||
minimatch x 525,876 ops/sec ±0.60% (88 runs sampled)
|
||||
|
||||
# .makeRe globstar
|
||||
picomatch x 1,592,742 ops/sec ±0.42% (90 runs sampled)
|
||||
minimatch x 962,043 ops/sec ±1.76% (91 runs sampled)d)
|
||||
|
||||
# .makeRe globstars
|
||||
picomatch x 1,615,199 ops/sec ±0.35% (94 runs sampled)
|
||||
minimatch x 477,179 ops/sec ±1.33% (91 runs sampled)
|
||||
|
||||
# .makeRe with leading star
|
||||
picomatch x 1,220,856 ops/sec ±0.40% (92 runs sampled)
|
||||
minimatch x 453,564 ops/sec ±1.43% (94 runs sampled)
|
||||
|
||||
# .makeRe - basic braces
|
||||
picomatch x 392,067 ops/sec ±0.70% (90 runs sampled)
|
||||
minimatch x 99,532 ops/sec ±2.03% (87 runs sampled))
|
||||
```
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
## Philosophies
|
||||
|
||||
The goal of this library is to be blazing fast, without compromising on accuracy.
|
||||
|
||||
**Accuracy**
|
||||
|
||||
The number one of goal of this library is accuracy. However, it's not unusual for different glob implementations to have different rules for matching behavior, even with simple wildcard matching. It gets increasingly more complicated when combinations of different features are combined, like when extglobs are combined with globstars, braces, slashes, and so on: `!(**/{a,b,*/c})`.
|
||||
|
||||
Thus, given that there is no canonical glob specification to use as a single source of truth when differences of opinion arise regarding behavior, sometimes we have to implement our best judgement and rely on feedback from users to make improvements.
|
||||
|
||||
**Performance**
|
||||
|
||||
Although this library performs well in benchmarks, and in most cases it's faster than other popular libraries we benchmarked against, we will always choose accuracy over performance. It's not helpful to anyone if our library is faster at returning the wrong answer.
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
## About
|
||||
|
||||
<details>
|
||||
<summary><strong>Contributing</strong></summary>
|
||||
|
||||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
||||
|
||||
Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Running Tests</strong></summary>
|
||||
|
||||
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
||||
|
||||
```sh
|
||||
npm install && npm test
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><strong>Building docs</strong></summary>
|
||||
|
||||
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
||||
|
||||
To generate the readme, run the following command:
|
||||
|
||||
```sh
|
||||
npm install -g verbose/verb#dev verb-generate-readme && verb
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
### Author
|
||||
|
||||
**Jon Schlinkert**
|
||||
|
||||
* [GitHub Profile](https://github.com/jonschlinkert)
|
||||
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
||||
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
||||
|
||||
### License
|
||||
|
||||
Copyright © 2017-present, [Jon Schlinkert](https://github.com/jonschlinkert).
|
||||
Released under the [MIT License](LICENSE).
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = require('./lib/picomatch');
|
||||
179
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/lib/constants.js
generated
vendored
Normal file
179
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/lib/constants.js
generated
vendored
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const WIN_SLASH = '\\\\/';
|
||||
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
||||
|
||||
/**
|
||||
* Posix glob regex
|
||||
*/
|
||||
|
||||
const DOT_LITERAL = '\\.';
|
||||
const PLUS_LITERAL = '\\+';
|
||||
const QMARK_LITERAL = '\\?';
|
||||
const SLASH_LITERAL = '\\/';
|
||||
const ONE_CHAR = '(?=.)';
|
||||
const QMARK = '[^/]';
|
||||
const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
||||
const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
||||
const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
||||
const NO_DOT = `(?!${DOT_LITERAL})`;
|
||||
const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
|
||||
const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
|
||||
const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
|
||||
const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
|
||||
const STAR = `${QMARK}*?`;
|
||||
|
||||
const POSIX_CHARS = {
|
||||
DOT_LITERAL,
|
||||
PLUS_LITERAL,
|
||||
QMARK_LITERAL,
|
||||
SLASH_LITERAL,
|
||||
ONE_CHAR,
|
||||
QMARK,
|
||||
END_ANCHOR,
|
||||
DOTS_SLASH,
|
||||
NO_DOT,
|
||||
NO_DOTS,
|
||||
NO_DOT_SLASH,
|
||||
NO_DOTS_SLASH,
|
||||
QMARK_NO_DOT,
|
||||
STAR,
|
||||
START_ANCHOR
|
||||
};
|
||||
|
||||
/**
|
||||
* Windows glob regex
|
||||
*/
|
||||
|
||||
const WINDOWS_CHARS = {
|
||||
...POSIX_CHARS,
|
||||
|
||||
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
||||
QMARK: WIN_NO_SLASH,
|
||||
STAR: `${WIN_NO_SLASH}*?`,
|
||||
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
||||
NO_DOT: `(?!${DOT_LITERAL})`,
|
||||
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
||||
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
||||
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
||||
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
||||
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
||||
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`
|
||||
};
|
||||
|
||||
/**
|
||||
* POSIX Bracket Regex
|
||||
*/
|
||||
|
||||
const POSIX_REGEX_SOURCE = {
|
||||
alnum: 'a-zA-Z0-9',
|
||||
alpha: 'a-zA-Z',
|
||||
ascii: '\\x00-\\x7F',
|
||||
blank: ' \\t',
|
||||
cntrl: '\\x00-\\x1F\\x7F',
|
||||
digit: '0-9',
|
||||
graph: '\\x21-\\x7E',
|
||||
lower: 'a-z',
|
||||
print: '\\x20-\\x7E ',
|
||||
punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
|
||||
space: ' \\t\\r\\n\\v\\f',
|
||||
upper: 'A-Z',
|
||||
word: 'A-Za-z0-9_',
|
||||
xdigit: 'A-Fa-f0-9'
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
MAX_LENGTH: 1024 * 64,
|
||||
POSIX_REGEX_SOURCE,
|
||||
|
||||
// regular expressions
|
||||
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
||||
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
||||
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
||||
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
||||
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
||||
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
||||
|
||||
// Replace globs with equivalent patterns to reduce parsing time.
|
||||
REPLACEMENTS: {
|
||||
'***': '*',
|
||||
'**/**': '**',
|
||||
'**/**/**': '**'
|
||||
},
|
||||
|
||||
// Digits
|
||||
CHAR_0: 48, /* 0 */
|
||||
CHAR_9: 57, /* 9 */
|
||||
|
||||
// Alphabet chars.
|
||||
CHAR_UPPERCASE_A: 65, /* A */
|
||||
CHAR_LOWERCASE_A: 97, /* a */
|
||||
CHAR_UPPERCASE_Z: 90, /* Z */
|
||||
CHAR_LOWERCASE_Z: 122, /* z */
|
||||
|
||||
CHAR_LEFT_PARENTHESES: 40, /* ( */
|
||||
CHAR_RIGHT_PARENTHESES: 41, /* ) */
|
||||
|
||||
CHAR_ASTERISK: 42, /* * */
|
||||
|
||||
// Non-alphabetic chars.
|
||||
CHAR_AMPERSAND: 38, /* & */
|
||||
CHAR_AT: 64, /* @ */
|
||||
CHAR_BACKWARD_SLASH: 92, /* \ */
|
||||
CHAR_CARRIAGE_RETURN: 13, /* \r */
|
||||
CHAR_CIRCUMFLEX_ACCENT: 94, /* ^ */
|
||||
CHAR_COLON: 58, /* : */
|
||||
CHAR_COMMA: 44, /* , */
|
||||
CHAR_DOT: 46, /* . */
|
||||
CHAR_DOUBLE_QUOTE: 34, /* " */
|
||||
CHAR_EQUAL: 61, /* = */
|
||||
CHAR_EXCLAMATION_MARK: 33, /* ! */
|
||||
CHAR_FORM_FEED: 12, /* \f */
|
||||
CHAR_FORWARD_SLASH: 47, /* / */
|
||||
CHAR_GRAVE_ACCENT: 96, /* ` */
|
||||
CHAR_HASH: 35, /* # */
|
||||
CHAR_HYPHEN_MINUS: 45, /* - */
|
||||
CHAR_LEFT_ANGLE_BRACKET: 60, /* < */
|
||||
CHAR_LEFT_CURLY_BRACE: 123, /* { */
|
||||
CHAR_LEFT_SQUARE_BRACKET: 91, /* [ */
|
||||
CHAR_LINE_FEED: 10, /* \n */
|
||||
CHAR_NO_BREAK_SPACE: 160, /* \u00A0 */
|
||||
CHAR_PERCENT: 37, /* % */
|
||||
CHAR_PLUS: 43, /* + */
|
||||
CHAR_QUESTION_MARK: 63, /* ? */
|
||||
CHAR_RIGHT_ANGLE_BRACKET: 62, /* > */
|
||||
CHAR_RIGHT_CURLY_BRACE: 125, /* } */
|
||||
CHAR_RIGHT_SQUARE_BRACKET: 93, /* ] */
|
||||
CHAR_SEMICOLON: 59, /* ; */
|
||||
CHAR_SINGLE_QUOTE: 39, /* ' */
|
||||
CHAR_SPACE: 32, /* */
|
||||
CHAR_TAB: 9, /* \t */
|
||||
CHAR_UNDERSCORE: 95, /* _ */
|
||||
CHAR_VERTICAL_LINE: 124, /* | */
|
||||
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279, /* \uFEFF */
|
||||
|
||||
SEP: path.sep,
|
||||
|
||||
/**
|
||||
* Create EXTGLOB_CHARS
|
||||
*/
|
||||
|
||||
extglobChars(chars) {
|
||||
return {
|
||||
'!': { type: 'negate', open: '(?:(?!(?:', close: `))${chars.STAR})` },
|
||||
'?': { type: 'qmark', open: '(?:', close: ')?' },
|
||||
'+': { type: 'plus', open: '(?:', close: ')+' },
|
||||
'*': { type: 'star', open: '(?:', close: ')*' },
|
||||
'@': { type: 'at', open: '(?:', close: ')' }
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* Create GLOB_CHARS
|
||||
*/
|
||||
|
||||
globChars(win32) {
|
||||
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
||||
}
|
||||
};
|
||||
1091
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/lib/parse.js
generated
vendored
Normal file
1091
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/lib/parse.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
342
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/lib/picomatch.js
generated
vendored
Normal file
342
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/lib/picomatch.js
generated
vendored
Normal file
|
|
@ -0,0 +1,342 @@
|
|||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const scan = require('./scan');
|
||||
const parse = require('./parse');
|
||||
const utils = require('./utils');
|
||||
const constants = require('./constants');
|
||||
const isObject = val => val && typeof val === 'object' && !Array.isArray(val);
|
||||
|
||||
/**
|
||||
* Creates a matcher function from one or more glob patterns. The
|
||||
* returned function takes a string to match as its first argument,
|
||||
* and returns true if the string is a match. The returned matcher
|
||||
* function also takes a boolean as the second argument that, when true,
|
||||
* returns an object with additional information.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* // picomatch(glob[, options]);
|
||||
*
|
||||
* const isMatch = picomatch('*.!(*a)');
|
||||
* console.log(isMatch('a.a')); //=> false
|
||||
* console.log(isMatch('a.b')); //=> true
|
||||
* ```
|
||||
* @name picomatch
|
||||
* @param {String|Array} `globs` One or more glob patterns.
|
||||
* @param {Object=} `options`
|
||||
* @return {Function=} Returns a matcher function.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
const picomatch = (glob, options, returnState = false) => {
|
||||
if (Array.isArray(glob)) {
|
||||
const fns = glob.map(input => picomatch(input, options, returnState));
|
||||
const arrayMatcher = str => {
|
||||
for (const isMatch of fns) {
|
||||
const state = isMatch(str);
|
||||
if (state) return state;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
return arrayMatcher;
|
||||
}
|
||||
|
||||
const isState = isObject(glob) && glob.tokens && glob.input;
|
||||
|
||||
if (glob === '' || (typeof glob !== 'string' && !isState)) {
|
||||
throw new TypeError('Expected pattern to be a non-empty string');
|
||||
}
|
||||
|
||||
const opts = options || {};
|
||||
const posix = utils.isWindows(options);
|
||||
const regex = isState
|
||||
? picomatch.compileRe(glob, options)
|
||||
: picomatch.makeRe(glob, options, false, true);
|
||||
|
||||
const state = regex.state;
|
||||
delete regex.state;
|
||||
|
||||
let isIgnored = () => false;
|
||||
if (opts.ignore) {
|
||||
const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
|
||||
isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
|
||||
}
|
||||
|
||||
const matcher = (input, returnObject = false) => {
|
||||
const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
|
||||
const result = { glob, state, regex, posix, input, output, match, isMatch };
|
||||
|
||||
if (typeof opts.onResult === 'function') {
|
||||
opts.onResult(result);
|
||||
}
|
||||
|
||||
if (isMatch === false) {
|
||||
result.isMatch = false;
|
||||
return returnObject ? result : false;
|
||||
}
|
||||
|
||||
if (isIgnored(input)) {
|
||||
if (typeof opts.onIgnore === 'function') {
|
||||
opts.onIgnore(result);
|
||||
}
|
||||
result.isMatch = false;
|
||||
return returnObject ? result : false;
|
||||
}
|
||||
|
||||
if (typeof opts.onMatch === 'function') {
|
||||
opts.onMatch(result);
|
||||
}
|
||||
return returnObject ? result : true;
|
||||
};
|
||||
|
||||
if (returnState) {
|
||||
matcher.state = state;
|
||||
}
|
||||
|
||||
return matcher;
|
||||
};
|
||||
|
||||
/**
|
||||
* Test `input` with the given `regex`. This is used by the main
|
||||
* `picomatch()` function to test the input string.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* // picomatch.test(input, regex[, options]);
|
||||
*
|
||||
* console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
|
||||
* // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
|
||||
* ```
|
||||
* @param {String} `input` String to test.
|
||||
* @param {RegExp} `regex`
|
||||
* @return {Object} Returns an object with matching info.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.test = (input, regex, options, { glob, posix } = {}) => {
|
||||
if (typeof input !== 'string') {
|
||||
throw new TypeError('Expected input to be a string');
|
||||
}
|
||||
|
||||
if (input === '') {
|
||||
return { isMatch: false, output: '' };
|
||||
}
|
||||
|
||||
const opts = options || {};
|
||||
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
||||
let match = input === glob;
|
||||
let output = (match && format) ? format(input) : input;
|
||||
|
||||
if (match === false) {
|
||||
output = format ? format(input) : input;
|
||||
match = output === glob;
|
||||
}
|
||||
|
||||
if (match === false || opts.capture === true) {
|
||||
if (opts.matchBase === true || opts.basename === true) {
|
||||
match = picomatch.matchBase(input, regex, options, posix);
|
||||
} else {
|
||||
match = regex.exec(output);
|
||||
}
|
||||
}
|
||||
|
||||
return { isMatch: Boolean(match), match, output };
|
||||
};
|
||||
|
||||
/**
|
||||
* Match the basename of a filepath.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* // picomatch.matchBase(input, glob[, options]);
|
||||
* console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
|
||||
* ```
|
||||
* @param {String} `input` String to test.
|
||||
* @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
|
||||
* @return {Boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.matchBase = (input, glob, options, posix = utils.isWindows(options)) => {
|
||||
const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
|
||||
return regex.test(path.basename(input));
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if **any** of the given glob `patterns` match the specified `string`.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* // picomatch.isMatch(string, patterns[, options]);
|
||||
*
|
||||
* console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
|
||||
* console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
|
||||
* ```
|
||||
* @param {String|Array} str The string to test.
|
||||
* @param {String|Array} patterns One or more glob patterns to use for matching.
|
||||
* @param {Object} [options] See available [options](#options).
|
||||
* @return {Boolean} Returns true if any patterns match `str`
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
||||
|
||||
/**
|
||||
* Parse a glob pattern to create the source string for a regular
|
||||
* expression.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* const result = picomatch.parse(pattern[, options]);
|
||||
* ```
|
||||
* @param {String} `pattern`
|
||||
* @param {Object} `options`
|
||||
* @return {Object} Returns an object with useful properties and output to be used as a regex source string.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.parse = (pattern, options) => {
|
||||
if (Array.isArray(pattern)) return pattern.map(p => picomatch.parse(p, options));
|
||||
return parse(pattern, { ...options, fastpaths: false });
|
||||
};
|
||||
|
||||
/**
|
||||
* Scan a glob pattern to separate the pattern into segments.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* // picomatch.scan(input[, options]);
|
||||
*
|
||||
* const result = picomatch.scan('!./foo/*.js');
|
||||
* console.log(result);
|
||||
* { prefix: '!./',
|
||||
* input: '!./foo/*.js',
|
||||
* start: 3,
|
||||
* base: 'foo',
|
||||
* glob: '*.js',
|
||||
* isBrace: false,
|
||||
* isBracket: false,
|
||||
* isGlob: true,
|
||||
* isExtglob: false,
|
||||
* isGlobstar: false,
|
||||
* negated: true }
|
||||
* ```
|
||||
* @param {String} `input` Glob pattern to scan.
|
||||
* @param {Object} `options`
|
||||
* @return {Object} Returns an object with
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.scan = (input, options) => scan(input, options);
|
||||
|
||||
/**
|
||||
* Compile a regular expression from the `state` object returned by the
|
||||
* [parse()](#parse) method.
|
||||
*
|
||||
* @param {Object} `state`
|
||||
* @param {Object} `options`
|
||||
* @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
|
||||
* @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
|
||||
* @return {RegExp}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
||||
if (returnOutput === true) {
|
||||
return state.output;
|
||||
}
|
||||
|
||||
const opts = options || {};
|
||||
const prepend = opts.contains ? '' : '^';
|
||||
const append = opts.contains ? '' : '$';
|
||||
|
||||
let source = `${prepend}(?:${state.output})${append}`;
|
||||
if (state && state.negated === true) {
|
||||
source = `^(?!${source}).*$`;
|
||||
}
|
||||
|
||||
const regex = picomatch.toRegex(source, options);
|
||||
if (returnState === true) {
|
||||
regex.state = state;
|
||||
}
|
||||
|
||||
return regex;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a regular expression from a parsed glob pattern.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* const state = picomatch.parse('*.js');
|
||||
* // picomatch.compileRe(state[, options]);
|
||||
*
|
||||
* console.log(picomatch.compileRe(state));
|
||||
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
||||
* ```
|
||||
* @param {String} `state` The object returned from the `.parse` method.
|
||||
* @param {Object} `options`
|
||||
* @param {Boolean} `returnOutput` Implementors may use this argument to return the compiled output, instead of a regular expression. This is not exposed on the options to prevent end-users from mutating the result.
|
||||
* @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
|
||||
* @return {RegExp} Returns a regex created from the given pattern.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
||||
if (!input || typeof input !== 'string') {
|
||||
throw new TypeError('Expected a non-empty string');
|
||||
}
|
||||
|
||||
let parsed = { negated: false, fastpaths: true };
|
||||
|
||||
if (options.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
|
||||
parsed.output = parse.fastpaths(input, options);
|
||||
}
|
||||
|
||||
if (!parsed.output) {
|
||||
parsed = parse(input, options);
|
||||
}
|
||||
|
||||
return picomatch.compileRe(parsed, options, returnOutput, returnState);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a regular expression from the given regex source string.
|
||||
*
|
||||
* ```js
|
||||
* const picomatch = require('picomatch');
|
||||
* // picomatch.toRegex(source[, options]);
|
||||
*
|
||||
* const { output } = picomatch.parse('*.js');
|
||||
* console.log(picomatch.toRegex(output));
|
||||
* //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
|
||||
* ```
|
||||
* @param {String} `source` Regular expression source string.
|
||||
* @param {Object} `options`
|
||||
* @return {RegExp}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
picomatch.toRegex = (source, options) => {
|
||||
try {
|
||||
const opts = options || {};
|
||||
return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
|
||||
} catch (err) {
|
||||
if (options && options.debug === true) throw err;
|
||||
return /$^/;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Picomatch constants.
|
||||
* @return {Object}
|
||||
*/
|
||||
|
||||
picomatch.constants = constants;
|
||||
|
||||
/**
|
||||
* Expose "picomatch"
|
||||
*/
|
||||
|
||||
module.exports = picomatch;
|
||||
391
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/lib/scan.js
generated
vendored
Normal file
391
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/lib/scan.js
generated
vendored
Normal file
|
|
@ -0,0 +1,391 @@
|
|||
'use strict';
|
||||
|
||||
const utils = require('./utils');
|
||||
const {
|
||||
CHAR_ASTERISK, /* * */
|
||||
CHAR_AT, /* @ */
|
||||
CHAR_BACKWARD_SLASH, /* \ */
|
||||
CHAR_COMMA, /* , */
|
||||
CHAR_DOT, /* . */
|
||||
CHAR_EXCLAMATION_MARK, /* ! */
|
||||
CHAR_FORWARD_SLASH, /* / */
|
||||
CHAR_LEFT_CURLY_BRACE, /* { */
|
||||
CHAR_LEFT_PARENTHESES, /* ( */
|
||||
CHAR_LEFT_SQUARE_BRACKET, /* [ */
|
||||
CHAR_PLUS, /* + */
|
||||
CHAR_QUESTION_MARK, /* ? */
|
||||
CHAR_RIGHT_CURLY_BRACE, /* } */
|
||||
CHAR_RIGHT_PARENTHESES, /* ) */
|
||||
CHAR_RIGHT_SQUARE_BRACKET /* ] */
|
||||
} = require('./constants');
|
||||
|
||||
const isPathSeparator = code => {
|
||||
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
||||
};
|
||||
|
||||
const depth = token => {
|
||||
if (token.isPrefix !== true) {
|
||||
token.depth = token.isGlobstar ? Infinity : 1;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Quickly scans a glob pattern and returns an object with a handful of
|
||||
* useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
|
||||
* `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
|
||||
* with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
|
||||
*
|
||||
* ```js
|
||||
* const pm = require('picomatch');
|
||||
* console.log(pm.scan('foo/bar/*.js'));
|
||||
* { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
|
||||
* ```
|
||||
* @param {String} `str`
|
||||
* @param {Object} `options`
|
||||
* @return {Object} Returns an object with tokens and regex source string.
|
||||
* @api public
|
||||
*/
|
||||
|
||||
const scan = (input, options) => {
|
||||
const opts = options || {};
|
||||
|
||||
const length = input.length - 1;
|
||||
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
||||
const slashes = [];
|
||||
const tokens = [];
|
||||
const parts = [];
|
||||
|
||||
let str = input;
|
||||
let index = -1;
|
||||
let start = 0;
|
||||
let lastIndex = 0;
|
||||
let isBrace = false;
|
||||
let isBracket = false;
|
||||
let isGlob = false;
|
||||
let isExtglob = false;
|
||||
let isGlobstar = false;
|
||||
let braceEscaped = false;
|
||||
let backslashes = false;
|
||||
let negated = false;
|
||||
let negatedExtglob = false;
|
||||
let finished = false;
|
||||
let braces = 0;
|
||||
let prev;
|
||||
let code;
|
||||
let token = { value: '', depth: 0, isGlob: false };
|
||||
|
||||
const eos = () => index >= length;
|
||||
const peek = () => str.charCodeAt(index + 1);
|
||||
const advance = () => {
|
||||
prev = code;
|
||||
return str.charCodeAt(++index);
|
||||
};
|
||||
|
||||
while (index < length) {
|
||||
code = advance();
|
||||
let next;
|
||||
|
||||
if (code === CHAR_BACKWARD_SLASH) {
|
||||
backslashes = token.backslashes = true;
|
||||
code = advance();
|
||||
|
||||
if (code === CHAR_LEFT_CURLY_BRACE) {
|
||||
braceEscaped = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
||||
braces++;
|
||||
|
||||
while (eos() !== true && (code = advance())) {
|
||||
if (code === CHAR_BACKWARD_SLASH) {
|
||||
backslashes = token.backslashes = true;
|
||||
advance();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (code === CHAR_LEFT_CURLY_BRACE) {
|
||||
braces++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
||||
isBrace = token.isBrace = true;
|
||||
isGlob = token.isGlob = true;
|
||||
finished = true;
|
||||
|
||||
if (scanToEnd === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (braceEscaped !== true && code === CHAR_COMMA) {
|
||||
isBrace = token.isBrace = true;
|
||||
isGlob = token.isGlob = true;
|
||||
finished = true;
|
||||
|
||||
if (scanToEnd === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
||||
braces--;
|
||||
|
||||
if (braces === 0) {
|
||||
braceEscaped = false;
|
||||
isBrace = token.isBrace = true;
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scanToEnd === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (code === CHAR_FORWARD_SLASH) {
|
||||
slashes.push(index);
|
||||
tokens.push(token);
|
||||
token = { value: '', depth: 0, isGlob: false };
|
||||
|
||||
if (finished === true) continue;
|
||||
if (prev === CHAR_DOT && index === (start + 1)) {
|
||||
start += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
lastIndex = index + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (opts.noext !== true) {
|
||||
const isExtglobChar = code === CHAR_PLUS
|
||||
|| code === CHAR_AT
|
||||
|| code === CHAR_ASTERISK
|
||||
|| code === CHAR_QUESTION_MARK
|
||||
|| code === CHAR_EXCLAMATION_MARK;
|
||||
|
||||
if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
|
||||
isGlob = token.isGlob = true;
|
||||
isExtglob = token.isExtglob = true;
|
||||
finished = true;
|
||||
if (code === CHAR_EXCLAMATION_MARK && index === start) {
|
||||
negatedExtglob = true;
|
||||
}
|
||||
|
||||
if (scanToEnd === true) {
|
||||
while (eos() !== true && (code = advance())) {
|
||||
if (code === CHAR_BACKWARD_SLASH) {
|
||||
backslashes = token.backslashes = true;
|
||||
code = advance();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (code === CHAR_RIGHT_PARENTHESES) {
|
||||
isGlob = token.isGlob = true;
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (code === CHAR_ASTERISK) {
|
||||
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
||||
isGlob = token.isGlob = true;
|
||||
finished = true;
|
||||
|
||||
if (scanToEnd === true) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (code === CHAR_QUESTION_MARK) {
|
||||
isGlob = token.isGlob = true;
|
||||
finished = true;
|
||||
|
||||
if (scanToEnd === true) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
||||
while (eos() !== true && (next = advance())) {
|
||||
if (next === CHAR_BACKWARD_SLASH) {
|
||||
backslashes = token.backslashes = true;
|
||||
advance();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
||||
isBracket = token.isBracket = true;
|
||||
isGlob = token.isGlob = true;
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (scanToEnd === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
||||
negated = token.negated = true;
|
||||
start++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
||||
isGlob = token.isGlob = true;
|
||||
|
||||
if (scanToEnd === true) {
|
||||
while (eos() !== true && (code = advance())) {
|
||||
if (code === CHAR_LEFT_PARENTHESES) {
|
||||
backslashes = token.backslashes = true;
|
||||
code = advance();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (code === CHAR_RIGHT_PARENTHESES) {
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (isGlob === true) {
|
||||
finished = true;
|
||||
|
||||
if (scanToEnd === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.noext === true) {
|
||||
isExtglob = false;
|
||||
isGlob = false;
|
||||
}
|
||||
|
||||
let base = str;
|
||||
let prefix = '';
|
||||
let glob = '';
|
||||
|
||||
if (start > 0) {
|
||||
prefix = str.slice(0, start);
|
||||
str = str.slice(start);
|
||||
lastIndex -= start;
|
||||
}
|
||||
|
||||
if (base && isGlob === true && lastIndex > 0) {
|
||||
base = str.slice(0, lastIndex);
|
||||
glob = str.slice(lastIndex);
|
||||
} else if (isGlob === true) {
|
||||
base = '';
|
||||
glob = str;
|
||||
} else {
|
||||
base = str;
|
||||
}
|
||||
|
||||
if (base && base !== '' && base !== '/' && base !== str) {
|
||||
if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
||||
base = base.slice(0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.unescape === true) {
|
||||
if (glob) glob = utils.removeBackslashes(glob);
|
||||
|
||||
if (base && backslashes === true) {
|
||||
base = utils.removeBackslashes(base);
|
||||
}
|
||||
}
|
||||
|
||||
const state = {
|
||||
prefix,
|
||||
input,
|
||||
start,
|
||||
base,
|
||||
glob,
|
||||
isBrace,
|
||||
isBracket,
|
||||
isGlob,
|
||||
isExtglob,
|
||||
isGlobstar,
|
||||
negated,
|
||||
negatedExtglob
|
||||
};
|
||||
|
||||
if (opts.tokens === true) {
|
||||
state.maxDepth = 0;
|
||||
if (!isPathSeparator(code)) {
|
||||
tokens.push(token);
|
||||
}
|
||||
state.tokens = tokens;
|
||||
}
|
||||
|
||||
if (opts.parts === true || opts.tokens === true) {
|
||||
let prevIndex;
|
||||
|
||||
for (let idx = 0; idx < slashes.length; idx++) {
|
||||
const n = prevIndex ? prevIndex + 1 : start;
|
||||
const i = slashes[idx];
|
||||
const value = input.slice(n, i);
|
||||
if (opts.tokens) {
|
||||
if (idx === 0 && start !== 0) {
|
||||
tokens[idx].isPrefix = true;
|
||||
tokens[idx].value = prefix;
|
||||
} else {
|
||||
tokens[idx].value = value;
|
||||
}
|
||||
depth(tokens[idx]);
|
||||
state.maxDepth += tokens[idx].depth;
|
||||
}
|
||||
if (idx !== 0 || value !== '') {
|
||||
parts.push(value);
|
||||
}
|
||||
prevIndex = i;
|
||||
}
|
||||
|
||||
if (prevIndex && prevIndex + 1 < input.length) {
|
||||
const value = input.slice(prevIndex + 1);
|
||||
parts.push(value);
|
||||
|
||||
if (opts.tokens) {
|
||||
tokens[tokens.length - 1].value = value;
|
||||
depth(tokens[tokens.length - 1]);
|
||||
state.maxDepth += tokens[tokens.length - 1].depth;
|
||||
}
|
||||
}
|
||||
|
||||
state.slashes = slashes;
|
||||
state.parts = parts;
|
||||
}
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
module.exports = scan;
|
||||
64
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/lib/utils.js
generated
vendored
Normal file
64
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/lib/utils.js
generated
vendored
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const win32 = process.platform === 'win32';
|
||||
const {
|
||||
REGEX_BACKSLASH,
|
||||
REGEX_REMOVE_BACKSLASH,
|
||||
REGEX_SPECIAL_CHARS,
|
||||
REGEX_SPECIAL_CHARS_GLOBAL
|
||||
} = require('./constants');
|
||||
|
||||
exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
|
||||
exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
|
||||
exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str);
|
||||
exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
|
||||
exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');
|
||||
|
||||
exports.removeBackslashes = str => {
|
||||
return str.replace(REGEX_REMOVE_BACKSLASH, match => {
|
||||
return match === '\\' ? '' : match;
|
||||
});
|
||||
};
|
||||
|
||||
exports.supportsLookbehinds = () => {
|
||||
const segs = process.version.slice(1).split('.').map(Number);
|
||||
if (segs.length === 3 && segs[0] >= 9 || (segs[0] === 8 && segs[1] >= 10)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
exports.isWindows = options => {
|
||||
if (options && typeof options.windows === 'boolean') {
|
||||
return options.windows;
|
||||
}
|
||||
return win32 === true || path.sep === '\\';
|
||||
};
|
||||
|
||||
exports.escapeLast = (input, char, lastIdx) => {
|
||||
const idx = input.lastIndexOf(char, lastIdx);
|
||||
if (idx === -1) return input;
|
||||
if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1);
|
||||
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
||||
};
|
||||
|
||||
exports.removePrefix = (input, state = {}) => {
|
||||
let output = input;
|
||||
if (output.startsWith('./')) {
|
||||
output = output.slice(2);
|
||||
state.prefix = './';
|
||||
}
|
||||
return output;
|
||||
};
|
||||
|
||||
exports.wrapOutput = (input, state = {}, options = {}) => {
|
||||
const prepend = options.contains ? '' : '^';
|
||||
const append = options.contains ? '' : '$';
|
||||
|
||||
let output = `${prepend}(?:${input})${append}`;
|
||||
if (state.negated === true) {
|
||||
output = `(?:^(?!${output}).*$)`;
|
||||
}
|
||||
return output;
|
||||
};
|
||||
84
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/package.json
generated
vendored
Normal file
84
node_modules/.store/anymatch@3.1.3/node_modules/picomatch/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
{
|
||||
"name": "picomatch",
|
||||
"description": "Blazing fast and accurate glob matcher written in JavaScript, with no dependencies and full support for standard and extended Bash glob features, including braces, extglobs, POSIX brackets, and regular expressions.",
|
||||
"version": "2.3.1",
|
||||
"homepage": "https://github.com/micromatch/picomatch",
|
||||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
||||
"funding": "https://github.com/sponsors/jonschlinkert",
|
||||
"repository": "micromatch/picomatch",
|
||||
"bugs": {
|
||||
"url": "https://github.com/micromatch/picomatch/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"index.js",
|
||||
"lib"
|
||||
],
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=8.6"
|
||||
},
|
||||
"scripts": {
|
||||
"lint": "eslint --cache --cache-location node_modules/.cache/.eslintcache --report-unused-disable-directives --ignore-path .gitignore .",
|
||||
"mocha": "mocha --reporter dot",
|
||||
"test": "npm run lint && npm run mocha",
|
||||
"test:ci": "npm run test:cover",
|
||||
"test:cover": "nyc npm run mocha"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^6.8.0",
|
||||
"fill-range": "^7.0.1",
|
||||
"gulp-format-md": "^2.0.0",
|
||||
"mocha": "^6.2.2",
|
||||
"nyc": "^15.0.0",
|
||||
"time-require": "github:jonschlinkert/time-require"
|
||||
},
|
||||
"keywords": [
|
||||
"glob",
|
||||
"match",
|
||||
"picomatch"
|
||||
],
|
||||
"nyc": {
|
||||
"reporter": [
|
||||
"html",
|
||||
"lcov",
|
||||
"text-summary"
|
||||
]
|
||||
},
|
||||
"verb": {
|
||||
"toc": {
|
||||
"render": true,
|
||||
"method": "preWrite",
|
||||
"maxdepth": 3
|
||||
},
|
||||
"layout": "empty",
|
||||
"tasks": [
|
||||
"readme"
|
||||
],
|
||||
"plugins": [
|
||||
"gulp-format-md"
|
||||
],
|
||||
"lint": {
|
||||
"reflinks": true
|
||||
},
|
||||
"related": {
|
||||
"list": [
|
||||
"braces",
|
||||
"micromatch"
|
||||
]
|
||||
},
|
||||
"reflinks": [
|
||||
"braces",
|
||||
"expand-brackets",
|
||||
"extglob",
|
||||
"fill-range",
|
||||
"micromatch",
|
||||
"minimatch",
|
||||
"nanomatch",
|
||||
"picomatch"
|
||||
]
|
||||
},
|
||||
"__npminstall_done": true,
|
||||
"_from": "picomatch@2.3.1",
|
||||
"_resolved": "https://registry.npmmirror.com/picomatch/-/picomatch-2.3.1.tgz"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue