resistor-color.ts 373 B

1234567891011121314151617181920
  1. export const colorCode = (name: string): number => {
  2. const num = COLORS.indexOf(name.toLowerCase())
  3. if (num == -1) {
  4. throw new Error(`Invalid color name "${name}"`);
  5. }
  6. return num;
  7. }
  8. export const COLORS: string[] = [
  9. 'black',
  10. 'brown',
  11. 'red',
  12. 'orange',
  13. 'yellow',
  14. 'green',
  15. 'blue',
  16. 'violet',
  17. 'grey',
  18. 'white',
  19. ];