mechanical-tolerance-calculator 1.0.8 → 1.0.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 +24 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -96,38 +96,51 @@ function returnTolerancesFor(executableMaterialType, spec = "") {
|
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
function isValidMeasurement(measurement) {
|
|
100
|
+
const num = Number(measurement);
|
|
101
|
+
return !isNaN(num) && num >= 0 && num < 1000;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function validateMeasurement(measurement) {
|
|
105
|
+
const isMeasurementValid = isValidMeasurement(measurement);
|
|
106
|
+
if (!isMeasurementValid) {
|
|
107
|
+
return { error: "Measurement must be between 0 to 1000." };
|
|
108
|
+
}
|
|
109
|
+
return measurement;
|
|
110
|
+
}
|
|
111
|
+
|
|
99
112
|
function parseNominalFromMeasurement(
|
|
100
113
|
measurement,
|
|
101
114
|
materialType,
|
|
102
115
|
THRESHOLD = 0.9
|
|
103
116
|
) {
|
|
104
|
-
const
|
|
117
|
+
const validatedMeasurement = validateMeasurement(measurement);
|
|
105
118
|
|
|
106
119
|
// For shafts: upper_deviation is 0, so measurement ≤ nominal
|
|
107
120
|
// Therefore, nominal must be ceiling of measurement
|
|
108
121
|
if (materialType === "shafts") {
|
|
109
|
-
const standardNominal = Math.ceil(
|
|
122
|
+
const standardNominal = Math.ceil(validatedMeasurement); //a standard shaft will always have measurements less than the nominal
|
|
110
123
|
|
|
111
124
|
//however, in some cases, we get shafts going beyond the upper deviation
|
|
112
125
|
//so, we work with a threshold of 0.10 (meaning, a shaft can only go upto 0.10 of it's upper deviation)
|
|
113
|
-
if (standardNominal -
|
|
114
|
-
return Math.floor(
|
|
126
|
+
if (standardNominal - validatedMeasurement >= THRESHOLD) {
|
|
127
|
+
return Math.floor(validatedMeasurement);
|
|
115
128
|
}
|
|
116
|
-
return Math.ceil(
|
|
129
|
+
return Math.ceil(validatedMeasurement);
|
|
117
130
|
}
|
|
118
131
|
|
|
119
132
|
// For bores: lower_deviation is 0, so measurement ≥ nominal
|
|
120
133
|
// Therefore, nominal must be floor of measurement
|
|
121
134
|
if (materialType === "housingBores" || materialType === "shellBores") {
|
|
122
|
-
const standardNominal = Math.floor(
|
|
135
|
+
const standardNominal = Math.floor(validatedMeasurement);
|
|
123
136
|
|
|
124
|
-
return
|
|
125
|
-
? Math.ceil(
|
|
137
|
+
return validatedMeasurement - standardNominal >= THRESHOLD
|
|
138
|
+
? Math.ceil(validatedMeasurement)
|
|
126
139
|
: standardNominal;
|
|
127
140
|
}
|
|
128
141
|
|
|
129
142
|
// Default: round to nearest
|
|
130
|
-
return Math.round(
|
|
143
|
+
return Math.round(validatedMeasurement);
|
|
131
144
|
}
|
|
132
145
|
|
|
133
146
|
const MATERIAL_TYPE_CONFIG = {
|
|
@@ -466,6 +479,8 @@ function validateMeasurements(measurements) {
|
|
|
466
479
|
error: "Measurements array cannot be empty",
|
|
467
480
|
};
|
|
468
481
|
}
|
|
482
|
+
|
|
483
|
+
measurements.forEach((a) => validateMeasurement(a));
|
|
469
484
|
return null;
|
|
470
485
|
}
|
|
471
486
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mechanical-tolerance-calculator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.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": {
|