Class Index | File Index

Classes


Function Namespace Pot.Collection


Defined in: <pot.js>.

Function Namespace Summary
Constructor Attributes Constructor Name and Description
 
Pot.Collection(object, (index))
Collection.
Method Summary
Method Attributes Method Name and Description
<static>  
Pot.Collection.alphanumSort(array, (func))
Sorting with humaneness.
<static>  
Pot.Collection.arrayize(object, (index))
Treated as an array of arguments given then return it as an array.
<static>  
Pot.Collection.flatten(array)
Convert to one-dimensional array from multi-dimensional array.
<static>  
Pot.Collection.merge()
Merge some arrays or objects to base object.
<static>  
Pot.Collection.unique(object, (loose), (ignoreCase))
Returns an array with the given unique array.
Function Namespace Detail
Pot.Collection(object, (index))
Collection. Array utilities. Treated as an array of arguments given then return it as an array.
Parameters:
{*} object
A target object.
{Number} (index)
Optional, The first index to slice the array.
Returns:
{Array} Return an array of result.
See:
Pot.Collection.arrayize
Method Detail
<static> {Function} Pot.Collection.alphanumSort(array, (func))
Sorting with humaneness. (natural sort) Based: alphanum-sorting library that is below link.
  debug(alphanumSort(
              ['a10', 'a2', 'a100', 'a1', 'a12']
  ));
  // @results ['a1', 'a2', 'a10', 'a12', 'a100']
  var arr = [{v: 'a10'}, {v: 'a2'}, {v: 'a100'}, {v: 'a1'}];
  debug(alphanumSort(arr, function(item) {
    // Specify variable (property name).
    return item.v;
  }));
  // @results [{v: 'a1'}, {v: 'a2'}, {v: 'a10'}, {v: 'a100'}]
Parameters:
{Array} array
A target array.
{Function} (func)
Callback function if need specify arguments.
Returns:
{Array} An array of result `array`.
See:
http://www.davekoelle.com/alphanum.html

<static> {Function} Pot.Collection.arrayize(object, (index))
Treated as an array of arguments given then return it as an array.
  debug(arrayize(null));               // [null]
  debug(arrayize((void 0)));           // [undefined]
  debug(arrayize(true));               // [true]
  debug(arrayize(false));              // [false]
  debug(arrayize(new Boolean(true)));  // [Boolean(false)]
  debug(arrayize(Boolean));            // [Boolean]
  debug(arrayize(''));                 // ['']
  debug(arrayize('hoge'));             // ['hoge']
  debug(arrayize(new String('hoge'))); // [String {'hoge'}]
  debug(arrayize(String));             // [String]
  debug(arrayize(100));                // [100]
  debug(arrayize(-100));               // [-100]
  debug(arrayize(NaN));                // [NaN]
  debug(arrayize(12410.505932095032)); // [12410.505932095032]
  debug(arrayize(new Number(100)));    // [Number {100}]
  debug(arrayize(Number));             // [Number]
  debug(arrayize(Error('error')));     // [Error {'error'}]
  debug(arrayize(new Error('error'))); // [Error {'error'}]
  debug(arrayize(Error));              // [Error]
  debug(arrayize(/(foo|bar)/i));       // [/(foo|bar)/i]
  debug(arrayize(new RegExp('hoge'))); // [/hoge/]
  debug(arrayize(new RegExp()));       // [/(?:)/]
  debug(arrayize(RegExp));             // [RegExp]
  debug(arrayize(TypeError));          // [TypeError]
  debug(arrayize(encodeURI));          // [encodeURI]
  debug(arrayize(window));             // [window]
  debug(arrayize(document));           // [document]
  debug(arrayize(document.body));      // [body]
  debug(arrayize([]));                 // []
  debug(arrayize(new Array(1, 2, 3))); // [1, 2, 3]
  debug(arrayize([1, 2, 3]));          // [1, 2, 3]
  debug(arrayize(Array));              // [Array]
  debug(arrayize(Array.prototype));    // [Array.prototype]
  debug(arrayize([[]]));               // [[]]
  debug(arrayize([[100]]));            // [[100]]
  debug(arrayize({}));                 // [{}]
  debug(arrayize({foo: 'bar'}));       // [{foo: 'bar'}]
  debug(arrayize(new Object()));       // [Object {}]
  debug(arrayize(new Object('foo')));  // [Object {'foo'}]
  debug(arrayize(Object));             // [Object]
  debug(arrayize(document.getElementsByTagName('div')));
  // @results  [<div/>, <div/>, <div/> ...]
  (function(a, b, c) {
    debug(arrayize(arguments));
    // @results  [1, 2, 3]
  })(1, 2, 3);
  (function(a, b, c) {
    debug(arrayize(arguments, 2));
    // @results  [3]
  })(1, 2, 3);
Parameters:
{*} object
A target object.
{Number} (index)
Optional, The first index to slice the array.
Returns:
{Array} Return an array of result.

<static> {Function} Pot.Collection.flatten(array)
Convert to one-dimensional array from multi-dimensional array.
  debug(flatten(
              [1,2,3,[4,5,6,[7,8,[9],10],11],12]
  ));
  // @results [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Parameters:
{Array} array
A target array.
Returns:
{Array} An array which has only one dimension.

<static> {Function} Pot.Collection.merge()
Merge some arrays or objects to base object. The type of first argument will be to base type.
  var array1 = [1, 2, 3];
  var array2 = [4, 5, 6];
  var result = merge(array1, array2);
  debug(result);
  // @results  [1, 2, 3, 4, 5, 6]
  var result = merge([], 1, 2, 'foo', {bar: 3});
  debug(result);
  // @results  [1, 2, 'foo', {bar: 3}]
  var obj1 = {foo: 1, bar: 2};
  var obj2 = {baz: 3};
  var result = merge(obj1, obj2);
  debug(result);
  // @results  {foo: 1, bar: 2, baz: 3}
  var result = merge({}, {foo: 1}, {bar: 2});
  debug(result);
  // @results  {foo: 1, bar: 2}
  var s1 = 'foo';
  var s2 = 'bar';
  var result = merge(s1, s2);
  debug(result);
  // @results  'foobar'
Parameters:
{Array|*} (...)
Array(s) to merge.
Returns:
{Array|*} Result of merged.

<static> {Function} Pot.Collection.unique(object, (loose), (ignoreCase))
Returns an array with the given unique array. Keep order without sorting.
  debug(unique(
              [1, 2, 3, 4, 5, 3, 5, 'a', 3, 'b', 'a', 'c', 2, 5]
  ));
  // @results [1, 2, 3, 4, 5, 'a', 'b', 'c']
  debug(unique(
              [5, 7, 8, 3, 6, 1, 7, 2, 3, 8, 4, 2, 9, 5]
  ));
  // @results [5, 7, 8, 3, 6, 1, 2, 4, 9]
  debug(unique(
              ['1', 1, '2', 2, 0, '0', '', null, false, (void 0)],
              true
  ));
  // @results ['1', '2', 0, null]
  debug(unique(
              ['abc', 'ABC', 'Foo', 'bar', 'foO', 'BaR'],
              false, true
  ));
  // @results ['abc', 'Foo', 'bar']
  debug(unique(
              {a: 1, b: 2, c: 3, d: 1, e: 3, f: 2}
  ));
  // @results {a: 1, b: 2, c: 3}
  debug(unique(
              {foo: 1, bar: 2, FOo: 3, Bar: '1', baZ: '2'},
              true, true
  ));
  // @results {foo: 1, bar: 2, FOo: 3}
  debug(unique(
              {a: 1, b: 2, c: 3, d: '1', e: '3', f: 5},
              true
  ));
  // @results {a: 1, b: 2, c: 3, f: 5}
  debug(unique('abcABCabc-----foobarBaZ'));
  // @results  'abcABC-forZ'
  debug(unique('abcABCabc-----foobarBaZ', true, true));
  // @results  'abc-forZ'
  debug(unique(
               [1, 1, [123], (function(a) { return a;}),
                [123], {a: 5}, (function(a) { return a; }), {a: 5}]
  ));
  // @results  [1, [123], (function() { return a; }), {a: 5}]
Parameters:
{Array|Object|String|*} object
Target object. (no change in this object).
{Boolean} (loose)
If passed TRUE then will be compared by loose operator (==), the default is strict comparison (===).
{Boolean} (ignoreCase)
If passed TRUE then will be ignored case sensitive.
Returns:
{Array|Object|String|*} Array with unique values.

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