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.
npm install mechanical-tolerance-calculatorCalculates international standard specifications and tolerances for bores, round bars, and metallic mechanical units.
Supports standard engineering fits and tolerance grades such as H7, H8, H9, h6, h8, h9, and IT5/IT6 based on ISO tolerance systems.
---
``bash`
npm install mechanical-tolerance-calculator
---
`javascript
// CommonJS
const { getAllTolerancesFor } = require("mechanical-tolerance-calculator");
// ES module
// import { getAllTolerancesFor } from "mechanical-tolerance-calculator";
// Example: Housing Bore Tolerances
const housingTolerances = getAllTolerancesFor("housing");
console.log(housingTolerances["housingBoresTolerances"]);
// Example: Checking Shaft Toleranace for a Measurement
const result = checkOneMeasurementFor('shaft', 179.91);
console.log(result);
// Exmaple: Checking Housing Specification Tolerance for a Collection of Measurements
const result = checkMultipleMeasurementsFor('housing', [240.05, 240.07, 240.09, 240.05, 240.06, 240.02, 240.09]);
console.log(result);
`API Documentation
This section documents the exported public methods of the Mechanical Tolerance Calculator library.
---
Returns all available ISO/ANSI tolerance specifications for a given material type.
).$3
- materialType (string)
The type of material to retrieve tolerances for.
Valid values (or substrings):
- "housing"
- "shaft"
- "shell"$3
- object On success
`json
{
"type": "housingBores" | "shafts" | "shellBores",
"specifications": {
"H6": [ { ... } ],
"H7": [ { ... } ],
"...": [ { ... } ]
}
} ` - On failure
`json
{
"error": "Unknown material type: . Valid types are 'housing', 'shaft', or 'shell'."
}
`$3
`js
const { getAllTolerancesFor } = require("mechanical-tolerance-calculator");const tolerances = getAllTolerancesFor("housing");
console.log(tolerances.specifications.H7);
`checkOneMeasurementFor(materialType: String, measurement: Number)
Checks whether a single measurement complies with the WA standard tolerance and IT grade for the given material type.
$3
- Uses WA standard specifications:
- Housing → H8 / IT6
- Shell → H9 / IT6
- Shaft → h9 / IT5
- Infers the nominal size from the measurement.
- Calculates upper and lower bounds.
- Evaluates whether the measurement meets specification and IT tolerance.$3
- materialType (string)
The type of material to check tolerance and specification for.
Valid values (or substrings):
- "housing"
- "shaft"
- "shell"
- measurement (number)
The measured diameter (must be between 0 and 1000).$3
- object On success
`json
{
"measurement": 24.982,
"nominal": 25,
"specification": "h9",
"IT_grade": "IT5",
"computed_specification_bounds": {
"upperBound": "25.000",
"lowerBound": "24.970"
},
"uncomputed_specification_bounds": {
"upperBound": "25.000 + 0.000",
"lowerBound": "25.000 - 0.030"
},
"matched_spec": { ... },
"meets_specification": {
"meetsSpec": true,
"reason": "24.982 falls between 24.970 and 25.000",
"concludedReason": "shaft is in acceptable size."
},
"meets_IT_tolerance": true
}
` - On failure
`json
{
"error": "Measurement must be between 0 to 1000."
}
`$3
`js
const { checkOneMeasurementFor } = require("mechanical-tolerance-calculator");const result = checkOneMeasurementFor("shaft", 179.91);
console.log(result.meets_IT_tolerance);
`checkMultipleMeasurementsFor(materialType: String, measurements: Numbers[])
Evaluates multiple measurements against WA standard tolerances and IT limits as a group.
$3
- Validates all measurements.
- Computes:
- Nominal size distribution
- Maximum and minimum measurements
- IT difference (max − min)
- Determines:
- Whether all measurements meet specification
- Whether the IT tolerance band is satisfied
- Overall compliance status$3
- materialType (string)
The type of material to check tolerance and specification for.
Valid values (or substrings):
- "housing"
- "shaft"
- "shell"
- measurement (number[])
An array of measured diameters (each between 0 and 1000).$3
- object On success
`json
{
"measurement": [24.982, 24.990, 24.975],
"nominal": 25,
"specification": "h9",
"IT_grade": "IT5",
"computed_specification_bounds": {
"upperBound": "25.000",
"lowerBound": "24.970"
},
"matched_spec": { ... },
"meets_specification": {
"meetsSpec": true,
"reason": "24.990 falls between 24.970 and 25.000"
},
"meets_IT_Tolerance": {
"meetsIT": true,
"reason": "The difference between 24.990 and 24.975 is less than or equal to 0.021."
},
"meets_final_compliance": true
}
` - On Validation Error
`json
{
"error": "Some measurements are invalid.",
"details": [
{ "index": 1, "value": -5, "error": "Invalid measurement: must be 0–1000" }
]
}
`$3
`js
const { checkMultipleMeasurementsFor } = require("mechanical-tolerance-calculator");const result = checkMultipleMeasurementsFor('housing', [240.05, 240.07, 240.09, 240.05, 240.06, 240.02, 240.09]);
console.log(result.meets_final_compliance);
`Features
- Compute ISO/ANSI tolerance limits and deviations for common designations.
- Support for both bores (holes) and shafts (round bars).
- Returns IT grade, upper/lower deviations, tolerance range, and absolute limits.
- Lightweight, zero external dependencies.
- Suitable for design tools, validation scripts, CAD/CAM pipelines, and educational purposes.
---
Reference Standards
- ISO 286-1: Geometrical Product Specifications (GPS) — Limits and Fits
- ANSI B4.2: Preferred Metric Limits and Fits
---
Examples / Typical Use Cases
- Engineering tolerance calculators and utilities
- Automated checks in CAD/CAM export workflows
- Manufacturing inspection tooling and QA scripts
- Educational examples for mechanical engineering courses
---
Development
Clone the repository or use the module directly after installing.
`bash
git clone
cd mechanical-tolerance-calculator
npm install
`---
Contributing
Contributions and bug reports are welcome. Please open issues or pull requests on the project repository and follow the repository CONTRIBUTING guidelines if present.
---
Author
Ajay Ghimire
---
License
MIT © 2025 Ajay Ghimire
---
Keywords (suggested for package.json)
`
mechanical tolerance, ISO 286, limits and fits, H7, h6, IT5, IT6, bore, shaft, tolerances, engineering
``