Class Index | File Index

Classes


Namespace Pot.Complex


Defined in: <pot.js>.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Complex.
Method Summary
Method Attributes Method Name and Description
<static>  
Pot.Complex.compareVersions(ver1, ver2, (operator))
Compare two version strings.
<static>  
Pot.Complex.convertToBase(value, from, to)
Convert to the base 2 to 62 string from the base x string.
<static>  
Pot.Complex.limit(x, min, max)
Return the value that limited in the range of maximum value from minimum value.
<static>  
Pot.Complex.numeric(value, (defaults))
Cast the value to numerical value.
Namespace Detail
Pot.Complex
Complex. Comp + Lex. Math and Numeric, lexical compare utilities.
Method Detail
<static> {Function} Pot.Complex.compareVersions(ver1, ver2, (operator))
Compare two version strings. Version strings are dot-separated sequences of version-parts. Numbers are base-10, and are zero if left out. Strings are compared basic textual versions (e.g., "beta" and "alpha" etc.).
  function compareVersionsRepr(a, b) {
    var x = compareVersions(a, b);
    if (x == 0) {
      return a + ' == ' + b;
    } else if (x > 0) {
      return a + ' > '  + b;
    } else {
      return a + ' < '  + b;
    }
  }
  debug(compareVersionsRepr('1.0pre', '1.0'));
  // @results '1.0pre < 1.0'
  debug(compareVersions('8.2.5rc', '8.2.5a'));
  // @results 1
  debug(compareVersions('8.2.50', '8.2.52'));
  // @results -1
  debug(compareVersions('5.3.0-dev', '5.3.0'));
  // @results -1
  debug(compareVersions('4.1.0.52', '4.01.0.51'));
  // @results 1
  debug(compareVersions('1.01a', '1.01'));
  // @results -1
  debug(compareVersions('1.0.0', '1.0.00'));
  // @results 0
  debug(compareVersions('2.1.0', '2.0.0', '<'));
  // @results false
  debug(compareVersions('2.1.0', '2.0.0', '>'));
  // @results true
  debug(compareVersions('2.1.0a', '2.1.0a', '=='));
  // @results true
Parameters:
{String|Number} ver1
The first version.
{String|Number} ver2
The second version.
{String} (operator)
(Optional) Comparison operator.
Returns:
{Number} If `ver1` and `ver2` are two version being compared, and the return value: - is smaller than 0, then A < B. - equals 0 then Version, then A == B. - is bigger than 0, then A > B.

<static> {Function} Pot.Complex.convertToBase(value, from, to)
Convert to the base 2 to 62 string from the base x string. That can work for big scale integers. The maximum base number is 62. The base number '0' will be not converted.
  var value = 'FFFFFFFF';
  var result = convertToBase(value, 16, 10);
  debug(result);
  // @results  result = '4294967295'
  var value = '9223372036854775807';
  var result = convertToBase(value, 10, 16);
  debug(result);
  // @results  result = '7FFFFFFFFFFFFFFF'
  var value = '11010100010011011010011101111' +
              '10110011001101101100111001101';
  var result = convertToBase(value, 2, 62);
  debug(result);
  // @results  result = 'HelloWorld'
Parameters:
{Number|String} value
the numeric or alphameric value.
{Number} from
the base number is in.
{Number} to
the base to convert number to.
Returns:
{String} the numbers of result which was converted to base to base.

<static> {Function} Pot.Complex.limit(x, min, max)
Return the value that limited in the range of maximum value from minimum value.
  var result = limit(5, 10, 50);
  debug(result);
  // @results 10
  var result = limit(80, 10, 50);
  debug(result);
  // @results 50
  var result = limit(5, 2, 8);
  debug(result);
  // @results 5
  var result = limit(-5, -10, -50);
  debug(result);
  // @results -10
  var result = limit(-80, -10, -50);
  debug(result);
  // @results -50
  var result = limit('F', 'A', 'C');
  debug(result);
  // @results 'C'
  var result = limit('b', 'a', 'z');
  debug(result);
  // @results 'b'
  var result = limit(1, 2, 4, 5, 10, 20);
  debug(result);
  // @results 2
  var result = limit(100, 2, 4, 5, 10, 20);
  debug(result);
  // @results 20
Parameters:
{Number|String|*} x
A target value.
{Number|String|*} min
The minimum value, or maximum value.
{Number|String|*} max
The maximum value, or minimum value.
Returns:
{Number|String|*} The value in the range of `max` from `min`.

<static> {Function} Pot.Complex.numeric(value, (defaults))
Cast the value to numerical value. All type of object can be convert.
  debug(numeric(0));               // 0
  debug(numeric(1234567890));      // 1234567890
  debug(numeric(new Number(25)));  // 25
  debug(numeric(null));            // 0
  debug(numeric((void 0)));        // 0
  debug(numeric(true));            // 1
  debug(numeric(false));           // 0
  debug(numeric('abc'));           // 2748
  debug(numeric('0xFF'));          // 255
  debug(numeric('1e8'));           // 100000000
  debug(numeric('10px'));          // 10
  debug(numeric('1,000,000ms.'));  // 1000000
  debug(numeric('-512 +1'));       // -512
  debug(numeric([]));              // 0
  debug(numeric(['hoge']));        // 1
  debug(numeric(new Date()));      // 1323446177282
Parameters:
{String|*} value
The target value to convert numeric value.
{Number} (defaults)
The default value if `value` is not numeric.
Returns:
{Number} Return the numeric value.

Documentation generated by JsDoc Toolkit 2.4.0 on Fri Sep 21 2012 19:32:22 GMT+0900 (JST)