Skip to content

Commit

Permalink
Merge pull request #55 from Nesopie/fix/cjs
Browse files Browse the repository at this point in the history
Fix/cjs
  • Loading branch information
junderw authored Jun 5, 2024
2 parents 082859c + 3aeb9b0 commit 5ceb0e3
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 96 deletions.
24 changes: 12 additions & 12 deletions dist/cjs/test/index.cjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
'use strict';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-ignore
const bech32Lib = require("../index.cjs");
const tape = require("tape");
const fixtures = require('../../../src/test/fixtures');
const fixtures = require("../../../src/test/fixtures");
function testValidFixture(f, bech32) {
if (f.hex) {
tape(`fromWords/toWords ${f.hex}`, (t) => {
t.plan(3);
const words = bech32.toWords(Buffer.from(f.hex, 'hex'));
const words = bech32.toWords(Buffer.from(f.hex, "hex"));
const bytes = Buffer.from(bech32.fromWords(f.words));
const bytes2 = Buffer.from(bech32.fromWordsUnsafe(f.words));
t.same(words, f.words);
t.same(bytes.toString('hex'), f.hex);
t.same(bytes2.toString('hex'), f.hex);
t.same(bytes.toString("hex"), f.hex);
t.same(bytes2.toString("hex"), f.hex);
});
}
tape(`encode ${f.prefix} ${f.hex || f.words}`, (t) => {
Expand All @@ -31,13 +31,13 @@ function testValidFixture(f, bech32) {
});
tape(`fails for ${f.string} with 1 bit flipped`, (t) => {
t.plan(2);
const buffer = Buffer.from(f.string, 'utf8');
buffer[f.string.lastIndexOf('1') + 1] ^= 0x1; // flip a bit, after the prefix
const str = buffer.toString('utf8');
const buffer = Buffer.from(f.string, "utf8");
buffer[f.string.lastIndexOf("1") + 1] ^= 0x1; // flip a bit, after the prefix
const str = buffer.toString("utf8");
t.equal(bech32.decodeUnsafe(str, f.limit), undefined);
t.throws(() => {
bech32.decode(str, f.limit);
}, new RegExp('Invalid checksum|Unknown character'));
}, new RegExp("Invalid checksum|Unknown character"));
});
// === compare of objects compares reference in memory, so this works
const wrongBech32 = bech32 === bech32Lib.bech32 ? bech32Lib.bech32m : bech32Lib.bech32;
Expand All @@ -46,7 +46,7 @@ function testValidFixture(f, bech32) {
t.equal(wrongBech32.decodeUnsafe(f.string, f.limit), undefined);
t.throws(() => {
wrongBech32.decode(f.string, f.limit);
}, new RegExp('Invalid checksum'));
}, new RegExp("Invalid checksum"));
});
}
function testInvalidFixture(f, bech32) {
Expand All @@ -59,7 +59,7 @@ function testInvalidFixture(f, bech32) {
});
}
if (f.string !== undefined || f.stringHex) {
const str = f.string || Buffer.from(f.stringHex, 'hex').toString('binary');
const str = f.string || Buffer.from(f.stringHex, "hex").toString("binary");
tape(`decode fails for ${str} (${f.exception})`, (t) => {
t.plan(2);
t.equal(bech32.decodeUnsafe(str), undefined);
Expand Down Expand Up @@ -90,7 +90,7 @@ fixtures.fromWords.invalid.forEach((f) => {
}, new RegExp(f.exception));
});
});
tape('toWords/toWordsUnsafe accept bytes as ArrayLike<number>', (t) => {
tape("toWords/toWordsUnsafe accept bytes as ArrayLike<number>", (t) => {
// Ensures that only the two operations from
// interface ArrayLike<T> {
// readonly length: number;
Expand Down
122 changes: 61 additions & 61 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
{
"name": "bech32",
"version": "2.0.0",
"description": "Bech32 encoding / decoding",
"type": "module",
"keywords": [
"base32",
"bech32",
"bech32m",
"bitcoin",
"crypto",
"crytography",
"decode",
"decoding",
"encode",
"encoding"
],
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/cjs/index.js",
"dist/cjs/index.d.ts",
"dist/esm/index.js"
],
"exports": {
".": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"types": "./dist/cjs/index.d.ts"
}
},
"license": "MIT",
"devDependencies": {
"@types/node": "^14.0.14",
"@types/tape": "^4.13.4",
"nyc": "^15.0.0",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"tap-dot": "*",
"tape": "^5.3.0",
"ts-node": "^10.9.2",
"tslint": "^6.1.3",
"tsx": "^4.7.2",
"typescript": "^3.9.5"
},
"repository": {
"url": "http://github.com/bitcoinjs/bech32",
"type": "git"
},
"scripts": {
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
"postbuild": "find dist/cjs -type f -name \"*.js\" -exec bash -c 'mv \"$0\" \"${0%.js}.cjs\"' {} \\;",
"clean": "rimraf dist",
"coverage": "nyc -x [src/test/*.ts] --check-coverage --branches 90 --functions 90 npm test",
"format": "npm run prettier -- --write",
"format:ci": "npm run prettier -- --check",
"gitdiff:ci": "npm run build && git diff --exit-code",
"lint:fix": "npm run lint -- --fix",
"lint": "tslint -p tsconfig.cjs.json -c tslint.json",
"prettier": "prettier --print-width 100 --single-quote --trailing-comma=all \"**/!(*.d).ts\"",
"test": "tape dist/cjs/test/*.cjs | tap-dot"
"name": "bech32",
"version": "2.0.0",
"description": "Bech32 encoding / decoding",
"type": "module",
"keywords": [
"base32",
"bech32",
"bech32m",
"bitcoin",
"crypto",
"crytography",
"decode",
"decoding",
"encode",
"encoding"
],
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.js",
"types": "dist/index.d.ts",
"files": [
"dist/cjs/index.cjs",
"dist/cjs/index.d.ts",
"dist/esm/index.js"
],
"exports": {
".": {
"require": "./dist/cjs/index.cjs",
"import": "./dist/esm/index.js",
"types": "./dist/cjs/index.d.ts"
}
},
"license": "MIT",
"devDependencies": {
"@types/node": "^14.0.14",
"@types/tape": "^4.13.4",
"nyc": "^15.0.0",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"tap-dot": "*",
"tape": "^5.3.0",
"ts-node": "^10.9.2",
"tslint": "^6.1.3",
"tsx": "^4.7.2",
"typescript": "^3.9.5"
},
"repository": {
"url": "http://github.com/bitcoinjs/bech32",
"type": "git"
},
"scripts": {
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
"postbuild": "find dist/cjs -type f -name \"*.js\" -exec bash -c 'mv \"$0\" \"${0%.js}.cjs\"' {} \\;",
"clean": "rimraf dist",
"coverage": "nyc -x [dist/cjs/test/*.ts] --check-coverage --branches 90 --functions 90 npm test",
"format": "npm run prettier -- --write",
"format:ci": "npm run prettier -- --check",
"gitdiff:ci": "npm run build && git diff --exit-code",
"lint:fix": "npm run lint -- --fix",
"lint": "tslint -p tsconfig.cjs.json -c tslint.json",
"prettier": "prettier --print-width 100 --single-quote --trailing-comma=all \"**/!(*.d).ts\"",
"test": "tape dist/cjs/test/*.cjs | tap-dot"
}
}
19 changes: 10 additions & 9 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"compilerOptions": {
"strict": true,
"resolveJsonModule": true,
"target": "es2015",
"moduleResolution": "node",
"noImplicitAny": true,
"preserveConstEnums": true
},
"include": ["src"]
"compilerOptions": {
"strict": true,
"resolveJsonModule": true,
"target": "es2015",
"moduleResolution": "node",
"noImplicitAny": true,
"preserveConstEnums": true
},
"include": ["src"],
"exclude": ["node_modules"]
}
15 changes: 7 additions & 8 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": false,
"outDir": "dist/cjs",
"module": "commonjs"
},
"exclude": ["node_modules"]
"extends": "./tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": false,
"outDir": "dist/cjs",
"module": "commonjs"
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"resolveJsonModule": true,
"module": "ESNext"
},
"exclude": ["node_modules", "src/test/**/*"]
"exclude": ["src/test/**/*"]
}
6 changes: 1 addition & 5 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
"rules": {
"arrow-parens": [true, "ban-single-arg-parens"],
"curly": false,
"indent": [
true,
"spaces",
2
],
"indent": [true, "spaces", 2],
"interface-name": [false],
"match-default-export-name": true,
"max-classes-per-file": [false],
Expand Down

0 comments on commit 5ceb0e3

Please sign in to comment.