Skip to content

Instantly share code, notes, and snippets.

@mrsweaters
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrsweaters/8849196 to your computer and use it in GitHub Desktop.
Save mrsweaters/8849196 to your computer and use it in GitHub Desktop.
find match in object keys
function(attrs, exp) {
if (typeof attrs === 'object' && attrs !== null) {
var keys = Object.getOwnPropertyNames(attrs),
i = keys.length,
type = '';
while (i--) {
var attr = attrs[keys[i]];
if (typeof attr === 'object') {
if (attr.name) {
var match = attr.name.match(new RegExp(exp, 'ig'));
if (match) type = match[0];
}
if (typeof attr.attributes === undefined) {
type = this.type(attr, exp);
}
}
}
return type;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment