Home Reference Source Repository

es6/utils/Runes.js

/**
 * @class Runes
 */

export default class Runes {
  /**
   * the Set of characters to use for our Runes
   *
   * @method     set
   * @returns    [a-zA-Z0-9]
   */
  static get set () {
    return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  }

  static get length () {
    return Runes.set.length
  }

  /**
   * gets a random member from Runes.set
   *
   * @method     randAlphaNumericChar
   * @return     {char}                a random member of Runes.set 
   */
  static randRune () {
    return Runes.set[
      Math.floor(
        Math.random() * Runes.length
      )
    ]
  }

  /**
   * a random string of `n` length composed from Runes.set
   *
   * @method     random
   * @param      {<type>}  n       { parameter_description }
   */
  static random (n) {
    return new Array(n).fill('').map(Runes.randRune).join('')
  }

  /**
   * lulz - good on you for reading docs
   *
   * @method     lpad
   * @param      {number}  n       padtato chips
   * @param      {<type>}  str     The str
   */
  static lpad (n, str) {
    while( n > 0 ) {
      n--
      str = ` ${str}`
    }

    return str
  }

}