Skip to content

Commit

Permalink
🧼
Browse files Browse the repository at this point in the history
  • Loading branch information
johntalton committed May 26, 2024
1 parent 61df1a2 commit fc83233
Show file tree
Hide file tree
Showing 17 changed files with 32 additions and 1,579 deletions.
566 changes: 0 additions & 566 deletions .eslintrc.json

This file was deleted.

6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
npm-debug.log*
node_modules/
lib/
lib/*.tsbuildinfo
coverage/
.nyc_output/
aod.min.js*
.DS_Store
.DS_Store
108 changes: 6 additions & 102 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,120 +1,24 @@
{
"name": "@johntalton/and-other-delights",
"version": "7.0.1",
"description": "",
"main": "src/aod.mjs",
"version": "8.0.0",
"license": "MIT",
"main": "./lib/index.js",
"exports": {
"import": "./src/aod.mjs"
".": "./lib/index.js"
},
"type": "module",
"files": [
"src/aod.mjs",
"src/**/*.ts",
"lib/**/*.js",
"lib/**/*.d.ts",
"lib/**/*.d.ts.map",
"lib/**/*.js.map"
],
"types": "lib/aod.d.ts",
"scripts": {
"lint": "npm --silent run lint:ts",
"lint:ts": "./node_modules/.bin/eslint --ext .ts src/*.ts",
"Xlint:js": "./node_modules/.bin/eslint -c .eslintrc.js.json lib/*.js",
"format": "npm --silent run format:beauty && npm --silent run format:min",
"format:beauty": "js-beautify -jslint-happy --indent-size 2 --space-in-empty-paren ./lib/*.js",
"format:min": "terser lib/*.js --source-map --output aod.min.js --ecma 2020 --comments some --compress --mangle",
"format:x-standard": "./node_modules/.bin/standard -v --fix ./lib/*.js",
"build": "tsc -p .",
"build:watch": "npm run build -- -w",
"test": "npm run test:mocha",
"test:mochaX": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha",
"test:mocha": "mocha",
"coverage": "npm --silent run coverage:c8",
"coverage:nyc": "nyc npm run test:mocha -- --reporter min",
"coverage:c8": "c8 --check-coverage --reporter text --reporter lcov --all --lines 60 --functions 5 --branches 50 npm --silent run test:mocha -- --no-parallel --reporter min",
"audit": "auditjs ossi --dev",
"clean": "rm -r .nyc_output coverage lib node_modules package-lock.json aod.min.js aod.min.js.map"
},
"mocha": {
"spec": [
"test/*.spec.js"
],
"grep": "@broken|@slow",
"invert": true,
"parallel": true,
"slow": 2,
"timeout": 31,
"watch": false,
"sort": false,
"forbitOnly": true,
"check-leaks": true,
"global": []
},
"nyc": {
"include": [
"src/*.ts"
],
"branches": 30,
"lines": 50,
"extends": "@istanbuljs/nyc-config-typescript",
"all": true,
"check-coverage": true,
"require": [
"ts-node/register/transpile-only",
"source-map-support/register"
],
"instrument": true,
"sourceMap": true,
"exclude-after-remap": false,
"produce-source-map": true,
"cache": false,
"reporter": [
"lcov",
"text",
"text-summary"
]
"build:watch": "npm run build -- -w"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@johntalton/eslint-config": "github:johntalton/eslint-config",
"@types/chai": "^4.2.11",
"@types/mocha": "^10.0.6",
"@types/node": "^20.10.5",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"auditjs": "^4.0.18",
"c8": "^9.1.0",
"chai": "^5.1.0",
"eslint": "^8.22.0",
"eslint-import-resolver-typescript": "^3.4.1",
"eslint-plugin-fp": "^2.3.0",
"eslint-plugin-functional": "^6.0.0",
"eslint-plugin-immutable": "^1.0.0",
"eslint-plugin-import": "^2.21.2",
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-no-loops": "^0.3.0",
"eslint-plugin-no-use-extend-native": "^0.5.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-security": "^2.1.0",
"eslint-plugin-spellcheck": "^0.0.20",
"js-beautify": "^1.11.0",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"source-map-support": "^0.5.19",
"standard": "^17.0.0",
"terser": "^5.0.0",
"ts-node": "^10.0.0",
"typescript": "^5.3.3"
},
"repository": {
"type": "git",
"url": "git+https://github.com/johntalton/and-other-delights.git"
},
"author": "johntalton@gmail.com",
"license": "MIT",
"bugs": {
"url": "https://github.com/johntalton/and-other-delights/issues"
},
"homepage": "https://github.com/johntalton/and-other-delights#readme"
}
}
10 changes: 0 additions & 10 deletions src/aod.mjs

This file was deleted.

11 changes: 0 additions & 11 deletions src/aod.ts

This file was deleted.

170 changes: 0 additions & 170 deletions src/busutil.ts

This file was deleted.

30 changes: 19 additions & 11 deletions src/i2c-addressed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,30 @@ export class I2CAddressedBus implements _I2CAddressedBus {
private readonly bus: I2CBus
private readonly options: ABOptions

static from(bus: I2CBus, address: I2CAddress, options?: Partial<ABOptions>): I2CAddressedBus {
static from(bus: I2CBus, address: I2CAddress, options: Partial<ABOptions> = {}): I2CAddressedBus {
return new I2CAddressedBus(bus, address, options)
}

constructor(bus: I2CBus, address: I2CAddress, options: Partial<ABOptions> = DEFAULT_AB) {
constructor(bus: I2CBus, address: I2CAddress, {
sharedReadBuffer = undefined,
allocOnRead = true,
allowMixedReadBuffers = false,
maxReadLength = WARN_READ_LENGTH,
maxWriteLength = WARN_WRITE_LENGTH,
validateReadWriteLengths = true
}: Partial<ABOptions>) {
this.address = address
this.bus = bus

this.options = {
sharedReadBuffer: options.sharedReadBuffer ?? undefined,
allocOnRead: (options.allocOnRead ?? true) === true,
allowMixedReadBuffers: false,
maxReadLength: WARN_READ_LENGTH,
maxWriteLength: WARN_WRITE_LENGTH,
validateReadWriteLengths: true
}
...DEFAULT_AB,
sharedReadBuffer,
allocOnRead,
allowMixedReadBuffers,
maxReadLength,
maxWriteLength,
validateReadWriteLengths
}
}

get name(): string {
Expand Down Expand Up @@ -92,7 +100,7 @@ export class I2CAddressedBus implements _I2CAddressedBus {
close(): void { return this.bus.close() }

async readI2cBlock(cmd: number, length: number, readBufferSource?: I2CBufferSource): Promise<ArrayBuffer> {
if (length > this.options.maxReadLength) {
if (this.options.validateReadWriteLengths && length > this.options.maxReadLength) {
throw new Error('read length greater then max configured')
}

Expand All @@ -111,7 +119,7 @@ export class I2CAddressedBus implements _I2CAddressedBus {
async writeI2cBlock(cmd: number, bufferSource: I2CBufferSource): Promise<void> {
assertBufferSource(bufferSource)

if (bufferSource.byteLength > this.options.maxWriteLength) {
if (this.options.validateReadWriteLengths && bufferSource.byteLength > this.options.maxWriteLength) {
throw new Error('write length greater then max configured')
}

Expand Down
Loading

0 comments on commit fc83233

Please sign in to comment.