diff --git a/config.js b/config.js new file mode 100644 index 0000000..f5c17e9 --- /dev/null +++ b/config.js @@ -0,0 +1,8 @@ +// as default, NFT is disabled for everyone +export default { + MODULES: { + NFT: process.env.NFT && './src/modules/nft/index.js', + MARKER: process.env.MARKER && './src/modules/marker/index.js', + LOCATION: process.env.LOCATION && './src/modules/location/index.js', + }, +}; diff --git a/index.js b/index.js index ac895e4..0fe1bd1 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,17 @@ -import { BarcodeMarkerGenerator } from './src/tools/markers/barcode-marker-generator'; -import { PatternMarkerGenerator } from './src/tools/markers/pattern-marker-generator'; +import MODULES from './config'; -export class StudioBackend { - static getBarcodeMarkerSVGDataURI(matrixTypeId, value) { - return new BarcodeMarkerGenerator(matrixTypeId, value).asSVGDataURI(); - } +const promises = []; - static async getMarkerPattern(dataURI) { - return await new PatternMarkerGenerator(dataURI).toPattern(); +Object.keys(MODULES).forEach((module) => { + if (MODULES[module]) { + promises.push(import(MODULES[module])); } -} +}); + +Promise.all(promises) + .then(() => { + console.log('All AR Modules have been loaded'); + }) + .catch((err) => { + console.error('Error in loading AR Modules', err); +}); diff --git a/src/modules/location/index.js b/src/modules/location/index.js new file mode 100644 index 0000000..ffbaee1 --- /dev/null +++ b/src/modules/location/index.js @@ -0,0 +1 @@ +export class LocationModule {} diff --git a/src/modules/marker/index.js b/src/modules/marker/index.js new file mode 100644 index 0000000..e1f8cba --- /dev/null +++ b/src/modules/marker/index.js @@ -0,0 +1,8 @@ +import { BarcodeMarkerGenerator } from './tools/barcode-marker-generator'; +import { PatternMarkerGenerator } from './src/modules/marker/tools/pattern-marker-generator'; + +export class MarkerModule { + static getBarcodeMarkerSVGDataURI(matrixTypeId, value) { + return new BarcodeMarkerGenerator(matrixTypeId, value).asSVGDataURI(); + } +} diff --git a/src/tools/markers/barcode-marker-generator.js b/src/modules/marker/tools/barcode-marker-generator.js similarity index 100% rename from src/tools/markers/barcode-marker-generator.js rename to src/modules/marker/tools/barcode-marker-generator.js diff --git a/src/tools/markers/helpers.js b/src/modules/marker/tools/helpers.js similarity index 100% rename from src/tools/markers/helpers.js rename to src/modules/marker/tools/helpers.js diff --git a/src/tools/markers/matrix-encoders.js b/src/modules/marker/tools/matrix-encoders.js similarity index 100% rename from src/tools/markers/matrix-encoders.js rename to src/modules/marker/tools/matrix-encoders.js diff --git a/src/tools/markers/pattern-marker-generator.js b/src/modules/marker/tools/pattern-marker-generator.js similarity index 100% rename from src/tools/markers/pattern-marker-generator.js rename to src/modules/marker/tools/pattern-marker-generator.js diff --git a/src/modules/nft/index.js b/src/modules/nft/index.js new file mode 100644 index 0000000..1f971b3 --- /dev/null +++ b/src/modules/nft/index.js @@ -0,0 +1,2 @@ +export class NFTModule { +} diff --git a/test/matrix-generator/index.js b/test/matrix-generator/index.js index 9f2c258..78d300f 100644 --- a/test/matrix-generator/index.js +++ b/test/matrix-generator/index.js @@ -1,57 +1,57 @@ -import { expect } from 'chai'; -import * as encoders from '../../src/tools/markers/matrix-encoders'; +import {expect} from 'chai'; +import * as encoders from '../../src/modules/marker/tools/matrix-encoders'; import codewords from './codewords.json'; function bitStringToBitArray(str) { - return str.split('').map(c => (c == '1' ? true : false)); + return str.split('').map(c => (c == '1' ? true : false)); } -describe('matrix-generator', function () { - it('correctly encodes 3x3_hamming_6_3', function () { - for (let i = 0; i < codewords.hamming_6_3.length; ++i) { - expect(encoders.encode_3x3_hamming_6_3(i)).to.eql( - bitStringToBitArray(codewords.hamming_6_3[i]), - ); - } - }); +describe('matrix-generator', function() { + it('correctly encodes 3x3_hamming_6_3', function() { + for (let i = 0; i < codewords.hamming_6_3.length; ++i) { + expect(encoders.encode_3x3_hamming_6_3(i)).to.eql( + bitStringToBitArray(codewords.hamming_6_3[i]), + ); + } + }); - it('correctly encodes 3x3_parity_6_5', function () { - for (let i = 0; i < codewords.parity_6_5.length; ++i) { - expect(encoders.encode_3x3_parity_6_5(i)).to.eql( - bitStringToBitArray(codewords.parity_6_5[i]), - ); - } - }); + it('correctly encodes 3x3_parity_6_5', function() { + for (let i = 0; i < codewords.parity_6_5.length; ++i) { + expect(encoders.encode_3x3_parity_6_5(i)).to.eql( + bitStringToBitArray(codewords.parity_6_5[i]), + ); + } + }); - it('correctly encodes 4x4_bch_13_5_5', function () { - for (let i = 0; i < codewords.bch_13_5_5.length; ++i) { - expect(encoders.encode_4x4_bch_13_5_5(i)).to.eql( - bitStringToBitArray(codewords.bch_13_5_5[i]), - ); - } - }); + it('correctly encodes 4x4_bch_13_5_5', function() { + for (let i = 0; i < codewords.bch_13_5_5.length; ++i) { + expect(encoders.encode_4x4_bch_13_5_5(i)).to.eql( + bitStringToBitArray(codewords.bch_13_5_5[i]), + ); + } + }); - it('correctly encodes 4x4_bch_13_9_3', function () { - for (let i = 0; i < codewords.bch_13_9_3.length; ++i) { - expect(encoders.encode_4x4_bch_13_9_3(i)).to.eql( - bitStringToBitArray(codewords.bch_13_9_3[i]), - ); - } - }); + it('correctly encodes 4x4_bch_13_9_3', function() { + for (let i = 0; i < codewords.bch_13_9_3.length; ++i) { + expect(encoders.encode_4x4_bch_13_9_3(i)).to.eql( + bitStringToBitArray(codewords.bch_13_9_3[i]), + ); + } + }); - it('correctly encodes 5x5_bch_22_7_7', function () { - for (let i = 0; i < codewords.bch_22_7_7.length; ++i) { - expect(encoders.encode_5x5_bch_22_7_7(i)).to.eql( - bitStringToBitArray(codewords.bch_22_7_7[i]), - ); - } - }); + it('correctly encodes 5x5_bch_22_7_7', function() { + for (let i = 0; i < codewords.bch_22_7_7.length; ++i) { + expect(encoders.encode_5x5_bch_22_7_7(i)).to.eql( + bitStringToBitArray(codewords.bch_22_7_7[i]), + ); + } + }); - it('correctly encodes 5x5_bch_22_12_5', function () { - for (let i = 0; i < codewords.bch_22_12_5.length; ++i) { - expect(encoders.encode_5x5_bch_22_12_5(i)).to.eql( - bitStringToBitArray(codewords.bch_22_12_5[i]), - ); - } - }); + it('correctly encodes 5x5_bch_22_12_5', function() { + for (let i = 0; i < codewords.bch_22_12_5.length; ++i) { + expect(encoders.encode_5x5_bch_22_12_5(i)).to.eql( + bitStringToBitArray(codewords.bch_22_12_5[i]), + ); + } + }); }); diff --git a/test/pattern-marker-generator/index.js b/test/pattern-marker-generator/index.js index ec4ce78..58ceb35 100644 --- a/test/pattern-marker-generator/index.js +++ b/test/pattern-marker-generator/index.js @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import * as generator from '../../src/tools/markers/pattern-marker-generator.js'; +import * as generator from '../../src/modules/marker/tools/pattern-marker-generator.js'; describe('pattern-marker-generator', function () { it('correctly generates pattern marker', function () {