Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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' ]

Expand Down Expand Up @@ -59,7 +59,16 @@ const parseValue = (val: string, type: string): InputValue => {
return val.trim()
}

export const getInput = (key: string | Array<string> | IOpts, opts: IOpts): InputValue => {
// eslint-disable-next-line no-unused-vars
export function getInput(key: string | Array<string> | IOpts, opts: BooleanOpts): boolean;
// eslint-disable-next-line no-unused-vars,no-redeclare
export function getInput(key: string | Array<string> | IOpts, opts: StringOpts): string;
// eslint-disable-next-line no-unused-vars,no-redeclare
export function getInput(key: string | Array<string> | IOpts, opts: NumberOpts): number;
// eslint-disable-next-line no-unused-vars,no-redeclare
export function getInput(key: string | Array<string> | IOpts, opts: ArrayOpts): BaseInputValue[];
// eslint-disable-next-line no-redeclare
export function getInput(key: string | Array<string> | IOpts, opts: IOpts): InputValue {
let parsedOptions: IOpts
if (typeof key === 'string' || Array.isArray(key)) {
parsedOptions = {
Expand Down
50 changes: 35 additions & 15 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
/* eslint-disable no-unused-vars */
type ModifierFunction = (val: InputValue) => InputValue

export type InputValue = undefined | string | boolean | number | Array<string | boolean | number>

export interface IOpts {
key?: string | Array<string>
type?: string
required?: boolean,
disableable?: boolean
default?: InputValue
modifier?: ModifierFunction
export type BaseInputValue = string | boolean | number;

export type InputValue = undefined | BaseInputValue | Array<BaseInputValue>

export type IOpts = BooleanOpts | StringOpts | NumberOpts | ArrayOpts | BaseOpts<InputValue>;

export interface BooleanOpts extends BaseOpts<boolean> {
type: 'boolean';
}

export interface StringOpts extends BaseOpts<string> {
type: 'string';
}

export interface NumberOpts extends BaseOpts<number> {
type: 'number';
}

export interface ArrayOpts extends BaseOpts<BaseInputValue[]> {
type: 'array';
}

export interface BaseOpts<T extends InputValue> {
key?: string | Array<string>
type?: string
required?: boolean,
disableable?: boolean
default?: T
modifier?: ModifierFunction
}

export interface IParsedOpts {
key: string | Array<string>
type: string
required: boolean,
disableable: boolean
default?: InputValue
modifier?: ModifierFunction
key: string | Array<string>
type: string
required: boolean,
disableable: boolean
default?: InputValue
modifier?: ModifierFunction
}