baas.io Javascript SDK v0.9.0 src/util/util.js

Utils

property
Baas.Utils

    Description

    A class to model a Baas Utils.

    Source

    Baas.Utils = (function () {

    isUUID

    function
    isUUID()
    • @public:
    • @method: isUUID
    • @param: {string}uuidThe string to test
    • @returns: {Boolean} true if string is uuid

    Description

    Tests if the string is a uuid

    Source

    function isUUID(uuid){
          var uuidValueRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
          if (!uuid) return false;
          return uuidValueRegex.test(uuid);
        }

    encodeParams

    function
    encodeParams()

      Description

      method to encode the query string parameters

      @method encodeParams
      @public
      @params {object} params - an object of name value pairs that will be urlencoded
      @return {string} Returns the encoded string

      Source

      function encodeParams(params){
            tail = [];
            var item = [];
            if (params instanceof Array) {
              for (i in params) {
                item = params[i];
                if ((item instanceof Array) && (item.length > 1)) {
                  tail.push(item[0] + "=" + encodeURIComponent(item[1]));
                }
              }
            } else {
              for (var key in params) {
                if (params.hasOwnProperty(key)) {
                  var value = params[key];
                  if (value instanceof Array) {
                    for (i in value) {
                      item = value[i];
                      tail.push(key + "=" + encodeURIComponent(item));
                    }
                  } else {
                    tail.push(key + "=" + encodeURIComponent(value));
                  }
                }
              }
            }
            return tail.join("&");
          }
      
          return{
            isUUID:isUUID,
            encodeParams:encodeParams
          }
        })()