Skip to content

Commit

Permalink
Merge PR #11 from 'nodech/ts-lint'
Browse files Browse the repository at this point in the history
  • Loading branch information
nodech committed Aug 31, 2023
2 parents 76c2dca + 9b6141f commit 7ad9446
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 25 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@ jobs:
node-version: 20.x

- name: Install tools
run: npm install --location=global bslint
run: npm install --location=global bslint typescript

- name: Install dependencies
run: npm install

- name: Lint
run: npm run lint

- name: Lint types
run: npm run lint-types

test:
name: Test
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion lib/bcfg.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

'use strict';

module.exports = require('./config');
const {Config} = require('./config');

module.exports = Config;
43 changes: 24 additions & 19 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ class Config {

/**
* Open a config file.
* @param {String|String[]} file - e.g. `bcoin.conf`, or array of strings
* @param {String|String[]} files - e.g. `bcoin.conf`, or array of strings
* @throws on IO error
*/

open(files) {
// @ts-ignore
if (fs.unsupported)
return;

Expand Down Expand Up @@ -1037,9 +1038,11 @@ class Config {

parseQuery(query) {
if (typeof query !== 'string') {
// @ts-ignore
if (!global.location)
return {};

// @ts-ignore
query = global.location.search;

if (typeof query !== 'string')
Expand All @@ -1057,9 +1060,11 @@ class Config {

parseHash(hash) {
if (typeof hash !== 'string') {
// @ts-ignore
if (!global.location)
return {};

// @ts-ignore
hash = global.location.hash;

if (typeof hash !== 'string')
Expand Down Expand Up @@ -1187,39 +1192,39 @@ function fromFloat(num, exp) {
sign = -1;
}

let hi = str;
let lo = '0';
let shi = str;
let slo = '0';

const index = str.indexOf('.');

if (index !== -1) {
hi = str.substring(0, index);
lo = str.substring(index + 1);
shi = str.substring(0, index);
slo = str.substring(index + 1);
}

hi = hi.replace(/^0+/, '');
lo = lo.replace(/0+$/, '');
shi = shi.replace(/^0+/, '');
slo = slo.replace(/0+$/, '');

assert(hi.length <= 16 - exp,
assert(shi.length <= 16 - exp,
'Fixed number string exceeds 2^53-1.');

assert(lo.length <= exp,
assert(slo.length <= exp,
'Too many decimal places in fixed number string.');

if (hi.length === 0)
hi = '0';
if (shi.length === 0)
shi = '0';

while (lo.length < exp)
lo += '0';
while (slo.length < exp)
slo += '0';

if (lo.length === 0)
lo = '0';
if (slo.length === 0)
slo = '0';

assert(/^\d+$/.test(hi) && /^\d+$/.test(lo),
assert(/^\d+$/.test(shi) && /^\d+$/.test(slo),
'Non-numeric characters in fixed number string.');

hi = parseInt(hi, 10);
lo = parseInt(lo, 10);
const hi = parseInt(shi, 10);
const lo = parseInt(slo, 10);

const mult = Math.pow(10, exp);
const maxLo = Number.MAX_SAFE_INTEGER % mult;
Expand All @@ -1235,4 +1240,4 @@ function fromFloat(num, exp) {
* Expose
*/

module.exports = Config;
exports.Config = Config;
4 changes: 3 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

module.exports = require('fs');
const fs = require('fs');

module.exports = fs;
15 changes: 14 additions & 1 deletion package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
"main": "./lib/bcfg.js",
"scripts": {
"lint": "eslint lib/ test/",
"lint-types": "tsc -p .",
"test": "bmocha --reporter spec test/*-test.js"
},
"dependencies": {
"bsert": "~0.0.12"
},
"devDependencies": {
"bmocha": "^2.1.0"
"bmocha": "^2.1.0",
"bts-type-deps": "^0.0.3"
},
"engines": {
"node": ">=14.0.0"
Expand Down
2 changes: 1 addition & 1 deletion test/bcfg-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const assert = require('bsert');
const Config = require('../lib/config');
const {Config} = require('../lib/config');

describe('bcfg', function() {
it('should filter options', () => {
Expand Down
31 changes: 31 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"include": [
"lib/**/*.js"
],
"compilerOptions": {
"rootDir": ".",
"target": "ES2020",
"lib": [
"ES2020"
],

"noEmit": true,

"allowJs": true,
"checkJs": true,
"maxNodeModuleJsDepth": 10,

"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,

"stripInternal": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": false,

"typeRoots": [
"node_modules/bts-type-deps/types"
]
}
}

0 comments on commit 7ad9446

Please sign in to comment.