node-web-i2c 1.1.12 → 1.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +5 -3
  2. package/index.ts +9 -9
  3. package/package.json +12 -7
package/index.js CHANGED
@@ -4,14 +4,15 @@ exports.requestI2CAccess = exports.OperationError = exports.I2CPort = exports.I2
4
4
  const i2c_bus_1 = require("i2c-bus");
5
5
  const I2CPortMapSizeMax = 32;
6
6
  const Uint16Max = 65535;
7
- function parseUint16(string) {
8
- const n = Number.parseInt(string, 10);
7
+ function parseUint16(parseString) {
8
+ const n = Number.parseInt(parseString, 10);
9
9
  if (0 <= n && n <= Uint16Max)
10
10
  return n;
11
11
  else
12
12
  throw new RangeError(`Must be between 0 and ${Uint16Max}.`);
13
13
  }
14
14
  class I2CAccess {
15
+ _ports;
15
16
  constructor(ports) {
16
17
  this._ports = ports == null ? new I2CPortMap() : ports;
17
18
  }
@@ -29,6 +30,7 @@ class I2CPortMap extends Map {
29
30
  }
30
31
  exports.I2CPortMap = I2CPortMap;
31
32
  class I2CPort {
33
+ _portNumber;
32
34
  constructor(portNumber) {
33
35
  this._portNumber = parseUint16(portNumber.toString());
34
36
  }
@@ -39,7 +41,7 @@ class I2CPort {
39
41
  return `i2c-${this.portNumber}`;
40
42
  }
41
43
  async open(slaveAddress) {
42
- const bus = await i2c_bus_1.openPromisified(this.portNumber).catch((error) => {
44
+ const bus = await (0, i2c_bus_1.openPromisified)(this.portNumber).catch((error) => {
43
45
  throw new OperationError(error);
44
46
  });
45
47
  return {
package/index.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { openPromisified } from "i2c-bus";
1
+ import { openPromisified } from 'i2c-bus';
2
2
 
3
3
  const I2CPortMapSizeMax = 32;
4
4
 
5
5
  const Uint16Max = 65535;
6
6
 
7
- function parseUint16(string: string) {
8
- const n = Number.parseInt(string, 10);
7
+ function parseUint16(parseString: string) {
8
+ const n = Number.parseInt(parseString, 10);
9
9
  if (0 <= n && n <= Uint16Max) return n;
10
10
  else throw new RangeError(`Must be between 0 and ${Uint16Max}.`);
11
11
  }
@@ -69,7 +69,7 @@ export class I2CPort {
69
69
  try {
70
70
  await bus.writeByte(slaveAddress, cmd, byte);
71
71
  return byte;
72
- } catch (error) {
72
+ } catch (error: any) {
73
73
  throw new OperationError(error);
74
74
  }
75
75
  },
@@ -77,7 +77,7 @@ export class I2CPort {
77
77
  try {
78
78
  await bus.writeWord(slaveAddress, cmd, word);
79
79
  return word;
80
- } catch (error) {
80
+ } catch (error: any) {
81
81
  throw new OperationError(error);
82
82
  }
83
83
  },
@@ -87,7 +87,7 @@ export class I2CPort {
87
87
  try {
88
88
  const byte = await bus.receiveByte(slaveAddress);
89
89
  return byte;
90
- } catch (error) {
90
+ } catch (error: any) {
91
91
  throw new OperationError(error);
92
92
  }
93
93
  },
@@ -100,7 +100,7 @@ export class I2CPort {
100
100
  Buffer.allocUnsafe(length)
101
101
  );
102
102
  return new Uint8Array(buffer.slice(0, bytesRead));
103
- } catch (error) {
103
+ } catch (error: any) {
104
104
  throw new OperationError(error);
105
105
  }
106
106
  },
@@ -109,7 +109,7 @@ export class I2CPort {
109
109
  try {
110
110
  await bus.sendByte(slaveAddress, byte);
111
111
  return byte;
112
- } catch (error) {
112
+ } catch (error: any) {
113
113
  throw new OperationError(error);
114
114
  }
115
115
  },
@@ -122,7 +122,7 @@ export class I2CPort {
122
122
  Buffer.from(bytes)
123
123
  );
124
124
  return new Uint8Array(buffer.slice(0, bytesWritten));
125
- } catch (error) {
125
+ } catch (error: any) {
126
126
  throw new OperationError(error);
127
127
  }
128
128
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-web-i2c",
3
- "version": "1.1.12",
3
+ "version": "1.1.16",
4
4
  "description": "I2C access with Node.js",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -14,19 +14,24 @@
14
14
  "license": "MIT",
15
15
  "dependencies": {
16
16
  "@types/i2c-bus": "^5.1.0",
17
- "@types/node": "^14.14.25",
18
- "i2c-bus": "^5.2.1"
17
+ "@types/node": "^16.11.12",
18
+ "i2c-bus": "^5.2.2"
19
19
  },
20
20
  "devDependencies": {
21
- "@typescript-eslint/eslint-plugin": "^4.22.0",
22
- "@typescript-eslint/parser": "^4.22.0",
23
- "eslint": "^8.0.0",
21
+ "@types/node": "^16.11.12",
22
+ "@typescript-eslint/eslint-plugin": "^5.6.0",
23
+ "@typescript-eslint/parser": "^5.6.0",
24
+ "eslint": "^8.4.1",
25
+ "husky": "^7.0.4",
26
+ "lint-staged": "^12.1.2",
27
+ "prettier": "^2.5.1",
24
28
  "typescript": "^4.2.4"
25
29
  },
26
30
  "scripts": {
27
31
  "build": "tsc",
28
32
  "lint": "eslint index.ts",
29
- "prepare": "npm run build"
33
+ "prepare": "husky install && rm -rf dist && npm run build",
34
+ "precommit": "lint-staged"
30
35
  },
31
36
  "keywords": [
32
37
  "hardware",