Skip to content

Instantly share code, notes, and snippets.

@sjungling
Created November 21, 2013 21:28
Show Gist options
  • Save sjungling/7590006 to your computer and use it in GitHub Desktop.
Save sjungling/7590006 to your computer and use it in GitHub Desktop.
helper for normalizing facet unqiue ids
var getFacetUniqueId = function getFacetUniqueId(facet) {
var facetComponents;
if (typeof facet === 'string') {
facetComponents = facet.split('=');
}
if (_.isObject(facet)) {
if (_.has(facet, 'name') && _.has(facet, 'value')) {
facetComponents = [facet.name, facet.value];
}
}
if (_.isArray(facet)) {
facetComponents = facet;
}
if (_.isArray(facetComponents)) {
return 'F' + facetComponents[0].replace(/f/i,'') + '-' + decodeURIComponent(facetComponents[1]).toLowerCase().replace(/\W/g,'');
}
return undefined;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment