|
5 vuotta sitten | |
---|---|---|
.. | ||
README.md | 5 vuotta sitten | |
gs1_wasm.d.ts | 5 vuotta sitten | |
gs1_wasm.js | 5 vuotta sitten | |
gs1_wasm_bg.d.ts | 5 vuotta sitten | |
gs1_wasm_bg.wasm | 5 vuotta sitten | |
package.json | 5 vuotta sitten |
EPC to EAN
Because WebAssembly is meant to be loaded asynchronous, an extra step is necessary to use this library. Assuming a webpack environment that supports import()
:
// load the package
const loadGS1 = import('./gs1-wasm') // no global package yet
// gs1-wasm doesn't support arrays directly but instead takes a string of
// separated values. This makes the data handling much easier in WebAssembly.
// Any separator is allowed and there is no default.
const separator = ','
const epcList = [
'3034F44BF043E6800000D970',
'3034F44BF059A2800000E55C',
'3034F457D8374EC000009B82'
].join(separator)
loadGS1.then((gs1) => {
// batch_epc2ean takes a (stringified) list of EPCs and returns a
// (stringified) list of EANs. Both are using the string given in the
// second argument as separator
const eans = gs1.batch_epc2ean(epcList, separator)
console.log('converted', epcList, 'to', eans.split(','))
})
To build the package, wasm-pack
is used. You also need to make sure that you have installed the wasm32-unknown-unknown target.
rustup target add wasm32-unknown-unknown
cargo install wasm-pack
Now building the package is done by wasm-pack build
.