Skip to content

Instantly share code, notes, and snippets.

@leachdaniel
Created November 3, 2017 00:46
Show Gist options
  • Save leachdaniel/9f9cb6630d869cb5b5be787d44c1ebec to your computer and use it in GitHub Desktop.
Save leachdaniel/9f9cb6630d869cb5b5be787d44c1ebec to your computer and use it in GitHub Desktop.
function CaseInsensitiveLookup() {
this.obj = {};
this.keys = {};
this.getKey = function(key) {
if (key) {
var lKey = key.toLowerCase(),
lastKey = this.keys[lKey];
return this.keys[lKey] = (lastKey || key);
}
}
this.getKeys = function() {
return Object.keys(this.obj);
}
this.getValue = function(key) {
return this.obj[this.getKey(key)];
}
this.setValue = function(key, value) {
this.obj[this.getKey(key)] = value;
}
this.getObject = function() {
return this.obj;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment