koehr ffd1dbe91c initial version 5 vuotta sitten
..
README.md ffd1dbe91c initial version 5 vuotta sitten
gs1_wasm.d.ts ffd1dbe91c initial version 5 vuotta sitten
gs1_wasm.js ffd1dbe91c initial version 5 vuotta sitten
gs1_wasm_bg.d.ts ffd1dbe91c initial version 5 vuotta sitten
gs1_wasm_bg.wasm ffd1dbe91c initial version 5 vuotta sitten
package.json ffd1dbe91c initial version 5 vuotta sitten

README.md

EPC to EAN

A webassembly library for batch conversion of EPCs to EANs written in Rust using wasm-pack and the GS1 crate.

Usage

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(','))
})

Building

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.