This commit is contained in:
2025-08-12 15:04:01 +08:00
parent df3f5f5269
commit 6708fb8eeb
544 changed files with 75169 additions and 17 deletions
@@ -0,0 +1,48 @@
// Encoding documentation
// https://en.wikipedia.org/wiki/MSI_Barcode#Character_set_and_binary_lookup
import Barcode from "../Barcode.js";
class MSI extends Barcode{
constructor(data, options){
super(data, options);
}
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
};
}
valid(){
return this.data.search(/^[0-9]+$/) !== -1;
}
}
function addZeroes(number, n){
for(var i = 0; i < n; i++){
number = "0" + number;
}
return number;
}
export default MSI;
@@ -0,0 +1,10 @@
import MSI from './MSI.js';
import {mod10} from './checksums.js';
class MSI10 extends MSI{
constructor(data, options){
super(data + mod10(data), options);
}
}
export default MSI10;
@@ -0,0 +1,12 @@
import MSI from './MSI.js';
import {mod10} from './checksums.js';
class MSI1010 extends MSI{
constructor(data, options){
data += mod10(data);
data += mod10(data);
super(data, options);
}
}
export default MSI1010;
@@ -0,0 +1,10 @@
import MSI from './MSI.js';
import {mod11} from './checksums.js';
class MSI11 extends MSI{
constructor(data, options){
super(data + mod11(data), options);
}
}
export default MSI11;
@@ -0,0 +1,12 @@
import MSI from './MSI.js';
import {mod10, mod11} from './checksums.js';
class MSI1110 extends MSI{
constructor(data, options){
data += mod11(data);
data += mod10(data);
super(data, options);
}
}
export default MSI1110;
@@ -0,0 +1,23 @@
export 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;
}
export 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,7 @@
import MSI from './MSI.js';
import MSI10 from './MSI10.js';
import MSI11 from './MSI11.js';
import MSI1010 from './MSI1010.js';
import MSI1110 from './MSI1110.js';
export {MSI, MSI10, MSI11, MSI1010, MSI1110};