mechanical-tolerance-calculator 1.1.8 → 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.
Files changed (3) hide show
  1. package/index.js +61 -49
  2. package/package.json +1 -1
  3. package/test.js +1 -6
package/index.js CHANGED
@@ -1,14 +1,24 @@
1
1
  const tolerances = require("./Tolerances.json");
2
2
 
3
+ /* Validates the material type passed is not an empty string. */
4
+ function validateMaterialType(materialType) {
5
+ if (typeof materialType != "string") {
6
+ // checks if
7
+ return { error: "Material type must be a string." };
8
+ }
9
+
10
+ if (
11
+ materialType == undefined ||
12
+ materialType == null ||
13
+ materialType.trim() === ""
14
+ ) {
15
+ return { error: "Material type is required and cannot be empty." };
16
+ }
17
+
18
+ return materialType;
19
+ }
3
20
  /**
4
21
  * Returns all tolerances for the given material type.
5
- * @description
6
- * The function checks the provided material type string to determine
7
- * which category of tolerances to return. It supports 'housing', 'shaft',
8
- * and 'shell' as valid material types. If the input is invalid or does not
9
- * match any known category, an error message is returned.
10
- * @param {string} materialType
11
- * @returns {object} An object containing the relevant tolerances or an error message.
12
22
  */
13
23
  function getAllTolerancesFor(materialType) {
14
24
  const validatedMaterialType = validateMaterialType(materialType);
@@ -32,13 +42,6 @@ function getAllTolerancesFor(materialType) {
32
42
 
33
43
  /**
34
44
  * Returns Camco Standard specification and tolerances for the given material type.
35
- * @description
36
- * The function checks the provided material type string to determine
37
- * which category of camco standard tolerances to return. It supports 'housing', 'shaft',
38
- * and 'shell' as valid material types. If the input is invalid or does not
39
- * match any known category, an error message is returned.
40
- * @param {string} materialType
41
- * @returns {object} An object containing the relevant tolerances or an error message.
42
45
  */
43
46
  function getCamcoStandardTolerancesFor(materialType) {
44
47
  const validatedMaterialType = validateMaterialType(materialType);
@@ -58,22 +61,6 @@ function getCamcoStandardTolerancesFor(materialType) {
58
61
  }
59
62
  }
60
63
 
61
- function validateMaterialType(materialType) {
62
- if (typeof materialType != "string") {
63
- return { error: "Material type must be a string." };
64
- }
65
-
66
- if (
67
- materialType == undefined ||
68
- materialType == null ||
69
- materialType.trim() === ""
70
- ) {
71
- return { error: "Material type is required and cannot be empty." };
72
- }
73
-
74
- return materialType;
75
- }
76
-
77
64
  function returnTolerancesFor(executableMaterialType, spec = "") {
78
65
  if (spec) {
79
66
  const allTolerances = tolerances[executableMaterialType];
@@ -435,6 +422,7 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
435
422
  largestMeasurement,
436
423
  smallestMeasurement,
437
424
  baseITValue,
425
+ baseSpec.IT_grade,
438
426
  );
439
427
 
440
428
  const meetsSpec = withInSpecs.every((v) => v === true);
@@ -443,6 +431,7 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
443
431
  mostFarMeasurement,
444
432
  baseSpec.computed_specification_bounds.lowerBound,
445
433
  baseSpec.computed_specification_bounds.upperBound,
434
+ baseSpec.specification,
446
435
  );
447
436
 
448
437
  const isOverSized =
@@ -450,49 +439,72 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
450
439
  const isWithinSizeRange =
451
440
  mostFarMeasurement <= baseSpec.computed_specification_bounds.upperBound &&
452
441
  mostFarMeasurement >= baseSpec.computed_specification_bounds.lowerBound;
453
- const outcome =
454
- (isWithinSizeRange
455
- ? `${materialType} is acceptable in size`
456
- : isOverSized
457
- ? `${materialType} is over-sized`
458
- : `${materialType} is under-sized`) +
459
- (isWithinSizeRange && meetsIT
460
- ? `, and `
461
- : !meetsIT && isWithinSizeRange
462
- ? `, but `
463
- : `, and `) +
464
- (meetsIT ? `meets IT tolerance.` : `doesn't meet IT tolerance.`);
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.";
465
470
  return {
466
471
  ...baseSpec,
467
472
  measurement: measurements,
468
473
  meets_specification: { meetsSpec, reason: specMeetingReason },
469
474
  meets_IT_Tolerance: { meetsIT, reason: itMeetingReason },
470
- meets_final_compliance: meetsIT === true && meetsSpec === true,
475
+ meets_final_compliance: final_compliance,
476
+ generalized_outcome: outcome1 + " " + outcome2 + " " + outcome3,
471
477
  };
472
478
  }
473
479
 
474
- function generateReasonForSpecs(spec, measurement, base1, base2) {
480
+ function generateReasonForSpecs(spec, measurement, base1, base2, specType) {
475
481
  if (spec === true) {
476
482
  return `${parseToFixedThreeString(
477
483
  measurement,
478
- )} falls between ${base1} and ${base2}`;
484
+ )} falls between ${base1} and ${base2}. So, the material meets ${specType} specification.`;
479
485
  }
480
486
  return `${parseToFixedThreeString(
481
487
  measurement,
482
- )} doesn't fall between ${base1} and ${base2}`;
488
+ )} doesn't fall between ${base1} and ${base2}. So, the material doesn't meet ${specType} specification.`;
483
489
  }
484
490
 
485
- function generateReasonForTolerances(spec, measurement1, measurement2, base) {
491
+ function generateReasonForTolerances(
492
+ spec,
493
+ measurement1,
494
+ measurement2,
495
+ base,
496
+ toleranceType,
497
+ ) {
486
498
  if (spec === true) {
487
499
  return `The difference between ${parseToFixedThreeString(
488
500
  measurement1,
489
501
  )} and ${parseToFixedThreeString(
490
502
  measurement2,
491
- )} is less than or equal to ${base}.`;
503
+ )} is less than or equal to ${base}. So, it meets ${toleranceType} Tolerance.`;
492
504
  }
493
505
  return `The difference between ${parseToFixedThreeString(
494
506
  measurement1,
495
- )} and ${parseToFixedThreeString(measurement2)} is greater than ${base}.`;
507
+ )} and ${parseToFixedThreeString(measurement2)} is greater than ${base}. So, it doesn't meet ${toleranceType} Tolerance.`;
496
508
  }
497
509
 
498
510
  function validateMeasurements(measurements) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mechanical-tolerance-calculator",
3
- "version": "1.1.8",
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,9 +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(
5
- checkMultipleMeasurementsFor(
6
- "housing",
7
- [100.04, 100.05, 100.05, 98.08, 98.07, 100.09, 98.07, 98.03],
8
- ),
9
- );
4
+ console.log(checkMultipleMeasurementsFor("housing", [99.99, 99.98, 99.99]));