A simple module to calculate properties for resistors.
- Convert resistor bands to standard resistor notation
- Convert standard resistor notation to resistor bands
- Convert a number to standard resistor notation
- Convert standard resistor notation to a number
npm install resistor-dataconst { bandsToNotation, notationToBands, notationToValue, valueToNotation } = require('resistor-data');
bandsToNotation(['red', 'yellow', 'black', 'brown', 'brown']); // ['2k4', 1]
notationToBands(['2k4', 1], 5); // ['red', 'yellow', 'black', 'brown', 'brown']
notationToValue('2k4'); // 2400
valueToNotation(2400); // '2k4'import {
bandsToNotation,
notationToBands,
notationToValue,
valueToNotation,
} from 'resistor-data';
import type { ResistorColor, ResistorTolerance, ResistorData, BandCount } from 'resistor-data';
// ResistorData is [notation: string, tolerance: ResistorTolerance]
const result: ResistorData = bandsToNotation(['red', 'yellow', 'black', 'brown', 'brown']);
// result => ['2k4', 1]
const bands: ResistorColor[] = notationToBands(['2k4', 1], 5);
// bands => ['red', 'yellow', 'black', 'brown', 'brown']
const value: number = notationToValue('2k4'); // 2400
const notation: string = valueToNotation(2400); // '2k4'Converts an array of 4 or 5 resistor band colour names into [notation, tolerance].
bandsToNotation(['orange', 'orange', 'black', 'red', 'brown']); // ['33k', 1]Converts a [notation, tolerance] pair into an array of colour names. bands defaults to 5.
notationToBands(['33k', 1], 4); // ['orange', 'orange', 'orange', 'brown']
notationToBands(['33k', 1], 5); // ['orange', 'orange', 'black', 'red', 'brown']Converts standard resistor notation to a numeric value.
notationToValue('5k'); // 5000
notationToValue('5k5'); // 5500
notationToValue('1M2'); // 1200000Converts a numeric value to standard resistor notation.
valueToNotation(3000); // '3k'
valueToNotation(3300); // '3k3'
valueToNotation(1000000); // '1m'| Type | Description |
|---|---|
ResistorColor |
Union of valid band colour strings ('black', 'brown', 'red', ...) |
ResistorTolerance |
Union of valid tolerance values (0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 20) |
ResistorData |
Tuple returned by bandsToNotation: [notation: string, tolerance: ResistorTolerance] |
BandCount |
4 | 5 |