mechanical-tolerance-calculator 1.1.3 → 1.1.5
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 +20 -19
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -101,14 +101,6 @@ function isValidMeasurement(measurement) {
|
|
|
101
101
|
return !isNaN(num) && num >= 0 && num < 1000;
|
|
102
102
|
}
|
|
103
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
|
-
|
|
112
104
|
function parseNominalFromMeasurement(
|
|
113
105
|
measurement,
|
|
114
106
|
materialType,
|
|
@@ -371,10 +363,27 @@ function processIndividualMeasurement(materialType, measurement, tolerances) {
|
|
|
371
363
|
}
|
|
372
364
|
|
|
373
365
|
function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
374
|
-
const
|
|
375
|
-
if (
|
|
376
|
-
return
|
|
366
|
+
const validated = validateMeasurements(measurements);
|
|
367
|
+
if (validated) {
|
|
368
|
+
return validated;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const errors = [];
|
|
372
|
+
|
|
373
|
+
measurements.forEach((m, index) => {
|
|
374
|
+
if (!isValidMeasurement(m)) {
|
|
375
|
+
errors.push({
|
|
376
|
+
index,
|
|
377
|
+
value: m,
|
|
378
|
+
error: "Invalid measurement: must be 0–1000",
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
if (errors.length > 0) {
|
|
384
|
+
return { error: "Some measurements are invalid.", details: errors };
|
|
377
385
|
}
|
|
386
|
+
|
|
378
387
|
const camcoStandardTolerances = getCamcoStandardTolerancesFor(materialType);
|
|
379
388
|
|
|
380
389
|
let largestMeasurement = Math.max(...measurements);
|
|
@@ -388,9 +397,6 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
388
397
|
let count = 0;
|
|
389
398
|
let withInSpecs = [];
|
|
390
399
|
const results = measurements.map((measurement) => {
|
|
391
|
-
if (!isValidMeasurement(measurement)) {
|
|
392
|
-
return { error: "Measurement must be between 0 to 1000." };
|
|
393
|
-
}
|
|
394
400
|
const result = processIndividualMeasurement(
|
|
395
401
|
camcoStandardTolerances.type,
|
|
396
402
|
measurement,
|
|
@@ -499,11 +505,6 @@ function validateMeasurements(measurements) {
|
|
|
499
505
|
};
|
|
500
506
|
}
|
|
501
507
|
|
|
502
|
-
measurements.forEach((a) => {
|
|
503
|
-
if (!isValidMeasurement(a)) {
|
|
504
|
-
return { error: "Measurement must be between 0 to 1000." };
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
508
|
return null;
|
|
508
509
|
}
|
|
509
510
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mechanical-tolerance-calculator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
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": {
|