Skip to content

Commit

Permalink
refactor: remove IGenericObject interface in favor of Record
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Jul 14, 2020
1 parent f23da64 commit e3c8660
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/flags/lib/flags.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import camelCase from '../../x/camelCase.ts';
import { normalize } from './normalize.ts';
import { IFlagArgument, IFlagOptions, IFlags, IFlagsResult, IFlagValue, IFlagValueType, IGenericObject, IParseOptions, IType, OptionType } from './types.ts';
import { IFlagArgument, IFlagOptions, IFlags, IFlagsResult, IFlagValue, IFlagValueType, IParseOptions, IType, OptionType } from './types.ts';
import { boolean } from './types/boolean.ts';
import { number } from './types/number.ts';
import { string } from './types/string.ts';
import { validateFlags } from './validate-flags.ts';

const Types: IGenericObject<IType<any>> = {
const Types: Record<string, IType<any>> = {
[ OptionType.STRING ]: string,
[ OptionType.NUMBER ]: number,
[ OptionType.BOOLEAN ]: boolean
Expand Down
6 changes: 1 addition & 5 deletions packages/flags/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
export interface IGenericObject<T> {
[ name: string ]: T;
}

export type IType<T> = ( option: IFlagOptions, arg: IFlagArgument, value: string ) => T | undefined;

export enum OptionType {
Expand All @@ -23,7 +19,7 @@ export type IFlagValue = IFlagValueType | IFlagValueType[];
/**
* An object which represents all flags.
*/
export type IFlags = IGenericObject<undefined | IFlagValue | IFlagValue[]>;
export type IFlags = Record<string, undefined | IFlagValue | IFlagValue[]>;

/**
* Parse result.
Expand Down
4 changes: 2 additions & 2 deletions packages/flags/lib/validate-flags.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import camelCase from '../../x/camelCase.ts';
import paramCase from '../../x/paramCase.ts';
import { getOption } from './flags.ts';
import { IFlagArgument, IFlagOptions, IFlags, IFlagValue, IGenericObject } from './types.ts';
import { IFlagArgument, IFlagOptions, IFlags, IFlagValue } from './types.ts';

// @TODO: add support for knownFlaks

Expand All @@ -21,7 +21,7 @@ interface IFlagOptionsMap {
*/
export function validateFlags( flags: IFlagOptions[], values: IFlags, knownFlaks?: IFlags, allowEmpty?: boolean ): void {

const defaultValues: IGenericObject<boolean> = {};
const defaultValues: Record<string, boolean> = {};
// Set default value's
for ( const option of flags ) {
const name: string = camelCase( option.name );
Expand Down
12 changes: 4 additions & 8 deletions packages/keycode/lib/key-codes.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export interface IGenericObject<T> {
[ name: string ]: T;
}

export const KeyMap: IGenericObject<string> = {
export const KeyMap: Record<string, string> = {

/* xterm/gnome ESC O letter */
'OP': 'f1',
Expand Down Expand Up @@ -68,7 +64,7 @@ export const KeyMap: IGenericObject<string> = {
'[8~': 'end'
};

export const KeyMapShift: IGenericObject<string> = {
export const KeyMapShift: Record<string, string> = {

/* rxvt keys with modifiers */
'[a': 'up',
Expand All @@ -87,7 +83,7 @@ export const KeyMapShift: IGenericObject<string> = {
'[Z': 'tab'
};

export const KeyMapCtrl: IGenericObject<string> = {
export const KeyMapCtrl: Record<string, string> = {

/* rxvt keys with modifiers */
'Oa': 'up',
Expand All @@ -104,7 +100,7 @@ export const KeyMapCtrl: IGenericObject<string> = {
'[8^': 'end'
};

export const SpecialKeyMap: IGenericObject<string> = {
export const SpecialKeyMap: Record<string, string> = {
'\r': 'return',
'\n': 'enter',
'\t': 'tab',
Expand Down

0 comments on commit e3c8660

Please sign in to comment.