diff --git a/src/index.ts b/src/index.ts index 109abb4..5eb1cc0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import dotenv from 'dotenv' -dotenv.config() +import { ArrayOpts, BaseInputValue, BooleanOpts, InputValue, IOpts, IParsedOpts, NumberOpts, StringOpts } from './types' -import { IOpts, IParsedOpts, InputValue } from './types' +dotenv.config() const VALID_TYPES = [ 'string', 'array', 'boolean', 'number' ] @@ -59,7 +59,16 @@ const parseValue = (val: string, type: string): InputValue => { return val.trim() } -export const getInput = (key: string | Array | IOpts, opts: IOpts): InputValue => { +// eslint-disable-next-line no-unused-vars +export function getInput(key: string | Array | IOpts, opts: BooleanOpts): boolean; +// eslint-disable-next-line no-unused-vars,no-redeclare +export function getInput(key: string | Array | IOpts, opts: StringOpts): string; +// eslint-disable-next-line no-unused-vars,no-redeclare +export function getInput(key: string | Array | IOpts, opts: NumberOpts): number; +// eslint-disable-next-line no-unused-vars,no-redeclare +export function getInput(key: string | Array | IOpts, opts: ArrayOpts): BaseInputValue[]; +// eslint-disable-next-line no-redeclare +export function getInput(key: string | Array | IOpts, opts: IOpts): InputValue { let parsedOptions: IOpts if (typeof key === 'string' || Array.isArray(key)) { parsedOptions = { diff --git a/src/types.ts b/src/types.ts index f5529a6..4e79619 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,22 +1,42 @@ /* eslint-disable no-unused-vars */ type ModifierFunction = (val: InputValue) => InputValue -export type InputValue = undefined | string | boolean | number | Array - -export interface IOpts { - key?: string | Array - type?: string - required?: boolean, - disableable?: boolean - default?: InputValue - modifier?: ModifierFunction +export type BaseInputValue = string | boolean | number; + +export type InputValue = undefined | BaseInputValue | Array + +export type IOpts = BooleanOpts | StringOpts | NumberOpts | ArrayOpts | BaseOpts; + +export interface BooleanOpts extends BaseOpts { + type: 'boolean'; +} + +export interface StringOpts extends BaseOpts { + type: 'string'; +} + +export interface NumberOpts extends BaseOpts { + type: 'number'; +} + +export interface ArrayOpts extends BaseOpts { + type: 'array'; +} + +export interface BaseOpts { + key?: string | Array + type?: string + required?: boolean, + disableable?: boolean + default?: T + modifier?: ModifierFunction } export interface IParsedOpts { - key: string | Array - type: string - required: boolean, - disableable: boolean - default?: InputValue - modifier?: ModifierFunction + key: string | Array + type: string + required: boolean, + disableable: boolean + default?: InputValue + modifier?: ModifierFunction } \ No newline at end of file