Skip to content

Commit

Permalink
undefined key now return undefined value
Browse files Browse the repository at this point in the history
  • Loading branch information
dcharbonnier committed Nov 13, 2019
1 parent a67329f commit fa5df47
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/polyfill/Dict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,36 @@ export class Dict<K extends string, T> {
private data: { [key: string]: T } = {};

public get(key: K): T {
return this.data[key.toString()];
return key === void 0 ? void 0 : this.data[key.toString()];
}

public clear() {
return this.data = {};
}

public set(key: K, value: T) {
this.data[key ? key.toString() : key] = value;
if (key === void 0) {
return;
}
this.data[key.toString()] = value;
}

public has(key: K) {
return this.data[key ? key.toString() : key] !== void 0;
public has(key: K): boolean {
return key !== void 0 && this.data[key.toString()] !== void 0;
}

public delete(key: K) {
delete this.data[key ? key.toString() : key];
if (key === void 0) {
return;
}
delete this.data[key.toString()];
}
public keys() {
return Object.keys(this.data);
}

public values(): T[] {
return this.keys().map((key) => this.data[key ? key.toString() : key]);
return this.keys().map((key) => this.data[key]);
}

}

0 comments on commit fa5df47

Please sign in to comment.