resistor-calc
v1.0.0
Published
A npm library to calculate the value of electronic resistance based on the colors of the resistor or vice versa.
Downloads
113
Maintainers
Readme
⚡ resistor-calc
A npm library to calculate the value of electronic resistance based on the colors of the resistor or vice versa.

Install
npm install resistor-calcTest
npm run testBuild
npm run buildFunctions
parseResistor(colors: string[]): ResistorResult
Takes a 4-band resistor color array and returns the value, min, max, and tolerance.
const result = parseResistor(['brown','black','red','gold']);
console.log(result);
/*
{
value: 1000,
min: 950,
max: 1050,
tolerance: 5,
unit: 'Ω'
}
*/resistorToColors(value: number, tolerance: number): string[]
Takes a resistor value and tolerance and returns the corresponding color bands.
const colors = resistorToColors(4700, 5);
console.log(colors);
// ['yellow','violet','red','gold']Types
type ResistorResult = {
value: number;
min: number;
max: number;
tolerance: number;
unit: 'Ω';
}Error Handling
parseResistorthrows an error if an invalid color or band count is provided.resistorToColorsthrows an error if the value or tolerance cannot be mapped to a valid color.
