sergiss / epc-tds Goto Github PK
View Code? Open in Web Editor NEW:factory: EPC Tag Data Standard encoding and decoding library, written in typescript/javascript for Node.js
License: MIT License
:factory: EPC Tag Data Standard encoding and decoding library, written in typescript/javascript for Node.js
License: MIT License
As far as I understand if I encode EAN8 value to EPC and then decode this EPC back to EAN I should get the original EAN value but this never happens.
Example of code:
`
const epcToEan = (epc: string): string => {
const data = tds.valueOf(epc);
const result = data.toBarcode() as string;
return result;
};
const eanToEpc = (ean: string): string => {
const epc = new tds.Sgtin96().setGtin(ean);
return epc.toHexString();
};
console.log('eanToEpc -> epcToEan:', epcToEan(eanToEpc('60573421')));
`
I was expecting to receive 60573421 as a result but I receive 60000005734216.
What am I doing wrong?
Hi,
First of all many thanks for this library.
May I know whether this library supports typescript ?
Hello,
Is it possible to use this library in a web browser?
Hi,
Thanks for the library, very useful.
After starting to experiment with this library, I ran into problems which seem to originate from how BigInts and Numbers are being handled. I played with GIAI-96 values, but I suspect this issue might apply to many more formats as well. Case example:
// Testing with 34144B5A1C6A94D74F834DC7 / urn:epc:tag:giai-96:0.1234567.30000000004214215
const t = tds.fromTagURI("urn:epc:tag:giai-96:0.1234567.30000000004214215")
console.log(t.toTagURI()) // 'urn:epc:tag:giai-96:0.1234567.30000000004214216' <-- incorrect assetReference
console.log(t.getAssetReference()) // 30000000004214216 <-- incorrect assetReference
console.log(t.toHexString()) // '34144B5A1C6A94D74F834DC8' <-- incorrect hexString
As far as I could investigate this, this seems to relate to the fact that 30000000004214215 > Number.MAX_SAFE_INTEGER
. In https://github.com/sergiss/epc-tds/blob/master/epc/utils/bit-array.js#L78 a BigInt is casted to a Number
, where things fail:
> var big = BigInt(30000000004214215)
undefined
> Number(big)
30000000004214216
I'm afraid I don't understand all the corners of the library and EPC values well-enough to provide a proper fix, but I believe BigInts should be used everywhere in the library when dealing with the values. Then, when outputting the values, perhaps a bigger question from dev experience point of view is whether e.g. getAssetReference()
should output BigInts or strings - I guess BigInt would be more correct.
Here's a simple snippet which could be added to your test.js
for validating this case with GIAI-96 values, might be useful:
function withLargeValues() {
// 30000000004214215 > Number.MAX_SAFE_INTEGER
const tagUri = "urn:epc:tag:giai-96:0.1234567.30000000004214215"
const epc = tds.fromTagURI(tagUri)
const resultTagUri = epc.toTagURI()
if (resultTagUri !== tagUri) {
throw Error(`Giai96, expected: ${tagUri}, got: ${resultTagUri}`)
}
}
withLargeValues()
Apparently I have an unsupported EPC, I'm not familiar with the common ones, is this not a common EPC?
4453490063370A451349BB6E
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.