mechanical-tolerance-calculator 1.1.1 → 1.1.3
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 -36
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -114,33 +114,34 @@ function parseNominalFromMeasurement(
|
|
|
114
114
|
materialType,
|
|
115
115
|
THRESHOLD = 0.9
|
|
116
116
|
) {
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
if (!isValidMeasurement(measurement)) {
|
|
118
|
+
return { error: "Measurement must be between 0 to 1000." };
|
|
119
|
+
}
|
|
119
120
|
// For shafts: upper_deviation is 0, so measurement ≤ nominal
|
|
120
121
|
// Therefore, nominal must be ceiling of measurement
|
|
121
122
|
if (materialType === "shafts") {
|
|
122
|
-
const standardNominal = Math.ceil(
|
|
123
|
+
const standardNominal = Math.ceil(measurement); //a standard shaft will always have measurements less than the nominal
|
|
123
124
|
|
|
124
125
|
//however, in some cases, we get shafts going beyond the upper deviation
|
|
125
126
|
//so, we work with a threshold of 0.10 (meaning, a shaft can only go upto 0.10 of it's upper deviation)
|
|
126
|
-
if (standardNominal -
|
|
127
|
-
return Math.floor(
|
|
127
|
+
if (standardNominal - measurement >= THRESHOLD) {
|
|
128
|
+
return Math.floor(measurement);
|
|
128
129
|
}
|
|
129
|
-
return Math.ceil(
|
|
130
|
+
return Math.ceil(measurement);
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
// For bores: lower_deviation is 0, so measurement ≥ nominal
|
|
133
134
|
// Therefore, nominal must be floor of measurement
|
|
134
135
|
if (materialType === "housingBores" || materialType === "shellBores") {
|
|
135
|
-
const standardNominal = Math.floor(
|
|
136
|
+
const standardNominal = Math.floor(measurement);
|
|
136
137
|
|
|
137
|
-
return
|
|
138
|
-
? Math.ceil(
|
|
138
|
+
return measurement - standardNominal >= THRESHOLD
|
|
139
|
+
? Math.ceil(measurement)
|
|
139
140
|
: standardNominal;
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
// Default: round to nearest
|
|
143
|
-
return Math.round(
|
|
144
|
+
return Math.round(measurement);
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
const MATERIAL_TYPE_CONFIG = {
|
|
@@ -185,8 +186,10 @@ function calculateUncomputedBounds(nominal, spec) {
|
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
function checkMeetsSpecification(measurement, bounds) {
|
|
188
|
-
|
|
189
|
-
|
|
189
|
+
if (!isValidMeasurement(measurement)) {
|
|
190
|
+
return { error: "Measurement must be between 0 to 1000." };
|
|
191
|
+
}
|
|
192
|
+
const measure = parseStringFloat(measurement);
|
|
190
193
|
const upper = parseStringFloat(bounds.upperBound);
|
|
191
194
|
const lower = parseStringFloat(bounds.lowerBound);
|
|
192
195
|
|
|
@@ -194,6 +197,9 @@ function checkMeetsSpecification(measurement, bounds) {
|
|
|
194
197
|
}
|
|
195
198
|
|
|
196
199
|
function processMeasurement(materialType, measurement, tolerances) {
|
|
200
|
+
if (!isValidMeasurement(measurement)) {
|
|
201
|
+
return { error: "Measurement must be between 0 to 1000." };
|
|
202
|
+
}
|
|
197
203
|
const config = MATERIAL_TYPE_CONFIG[materialType];
|
|
198
204
|
|
|
199
205
|
if (!config) {
|
|
@@ -203,12 +209,8 @@ function processMeasurement(materialType, measurement, tolerances) {
|
|
|
203
209
|
};
|
|
204
210
|
}
|
|
205
211
|
|
|
206
|
-
const validatedMeasurement = validateMeasurement(measurement);
|
|
207
212
|
// Calculate nominal diameter
|
|
208
|
-
const nominal = parseNominalFromMeasurement(
|
|
209
|
-
validatedMeasurement,
|
|
210
|
-
materialType
|
|
211
|
-
);
|
|
213
|
+
const nominal = parseNominalFromMeasurement(measurement, materialType);
|
|
212
214
|
|
|
213
215
|
// Find matching specification
|
|
214
216
|
const matchedSpec = findMatchingSpec(
|
|
@@ -265,10 +267,12 @@ function processMeasurement(materialType, measurement, tolerances) {
|
|
|
265
267
|
}
|
|
266
268
|
|
|
267
269
|
function processOneMeasurement(materialType, measurement, tolerances) {
|
|
268
|
-
|
|
270
|
+
if (!isValidMeasurement(measurement)) {
|
|
271
|
+
return { error: "Measurement must be between 0 to 1000." };
|
|
272
|
+
}
|
|
269
273
|
const processedMeasurement = processMeasurement(
|
|
270
274
|
materialType,
|
|
271
|
-
|
|
275
|
+
measurement,
|
|
272
276
|
tolerances
|
|
273
277
|
);
|
|
274
278
|
return {
|
|
@@ -278,14 +282,16 @@ function processOneMeasurement(materialType, measurement, tolerances) {
|
|
|
278
282
|
}
|
|
279
283
|
|
|
280
284
|
function checkOneMeasurementFor(materialType, measurement) {
|
|
285
|
+
if (!isValidMeasurement(measurement)) {
|
|
286
|
+
return { error: "Measurement must be between 0 to 1000." };
|
|
287
|
+
}
|
|
281
288
|
const camcoStandardTolerances = getCamcoStandardTolerancesFor(materialType);
|
|
282
289
|
|
|
283
290
|
if (camcoStandardTolerances.error) {
|
|
284
291
|
return camcoStandardTolerances;
|
|
285
292
|
}
|
|
286
293
|
|
|
287
|
-
|
|
288
|
-
if (typeof measurement !== "number" || isNaN(validatedMeasurement)) {
|
|
294
|
+
if (typeof measurement !== "number" || isNaN(measurement)) {
|
|
289
295
|
return {
|
|
290
296
|
error: true,
|
|
291
297
|
message: "Invalid measurement value",
|
|
@@ -294,7 +300,7 @@ function checkOneMeasurementFor(materialType, measurement) {
|
|
|
294
300
|
|
|
295
301
|
return processOneMeasurement(
|
|
296
302
|
camcoStandardTolerances.type,
|
|
297
|
-
|
|
303
|
+
measurement,
|
|
298
304
|
camcoStandardTolerances
|
|
299
305
|
);
|
|
300
306
|
}
|
|
@@ -353,10 +359,12 @@ function parseStringFloat(value) {
|
|
|
353
359
|
return isNaN(parsed) ? 0 : parsed;
|
|
354
360
|
}
|
|
355
361
|
function processIndividualMeasurement(materialType, measurement, tolerances) {
|
|
356
|
-
|
|
362
|
+
if (!isValidMeasurement(measurement)) {
|
|
363
|
+
return { error: "Measurement must be between 0 to 1000." };
|
|
364
|
+
}
|
|
357
365
|
const processedMeasurement = processMeasurement(
|
|
358
366
|
materialType,
|
|
359
|
-
|
|
367
|
+
measurement,
|
|
360
368
|
tolerances
|
|
361
369
|
);
|
|
362
370
|
return processedMeasurement;
|
|
@@ -380,6 +388,9 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
380
388
|
let count = 0;
|
|
381
389
|
let withInSpecs = [];
|
|
382
390
|
const results = measurements.map((measurement) => {
|
|
391
|
+
if (!isValidMeasurement(measurement)) {
|
|
392
|
+
return { error: "Measurement must be between 0 to 1000." };
|
|
393
|
+
}
|
|
383
394
|
const result = processIndividualMeasurement(
|
|
384
395
|
camcoStandardTolerances.type,
|
|
385
396
|
measurement,
|
|
@@ -452,32 +463,27 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
452
463
|
}
|
|
453
464
|
|
|
454
465
|
function generateReasonForSpecs(spec, measurement, base1, base2) {
|
|
455
|
-
const validatedMeasurement = validateMeasurement(measurement);
|
|
456
466
|
if (spec === true) {
|
|
457
467
|
return `${parseToFixedThreeString(
|
|
458
|
-
|
|
468
|
+
measurement
|
|
459
469
|
)} falls between ${base1} and ${base2}`;
|
|
460
470
|
}
|
|
461
471
|
return `${parseToFixedThreeString(
|
|
462
|
-
|
|
472
|
+
measurement
|
|
463
473
|
)} doesn't fall between ${base1} and ${base2}`;
|
|
464
474
|
}
|
|
465
475
|
|
|
466
476
|
function generateReasonForTolerances(spec, measurement1, measurement2, base) {
|
|
467
|
-
const validatedMeasurement1 = validateMeasurement(measurement1);
|
|
468
|
-
const validatedMeasurement2 = validateMeasurement(measurement2);
|
|
469
477
|
if (spec === true) {
|
|
470
478
|
return `The difference between ${parseToFixedThreeString(
|
|
471
|
-
|
|
479
|
+
measurement1
|
|
472
480
|
)} and ${parseToFixedThreeString(
|
|
473
|
-
|
|
481
|
+
measurement2
|
|
474
482
|
)} is less than or equal to ${base}.`;
|
|
475
483
|
}
|
|
476
484
|
return `The difference between ${parseToFixedThreeString(
|
|
477
|
-
|
|
478
|
-
)} and ${parseToFixedThreeString(
|
|
479
|
-
validatedMeasurement2
|
|
480
|
-
)} is greater than ${base}.`;
|
|
485
|
+
measurement1
|
|
486
|
+
)} and ${parseToFixedThreeString(measurement2)} is greater than ${base}.`;
|
|
481
487
|
}
|
|
482
488
|
|
|
483
489
|
function validateMeasurements(measurements) {
|
|
@@ -494,7 +500,9 @@ function validateMeasurements(measurements) {
|
|
|
494
500
|
}
|
|
495
501
|
|
|
496
502
|
measurements.forEach((a) => {
|
|
497
|
-
|
|
503
|
+
if (!isValidMeasurement(a)) {
|
|
504
|
+
return { error: "Measurement must be between 0 to 1000." };
|
|
505
|
+
}
|
|
498
506
|
});
|
|
499
507
|
return null;
|
|
500
508
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mechanical-tolerance-calculator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
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": {
|