Skip to content

buglessir/resistor-calc

Repository files navigation

⚡ resistor-calc

A npm library to calculate the value of electronic resistance based on the colors of the resistor or vice versa.

npm version npm license npm downloads npm bundle size


resistor-calc

Install

npm install resistor-calc

Test

npm run test

Build

npm run build

Functions

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

  • parseResistor throws an error if an invalid color or band count is provided.

  • resistorToColors throws an error if the value or tolerance cannot be mapped to a valid color.

About

A npm library to calculate the value of electronic resistance based on the colors of the resistor or vice versa.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors