mechanical-tolerance-calculator 1.0.4 → 1.0.5
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.
- package/README.md +1 -1
- package/index.js +123 -8
- package/package.json +1 -1
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -117,12 +117,14 @@ const MATERIAL_TYPE_CONFIG = {
|
|
|
117
117
|
shafts: {
|
|
118
118
|
specification: "h9",
|
|
119
119
|
itGrade: "IT5",
|
|
120
|
+
|
|
120
121
|
rangeMatch: (nominal, spec) =>
|
|
121
122
|
nominal > spec.minimum_diameter && nominal <= spec.maximum_diameter,
|
|
122
123
|
},
|
|
123
124
|
housingBores: {
|
|
124
125
|
specification: "H8",
|
|
125
126
|
itGrade: "IT6",
|
|
127
|
+
|
|
126
128
|
rangeMatch: (nominal, spec) =>
|
|
127
129
|
nominal >= spec.minimum_diameter && nominal < spec.maximum_diameter,
|
|
128
130
|
},
|
|
@@ -147,8 +149,8 @@ function calculateComputedBounds(nominal, spec) {
|
|
|
147
149
|
|
|
148
150
|
function calculateUncomputedBounds(nominal, spec) {
|
|
149
151
|
return {
|
|
150
|
-
upperBound: parseUncomputedBound(nominal, spec.upper_deviation),
|
|
151
|
-
lowerBound: parseUncomputedBound(nominal, spec.lower_deviation),
|
|
152
|
+
upperBound: parseUncomputedBound(nominal, spec.upper_deviation, "+"),
|
|
153
|
+
lowerBound: parseUncomputedBound(nominal, spec.lower_deviation, "-"),
|
|
152
154
|
};
|
|
153
155
|
}
|
|
154
156
|
|
|
@@ -194,6 +196,13 @@ function processMeasurement(materialType, measurement, tolerances) {
|
|
|
194
196
|
|
|
195
197
|
// Check if measurement meets specification
|
|
196
198
|
const meetsSpec = checkMeetsSpecification(measurement, computedBounds);
|
|
199
|
+
const specMeetingReason = meetsSpec
|
|
200
|
+
? `${parseToFixedThreeString(measurement)} falls between ${
|
|
201
|
+
computedBounds.lowerBound
|
|
202
|
+
} and ${computedBounds.upperBound}`
|
|
203
|
+
: `${parseToFixedThreeString(measurement)} doesn't fall between ${
|
|
204
|
+
computedBounds.lowerBound
|
|
205
|
+
} and ${computedBounds.upperBound}`;
|
|
197
206
|
|
|
198
207
|
return {
|
|
199
208
|
measurement: parseStringFloat(measurement),
|
|
@@ -202,9 +211,21 @@ function processMeasurement(materialType, measurement, tolerances) {
|
|
|
202
211
|
IT_grade: config.itGrade,
|
|
203
212
|
computed_specification_bounds: computedBounds,
|
|
204
213
|
uncomputed_specification_bounds: uncomputedBounds,
|
|
205
|
-
meet_specification: meetsSpec,
|
|
206
|
-
meets_IT_tolerance: meetsSpec,
|
|
207
214
|
matched_spec: matchedSpec,
|
|
215
|
+
|
|
216
|
+
meets_specification: { meetsSpec, reason: specMeetingReason },
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function processOneMeasurement(materialType, measurement, tolerances) {
|
|
221
|
+
const processedMeasurement = processMeasurement(
|
|
222
|
+
materialType,
|
|
223
|
+
measurement,
|
|
224
|
+
tolerances
|
|
225
|
+
);
|
|
226
|
+
return {
|
|
227
|
+
...processedMeasurement,
|
|
228
|
+
meets_IT_tolerance: processedMeasurement.meet_specification,
|
|
208
229
|
};
|
|
209
230
|
}
|
|
210
231
|
|
|
@@ -222,7 +243,7 @@ function checkOneMeasurementFor(materialType, measurement) {
|
|
|
222
243
|
};
|
|
223
244
|
}
|
|
224
245
|
|
|
225
|
-
return
|
|
246
|
+
return processOneMeasurement(
|
|
226
247
|
camcoStandardTolerances.type,
|
|
227
248
|
measurement,
|
|
228
249
|
camcoStandardTolerances
|
|
@@ -233,17 +254,23 @@ function parseComputedBound(base, value, decimalCount) {
|
|
|
233
254
|
return Number(base + parseStringFloat(value)).toFixed(decimalCount);
|
|
234
255
|
}
|
|
235
256
|
|
|
236
|
-
function parseUncomputedBound(value1, value2) {
|
|
257
|
+
function parseUncomputedBound(value1, value2, sign) {
|
|
237
258
|
if (value2.startsWith("-")) {
|
|
238
259
|
return (
|
|
239
260
|
parseToFixedThreeString(value1) +
|
|
240
|
-
"
|
|
261
|
+
" " +
|
|
262
|
+
sign +
|
|
263
|
+
" " +
|
|
241
264
|
parseToFixedThreeString(value2.slice(1, value2.length))
|
|
242
265
|
);
|
|
243
266
|
}
|
|
244
267
|
|
|
245
268
|
return (
|
|
246
|
-
parseToFixedThreeString(value1) +
|
|
269
|
+
parseToFixedThreeString(value1) +
|
|
270
|
+
" " +
|
|
271
|
+
sign +
|
|
272
|
+
" " +
|
|
273
|
+
parseToFixedThreeString(value2)
|
|
247
274
|
);
|
|
248
275
|
}
|
|
249
276
|
|
|
@@ -276,10 +303,98 @@ function parseStringFloat(value) {
|
|
|
276
303
|
// Return 0 if parsing fails (NaN)
|
|
277
304
|
return isNaN(parsed) ? 0 : parsed;
|
|
278
305
|
}
|
|
306
|
+
function processIndividualMeasurement(
|
|
307
|
+
materialType,
|
|
308
|
+
measurement,
|
|
309
|
+
tolerances,
|
|
310
|
+
meetsIT,
|
|
311
|
+
ITMeetingReason
|
|
312
|
+
) {
|
|
313
|
+
const processedMeasurement = processMeasurement(
|
|
314
|
+
materialType,
|
|
315
|
+
measurement,
|
|
316
|
+
tolerances
|
|
317
|
+
);
|
|
318
|
+
return {
|
|
319
|
+
...processedMeasurement,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
324
|
+
const validation = validateMeasurements(measurements);
|
|
325
|
+
if (validation?.error) {
|
|
326
|
+
return validation;
|
|
327
|
+
}
|
|
328
|
+
const camcoStandardTolerances = getCamcoStandardTolerancesFor(materialType);
|
|
329
|
+
|
|
330
|
+
let largestMeasurement = Math.max(...measurements);
|
|
331
|
+
let smallestMeasurement = Math.min(...measurements);
|
|
332
|
+
let ITDifference = parseToFixedThreeString(
|
|
333
|
+
largestMeasurement - smallestMeasurement
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
const ITs = {
|
|
337
|
+
IT5: 0,
|
|
338
|
+
IT6: 0,
|
|
339
|
+
IT7: 0,
|
|
340
|
+
IT8: 0,
|
|
341
|
+
IT9: 0,
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
const results = measurements.map((measurement) => {
|
|
345
|
+
const result = processIndividualMeasurement(
|
|
346
|
+
camcoStandardTolerances.type,
|
|
347
|
+
measurement,
|
|
348
|
+
camcoStandardTolerances
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
ITs[result.IT_grade]++;
|
|
352
|
+
|
|
353
|
+
return result;
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
const baseSpec = results[0];
|
|
357
|
+
const baseITValue = baseSpec.matched_spec[baseSpec.IT_grade];
|
|
358
|
+
|
|
359
|
+
const meetsIT = ITDifference <= baseITValue;
|
|
360
|
+
const itMeetingReason = meetsIT
|
|
361
|
+
? `The difference between ${parseToFixedThreeString(
|
|
362
|
+
largestMeasurement
|
|
363
|
+
)} and ${parseToFixedThreeString(
|
|
364
|
+
smallestMeasurement
|
|
365
|
+
)} is less than or equal to ${baseITValue}.`
|
|
366
|
+
: `The difference between ${parseToFixedThreeString(
|
|
367
|
+
largestMeasurement
|
|
368
|
+
)} and ${parseToFixedThreeString(
|
|
369
|
+
smallestMeasurement
|
|
370
|
+
)} is greater than to ${baseITValue}.`;
|
|
371
|
+
|
|
372
|
+
return {
|
|
373
|
+
baseSpec,
|
|
374
|
+
meets_IT_Tolerance: { meetsIT, reason: itMeetingReason },
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function validateMeasurements(measurements) {
|
|
379
|
+
if (!Array.isArray(measurements)) {
|
|
380
|
+
return {
|
|
381
|
+
error: "Measurements must be an array of numbers",
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (measurements.length === 0) {
|
|
386
|
+
return {
|
|
387
|
+
error: "Measurements array cannot be empty",
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
279
393
|
|
|
280
394
|
module.exports = {
|
|
281
395
|
getAllTolerancesFor,
|
|
282
396
|
getCamcoStandardTolerancesFor,
|
|
283
397
|
parseNominalFromMeasurement,
|
|
284
398
|
checkOneMeasurementFor,
|
|
399
|
+
checkMultipleMeasurementsFor,
|
|
285
400
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mechanical-tolerance-calculator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
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": {
|