mirror of https://github.com/espruino/BangleApps
Espruino doesn't support search or {} Regex quantifier, replace with test
parent
67e7e71df1
commit
fd2b347349
|
@ -24,7 +24,7 @@ class EAN13 extends EAN {
|
|||
|
||||
constructor(data, options) {
|
||||
// Add checksum if it does not exist
|
||||
if (data.search(/^[0-9]{12}$/) !== -1) {
|
||||
if (/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(data)) {
|
||||
data += checksum(data);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ class EAN13 extends EAN {
|
|||
|
||||
valid() {
|
||||
return (
|
||||
this.data.search(/^[0-9]{13}$/) !== -1 &&
|
||||
/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(this.data) &&
|
||||
+this.data[12] === checksum(this.data)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ class EAN2 extends Barcode {
|
|||
}
|
||||
|
||||
valid() {
|
||||
return this.data.search(/^[0-9]{2}$/) !== -1;
|
||||
return /^[0-9][0-9]$/.test(this.data);
|
||||
}
|
||||
|
||||
encode(){
|
||||
|
|
|
@ -24,7 +24,7 @@ class EAN5 extends Barcode {
|
|||
}
|
||||
|
||||
valid() {
|
||||
return this.data.search(/^[0-9]{5}$/) !== -1;
|
||||
return /^[0-9][0-9][0-9][0-9][0-9]$/.test(this.data);
|
||||
}
|
||||
|
||||
encode() {
|
||||
|
|
|
@ -20,7 +20,7 @@ class EAN8 extends EAN {
|
|||
|
||||
constructor(data, options) {
|
||||
// Add checksum if it does not exist
|
||||
if (data.search(/^[0-9]{7}$/) !== -1) {
|
||||
if (/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(data)) {
|
||||
data += checksum(data);
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ class EAN8 extends EAN {
|
|||
|
||||
valid() {
|
||||
return (
|
||||
this.data.search(/^[0-9]{8}$/) !== -1 &&
|
||||
/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(this.data) &&
|
||||
+this.data[7] === checksum(this.data)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ const Barcode = require("cards.Barcode.js");
|
|||
class UPC extends Barcode{
|
||||
constructor(data, options){
|
||||
// Add checksum if it does not exist
|
||||
if(data.search(/^[0-9]{11}$/) !== -1){
|
||||
if(/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(data)){
|
||||
data += checksum(data);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ class UPC extends Barcode{
|
|||
}
|
||||
|
||||
valid(){
|
||||
return this.data.search(/^[0-9]{12}$/) !== -1 &&
|
||||
return /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(this.data) &&
|
||||
this.data[11] == checksum(this.data);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,14 +41,14 @@ class UPCE extends Barcode{
|
|||
// is a UPC-A check or number system digit.
|
||||
super(data, options);
|
||||
this.isValid = false;
|
||||
if(data.search(/^[0-9]{6}$/) !== -1){
|
||||
if(/^[0-9][0-9][0-9][0-9][0-9][0-9]$/.test(data)){
|
||||
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){
|
||||
else if(/^[01][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/.test(data)){
|
||||
this.middleDigits = data.substring(1, data.length - 1);
|
||||
this.upcA = expandToUPCA(this.middleDigits, data[0]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue