mechanical-tolerance-calculator 1.1.9 → 1.2.0
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 +44 -20
- package/package.json +1 -1
- package/test.js +1 -1
package/index.js
CHANGED
|
@@ -422,6 +422,7 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
422
422
|
largestMeasurement,
|
|
423
423
|
smallestMeasurement,
|
|
424
424
|
baseITValue,
|
|
425
|
+
baseSpec.IT_grade,
|
|
425
426
|
);
|
|
426
427
|
|
|
427
428
|
const meetsSpec = withInSpecs.every((v) => v === true);
|
|
@@ -430,6 +431,7 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
430
431
|
mostFarMeasurement,
|
|
431
432
|
baseSpec.computed_specification_bounds.lowerBound,
|
|
432
433
|
baseSpec.computed_specification_bounds.upperBound,
|
|
434
|
+
baseSpec.specification,
|
|
433
435
|
);
|
|
434
436
|
|
|
435
437
|
const isOverSized =
|
|
@@ -437,50 +439,72 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
437
439
|
const isWithinSizeRange =
|
|
438
440
|
mostFarMeasurement <= baseSpec.computed_specification_bounds.upperBound &&
|
|
439
441
|
mostFarMeasurement >= baseSpec.computed_specification_bounds.lowerBound;
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
442
|
+
|
|
443
|
+
const outcome1 = isWithinSizeRange
|
|
444
|
+
? `${materialType} is acceptable in size.`
|
|
445
|
+
: isOverSized
|
|
446
|
+
? `${materialType} is over-sized.`
|
|
447
|
+
: `${materialType} is under-sized.`;
|
|
448
|
+
|
|
449
|
+
const outcome2 =
|
|
450
|
+
isWithinSizeRange && meetsIT
|
|
451
|
+
? "And, it meets IT tolerance."
|
|
452
|
+
: !isWithinSizeRange && meetsIT
|
|
453
|
+
? "However, it meets IT tolerance."
|
|
454
|
+
: `${!isWithinSizeRange ? "And, " : "But, "}it fails IT tolerance.`;
|
|
455
|
+
|
|
456
|
+
// const outcome2 = meetsIT ? ""
|
|
457
|
+
|
|
458
|
+
// (isWithinSizeRange && meetsIT
|
|
459
|
+
// ? `, and `
|
|
460
|
+
// : !meetsIT && isWithinSizeRange
|
|
461
|
+
// ? `, but `
|
|
462
|
+
// : `, and `) +
|
|
463
|
+
// (meetsIT ? `meets IT tolerance.` : `doesn't meet IT tolerance.`);
|
|
464
|
+
|
|
465
|
+
const final_compliance = meetsIT === true && meetsSpec === true;
|
|
466
|
+
|
|
467
|
+
const outcome3 = final_compliance
|
|
468
|
+
? "Finally, it meets final compliance and is acceptable to use."
|
|
469
|
+
: "Finally, it doesn't meet final compliance and is not acceptable to use.";
|
|
452
470
|
return {
|
|
453
471
|
...baseSpec,
|
|
454
472
|
measurement: measurements,
|
|
455
473
|
meets_specification: { meetsSpec, reason: specMeetingReason },
|
|
456
474
|
meets_IT_Tolerance: { meetsIT, reason: itMeetingReason },
|
|
457
|
-
meets_final_compliance:
|
|
458
|
-
generalized_outcome:
|
|
475
|
+
meets_final_compliance: final_compliance,
|
|
476
|
+
generalized_outcome: outcome1 + " " + outcome2 + " " + outcome3,
|
|
459
477
|
};
|
|
460
478
|
}
|
|
461
479
|
|
|
462
|
-
function generateReasonForSpecs(spec, measurement, base1, base2) {
|
|
480
|
+
function generateReasonForSpecs(spec, measurement, base1, base2, specType) {
|
|
463
481
|
if (spec === true) {
|
|
464
482
|
return `${parseToFixedThreeString(
|
|
465
483
|
measurement,
|
|
466
|
-
)} falls between ${base1} and ${base2}
|
|
484
|
+
)} falls between ${base1} and ${base2}. So, the material meets ${specType} specification.`;
|
|
467
485
|
}
|
|
468
486
|
return `${parseToFixedThreeString(
|
|
469
487
|
measurement,
|
|
470
|
-
)} doesn't fall between ${base1} and ${base2}
|
|
488
|
+
)} doesn't fall between ${base1} and ${base2}. So, the material doesn't meet ${specType} specification.`;
|
|
471
489
|
}
|
|
472
490
|
|
|
473
|
-
function generateReasonForTolerances(
|
|
491
|
+
function generateReasonForTolerances(
|
|
492
|
+
spec,
|
|
493
|
+
measurement1,
|
|
494
|
+
measurement2,
|
|
495
|
+
base,
|
|
496
|
+
toleranceType,
|
|
497
|
+
) {
|
|
474
498
|
if (spec === true) {
|
|
475
499
|
return `The difference between ${parseToFixedThreeString(
|
|
476
500
|
measurement1,
|
|
477
501
|
)} and ${parseToFixedThreeString(
|
|
478
502
|
measurement2,
|
|
479
|
-
)} is less than or equal to ${base}.`;
|
|
503
|
+
)} is less than or equal to ${base}. So, it meets ${toleranceType} Tolerance.`;
|
|
480
504
|
}
|
|
481
505
|
return `The difference between ${parseToFixedThreeString(
|
|
482
506
|
measurement1,
|
|
483
|
-
)} and ${parseToFixedThreeString(measurement2)} is greater than ${base}.`;
|
|
507
|
+
)} and ${parseToFixedThreeString(measurement2)} is greater than ${base}. So, it doesn't meet ${toleranceType} Tolerance.`;
|
|
484
508
|
}
|
|
485
509
|
|
|
486
510
|
function validateMeasurements(measurements) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mechanical-tolerance-calculator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
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,4 +1,4 @@
|
|
|
1
1
|
const { checkMultipleMeasurementsFor } = require("./index");
|
|
2
2
|
// console.log(checkMultipleMeasurementsFor("housing", [100.04, 100.05]));
|
|
3
3
|
// console.log(checkMultipleMeasurementsFor("housing", [100.04, 100.05, 95.06]));
|
|
4
|
-
console.log(checkMultipleMeasurementsFor("
|
|
4
|
+
console.log(checkMultipleMeasurementsFor("housing", [99.99, 99.98, 99.99]));
|