Skip to content

Commit

Permalink
Homogenize example and remove reference to borsh-js
Browse files Browse the repository at this point in the history
The current examples differ on what they encode / decode, but more
importantly, they refer to a `borsh-js` package that does not exist

I have modified the dependencies to use the actual Borsh encoding, and
homogenized the code so they execute exactly the same code
  • Loading branch information
Guillermo Alejandro Gallardo Diez authored and Guillermo Alejandro Gallardo Diez committed Dec 20, 2024
1 parent 95c5e68 commit 88d0822
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
6 changes: 5 additions & 1 deletion examples/cjs/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const borsh = require('borsh-js');
const borsh = require('borsh');

const encodedU16 = borsh.serialize('u16', 2);
const decodedU16 = borsh.deserialize('u16', encodedU16);
Expand All @@ -7,3 +7,7 @@ console.log(decodedU16);
const encodedStr = borsh.serialize('string', 'testing');
const decodedStr = borsh.deserialize('string', encodedStr);
console.log(decodedStr);

const encodedU64 = borsh.serialize('u64', '100000000000000000');
const decodedU64 = borsh.deserialize('u64', encodedU64);
console.log(decodedU64);
5 changes: 4 additions & 1 deletion examples/cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"version": "2.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"borsh-js": "file:../../"
"borsh": "^2"
}
}
12 changes: 8 additions & 4 deletions examples/esm/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import * as borsh from 'borsh-js';
import * as borsh from 'borsh';

const encodedU16 = borsh.serialize('u16', 2);
const decodedU16 = borsh.deserialize('u16', encodedU16);
console.log(decodedU16);

const encodedStr = borsh.serialize('u64', '100000000000000000');
const decodedStr = borsh.deserialize('u64', encodedStr);
console.log(decodedStr);
const encodedStr = borsh.serialize('string', 'testing');
const decodedStr = borsh.deserialize('string', encodedStr);
console.log(decodedStr);

const encodedU64 = borsh.serialize('u64', '100000000000000000');
const decodedU64 = borsh.deserialize('u64', encodedU64);
console.log(decodedU64);
5 changes: 4 additions & 1 deletion examples/esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"borsh-js": "file:../../"
"borsh": "^2"
}
}

0 comments on commit 88d0822

Please sign in to comment.