mechanical-tolerance-calculator 1.0.1 โ 1.0.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/README.md +212 -0
- package/Tolerances.json +1534 -0
- package/index.js +138 -3
- package/package.json +1 -1
- package/Readme.md +0 -91
package/index.js
CHANGED
|
@@ -1,5 +1,140 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const tolerances = require("./Tolerances.json");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 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
|
+
*/
|
|
13
|
+
function getAllTolerancesFor(materialType) {
|
|
14
|
+
const validatedMaterialType = validateMaterialType(materialType);
|
|
15
|
+
|
|
16
|
+
const trimmedMaterialType = validatedMaterialType.trim().toLowerCase(); // normalize input
|
|
17
|
+
if (trimmedMaterialType.includes("housing")) {
|
|
18
|
+
// includes to allow variations like "housing bore"
|
|
19
|
+
return returnTolerancesFor("housingBores"); // return relevant tolerances
|
|
20
|
+
} else if (trimmedMaterialType.includes("shaft")) {
|
|
21
|
+
// includes to allow variations like "shaft rod"
|
|
22
|
+
return returnTolerancesFor("shafts"); // return relevant tolerances
|
|
23
|
+
} else if (trimmedMaterialType.includes("shell")) {
|
|
24
|
+
// includes to allow variations like "shell bore"
|
|
25
|
+
return returnTolerancesFor("shellBores"); // return relevant tolerances
|
|
26
|
+
} else {
|
|
27
|
+
return {
|
|
28
|
+
error: `Unknown material type: ${materialType}. Valid types are 'housing', 'shaft', or 'shell'.`, // error for invalid typefac
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 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
|
+
*/
|
|
43
|
+
function getCamcoStandardTolerancesFor(materialType) {
|
|
44
|
+
const validatedMaterialType = validateMaterialType(materialType);
|
|
45
|
+
|
|
46
|
+
const trimmedMaterialType = validatedMaterialType.trim().toLowerCase();
|
|
47
|
+
|
|
48
|
+
if (trimmedMaterialType.includes("housing")) {
|
|
49
|
+
return returnTolerancesFor("housingBores", "H8");
|
|
50
|
+
} else if (trimmedMaterialType.includes("shell")) {
|
|
51
|
+
return returnTolerancesFor("shellBores", "H9");
|
|
52
|
+
} else if (trimmedMaterialType.includes("shaft")) {
|
|
53
|
+
return returnTolerancesFor("shafts", "h9");
|
|
54
|
+
} else {
|
|
55
|
+
return {
|
|
56
|
+
error: `Unknown material type: ${materialType}. Valid types are 'housing', 'shaft', or 'shell'.`,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
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
|
+
function returnTolerancesFor(executableMaterialType, spec = "") {
|
|
78
|
+
if (spec) {
|
|
79
|
+
const allTolerances = tolerances[executableMaterialType];
|
|
80
|
+
if (!Object.keys(allTolerances).includes(spec)) {
|
|
81
|
+
return {
|
|
82
|
+
error: `Currently available specifications are ${Object.keys(
|
|
83
|
+
allTolerances
|
|
84
|
+
)}`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
type: executableMaterialType,
|
|
89
|
+
specification: tolerances[executableMaterialType][spec],
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
type: executableMaterialType,
|
|
95
|
+
specifications: tolerances[executableMaterialType],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function parseNominalFromMeasurement(measurement) {
|
|
100
|
+
const nominalString = measurement.toString();
|
|
101
|
+
let nominal = "";
|
|
102
|
+
for (let index = 0; index < nominalString.length; index++) {
|
|
103
|
+
if (nominalString[index] === ".") {
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
nominal += nominalString[index];
|
|
107
|
+
}
|
|
108
|
+
return parseInt(nominal);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function checkOneMeasurementFor(materialType, measurement) {
|
|
112
|
+
const camcoStandardTolerances = getCamcoStandardTolerancesFor(materialType);
|
|
113
|
+
let nominal = parseNominalFromMeasurement(measurement);
|
|
114
|
+
let matchedSpec = {};
|
|
115
|
+
if (camcoStandardTolerances.type === "shafts") {
|
|
116
|
+
const shaftNominal = nominal + 1;
|
|
117
|
+
const specs = camcoStandardTolerances["specification"];
|
|
118
|
+
Array.from(specs).forEach((spec) => {
|
|
119
|
+
if (
|
|
120
|
+
shaftNominal > spec.minimum_diameter &&
|
|
121
|
+
shaftNominal <= spec.maximum_diameter
|
|
122
|
+
) {
|
|
123
|
+
matchedSpec = spec;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const check = Number(matchedSpec.upper_deviation).toFixed(3);
|
|
128
|
+
console.log(check);
|
|
129
|
+
}
|
|
130
|
+
console.log(nominal);
|
|
131
|
+
|
|
132
|
+
console.log(matchedSpec);
|
|
3
133
|
}
|
|
4
134
|
|
|
5
|
-
module.exports =
|
|
135
|
+
module.exports = {
|
|
136
|
+
getAllTolerancesFor,
|
|
137
|
+
getCamcoStandardTolerancesFor,
|
|
138
|
+
parseNominalFromMeasurement,
|
|
139
|
+
checkOneMeasurementFor,
|
|
140
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mechanical-tolerance-calculator",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.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": {
|
package/Readme.md
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
๐งฎ Mechanical Tolerance Calculator
|
|
2
|
-
|
|
3
|
-
Mechanical Tolerance Calculator is a lightweight JavaScript utility for calculating international standard specifications and tolerances for bores, round bars, and metallic mechanical units.
|
|
4
|
-
It supports common engineering fit and tolerance designations such as H7, H8, H9, h8, h9, and IT5โIT6 according to ISO/ANSI standards.
|
|
5
|
-
|
|
6
|
-
๐ Features
|
|
7
|
-
|
|
8
|
-
Calculates standard tolerances (IT grades) and shaft/hole deviations.
|
|
9
|
-
|
|
10
|
-
Supports ISO system of limits and fits (e.g., H7/h6, H8/f7).
|
|
11
|
-
|
|
12
|
-
Works for both bores (holes) and shafts (round bars).
|
|
13
|
-
|
|
14
|
-
Returns tolerance ranges, upper/lower deviations, and clearance/interference fit results.
|
|
15
|
-
|
|
16
|
-
Lightweight and dependency-free.
|
|
17
|
-
|
|
18
|
-
๐ฆ Installation
|
|
19
|
-
npm install mechanical-tolerance-calculator
|
|
20
|
-
|
|
21
|
-
or using yarn:
|
|
22
|
-
|
|
23
|
-
yarn add mechanical-tolerance-calculator
|
|
24
|
-
|
|
25
|
-
๐งฐ Usage
|
|
26
|
-
import { calculateTolerance } from "mechanical-tolerance-calculator";
|
|
27
|
-
|
|
28
|
-
// Example: Hole tolerance for H7, nominal size 50 mm
|
|
29
|
-
const hole = calculateTolerance("H7", 50);
|
|
30
|
-
console.log(hole);
|
|
31
|
-
/_
|
|
32
|
-
{
|
|
33
|
-
type: "hole",
|
|
34
|
-
nominal: 50,
|
|
35
|
-
designation: "H7",
|
|
36
|
-
upperDeviation: 0.025,
|
|
37
|
-
lowerDeviation: 0.000,
|
|
38
|
-
tolerance: 0.025,
|
|
39
|
-
ITGrade: 7
|
|
40
|
-
}
|
|
41
|
-
_/
|
|
42
|
-
|
|
43
|
-
// Example: Shaft tolerance for h6, nominal size 50 mm
|
|
44
|
-
const shaft = calculateTolerance("h6", 50);
|
|
45
|
-
console.log(shaft);
|
|
46
|
-
/_
|
|
47
|
-
{
|
|
48
|
-
type: "shaft",
|
|
49
|
-
nominal: 50,
|
|
50
|
-
designation: "h6",
|
|
51
|
-
upperDeviation: 0.000,
|
|
52
|
-
lowerDeviation: -0.016,
|
|
53
|
-
tolerance: 0.016,
|
|
54
|
-
ITGrade: 6
|
|
55
|
-
}
|
|
56
|
-
_/
|
|
57
|
-
|
|
58
|
-
โ๏ธ API Reference
|
|
59
|
-
calculateTolerance(designation, nominalSize)
|
|
60
|
-
Parameter Type Description
|
|
61
|
-
designation string ISO/ANSI tolerance designation (e.g. "H7", "h6", "IT6")
|
|
62
|
-
nominalSize number Nominal dimension in millimeters
|
|
63
|
-
|
|
64
|
-
Returns:
|
|
65
|
-
An object containing tolerance values and deviation limits.
|
|
66
|
-
|
|
67
|
-
๐ Standards Referenced
|
|
68
|
-
|
|
69
|
-
ISO 286-1: Geometrical Product Specifications (GPS) โ Limits and Fits
|
|
70
|
-
|
|
71
|
-
ANSI B4.2: Preferred Metric Limits and Fits
|
|
72
|
-
|
|
73
|
-
๐งช Example Applications
|
|
74
|
-
|
|
75
|
-
Mechanical part design and inspection tools
|
|
76
|
-
|
|
77
|
-
CAD/CAM automation scripts
|
|
78
|
-
|
|
79
|
-
Manufacturing tolerance checkers
|
|
80
|
-
|
|
81
|
-
Educational or research tools for mechanical engineering
|
|
82
|
-
|
|
83
|
-
๐งโ๐ป Contributing
|
|
84
|
-
|
|
85
|
-
Contributions, issues, and feature requests are welcome!
|
|
86
|
-
Feel free to open a GitHub issue
|
|
87
|
-
or submit a pull request.
|
|
88
|
-
|
|
89
|
-
๐ License
|
|
90
|
-
|
|
91
|
-
MIT ยฉ 2025 Ajay Ghimire
|