A npm library to calculate the value of electronic resistance based on the colors of the resistor or vice versa.
npm install resistor-calcnpm run testnpm run buildTakes 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: 'Ω'
}
*/Takes a resistor value and tolerance and returns the corresponding color bands.
const colors = resistorToColors(4700, 5);
console.log(colors);
// ['yellow','violet','red','gold']type ResistorResult = {
value: number;
min: number;
max: number;
tolerance: number;
unit: 'Ω';
}-
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.
