Skip to content

Commit

Permalink
Merge pull request #18 from Nesopie/feat/ci
Browse files Browse the repository at this point in the history
feat: add ci for testing and linting
  • Loading branch information
junderw authored Jul 19, 2024
2 parents fb79672 + ff46313 commit b42ceb2
Show file tree
Hide file tree
Showing 5 changed files with 8,719 additions and 17 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/main_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Run Tests

on:
push:
branches:
- master
pull_request:

jobs:
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run test
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v4
with:
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm run standard
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules
.nyc_output
package-lock.json
22 changes: 11 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
// https://github.com/bitcoin/bips/blob/master/bip-0021.mediawiki
// bitcoin:<address>[?amount=<amount>][?label=<label>][?message=<message>]

var qs = require('qs')
const qs = require('qs')

function decode (uri, urnScheme) {
urnScheme = urnScheme || 'bitcoin'
var urnSchemeActual = uri.slice(0, urnScheme.length).toLowerCase()
const urnSchemeActual = uri.slice(0, urnScheme.length).toLowerCase()
if (urnSchemeActual !== urnScheme ||
uri.charAt(urnScheme.length) !== ':'
) throw new Error('Invalid BIP21 URI: ' + uri)

var split = uri.indexOf('?')
var address = uri.slice(urnScheme.length + 1, split === -1 ? undefined : split)
var query = split === -1 ? '' : uri.slice(split + 1)
var options = qs.parse(query)
const split = uri.indexOf('?')
const address = uri.slice(urnScheme.length + 1, split === -1 ? undefined : split)
const query = split === -1 ? '' : uri.slice(split + 1)
const options = qs.parse(query)

if (options.amount) {
options.amount = Number(options.amount)
if (!isFinite(options.amount)) throw new Error('Invalid amount')
if (options.amount < 0) throw new Error('Invalid amount')
}

return { address: address, options: options }
return { address, options }
}

function encode (address, options, urnScheme) {
options = options || {}
var scheme = urnScheme || 'bitcoin'
var query = qs.stringify(options)
const scheme = urnScheme || 'bitcoin'
const query = qs.stringify(options)

if (options.amount) {
if (!isFinite(options.amount)) throw new TypeError('Invalid amount')
Expand All @@ -38,6 +38,6 @@ function encode (address, options, urnScheme) {
}

module.exports = {
decode: decode,
encode: encode
decode,
encode
}
Loading

0 comments on commit b42ceb2

Please sign in to comment.