Created
November 21, 2013 21:28
-
-
Save sjungling/7590006 to your computer and use it in GitHub Desktop.
helper for normalizing facet unqiue ids
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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