Skip to content

Commit

Permalink
Update dependencies and lint rules
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Jun 24, 2024
1 parent 61d7e04 commit a12be8c
Show file tree
Hide file tree
Showing 13 changed files with 4,527 additions and 3,375 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.cjs

This file was deleted.

17 changes: 8 additions & 9 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,30 @@ jobs:

strategy:
matrix:
node-version: [16, 18, 19]
node-version: [18, 20, 22]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7.27.0
- uses: actions/checkout@v4
- name: Enable pnpm
run: corepack enable
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- name: Install dependencies
run: pnpm install
run: pnpm install -r
- name: Check coding standards
run: npm run lint
- name: Static analysis - check types
run: npm run ts
run: npm run build
- name: Test with coverage
run: npm run test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
files: coverage/lcov.info
env_vars: OS,NODE
Expand Down
2 changes: 1 addition & 1 deletion ava.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export default {
files: [
'pkg/*/test/*.ava.js',
],
}
};
10 changes: 10 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import es6 from '@cto.af/eslint-config/es6.js';

export default [
{
ignores: [
'**/*.d.ts',
],
},
...es6,
];
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@
"private": "true",
"type": "module",
"scripts": {
"lint": "eslint . --ext js",
"lint": "eslint .",
"test": "c8 ava",
"snaps": "c8 ava --update-snapshots",
"ts": "npm run ts --workspaces --if-present"
"build": "npm run ts --workspaces --if-present"
},
"keywords": [],
"author": "Joe Hildebrand <joe-github@cursive.net>",
"license": "MIT",
"devDependencies": {
"@cto.af/eslint-config": "2.0.1",
"@types/node": "20.3.1",
"ava": "5.3.1",
"c8": "8.0.0",
"eslint": "8.43.0",
"@cto.af/eslint-config": "4.0.2",
"@types/node": "20.14.8",
"ava": "6.1.3",
"c8": "10.1.2",
"eslint": "8.57.0",
"eslint-plugin-node": "11.1.0",
"lerna": "^7.0.2",
"typescript": "5.1.3"
"lerna": "^8.1.5",
"typescript": "5.5.2"
},
"packageManager": "pnpm@9.4.0",
"engines": {
"node": ">=16"
"node": ">=18"
},
"workspaces": [
"pkg/*"
Expand Down
36 changes: 18 additions & 18 deletions pkg/chex-cli/bin/chex.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env node
/* eslint-disable no-console */

import {Command, Option} from 'commander'
import {Buffer} from 'buffer'
import fs from 'fs/promises'
import {hexDump} from '@cto.af/chex'
import {Command, Option} from 'commander';
import {Buffer} from 'buffer';
import fs from 'fs/promises';
import {hexDump} from '@cto.af/chex';

const program = new Command()
const program = new Command();
program
.argument('[file...]', 'file names to read or "-" for stdin')
.option('-c,--colors', 'force colors on even if stdout is not a tty')
Expand All @@ -15,37 +15,37 @@ program
'-s,--strings <encoding>',
'try to decode strings in this encoding'
).choices(['utf8', 'utf-8']))
.parse()
.parse();

const opts = program.opts()
const {args} = program
const opts = program.opts();
const {args} = program;
if (args.length === 0) {
args.push('-')
args.push('-');
}

function readStdin() {
return new Promise((resolve, reject) => {
const bufs = []
process.stdin.on('data', d => bufs.push(d))
process.stdin.on('end', () => resolve(new Uint8Array(Buffer.concat(bufs))))
process.stdin.on('error', reject)
})
const bufs = [];
process.stdin.on('data', d => bufs.push(d));
process.stdin.on('end', () => resolve(new Uint8Array(Buffer.concat(bufs))));
process.stdin.on('error', reject);
});
}

async function main(argv) {
for (const fn of argv) {
if (argv.length > 1) {
console.log(fn)
console.log(fn);
}
const buf = fn === '-' ?
await readStdin() :
new Uint8Array(await fs.readFile(fn))
new Uint8Array(await fs.readFile(fn));
console.log(hexDump(buf, {
colors: opts.colors || process.stdout.isTTY,
dots: opts.dots,
decode: opts.strings,
}))
}));
}
}

main(args).catch(console.error)
main(args).catch(console.error);
2 changes: 1 addition & 1 deletion pkg/chex-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
],
"dependencies": {
"@cto.af/chex": "workspace:*",
"commander": "11.0.0"
"commander": "12.1.0"
}
}
68 changes: 34 additions & 34 deletions pkg/chex/lib/encoding.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
export const charMap = '␀␁␂␃␄␅␆␇␈␉␊␋␌␍␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~␡.................................¡¢£¤¥¦§¨©ª«¬.®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ'
const utf8Map = '................................ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~.'
export const dotMap = utf8Map.padEnd(256, '.')
export const charMap = '␀␁␂␃␄␅␆␇␈␉␊␋␌␍␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~␡.................................¡¢£¤¥¦§¨©ª«¬.®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ';
const utf8Map = '................................ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~.';
export const dotMap = utf8Map.padEnd(256, '.');

// UTF-8, UTF16, UTF16BE, utf-16LE, etc.
const validEncoding = /^utf-?(?:(?<eight>8)|(?:16-?(?<endian>be|le)?))$/i
const validEncoding = /^utf-?(?:(?<eight>8)|(?:16-?(?<endian>be|le)?))$/i;

// Is the runtime encoding little-endian?
export const LITTLE = (new Uint16Array(
new Uint8Array([1, 2]).buffer
)[0] === 0x0201)
)[0] === 0x0201);

/**
* @param {string} e
* @returns {{eight: boolean, little: boolean}}
*/
export function parseEncoding(e) {
const m = e.match(validEncoding)
const m = e.match(validEncoding);
if (!m) {
throw new Error(`Unknown string encoding "${m}"`)
throw new Error(`Unknown string encoding "${m}"`);
}
return {
eight: Boolean(m.groups.eight),
little: m.groups.endian ?
(m.groups.endian.toLowerCase() === 'le') :
LITTLE,
}
};
}

/**
Expand All @@ -37,7 +37,7 @@ export function parseEncoding(e) {
/**
* @type {Decoded}
*/
const DECODE_ERROR = {str: '.', extra: 0}
const DECODE_ERROR = {str: '.', extra: 0};

/**
* Try to return a single printable grapheme cluster for the read point,
Expand All @@ -50,55 +50,55 @@ const DECODE_ERROR = {str: '.', extra: 0}
* @returns {Decoded}
*/
export function utf8decode(buf, offset, length) {
let val = buf[offset]
let extra = 0
let str = utf8Map[val]
let val = buf[offset];
let extra = 0;
let str = utf8Map[val];
if (str) {
return {str, extra}
return {str, extra};
}

if (((val & 0b11_000000) === 0b10_000000) || // Continuation
((val & 0b11111_000) === 0b11111_000)) { // 4 bytes max
return {...DECODE_ERROR, msg: 'continuation'}
return {...DECODE_ERROR, msg: 'continuation'};
}
if ((val & 0b111_00000) === 0b110_00000) {
val &= 0b000_11111
extra = 1
val &= 0b000_11111;
extra = 1;
} else if ((val & 0b1111_0000) === 0b1110_0000) {
val &= 0b0000_1111
extra = 2
val &= 0b0000_1111;
extra = 2;
} else { // Invariant: (val & 0b11111_000) === 0b11110_000
val &= 0b00000_111
extra = 3
val &= 0b00000_111;
extra = 3;
}

for (let i = 1; i <= extra; i++) {
if (offset + i >= length) {
return {...DECODE_ERROR, msg: 'truncated'}
return {...DECODE_ERROR, msg: 'truncated'};
}
const b = buf[offset + i]
const b = buf[offset + i];
if ((b & 0b11_000000) !== 0b10_000000) {
return {...DECODE_ERROR, msg: 'not continued'}
return {...DECODE_ERROR, msg: 'not continued'};
}
val = (val << 6) | (b & 0b00_111111)
val = (val << 6) | (b & 0b00_111111);
}

if ((val >= 0x1F1E6) && (val <= 0x1F1FF)) {
// REGIONAL INDICATORs.
// Turn the first one into A with a box around it, etc.
str = `${String.fromCharCode(val - 0x1f1a5)}\u20DE`
str = `${String.fromCharCode(val - 0x1f1a5)}\u20DE`;
} else {
str = String.fromCodePoint(val)
str = String.fromCodePoint(val);
if (/^\p{C}$/u.test(str)) {
return {...DECODE_ERROR, extra, msg: 'control'} // E.g. U+200B ZERO WIDTH SPACE
return {...DECODE_ERROR, extra, msg: 'control'}; // E.g. U+200B ZERO WIDTH SPACE
}
if (/^\p{Mn}$/u.test(str)) {
str = `\u25cc${str}` // Combining. Add a dotted circle in front
str = `\u25cc${str}`; // Combining. Add a dotted circle in front
}
}

// There are probably lots of other cases. Please file an issue!
return {str, extra}
return {str, extra};
}

/**
Expand All @@ -107,11 +107,11 @@ export function utf8decode(buf, offset, length) {
* @returns {Uint8Array}
*/
export function utf16encode(s, little) {
const len2 = s.length * 2
const ab = new ArrayBuffer(len2)
const dv = new DataView(ab)
const len2 = s.length * 2;
const ab = new ArrayBuffer(len2);
const dv = new DataView(ab);
for (let i = 0, j = 0; i < len2; i += 2, j++) {
dv.setUint16(i, s.charCodeAt(j), little)
dv.setUint16(i, s.charCodeAt(j), little);
}
return new Uint8Array(ab)
return new Uint8Array(ab);
}
Loading

0 comments on commit a12be8c

Please sign in to comment.