mechanical-tolerance-calculator 1.1.4 → 1.1.6
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 +32 -38
- package/package.json +1 -1
- package/test.js +3 -0
package/index.js
CHANGED
|
@@ -80,7 +80,7 @@ function returnTolerancesFor(executableMaterialType, spec = "") {
|
|
|
80
80
|
if (!Object.keys(allTolerances).includes(spec)) {
|
|
81
81
|
return {
|
|
82
82
|
error: `Currently available specifications are ${Object.keys(
|
|
83
|
-
allTolerances
|
|
83
|
+
allTolerances,
|
|
84
84
|
)}`,
|
|
85
85
|
};
|
|
86
86
|
}
|
|
@@ -97,22 +97,14 @@ function returnTolerancesFor(executableMaterialType, spec = "") {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
function isValidMeasurement(measurement) {
|
|
100
|
-
const num =
|
|
100
|
+
const num = parseFloat(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,
|
|
115
|
-
THRESHOLD = 0.9
|
|
107
|
+
THRESHOLD = 0.9,
|
|
116
108
|
) {
|
|
117
109
|
if (!isValidMeasurement(measurement)) {
|
|
118
110
|
return { error: "Measurement must be between 0 to 1000." };
|
|
@@ -216,7 +208,7 @@ function processMeasurement(materialType, measurement, tolerances) {
|
|
|
216
208
|
const matchedSpec = findMatchingSpec(
|
|
217
209
|
nominal,
|
|
218
210
|
tolerances.specification,
|
|
219
|
-
config.rangeMatch
|
|
211
|
+
config.rangeMatch,
|
|
220
212
|
);
|
|
221
213
|
|
|
222
214
|
if (!matchedSpec) {
|
|
@@ -238,16 +230,16 @@ function processMeasurement(materialType, measurement, tolerances) {
|
|
|
238
230
|
meetsSpec,
|
|
239
231
|
measurement,
|
|
240
232
|
computedBounds.lowerBound,
|
|
241
|
-
computedBounds.upperBound
|
|
233
|
+
computedBounds.upperBound,
|
|
242
234
|
);
|
|
243
235
|
|
|
244
236
|
const outcome =
|
|
245
237
|
measurement > computedBounds.upperBound
|
|
246
238
|
? `${materialType} is over-sized.`
|
|
247
239
|
: measurement >= computedBounds.lowerBound &&
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
240
|
+
measurement <= computedBounds.upperBound
|
|
241
|
+
? `${materialType} is in acceptable size.`
|
|
242
|
+
: `${materialType} is under-sized.`;
|
|
251
243
|
|
|
252
244
|
return {
|
|
253
245
|
measurement: parseStringFloat(measurement),
|
|
@@ -273,7 +265,7 @@ function processOneMeasurement(materialType, measurement, tolerances) {
|
|
|
273
265
|
const processedMeasurement = processMeasurement(
|
|
274
266
|
materialType,
|
|
275
267
|
measurement,
|
|
276
|
-
tolerances
|
|
268
|
+
tolerances,
|
|
277
269
|
);
|
|
278
270
|
return {
|
|
279
271
|
...processedMeasurement,
|
|
@@ -301,7 +293,7 @@ function checkOneMeasurementFor(materialType, measurement) {
|
|
|
301
293
|
return processOneMeasurement(
|
|
302
294
|
camcoStandardTolerances.type,
|
|
303
295
|
measurement,
|
|
304
|
-
camcoStandardTolerances
|
|
296
|
+
camcoStandardTolerances,
|
|
305
297
|
);
|
|
306
298
|
}
|
|
307
299
|
|
|
@@ -365,12 +357,17 @@ function processIndividualMeasurement(materialType, measurement, tolerances) {
|
|
|
365
357
|
const processedMeasurement = processMeasurement(
|
|
366
358
|
materialType,
|
|
367
359
|
measurement,
|
|
368
|
-
tolerances
|
|
360
|
+
tolerances,
|
|
369
361
|
);
|
|
370
362
|
return processedMeasurement;
|
|
371
363
|
}
|
|
372
364
|
|
|
373
365
|
function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
366
|
+
const validated = validateMeasurements(measurements);
|
|
367
|
+
if (validated) {
|
|
368
|
+
return validated;
|
|
369
|
+
}
|
|
370
|
+
|
|
374
371
|
const errors = [];
|
|
375
372
|
|
|
376
373
|
measurements.forEach((m, index) => {
|
|
@@ -392,7 +389,7 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
392
389
|
let largestMeasurement = Math.max(...measurements);
|
|
393
390
|
let smallestMeasurement = Math.min(...measurements);
|
|
394
391
|
let ITDifference = parseToFixedThreeString(
|
|
395
|
-
largestMeasurement - smallestMeasurement
|
|
392
|
+
largestMeasurement - smallestMeasurement,
|
|
396
393
|
);
|
|
397
394
|
|
|
398
395
|
let mostFarMeasurement = largestMeasurement;
|
|
@@ -400,13 +397,10 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
400
397
|
let count = 0;
|
|
401
398
|
let withInSpecs = [];
|
|
402
399
|
const results = measurements.map((measurement) => {
|
|
403
|
-
if (!isValidMeasurement(measurement)) {
|
|
404
|
-
return { error: "Measurement must be between 0 to 1000." };
|
|
405
|
-
}
|
|
406
400
|
const result = processIndividualMeasurement(
|
|
407
401
|
camcoStandardTolerances.type,
|
|
408
402
|
measurement,
|
|
409
|
-
camcoStandardTolerances
|
|
403
|
+
camcoStandardTolerances,
|
|
410
404
|
);
|
|
411
405
|
withInSpecs.push(result.meets_specification.meetsSpec);
|
|
412
406
|
nominals[result.nominal] = count++;
|
|
@@ -424,11 +418,11 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
424
418
|
let countOfMostOccuredNominal = Math.max(...Object.values(nominals));
|
|
425
419
|
|
|
426
420
|
let mostOccuredNominal = Object.keys(nominals).find(
|
|
427
|
-
(nominal) => nominals[nominal] === countOfMostOccuredNominal
|
|
421
|
+
(nominal) => nominals[nominal] === countOfMostOccuredNominal,
|
|
428
422
|
);
|
|
429
423
|
|
|
430
424
|
const baseSpec = results.find(
|
|
431
|
-
(result) => result.nominal === parseInt(mostOccuredNominal)
|
|
425
|
+
(result) => result.nominal === parseInt(mostOccuredNominal),
|
|
432
426
|
);
|
|
433
427
|
const baseITValue = baseSpec.matched_spec[baseSpec.IT_grade];
|
|
434
428
|
|
|
@@ -437,7 +431,7 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
437
431
|
meetsIT,
|
|
438
432
|
largestMeasurement,
|
|
439
433
|
smallestMeasurement,
|
|
440
|
-
baseITValue
|
|
434
|
+
baseITValue,
|
|
441
435
|
);
|
|
442
436
|
|
|
443
437
|
const meetsSpec = withInSpecs.every((v) => v === true);
|
|
@@ -445,7 +439,7 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
445
439
|
meetsSpec,
|
|
446
440
|
mostFarMeasurement,
|
|
447
441
|
baseSpec.computed_specification_bounds.lowerBound,
|
|
448
|
-
baseSpec.computed_specification_bounds.upperBound
|
|
442
|
+
baseSpec.computed_specification_bounds.upperBound,
|
|
449
443
|
);
|
|
450
444
|
|
|
451
445
|
const isOverSized =
|
|
@@ -457,44 +451,44 @@ function checkMultipleMeasurementsFor(materialType, measurements) {
|
|
|
457
451
|
(isWithinSizeRange
|
|
458
452
|
? `${materialType} is acceptable in size`
|
|
459
453
|
: isOverSized
|
|
460
|
-
|
|
461
|
-
|
|
454
|
+
? `${materialType} is over-sized`
|
|
455
|
+
: `${materialType} is under-sized`) +
|
|
462
456
|
(isWithinSizeRange && meetsIT
|
|
463
457
|
? `, and `
|
|
464
458
|
: !meetsIT && isWithinSizeRange
|
|
465
|
-
|
|
466
|
-
|
|
459
|
+
? `, but `
|
|
460
|
+
: `, and `) +
|
|
467
461
|
(meetsIT ? `meets IT tolerance.` : `doesn't meet IT tolerance.`);
|
|
468
462
|
return {
|
|
469
463
|
...baseSpec,
|
|
470
464
|
measurement: measurements,
|
|
471
465
|
meets_specification: { meetsSpec, reason: specMeetingReason },
|
|
472
466
|
meets_IT_Tolerance: { meetsIT, reason: itMeetingReason },
|
|
473
|
-
meets_final_compliance: meetsIT &&
|
|
467
|
+
meets_final_compliance: meetsIT === true && meetsSpec === true,
|
|
474
468
|
};
|
|
475
469
|
}
|
|
476
470
|
|
|
477
471
|
function generateReasonForSpecs(spec, measurement, base1, base2) {
|
|
478
472
|
if (spec === true) {
|
|
479
473
|
return `${parseToFixedThreeString(
|
|
480
|
-
measurement
|
|
474
|
+
measurement,
|
|
481
475
|
)} falls between ${base1} and ${base2}`;
|
|
482
476
|
}
|
|
483
477
|
return `${parseToFixedThreeString(
|
|
484
|
-
measurement
|
|
478
|
+
measurement,
|
|
485
479
|
)} doesn't fall between ${base1} and ${base2}`;
|
|
486
480
|
}
|
|
487
481
|
|
|
488
482
|
function generateReasonForTolerances(spec, measurement1, measurement2, base) {
|
|
489
483
|
if (spec === true) {
|
|
490
484
|
return `The difference between ${parseToFixedThreeString(
|
|
491
|
-
measurement1
|
|
485
|
+
measurement1,
|
|
492
486
|
)} and ${parseToFixedThreeString(
|
|
493
|
-
measurement2
|
|
487
|
+
measurement2,
|
|
494
488
|
)} is less than or equal to ${base}.`;
|
|
495
489
|
}
|
|
496
490
|
return `The difference between ${parseToFixedThreeString(
|
|
497
|
-
measurement1
|
|
491
|
+
measurement1,
|
|
498
492
|
)} and ${parseToFixedThreeString(measurement2)} is greater than ${base}.`;
|
|
499
493
|
}
|
|
500
494
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mechanical-tolerance-calculator",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
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
ADDED