mechanical-tolerance-calculator 1.1.6 → 1.1.8

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 (4) hide show
  1. package/README.md +186 -113
  2. package/index.js +4 -1
  3. package/package.json +1 -1
  4. package/test.js +8 -2
package/README.md CHANGED
@@ -22,132 +22,205 @@ const { getAllTolerancesFor } = require("mechanical-tolerance-calculator");
22
22
  // ES module
23
23
  // import { getAllTolerancesFor } from "mechanical-tolerance-calculator";
24
24
 
25
- // Example: Housing Bore Toelrances
25
+ // Example: Housing Bore Tolerances
26
26
  const housingTolerances = getAllTolerancesFor("housing");
27
27
  console.log(housingTolerances["housingBoresTolerances"]);
28
+
29
+ // Example: Checking Shaft Toleranace for a Measurement
30
+ const result = checkOneMeasurementFor('shaft', 179.91);
31
+ console.log(result);
32
+
33
+ // Exmaple: Checking Housing Specification Tolerance for a Collection of Measurements
34
+ const result = checkMultipleMeasurementsFor('housing', [240.05, 240.07, 240.09, 240.05, 240.06, 240.02, 240.09]);
35
+ console.log(result);
36
+
28
37
  ```
38
+ # API Documentation
39
+
40
+ This section documents the exported public methods of the **Mechanical Tolerance Calculator** library.
29
41
 
30
42
  ---
31
43
 
32
- ## API EXACPLES
33
-
34
- ### `getAllTolerancesFor(materialType: String)`
35
-
36
- **Parameters**
37
-
38
- - `materialType` (`string`) Type of material to check tolerances for (e.g. `"housing"`, `"shaft"`, `"shell"`).
39
-
40
- **Returns**
41
-
42
- An object with the following shape (example):
43
-
44
- ```json
45
- {
46
- "type": "housing bore" | "shaft" | "shell bore",
47
- "specifications": {
48
- "H6": [
49
- {
50
- "minimum_diameter": 0,
51
- "maximum_diameter": 3,
52
- "upper_deviation": 0.006,
53
- "lower_deviation": 0,
54
- "IT6": 0.006,
55
- "IT5": 0.004
56
- },
57
- {
58
- "minimum_diameter": 3,
59
- "maximum_diameter": 6,
60
- "upper_deviation": 0.008,
61
- "lower_deviation": 0,
62
- "IT6": 0.008,
63
- "IT5": 0.005
64
- }
65
- ],
66
-
67
- "H7": [
68
- {
69
- "minimum_diameter": 0,
70
- "maximum_diameter": 3,
71
- "upper_deviation": 0.01,
72
- "lower_deviation": 0,
73
- "IT7": 0.01,
74
- "IT6": 0.006,
75
- "IT5": 0.004
76
- },
77
- {
78
- "minimum_diameter": 3,
79
- "maximum_diameter": 6,
80
- "upper_deviation": 0.012,
81
- "lower_deviation": 0,
82
- "IT7": 0.012,
83
- "IT6": 0.008,
84
- "IT5": 0.005
85
- },
86
- ]
87
- }
88
- }
44
+ ## getAllTolerancesFor(materialType: String)
45
+
46
+ Returns all available ISO/ANSI tolerance specifications for a given material type.
47
+
48
+ ### Description
49
+ Determines the material category from the provided string and returns the full set of tolerance specifications associated with that category.
50
+ Supported material types include **housing**, **shaft**, and **shell** (case-insensitive and partial matches allowed, e.g. `"housing bore"`).
51
+
52
+ ### Parameters
53
+ - **materialType** (`string`)
54
+ The type of material to retrieve tolerances for.
55
+ Valid values (or substrings):
56
+ - `"housing"`
57
+ - `"shaft"`
58
+ - `"shell"`
59
+
60
+ ### Returns
61
+ - **object**
62
+
63
+ **On success**
64
+ ```json
65
+ {
66
+ "type": "housingBores" | "shafts" | "shellBores",
67
+ "specifications": {
68
+ "H6": [ { ... } ],
69
+ "H7": [ { ... } ],
70
+ "...": [ { ... } ]
71
+ }
72
+ } ```
73
+
74
+ - **On failure**
75
+ ```json
76
+ {
77
+ "error": "Unknown material type: <value>. Valid types are 'housing', 'shaft', or 'shell'."
78
+ }
79
+ ```
80
+
81
+ ### Example
82
+ ```js
83
+ const { getAllTolerancesFor } = require("mechanical-tolerance-calculator");
84
+
85
+ const tolerances = getAllTolerancesFor("housing");
86
+ console.log(tolerances.specifications.H7);
89
87
  ```
90
88
 
91
- - `type`: `"housing bore"` or `"shaft"` or `"shell bore"` inferred from the materialType parameter.
92
- - `specifications`: ISO or ANSI fit/tolerance designation associated with the entry (e.g., H7, h6, etc.).
89
+ ## checkOneMeasurementFor(materialType: String, measurement: Number)
90
+
91
+ Checks whether a single measurement complies with the WA standard tolerance and IT grade for the given material type.
92
+
93
+ ### Description
94
+ - Uses WA standard specifications:
95
+ - Housing → H8 / IT6
96
+ - Shell → H9 / IT6
97
+ - Shaft → h9 / IT5
98
+ - Infers the nominal size from the measurement.
99
+ - Calculates upper and lower bounds.
100
+ - Evaluates whether the measurement meets specification and IT tolerance.
101
+
102
+ ### Parameters
103
+ - **materialType** (`string`)
104
+ The type of material to check tolerance and specification for.
105
+ Valid values (or substrings):
106
+ - `"housing"`
107
+ - `"shaft"`
108
+ - `"shell"`
109
+ - **measurement** (`number`)
110
+ The measured diameter (must be between 0 and 1000).
111
+
112
+ ### Returns
113
+ - **object**
114
+
115
+ **On success**
116
+ ```json
117
+ {
118
+ "measurement": 24.982,
119
+ "nominal": 25,
120
+ "specification": "h9",
121
+ "IT_grade": "IT5",
122
+ "computed_specification_bounds": {
123
+ "upperBound": "25.000",
124
+ "lowerBound": "24.970"
125
+ },
126
+ "uncomputed_specification_bounds": {
127
+ "upperBound": "25.000 + 0.000",
128
+ "lowerBound": "25.000 - 0.030"
129
+ },
130
+ "matched_spec": { ... },
131
+ "meets_specification": {
132
+ "meetsSpec": true,
133
+ "reason": "24.982 falls between 24.970 and 25.000",
134
+ "concludedReason": "shaft is in acceptable size."
135
+ },
136
+ "meets_IT_tolerance": true
137
+ }
138
+ ```
93
139
 
94
- - `maximum_diameter`: The upper bound of the nominal diameter range (in millimetres) for which the tolerance values apply.
95
- - `minimum_diameter`: The upper bound of the nominal diameter range (in millimetres) for which the tolerance values apply.
96
- - `upper_deviation` / `lower_deviation`: The positive / negative deviation limit from the basic size (in millimetres).
97
- - `IT5` / `IT6` / `IT8`, etc: International Tolerance (IT) grades defining standard tolerance magnitudes for each grade level.
140
+ - **On failure**
141
+ ```json
142
+ {
143
+ "error": "Measurement must be between 0 to 1000."
144
+ }
145
+ ```
98
146
 
99
- ---
147
+ ### Example
148
+ ```js
149
+ const { checkOneMeasurementFor } = require("mechanical-tolerance-calculator");
100
150
 
101
- ## Example Output
102
-
103
- ```json
104
- {
105
- "type": "housing bore",
106
- "specifications": {
107
- "H6": [
108
- {
109
- "minimum_diameter": 0,
110
- "maximum_diameter": 3,
111
- "upper_deviation": 0.006,
112
- "lower_deviation": 0,
113
- "IT6": 0.006,
114
- "IT5": 0.004
115
- },
116
- {
117
- "minimum_diameter": 3,
118
- "maximum_diameter": 6,
119
- "upper_deviation": 0.008,
120
- "lower_deviation": 0,
121
- "IT6": 0.008,
122
- "IT5": 0.005
123
- }
124
- ],
125
-
126
- "H7": [
127
- {
128
- "minimum_diameter": 0,
129
- "maximum_diameter": 3,
130
- "upper_deviation": 0.01,
131
- "lower_deviation": 0,
132
- "IT7": 0.01,
133
- "IT6": 0.006,
134
- "IT5": 0.004
135
- },
136
- {
137
- "minimum_diameter": 3,
138
- "maximum_diameter": 6,
139
- "upper_deviation": 0.012,
140
- "lower_deviation": 0,
141
- "IT7": 0.012,
142
- "IT6": 0.008,
143
- "IT5": 0.005
144
- }
145
- ]
146
- }
147
- }
151
+ const result = checkOneMeasurementFor("shaft", 179.91);
152
+ console.log(result.meets_IT_tolerance);
148
153
  ```
149
154
 
150
- ---
155
+ ## checkMultipleMeasurementsFor(materialType: String, measurements: Numbers[])
156
+
157
+ Evaluates multiple measurements against WA standard tolerances and IT limits as a group.
158
+
159
+ ### Description
160
+ - Validates all measurements.
161
+ - Computes:
162
+ - Nominal size distribution
163
+ - Maximum and minimum measurements
164
+ - IT difference (max − min)
165
+ - Determines:
166
+ - Whether all measurements meet specification
167
+ - Whether the IT tolerance band is satisfied
168
+ - Overall compliance status
169
+
170
+ ### Parameters
171
+ - **materialType** (`string`)
172
+ The type of material to check tolerance and specification for.
173
+ Valid values (or substrings):
174
+ - `"housing"`
175
+ - `"shaft"`
176
+ - `"shell"`
177
+ - **measurement** (`number[]`)
178
+ An array of measured diameters (each between 0 and 1000).
179
+
180
+ ### Returns
181
+ - **object**
182
+
183
+ **On success**
184
+ ```json
185
+ {
186
+ "measurement": [24.982, 24.990, 24.975],
187
+ "nominal": 25,
188
+ "specification": "h9",
189
+ "IT_grade": "IT5",
190
+ "computed_specification_bounds": {
191
+ "upperBound": "25.000",
192
+ "lowerBound": "24.970"
193
+ },
194
+ "matched_spec": { ... },
195
+ "meets_specification": {
196
+ "meetsSpec": true,
197
+ "reason": "24.990 falls between 24.970 and 25.000"
198
+ },
199
+ "meets_IT_Tolerance": {
200
+ "meetsIT": true,
201
+ "reason": "The difference between 24.990 and 24.975 is less than or equal to 0.021."
202
+ },
203
+ "meets_final_compliance": true
204
+ }
205
+ ```
206
+
207
+ - **On Validation Error**
208
+ ```json
209
+ {
210
+ "error": "Some measurements are invalid.",
211
+ "details": [
212
+ { "index": 1, "value": -5, "error": "Invalid measurement: must be 0–1000" }
213
+ ]
214
+ }
215
+ ```
216
+
217
+ ### Example
218
+ ```js
219
+ const { checkMultipleMeasurementsFor } = require("mechanical-tolerance-calculator");
220
+
221
+ const result = checkMultipleMeasurementsFor('housing', [240.05, 240.07, 240.09, 240.05, 240.06, 240.02, 240.09]);
222
+ console.log(result.meets_final_compliance);
223
+ ```
151
224
 
152
225
  ## Features
153
226
 
package/index.js CHANGED
@@ -403,7 +403,10 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
403
403
  camcoStandardTolerances,
404
404
  );
405
405
  withInSpecs.push(result.meets_specification.meetsSpec);
406
- nominals[result.nominal] = count++;
406
+ const nominal = result.nominal;
407
+
408
+ // count occurrences
409
+ nominals[nominal] = (nominals[nominal] || 0) + 1;
407
410
 
408
411
  if (
409
412
  Math.abs(result.nominal - result.measurement) >
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mechanical-tolerance-calculator",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "Calculates international standard specification and tolerances for bores, round bars and metals of mechanical units. For examples; H7, H8, H9, h8, h9 specifications and IT5/IT6 tolerances.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test.js CHANGED
@@ -1,3 +1,9 @@
1
1
  const { checkMultipleMeasurementsFor } = require("./index");
2
-
3
- console.log(checkMultipleMeasurementsFor("housing", [100.04, 100.05, 100.06]));
2
+ // console.log(checkMultipleMeasurementsFor("housing", [100.04, 100.05]));
3
+ // console.log(checkMultipleMeasurementsFor("housing", [100.04, 100.05, 95.06]));
4
+ console.log(
5
+ checkMultipleMeasurementsFor(
6
+ "housing",
7
+ [100.04, 100.05, 100.05, 98.08, 98.07, 100.09, 98.07, 98.03],
8
+ ),
9
+ );