Sha256: dbacd77eb0ac5473b1d4d5f794dcf18b8d5e703d03815ed4ca5c7a9dac680232
Contents?: true
Size: 1.13 KB
Versions: 26
Compression:
Stored size: 1.13 KB
Contents
/** * Handles sanitization and construction of css class names. * @param {string=} opt_joinChar The character to join parts of the name on. * Defaults to '-'. * @constructor */ webfont.CssClassName = function(opt_joinChar) { /** @type {string} */ this.joinChar_ = opt_joinChar || webfont.CssClassName.DEFAULT_JOIN_CHAR; }; /** * @const * @type {string} */ webfont.CssClassName.DEFAULT_JOIN_CHAR = '-'; /** * Sanitizes a string for use as a css class name. Removes non-word and * underscore characters. * @param {string} name The string. * @return {string} The sanitized string. */ webfont.CssClassName.prototype.sanitize = function(name) { return name.replace(/[\W_]+/g, '').toLowerCase(); }; /** * Builds a complete css class name given a variable number of parts. * Sanitizes, then joins the parts together. * @param {...string} var_args The parts to join. * @return {string} The sanitized and joined string. */ webfont.CssClassName.prototype.build = function(var_args) { var parts = [] for (var i = 0; i < arguments.length; i++) { parts.push(this.sanitize(arguments[i])); } return parts.join(this.joinChar_); };
Version data entries
26 entries across 26 versions & 1 rubygems