ya-struct 0.0.2 → 0.0.3

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 (2) hide show
  1. package/lib/index.js +29 -12
  2. package/package.json +2 -2
package/lib/index.js CHANGED
@@ -68,7 +68,7 @@ const defineWithBuilderAndAbi = ({ builder, abi }) => {
68
68
  [fieldName]: value
69
69
  });
70
70
  } else {
71
- throw new Error("only Buffer and BigInt supported");
71
+ throw new Error(`only Buffer and BigInt supported, "${fieldName}" was of type "${typeof value}"`);
72
72
  }
73
73
  });
74
74
 
@@ -99,18 +99,35 @@ const defineWithBuilderAndAbi = ({ builder, abi }) => {
99
99
  };
100
100
  };
101
101
 
102
- const findHostDataModel = () => {
103
- if (process.arch === "x64") {
104
- if (process.platform === "win32") {
105
- return "LLP64";
106
- } else if (process.platform === "linux") {
107
- return "LP64";
108
- } else {
109
- throw new Error(`unsupported platform ${process.platform}`);
110
- }
111
- } else {
112
- throw new Error(`unsupported CPU architecture ${process.arch}`);
102
+ const hostDataModels = {
103
+ "x64": {
104
+ "win32": "LLP64",
105
+ "linux": "LP64"
106
+ },
107
+ "arm64": {
108
+ "linux": "LP64"
109
+ }
110
+ };
111
+
112
+ const findDataModelFor = ({ arch, platform }) => {
113
+ const archDataModels = hostDataModels[arch];
114
+ if (!archDataModels) {
115
+ throw new Error(`unsupported CPU architecture ${arch}`);
113
116
  }
117
+
118
+ const dataModel = archDataModels[platform];
119
+ if (!dataModel) {
120
+ throw new Error(`unsupported platform ${platform}`);
121
+ }
122
+
123
+ return dataModel;
124
+ };
125
+
126
+ const findHostDataModel = () => {
127
+ return findDataModelFor({
128
+ "arch": process.arch,
129
+ "platform": process.platform
130
+ });
114
131
  };
115
132
 
116
133
  const alignmentModels = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ya-struct",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.3",
5
5
  "description": "Yet Another Node.js Structure API",
6
6
  "main": "lib/index.js",
7
7
  "scripts": {
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "c8": "^7.9.0",
36
- "eslint": "^7.32.0",
36
+ "eslint": "^8.5.0",
37
37
  "mocha": "^9.1.1",
38
38
  "node-archibald": "^0.0.5"
39
39
  }