mechanical-tolerance-calculator 1.1.8 → 1.1.9
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 +18 -30
- package/package.json +1 -1
- 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];
|
|
@@ -468,6 +455,7 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
468
455
|
meets_specification: { meetsSpec, reason: specMeetingReason },
|
|
469
456
|
meets_IT_Tolerance: { meetsIT, reason: itMeetingReason },
|
|
470
457
|
meets_final_compliance: meetsIT === true && meetsSpec === true,
|
|
458
|
+
generalized_outcome: outcome,
|
|
471
459
|
};
|
|
472
460
|
}
|
|
473
461
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mechanical-tolerance-calculator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
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("shaft", [98.99, 98.98]));
|