Skip to content

Commit

Permalink
Merge pull request #82 from Nesopie/feat/hybrid
Browse files Browse the repository at this point in the history
feat: hybrid cjs and esm support
  • Loading branch information
junderw authored Jun 22, 2024
2 parents dd4c308 + dd4fe0a commit 223252c
Show file tree
Hide file tree
Showing 15 changed files with 6,565 additions and 148 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/main_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ jobs:
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 12
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm i
- run: npm ci
- run: npm run unit
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 12
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm i
- run: npm ci
- run: npm run standard
gitdiff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 12
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm i
- run: npm ci
- run: npm run gitdiff
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules

npm-debug.log
package-lock.json
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Base58

``` javascript
var BASE58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
var bs58 = require('base-x')(BASE58)
import basex from 'base-x'
var bs58 = basex(BASE58)

var decoded = bs58.decode('5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr')

Expand Down
49 changes: 26 additions & 23 deletions benchmark/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
'use strict'
var crypto = require('crypto')
var benchmark = require('benchmark')
var XorShift128Plus = require('xorshift.js').XorShift128Plus
const crypto = require('crypto')
const benchmark = require('benchmark')
const XorShift128Plus = require('xorshift.js').XorShift128Plus

var bs58ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
var bs58 = require('../')(bs58ALPHABET)
const bs58ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
const basex = require('../src/cjs/index.cjs').default
const bs58 = basex(bs58ALPHABET)

var fixtureIndex = 0
var resetFixtureIndex = function () { fixtureIndex = 0 }
var fixtures = new Array(10000)
var getNextFixture = function () {
var fixture = fixtures[fixtureIndex++]
// const bs58 = basex(bs58ALPHABET)

let fixtureIndex = 0
const resetFixtureIndex = function () { fixtureIndex = 0 }
const fixtures = new Array(10000)
const getNextFixture = function () {
const fixture = fixtures[fixtureIndex++]
if (fixtureIndex === fixtures.length) {
fixtureIndex = 0
}

return fixture
}

var seed = process.env.SEED || crypto.randomBytes(16).toString('hex')
const seed = process.env.SEED || crypto.randomBytes(16).toString('hex')
console.log('Seed: ' + seed)
var prng = new XorShift128Plus(seed)
for (var i = 0; i < fixtures.length; ++i) {
let source = prng.randomBytes(32)
const prng = new XorShift128Plus(seed)
for (let i = 0; i < fixtures.length; ++i) {
const source = prng.randomBytes(32)
fixtures[i] = { source, string: bs58.encode(source) }
}

Expand All @@ -49,12 +52,12 @@ new benchmark.Suite({
console.log('==================================================')
}
})
.add('encode', function () {
var fixture = getNextFixture()
bs58.encode(fixture.source)
}, {onStart: resetFixtureIndex, onCycle: resetFixtureIndex})
.add('decode', function () {
var fixture = getNextFixture()
bs58.decode(fixture.string)
}, {onStart: resetFixtureIndex, onCycle: resetFixtureIndex})
.run()
.add('encode', function () {
const fixture = getNextFixture()
bs58.encode(fixture.source)
}, { onStart: resetFixtureIndex, onCycle: resetFixtureIndex })
.add('decode', function () {
const fixture = getNextFixture()
bs58.decode(fixture.string)
}, { onStart: resetFixtureIndex, onCycle: resetFixtureIndex })
.run()
59 changes: 59 additions & 0 deletions benchmark/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 223252c

Please sign in to comment.