Skip to content

Commit

Permalink
Merge pull request #7 from suzanne-lee/get-key-count
Browse files Browse the repository at this point in the history
Added getKeyCount()
  • Loading branch information
AnyhowStep authored Jun 22, 2019
2 parents ccd20e8 + 9bde92d commit 62ad529
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dist/src/main/util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export declare function toKey<E extends typeof Enum, V extends number | string>(
export declare function toKey<E extends typeof Enum, K extends StringKeyOf<E>>(e: E, value: E[K]): K;
export declare function toKey<E extends typeof Enum>(e: E, value: E[StringKeyOf<E>]): StringKeyOf<E>;
export declare function toKey<E extends typeof Enum>(e: E, mixed: any): (StringKeyOf<E>) | undefined;
export declare function getKeyCount<E extends typeof Enum>(e: E): number;
export declare class WrappedEnum<E extends typeof Enum> {
private readonly e;
private readonly keys;
Expand All @@ -34,4 +35,5 @@ export declare class WrappedEnum<E extends typeof Enum> {
toKey<K extends StringKeyOf<E>>(mixed: E[K]): K;
toKey(mixed: E[StringKeyOf<E>]): StringKeyOf<E>;
toKey(mixed: any): (StringKeyOf<E>) | undefined;
getKeyCount(): number;
}
7 changes: 7 additions & 0 deletions dist/src/main/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/main/util.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/main/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ export function toKey<E extends typeof Enum> (e : E, mixed : any) : (StringKeyOf
export function toKey<E extends typeof Enum> (e : E, mixed : any) : (StringKeyOf<E>)|undefined {
return toKeyInternal(e, getKeys(e), mixed);
}
export function getKeyCount<E extends typeof Enum> (e : E) : number {
return getKeys(e).length;
}

export class WrappedEnum<E extends typeof Enum> {
private readonly e : E;
Expand Down Expand Up @@ -136,4 +139,7 @@ export class WrappedEnum<E extends typeof Enum> {
public toKey (mixed : any) : (StringKeyOf<E>)|undefined {
return toKeyInternal(this.e, this.keys, mixed);
}
public getKeyCount () : number {
return this.keys.length;
}
}

0 comments on commit 62ad529

Please sign in to comment.