Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export interface IConfig {
pin: number | string;
pullResistor?: number;
}
interface INormalizedConfig {
pin: number | string;
pullResistor: number;
}
export const LOW = 0;
export const HIGH = 1;
export const PULL_NONE = Gpio.PUD_OFF;
export const PULL_DOWN = Gpio.PUD_DOWN;
export const PULL_UP = Gpio.PUD_UP;
function parseConfig(config: number | string | IConfig): INormalizedConfig {
let pin: number | string;
let pullResistor: number;
if (typeof config === 'number' || typeof config === 'string') {
pin = config;
pullResistor = PULL_NONE;
} else if (typeof config === 'object') {
pin = config.pin;
pullResistor = config.pullResistor || PULL_NONE;
if ([ PULL_NONE, PULL_DOWN, PULL_UP].indexOf(pullResistor) === -1) {
throw new Error('Invalid pull resistor option ' + pullResistor);
}
} else {
throw new Error('Invalid pin or configuration');
}