Class Xid

java.lang.Object
com.google.javascript.jscomp.Xid

public class Xid extends Object
A simple utility for shortening identifiers in a stable way. Generates short substitution strings deterministically, using a compact (1 to 6 characters in length) repesentation of a 32-bit hash of the key. The string is suitable to be used as a JavaScript or CSS identifier. Collisions are possible but unlikely, depending on the underlying hash algorithm used. This substitution scheme uses case-sensitive names for maximum compression. Digits are also allowed in all but the first character of a class name. There are a few characters allowed by the CSS grammar that we choose not to use (e.g. the underscore and hyphen), to keep names simple. Xid should maintain as minimal dependencies as possible to ease its integration with other tools, such as server side HTML generators.
  • Constructor Details

  • Method Details

    • get

      public String get(String key)
      Gets the string that should be substituted for key. The same value will be consistently returned for any particular key.
      Parameters:
      key - the text to be replaced (never null)
      Returns:
      the value to substitute for key
    • getAsInt

      public int getAsInt(String key)
      Returns the underlying integer representation of the given key.