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

Version Path
webfontloader-1.3.0 src/core/cssclassname.js
webfontloader-1.2.1 src/core/cssclassname.js
webfontloader-1.2.0 src/core/cssclassname.js
webfontloader-1.1.2 src/core/cssclassname.js
webfontloader-1.1.1 src/core/cssclassname.js
webfontloader-1.1.0 src/core/cssclassname.js
webfontloader-1.0.31 src/core/cssclassname.js
webfontloader-1.0.30 src/core/cssclassname.js
webfontloader-1.0.29 src/core/cssclassname.js
webfontloader-1.0.28 src/core/cssclassname.js
webfontloader-1.0.27 src/core/cssclassname.js
webfontloader-1.0.26 src/core/cssclassname.js
webfontloader-1.0.25 src/core/cssclassname.js
webfontloader-1.0.24 src/core/cssclassname.js
webfontloader-1.0.22 src/core/cssclassname.js
webfontloader-1.0.21 src/core/cssclassname.js
webfontloader-1.0.20 src/core/cssclassname.js
webfontloader-1.0.19 src/core/cssclassname.js
webfontloader-1.0.18 src/core/cssclassname.js
webfontloader-1.0.16 src/core/cssclassname.js