mechanical-tolerance-calculator 1.1.5 → 1.1.6
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/index.js +27 -27
- package/package.json +1 -1
- package/test.js +3 -0
package/index.js
CHANGED
|
@@ -80,7 +80,7 @@ function returnTolerancesFor(executableMaterialType, spec = "") {
|
|
|
80
80
|
if (!Object.keys(allTolerances).includes(spec)) {
|
|
81
81
|
return {
|
|
82
82
|
error: `Currently available specifications are ${Object.keys(
|
|
83
|
-
allTolerances
|
|
83
|
+
allTolerances,
|
|
84
84
|
)}`,
|
|
85
85
|
};
|
|
86
86
|
}
|
|
@@ -97,14 +97,14 @@ function returnTolerancesFor(executableMaterialType, spec = "") {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
function isValidMeasurement(measurement) {
|
|
100
|
-
const num =
|
|
100
|
+
const num = parseFloat(measurement);
|
|
101
101
|
return !isNaN(num) && num >= 0 && num < 1000;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
function parseNominalFromMeasurement(
|
|
105
105
|
measurement,
|
|
106
106
|
materialType,
|
|
107
|
-
THRESHOLD = 0.9
|
|
107
|
+
THRESHOLD = 0.9,
|
|
108
108
|
) {
|
|
109
109
|
if (!isValidMeasurement(measurement)) {
|
|
110
110
|
return { error: "Measurement must be between 0 to 1000." };
|
|
@@ -208,7 +208,7 @@ function processMeasurement(materialType, measurement, tolerances) {
|
|
|
208
208
|
const matchedSpec = findMatchingSpec(
|
|
209
209
|
nominal,
|
|
210
210
|
tolerances.specification,
|
|
211
|
-
config.rangeMatch
|
|
211
|
+
config.rangeMatch,
|
|
212
212
|
);
|
|
213
213
|
|
|
214
214
|
if (!matchedSpec) {
|
|
@@ -230,16 +230,16 @@ function processMeasurement(materialType, measurement, tolerances) {
|
|
|
230
230
|
meetsSpec,
|
|
231
231
|
measurement,
|
|
232
232
|
computedBounds.lowerBound,
|
|
233
|
-
computedBounds.upperBound
|
|
233
|
+
computedBounds.upperBound,
|
|
234
234
|
);
|
|
235
235
|
|
|
236
236
|
const outcome =
|
|
237
237
|
measurement > computedBounds.upperBound
|
|
238
238
|
? `${materialType} is over-sized.`
|
|
239
239
|
: measurement >= computedBounds.lowerBound &&
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
measurement <= computedBounds.upperBound
|
|
241
|
+
? `${materialType} is in acceptable size.`
|
|
242
|
+
: `${materialType} is under-sized.`;
|
|
243
243
|
|
|
244
244
|
return {
|
|
245
245
|
measurement: parseStringFloat(measurement),
|
|
@@ -265,7 +265,7 @@ function processOneMeasurement(materialType, measurement, tolerances) {
|
|
|
265
265
|
const processedMeasurement = processMeasurement(
|
|
266
266
|
materialType,
|
|
267
267
|
measurement,
|
|
268
|
-
tolerances
|
|
268
|
+
tolerances,
|
|
269
269
|
);
|
|
270
270
|
return {
|
|
271
271
|
...processedMeasurement,
|
|
@@ -293,7 +293,7 @@ function checkOneMeasurementFor(materialType, measurement) {
|
|
|
293
293
|
return processOneMeasurement(
|
|
294
294
|
camcoStandardTolerances.type,
|
|
295
295
|
measurement,
|
|
296
|
-
camcoStandardTolerances
|
|
296
|
+
camcoStandardTolerances,
|
|
297
297
|
);
|
|
298
298
|
}
|
|
299
299
|
|
|
@@ -357,7 +357,7 @@ function processIndividualMeasurement(materialType, measurement, tolerances) {
|
|
|
357
357
|
const processedMeasurement = processMeasurement(
|
|
358
358
|
materialType,
|
|
359
359
|
measurement,
|
|
360
|
-
tolerances
|
|
360
|
+
tolerances,
|
|
361
361
|
);
|
|
362
362
|
return processedMeasurement;
|
|
363
363
|
}
|
|
@@ -389,7 +389,7 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
389
389
|
let largestMeasurement = Math.max(...measurements);
|
|
390
390
|
let smallestMeasurement = Math.min(...measurements);
|
|
391
391
|
let ITDifference = parseToFixedThreeString(
|
|
392
|
-
largestMeasurement - smallestMeasurement
|
|
392
|
+
largestMeasurement - smallestMeasurement,
|
|
393
393
|
);
|
|
394
394
|
|
|
395
395
|
let mostFarMeasurement = largestMeasurement;
|
|
@@ -400,7 +400,7 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
400
400
|
const result = processIndividualMeasurement(
|
|
401
401
|
camcoStandardTolerances.type,
|
|
402
402
|
measurement,
|
|
403
|
-
camcoStandardTolerances
|
|
403
|
+
camcoStandardTolerances,
|
|
404
404
|
);
|
|
405
405
|
withInSpecs.push(result.meets_specification.meetsSpec);
|
|
406
406
|
nominals[result.nominal] = count++;
|
|
@@ -418,11 +418,11 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
418
418
|
let countOfMostOccuredNominal = Math.max(...Object.values(nominals));
|
|
419
419
|
|
|
420
420
|
let mostOccuredNominal = Object.keys(nominals).find(
|
|
421
|
-
(nominal) => nominals[nominal] === countOfMostOccuredNominal
|
|
421
|
+
(nominal) => nominals[nominal] === countOfMostOccuredNominal,
|
|
422
422
|
);
|
|
423
423
|
|
|
424
424
|
const baseSpec = results.find(
|
|
425
|
-
(result) => result.nominal === parseInt(mostOccuredNominal)
|
|
425
|
+
(result) => result.nominal === parseInt(mostOccuredNominal),
|
|
426
426
|
);
|
|
427
427
|
const baseITValue = baseSpec.matched_spec[baseSpec.IT_grade];
|
|
428
428
|
|
|
@@ -431,7 +431,7 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
431
431
|
meetsIT,
|
|
432
432
|
largestMeasurement,
|
|
433
433
|
smallestMeasurement,
|
|
434
|
-
baseITValue
|
|
434
|
+
baseITValue,
|
|
435
435
|
);
|
|
436
436
|
|
|
437
437
|
const meetsSpec = withInSpecs.every((v) => v === true);
|
|
@@ -439,7 +439,7 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
439
439
|
meetsSpec,
|
|
440
440
|
mostFarMeasurement,
|
|
441
441
|
baseSpec.computed_specification_bounds.lowerBound,
|
|
442
|
-
baseSpec.computed_specification_bounds.upperBound
|
|
442
|
+
baseSpec.computed_specification_bounds.upperBound,
|
|
443
443
|
);
|
|
444
444
|
|
|
445
445
|
const isOverSized =
|
|
@@ -451,44 +451,44 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
451
451
|
(isWithinSizeRange
|
|
452
452
|
? `${materialType} is acceptable in size`
|
|
453
453
|
: isOverSized
|
|
454
|
-
|
|
455
|
-
|
|
454
|
+
? `${materialType} is over-sized`
|
|
455
|
+
: `${materialType} is under-sized`) +
|
|
456
456
|
(isWithinSizeRange && meetsIT
|
|
457
457
|
? `, and `
|
|
458
458
|
: !meetsIT && isWithinSizeRange
|
|
459
|
-
|
|
460
|
-
|
|
459
|
+
? `, but `
|
|
460
|
+
: `, and `) +
|
|
461
461
|
(meetsIT ? `meets IT tolerance.` : `doesn't meet IT tolerance.`);
|
|
462
462
|
return {
|
|
463
463
|
...baseSpec,
|
|
464
464
|
measurement: measurements,
|
|
465
465
|
meets_specification: { meetsSpec, reason: specMeetingReason },
|
|
466
466
|
meets_IT_Tolerance: { meetsIT, reason: itMeetingReason },
|
|
467
|
-
meets_final_compliance: meetsIT &&
|
|
467
|
+
meets_final_compliance: meetsIT === true && meetsSpec === true,
|
|
468
468
|
};
|
|
469
469
|
}
|
|
470
470
|
|
|
471
471
|
function generateReasonForSpecs(spec, measurement, base1, base2) {
|
|
472
472
|
if (spec === true) {
|
|
473
473
|
return `${parseToFixedThreeString(
|
|
474
|
-
measurement
|
|
474
|
+
measurement,
|
|
475
475
|
)} falls between ${base1} and ${base2}`;
|
|
476
476
|
}
|
|
477
477
|
return `${parseToFixedThreeString(
|
|
478
|
-
measurement
|
|
478
|
+
measurement,
|
|
479
479
|
)} doesn't fall between ${base1} and ${base2}`;
|
|
480
480
|
}
|
|
481
481
|
|
|
482
482
|
function generateReasonForTolerances(spec, measurement1, measurement2, base) {
|
|
483
483
|
if (spec === true) {
|
|
484
484
|
return `The difference between ${parseToFixedThreeString(
|
|
485
|
-
measurement1
|
|
485
|
+
measurement1,
|
|
486
486
|
)} and ${parseToFixedThreeString(
|
|
487
|
-
measurement2
|
|
487
|
+
measurement2,
|
|
488
488
|
)} is less than or equal to ${base}.`;
|
|
489
489
|
}
|
|
490
490
|
return `The difference between ${parseToFixedThreeString(
|
|
491
|
-
measurement1
|
|
491
|
+
measurement1,
|
|
492
492
|
)} and ${parseToFixedThreeString(measurement2)} is greater than ${base}.`;
|
|
493
493
|
}
|
|
494
494
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mechanical-tolerance-calculator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
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
ADDED