Namespace Pot
Defined in: <potlite.js>.
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
Define the object Pot.
|
| Field Attributes | Field Name and Description |
|---|---|
| <static> |
Pot.Cc
A shortcut of "Components.classes".
|
| <static> |
Pot.Ci
A shortcut of "Components.interfaces".
|
| <static> |
Pot.Cr
A shortcut of "Components.results".
|
| <static> |
Pot.Cu
A shortcut of "Components.utils".
|
| <static> |
Pot.Global
Global object.
|
|
Detect the Array type.
|
|
|
Detect the Boolean type.
|
|
|
Detect the Date type.
|
|
|
Detect the Error type.
|
|
|
Detect the Function type.
|
|
|
Detect the Number type.
|
|
|
Detect the Object type.
|
|
|
Detect the RegExp type.
|
|
|
Detect the String type.
|
|
| <static> |
Pot.LANG
Detect the browser/user language.
|
| <static> |
Pot.StopIteration
Emulate StopIteration.
|
| Method Attributes | Method Name and Description |
|---|---|
| <static> |
Pot.addPlugin(name, (method), (force))
Add plugin function.
|
| <static> |
Pot.arrayize(object, (index))
Treated as an array of arguments given then
return it as an array.
|
| <static> |
Pot.createBlob(value, (type))
Create new instance of Blob.
|
| <static> |
Pot.createConstructor((name), (proto), (init))
Create a constructor with prototype.
|
| <static> |
Pot.currentDocument()
Get the current DOM Document object if exists (i.e.
|
| <static> |
Pot.currentURI()
Get the current document URI (on web-browser)
or filename (on non-browser).
|
| <static> |
Pot.currentWindow()
Get the current DOM Window object if exists (i.e.
|
| <static> |
Pot.debug(msg)
Output to the console using log function for debug.
|
| <static> |
Pot.deferrizejQueryAjax()
Definition of jQuery plugin and convert Ajax function to deferred.
|
| <static> |
Pot.error(msg)
Output to the console using 'error' function for error logging.
|
| <static> |
Pot.format(fmt)
Formats to a string by arguments.
|
| <static> |
Pot.getErrorMessage(error, (defaults))
Get the error message from Error object.
|
| <static> |
Pot.getFunctionCode(func)
Get the function code.
|
| <static> |
Pot.globalEval(code)
Evaluates a script in a global context.
|
| <static> |
Pot.globalize((target), (advised))
Globalizes the Pot object properties.
|
| <static> |
Pot.hasPlugin(name)
Check whether Pot.Plugin has already specific name.
|
| <static> |
Pot.hasReturn(func)
Check whether the function has "return" statement.
|
| <static> |
Pot.indexOf(object, subject, (from))
Returns the first index at which a
given element can be found in the object, or -1 if it is not present.
|
| <static> |
Pot.invoke(object, method, (args))
Call the function with unknown number arguments.
|
| <static> |
Pot.isArguments(x)
Check whether the argument is Arguments object or not.
|
| <static> |
Pot.isArrayBuffer(x)
Check whether the argument is ArrayBuffer object or not.
|
| <static> |
Pot.isArrayLike(o)
Return whether the argument object like Array (i.e.
|
| <static> |
Pot.isBlob(x)
Check whether the argument is Blob or not.
|
| <static> |
Pot.isBuiltinMethod(method)
Check whether the argument function is the built-in method.
|
| <static> |
Pot.isDeferred(x)
Check whether the argument object is an instance of Pot.Deferred.
|
| <static> |
Pot.isDocument(x)
Check whether the argument object is Document.
|
| <static> |
Pot.isElement(x)
Check whether the argument object is Element.
|
| <static> |
Pot.isFileReader(x)
Check whether the argument is a instance of FileReader or not.
|
| <static> |
Pot.isImage(x)
Check whether the argument is a instance of Image or not.
|
| <static> |
Pot.isInt(n)
Returns whether the supplied number represents an integer,
i.e.
|
| <static> |
Pot.isIter(x)
Check whether the argument object is an instance of Pot.Iter.
|
| <static> |
Pot.isIterable(x)
Return whether the argument is Iterator or not.
|
| <static> |
Pot.isNativeCode(method)
Check whether the argument is the native code.
|
| <static> |
Pot.isNL(c)
Checks whether a token is line-break.
|
| <static> |
Pot.isNodeLike(x)
Check whether the object looks like a DOM node.
|
| <static> |
Pot.isNodeList(x)
Returns true if the object is a NodeList.
|
| <static> |
Pot.isNumeric(n)
Check whether the value can be numeric value.
|
| <static> |
Pot.isPercentEncoded(s)
Check whether the value is percent encoded.
|
| <static> |
Pot.isScalar(x)
Return whether the argument is scalar type.
|
| <static> |
Pot.isStopIter(o)
Return whether the argument is StopIteration or not.
|
| <static> |
Pot.isTypedArray(x)
Check whether the argument is TypedArray object or not.
|
| <static> |
Pot.isWindow(x)
Check whether the argument object is Window.
|
| <static> |
Pot.isWords(c)
Checks whether a token is words.
|
| <static> |
Pot.isWorkeroid(x)
Check whether the argument object is an instance of Pot.Workeroid.
|
| <static> |
Pot.joinTokens(tokens)
Joins the tokenized array.
|
| <static> |
Pot.keys(o)
Collect the object key names like ES5's Object.keys().
|
| <static> |
Pot.lastIndexOf(object, subject, (from))
Returns the last index at which a
given element can be found in the object, or -1 if it is not present.
|
| <static> |
Pot.listPlugin()
List the Pot.Plugin function names.
|
| <static> |
Pot.localEval(code, (scope))
Evaluates a script in a anonymous context.
|
| <static> |
Pot.noop()
Noop function.
|
| <static> |
Pot.now()
Get the current time as milliseconds.
|
| <static> |
Pot.override(object, properties, converters/overrider, overrider/converters)
Override the method of the object.
|
| <static> |
Pot.range(end/begin, (end), (step))
Create continuously array that
has numbers between start number and end number.
|
| <static> |
Pot.removePlugin(name)
Removes Pot.Plugin's function.
|
| <static> |
Pot.rescape(s)
Escape RegExp patterns.
|
| <static> |
Pot.stringify(x, (ignoreBoolean))
Evaluate a string can be a scalar value only.
|
| <static> |
Pot.tokenize(func)
Tokenize a function code simply.
|
| <static> |
Pot.toString()
toString.
|
| <static> |
Pot.trim(s, (chars), (ignoreCase))
Trim the white spaces including em (U+3000).
|
| <static> |
Pot.typeLikeOf(o)
Get the object type like of array or any types.
|
| <static> |
Pot.typeOf(o)
Get the object type as string.
|
| <static> |
Pot.update(target)
Extend target object from arguments.
|
Field Detail
<static>
{Object}
Pot.Cc
A shortcut of "Components.classes".
<static>
{Object}
Pot.Ci
A shortcut of "Components.interfaces".
<static>
{Object}
Pot.Cr
A shortcut of "Components.results".
<static>
{Object}
Pot.Cu
A shortcut of "Components.utils".
<static>
{Object}
Pot.Global
Global object. (e.g. window)
{Function}
isArray
Detect the Array type. (static)
{Function}
isBoolean
Detect the Boolean type. (static)
{Function}
isDate
Detect the Date type. (static)
{Function}
isError
Detect the Error type. (static)
{Function}
isFunction
Detect the Function type. (static)
{Function}
isNumber
Detect the Number type. (static)
{Function}
isObject
Detect the Object type. (static)
{Function}
isRegExp
Detect the RegExp type. (static)
{Function}
isString
Detect the String type. (static)
<static>
{String}
Pot.LANG
Detect the browser/user language.
if (Pot.LANG == 'ja') {
debug('ハローワールド');
}
<static>
{Object}
Pot.StopIteration
Emulate StopIteration.
Pot.forEach([1, 2, 3, 4, 5], function(v) {
if (v > 2) {
throw Pot.StopIteration;
}
debug(v);
});
Method Detail
<static>
{Function}
Pot.addPlugin(name, (method), (force))
Add plugin function.
Pot.addPlugin('foo', function() { alert('foo!') });
Pot.foo(); // 'foo!'
- Parameters:
- {String|Object} name
- A name of Plugin function. or object.
- {Function} (method)
- A plugin function.
- {Boolean} (force)
- Whether overwrite plugin. (default=false).
- Returns:
- {Boolean} Return success or failure.
<static>
{Function}
Pot.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.createBlob(value, (type))
Create new instance of Blob.
Pot.begin(function() {
var blob = Pot.createBlob('hoge');
var reader = new FileReader();
reader.readAsText(blob);
return reader;
}).then(function(res) {
Pot.debug(res); // 'hoge'
});
- Parameters:
- {*} value
- value.
- {(String)} (type)
- Optional MIME type.
- Returns:
- {Blob} Return new instance of Blob.
<static>
{Function}
Pot.createConstructor((name), (proto), (init))
Create a constructor with prototype.
That will set the toString method to constructor
if argument `name` specified.
If argument `init` has been specified in the string,
then that method will be used to initialize.
If argument `init` has been specified in a function,
then initialization will be execute by `init`.
If omitted argument `init`, and `proto` has 'init' function
then initialization will be execute by 'init' function.
var Hoge = Pot.createConstructor('Hoge', {
init : function(a, b, c) {
this.value = a + b + c;
},
getHoge : function() {
return 'hogehoge';
}
});
Pot.debug(new Hoge(1, 2, 3).value); // 6
Pot.debug(new Hoge().getHoge()); // 'hogehoge'
var Fuga = Pot.createConstructor({
value : 1,
addValue : function(v) {
this.value += v;
return this;
},
getValue : function() {
return this.value;
}
}, function(a, b, c) {
this.value += a + b + c;
});
Pot.debug(new Fuga(1, 2, 3).value); // 7
Pot.debug(new Fuga(1, 2, 3).addValue(10).getValue()); // 17
var Piyo = Pot.createConstructor('Piyo', {
initialize : function(a, b, c) {
this.value = a + b + c;
},
getValue : function() {
return this.value;
}
}, 'initialize');
Pot.debug(new Piyo(10, 20, 30).getValue()); // 60
- Parameters:
- {(String)} (name)
- (Optional) A name of constructor.
- {Object} (proto)
- prototype.
- {(Function|String)} (init)
- (Optional) initialization method name or initialization function.
- Returns:
- {Function} Return new constructor.
<static>
{Function}
Pot.currentDocument()
Get the current DOM Document object if exists (i.e., on web-browser).
- Returns:
- {Object} The current DOM Document object.
<static>
{Function}
Pot.currentURI()
Get the current document URI (on web-browser)
or filename (on non-browser).
- Returns:
- {String} The current URI.
<static>
{Function}
Pot.currentWindow()
Get the current DOM Window object if exists (i.e., on web-browser).
- Returns:
- {Object} The current DOM window object.
<static>
{Function}
Pot.debug(msg)
Output to the console using log function for debug.
debug('hoge'); // hoge
- Parameters:
- {*} msg
- A log message, or variable
<static>
{Function}
Pot.deferrizejQueryAjax()
Definition of jQuery plugin and convert Ajax function to deferred.
- $.pot
{Object} Pot object.
- $.fn.deferred
{Function} Deferrize jQuery method.
function(method, (original arguments))
- method :
{String} method name.
- (...) :
{*} original arguments.
<static>
{Function}
Pot.error(msg)
Output to the console using 'error' function for error logging.
Pot.error('Error!'); // Error!
- Parameters:
- {*} msg
- An error message, or variable.
<static>
{Function}
Pot.format(fmt)
Formats to a string by arguments.
var result = format('#1 + #2 + #3', 10, 20, 30);
debug(result);
// @results '10 + 20 + 30'
var result = format('J#1v#1#2 ECMA#2', 'a', 'Script');
debug(result);
// @results 'JavaScript ECMAScript'
- Parameters:
- {String} fmt
- A string format.
- {...*} (...)
- Format arguments.
- Returns:
- {String} Returns a formatted string.
<static>
{Function}
Pot.getErrorMessage(error, (defaults))
Get the error message from Error object.
var error = new Error('MyError!');
debug(getErrorMessage(error));
// @results 'MyError!'
- Parameters:
- {Error|*} error
- Error object.
- {String|*} (defaults)
- Optional message.
- Returns:
- {String} Return the error message, or 'error'.
<static>
{Function}
Pot.getFunctionCode(func)
Get the function code.
debug(getFunctionCode(function() { return 'hoge'; }));
// @results e.g.
// 'function () {' +
// ' return "hoge";' +
// '}'
debug(getFunctionCode('function() { return 1; }'));
// @results 'function() { return 1; }'
debug(getFunctionCode(1)); // ''
debug(getFunctionCode(false)); // ''
debug(getFunctionCode(true)); // ''
debug(getFunctionCode(null)); // ''
debug(getFunctionCode(void 0)); // ''
debug(getFunctionCode({})); // ''
debug(getFunctionCode(new Function('return 1')));
// @results e.g.
// 'function anonymous() {' +
// ' return 1;' +
// '}'
- Parameters:
- {Function|String} func
- Target function or string code.
- Returns:
- {String} Returns function code or empty string ''.
<static>
{Function}
Pot.globalEval(code)
Evaluates a script in a global context.
globalEval('function hoge() { return "hoge"; }');
debug(hoge());
// @results 'hoge'
- Parameters:
- {String} code
- The code to evaluate.
- Returns:
- {*} The value of evaluated result.
<static>
{Function}
Pot.globalize((target), (advised))
Globalizes the Pot object properties.
var obj = {
foo : function() { return 'foo'; },
bar : function() { return 'bar'; }
};
globalize(obj);
// e.g.,
debug(window.foo()); // 'foo'
debug(bar()); // 'bar'
var result, obj = [1, 2, 3];
//
// Test for before globalization.
try {
result = succeed(obj);
} catch (e) {
// Will be Error: ReferenceError: unique is not defined.
// Call by method to see a long object name from Pot.
result = Pot.Deferred.succeed(obj);
result.map(function(val) {
return val + 100;
}).then(function(res) {
debug(res);
// @results res = [101, 102, 103]
});
}
//
// Globalize the Pot object methods.
//
Pot.globalize();
//
// Then you can call the short method name easy.
var s = '';
forEach(range('A', 'C'), function(val, key) {
s += val + key;
});
debug(s);
// @results 'A0B0C0'
- Parameters:
- {Object} (target)
- A target object to globalize.
- {Boolean} (advised)
- (Optional) Whether to not overwrite the global object property names if a conflict with the Pot object property name.
- Returns:
- {Array} The property name(s) that not defined by conflict as an array.
<static>
{Function}
Pot.hasPlugin(name)
Check whether Pot.Plugin has already specific name.
debug( Pot.hasPlugin('hoge') ); // false
Pot.addPlugin('hoge', function() {});
debug( Pot.hasPlugin('hoge') ); // true
- Parameters:
- {String|Array} name
- A name of Plugin function. or Array.
- Returns:
- {Boolean} Returns whether Pot.Plugin has already specific name.
<static>
{Function}
Pot.hasReturn(func)
Check whether the function has "return" statement.
var func = function() {
return 'hoge';
};
debug(hasReturn(func));
// @results true
var func = function() {
var hoge = 1;
};
debug(hasReturn(func));
// @results false
var func = function return_test(return1, return$2) {
// dummy comment: return 'hoge';
var $return = 'return(1)' ? (function(a) {
if (a) {
return true;
}
return false;
})(/return true/) : "return false";
};
debug(hasReturn(func));
// @results false
var func = function() {
if (1) {
return (function() {
return 'hoge';
})();
}
};
debug(hasReturn(func));
// @results true
// See source code directly.
// Using E4X Syntax for test.
var func = function() {
// return 'hoge';
var e1 = <>return</>;
var e2 = <><![CDATA[
return 1;
]]></>;
var e3 = <> <div data={(function() {
return 'hoge';
})()}>
return 1;
</div></>;
var e4 = <><!--</>-->return 1;</>;
var re = /<><!--[\/]--><\/>/gim;
var e5 = <root><hoge fuga={(function() {
return 1;
})()} piyo="<root>">
<root>return</root>return;<!--</root>"<root>"-->return;
<!--return-->
</hoge></root>;
var root = "</root>";
var r = 'return(1)' ? (function(a) {
if (a) {
return true;
}
return false;
})(/return true/) : "return false";
};
debug(hasReturn(func));
// @results false
- Parameters:
- {Function|String} func
- The code or function to check.
- Returns:
- {Boolean} Whether the function has "return" statement.
<static>
Pot.indexOf(object, subject, (from))
Returns the first index at which a
given element can be found in the object, or -1 if it is not present.
This method like Array.prototype.indexOf
var array = [2, 5, 9];
var index = Pot.indexOf(array, 2);
// index is 0
index = Pot.indexOf(array, 7);
// index is -1
var object = {a: 2, b: 5, c: 9};
index = Pot.indexOf(object, 2);
// index is 'a'
index = Pot.indexOf(object, 7);
// index is -1
- Parameters:
- {Array|Object|*} object
- A target object.
- {*} subject
- A subject object.
- {*} (from)
- (Optional) The index at which to begin the search. Defaults to 0.
- Returns:
- Return the index of result, or -1.
<static>
{Function}
Pot.invoke(object, method, (args))
Call the function with unknown number arguments.
That is for cases where JavaScript sucks
built-in function like alert() on IE or other-browser when
calls the Function.apply.
debug(invoke(window, 'alert', 100));
debug(invoke(document, 'getElementById', 'container'));
debug(invoke(window, 'setTimeout', function() { debug(1); }, 2000));
- Parameters:
- {Object} object
- The context object (e.g. window)
- {String} method
- The callable function name.
- {Array|...*} (args)
- The function arguments.
- Returns:
- {*} The result of the called function.
<static>
{Function}
Pot.isArguments(x)
Check whether the argument is Arguments object or not.
(function(a, b, c) {
var obj = {foo : 1};
var arr = [1, 2, 3];
debug(isArguments(obj)); // false
debug(isArguments(arr)); // false
debug(isArguments(arguments)); // true
}(1, 2, 3));
- Parameters:
- {*} x
- Target object.
- Returns:
- {Boolean} Return true if argument is Arguments object.
<static>
{Function}
Pot.isArrayBuffer(x)
Check whether the argument is ArrayBuffer object or not.
var obj = {foo : 1};
var arr = [1, 2, 3];
var buf = new ArrayBuffer(10);
var uar = new Uint8Array(10);
debug(isArrayBuffer(obj)); // false
debug(isArrayBuffer(arr)); // false
debug(isArrayBuffer(buf)); // true
debug(isArrayBuffer(uar)); // false
- Parameters:
- {*} x
- Target object.
- Returns:
- {Boolean} Return true if argument is ArrayBuffer object.
<static>
{Function}
Pot.isArrayLike(o)
Return whether the argument object like Array (i.e. iterable)
(function() {
debug(Pot.isArray(arguments));
// @results false
debug(Pot.isArrayLike(arguments));
// @results true
})();
- Parameters:
- {*} o
- A target object
- Returns:
- {Boolean} ture or false (iterable or false)
<static>
{Function}
Pot.isBlob(x)
Check whether the argument is Blob or not.
var bb = new Pot.System.BlobBuilder();
bb.append('hoge');
var blob = bb.getBlob();
Pot.debug(Pot.isBlob(blob)); // true
Pot.debug(Pot.isBlob({})); // false
Pot.debug(Pot.isBlob('hoge')); // false
- Parameters:
- {*} x
- Target object.
- Returns:
- {Boolean} Return true if argument is Blob.
<static>
{Function}
Pot.isBuiltinMethod(method)
Check whether the argument function is the built-in method.
debug(isBuiltinMethod(null)); // false
debug(isBuiltinMethod((void 0))); // false
debug(isBuiltinMethod({foo: 1, bar: 2, baz: 3})); // false
debug(isBuiltinMethod('hoge')); // false
debug(isBuiltinMethod(window)); // false
debug(isBuiltinMethod(document)); // false
debug(isBuiltinMethod(document.body)); // false
debug(isBuiltinMethod(document.getElementById)); // true
debug(isBuiltinMethod(encodeURIComponent)); // true
debug(isBuiltinMethod(Array.prototype.slice)); // true
debug(isBuiltinMethod((function() {}))); // false
- Parameters:
- {Function} method
- The target method.
- Returns:
- {Boolean} Return true if the argument function is built-in, otherwise return false.
<static>
{Function}
Pot.isDeferred(x)
Check whether the argument object is an instance of Pot.Deferred.
var o = {hoge: 1};
var d = new Pot.Deferred();
debug(isDeferred(o)); // false
debug(isDeferred(d)); // true
- Parameters:
- {Object|*} x
- The target object to test.
- Returns:
- {Boolean} Return true if the argument object is an instance of Pot.Deferred, otherwise return false.
<static>
{Function}
Pot.isDocument(x)
Check whether the argument object is Document.
debug(isDocument(null)); // false
debug(isDocument((void 0))); // false
debug(isDocument({foo: 1, bar: 2, baz: 3})); // false
debug(isDocument('hoge')); // false
debug(isDocument(window)); // false
debug(isDocument(document)); // true
debug(isDocument(document.body)); // false
debug(isDocument(document.getElementById('container'))); // false
debug(isDocument(document.getElementsByTagName('div'))); // false
- Parameters:
- {Window|Element|Node|*} x
- The target object.
- Returns:
- {Boolean} Return true if the argument object is Document, otherwise return false.
<static>
{Function}
Pot.isElement(x)
Check whether the argument object is Element.
debug(isElement(null)); // false
debug(isElement((void 0))); // false
debug(isElement({foo: 1, bar: 2, baz: 3})); // false
debug(isElement('hoge')); // false
debug(isElement(window)); // false
debug(isElement(document)); // false
debug(isElement(document.body)); // true
debug(isElement(document.getElementById('container'))); // true
debug(isElement(document.getElementsByTagName('div'))); // false
- Parameters:
- {Element|Node|*} x
- The target object.
- Returns:
- {Boolean} Return true if the argument object is Element, otherwise return false.
<static>
{Function}
Pot.isFileReader(x)
Check whether the argument is a instance of FileReader or not.
var object = {hoge : 1};
var reader = new FileReader();
Pot.debug(Pot.isFileReader(object)); // false
Pot.debug(Pot.isFileReader(reader)); // true
- Parameters:
- {*} x
- Target object.
- Returns:
- {Boolean} Return true if argument is FileReader.
<static>
{Function}
Pot.isImage(x)
Check whether the argument is a instance of Image or not.
var object = {hoge : 1};
var image = new Image();
Pot.debug(Pot.isImage(object)); // false
Pot.debug(Pot.isImage(image)); // true
- Parameters:
- {*} x
- Target object.
- Returns:
- {Boolean} Return true if argument is Image.
<static>
{Function}
Pot.isInt(n)
Returns whether the supplied number represents an integer,
i.e. that is has no fractional component.
debug(isInt(0)); // true
debug(isInt(-524560620)); // true
debug(isInt(0.1205562)); // false
debug(isInt(1.5)); // false
debug(isInt(12345)); // true
debug(isInt(Number.MAX_VALUE)); // true
debug(isInt(Number.MAX_VALUE * 1000)); // false
debug(isInt(null)); // false
debug(isInt((void 0))); // false
debug(isInt('hoge')); // false
debug(isInt('')); // false
debug(isInt([100])); // false
- Parameters:
- {Number} n
- The number to test.
- Returns:
- {Boolean} Whether `n` is an integer.
<static>
{Function}
Pot.isIter(x)
Check whether the argument object is an instance of Pot.Iter.
var obj = {hoge: 1};
var iter = new Pot.Iter();
debug(isIter(obj)); // false
debug(isIter(iter)); // true
- Parameters:
- {Object|*} x
- The target object to test.
- Returns:
- {Boolean} Return true if the argument object is an instance of Pot.Iter, otherwise return false.
<static>
{Function}
Pot.isIterable(x)
Return whether the argument is Iterator or not.
var iter = new Pot.Iter();
var i = 0;
iter.next = function() {
if (i > 5) {
throw StopIteration;
}
return i++;
};
debug( isIterable(iter) ); // @results true
var func = function() {};
debug( isIterable(func) ); // @results false
var iter = (function() {
for (var i = 0; i < 10; i++) {
yield;
debug(i);
}
})();
debug( isIterable(iter) ); // @results true
- Parameters:
- {*} x
- Target object.
- Returns:
- {Boolean} Return true if argument is iterable.
<static>
{Function}
Pot.isNativeCode(method)
Check whether the argument is the native code.
debug(isNativeCode(null)); // false
debug(isNativeCode((void 0))); // false
debug(isNativeCode({foo: 1, bar: 2, baz: 3})); // false
debug(isNativeCode('hoge')); // false
debug(isNativeCode(window)); // false
debug(isNativeCode(document)); // false
debug(isNativeCode(document.body)); // false
debug(isNativeCode(document.getElementById)); // true
debug(isNativeCode(encodeURIComponent)); // true
debug(isNativeCode(Array.prototype.slice)); // true
debug(isNativeCode((function() {}))); // false
debug(isNativeCode(Math.max.toString())); // true
- Parameters:
- {String|Function} method
- The target method.
- Returns:
- {Boolean} Return true if the `method` is native code, otherwise return false.
<static>
{Function}
Pot.isNL(c)
Checks whether a token is line-break.
debug(isNL('abc')); // false
debug(isNL(' ')); // false
debug(isNL('\n')); // true
debug(isNL('\r')); // true
debug(isNL('\r\n')); // true
debug(isNL('\nhoge')); // false
debug(isNL('\r \n')); // false
debug(isNL('\r\n\r\n')); // true
// Note: includes U+2028 - U+2029
debug(isNL('\u2028\u2029')); // true
debug(isNL(null)); // false
debug(isNL(void 0)); // false
debug(isNL(false)); // false
debug(isNL(true)); // false
debug(isNL(new String('\n'))); // true
debug(isNL({})); // false
debug(isNL(['\n'])); // false
- Parameters:
- {String} c
- A string token.
- Returns:
- {Boolean} Returns whether a token is NL.
<static>
{Function}
Pot.isNodeLike(x)
Check whether the object looks like a DOM node.
debug(isNodeLike({foo: 1, bar: 2, baz: 3})); // false
debug(isNodeLike('hoge')); // false
debug(isNodeLike(window)); // false
debug(isNodeLike(document)); // true
debug(isNodeLike(document.body)); // true
debug(isNodeLike(document.getElementById('container'))); // true
debug(isNodeLike(document.getElementsByTagName('div'))); // false
- Parameters:
- {*} x
- The target object.
- Returns:
- {Boolean} Whether the object looks like a DOM node.
<static>
{Function}
Pot.isNodeList(x)
Returns true if the object is a NodeList.
var obj = new Array({foo: 1, bar: 2, baz: 3});
var nodes = document.getElementsByTagName('div');
debug(isNodeList(obj));
// @results false
debug(isNodeList(nodes));
// @results true
//
// Make dummy method for test.
obj.item = function() {};
debug(isNodeList(obj));
// @results false
- Parameters:
- {*} x
- The target object to test.
- Returns:
- {Boolean} Whether the object is a NodeList.
<static>
{Function}
Pot.isNumeric(n)
Check whether the value can be numeric value.
debug(isNumeric(0)); // true
debug(isNumeric(1234567890)); // true
debug(isNumeric(new Number(25))); // true
debug(isNumeric(null)); // false
debug(isNumeric((void 0))); // false
debug(isNumeric('abc')); // false
debug(isNumeric('0xFF')); // true
debug(isNumeric('1e8')); // true
debug(isNumeric('10px')); // false
debug(isNumeric('-512 +1')); // false
debug(isNumeric([])); // false
debug(isNumeric([100])); // false
debug(isNumeric(new Date())); // false
debug(isNumeric({})); // false
debug(isNumeric((function() {}))); // false
- Parameters:
- {Number|*} n
- The target value to test.
- Returns:
- {Boolean} Return true if the value is numeric, otherwise return false.
<static>
{Function}
Pot.isPercentEncoded(s)
Check whether the value is percent encoded.
debug(isPercentEncoded('abc')); // true
debug(isPercentEncoded('abc["hoge"]')); // false
debug(isPercentEncoded('%7B%20hoge%20%7D')); // true
- Parameters:
- {String|*} s
- The target string to test.
- Returns:
- {Boolean} Return true if the value is encoded, otherwise return false.
<static>
{Function}
Pot.isScalar(x)
Return whether the argument is scalar type.
This function treats as scalar type for
String or Number and Boolean types.
debug(isScalar(null)); // false
debug(isScalar((void 0))); // false
debug(isScalar('')); // true
debug(isScalar('abc')); // true
debug(isScalar(0)); // true
debug(isScalar(123)); // true
debug(isScalar(false)); // true
debug(isScalar(true)); // true
debug(isScalar(new Boolean(true))); // true
debug(isScalar([])); // false
debug(isScalar([1, 2, 3])); // false
debug(isScalar(/hoge/)); // false
debug(isScalar(new Error())); // false
debug(isScalar({})); // false
debug(isScalar({a: 1, b: 2})); // false
- Parameters:
- {*} x
- A target object.
- Returns:
- {Boolean} ture or false (scalar type or not).
<static>
{Function}
Pot.isStopIter(o)
Return whether the argument is StopIteration or not.
try {
for (var i = 0; i < 10; i++) {
if (i > 5) {
throw Pot.StopIteration;
}
debug(i);
}
} catch (e) {
if (Pot.isStopIter(e)) {
debug('StopIteration was thrown!');
} else {
throw e;
}
}
- Parameters:
- {*} o
- Target object.
- Returns:
- {Boolean} Return true if argument is StopIteration.
<static>
{Function}
Pot.isTypedArray(x)
Check whether the argument is TypedArray object or not.
var obj = {foo : 1};
var arr = [1, 2, 3];
var buf = new ArrayBuffer(10);
var uar = new Uint8Array(10);
debug(isTypedArray(obj)); // false
debug(isTypedArray(arr)); // false
debug(isTypedArray(buf)); // true
debug(isTypedArray(uar)); // true
- Parameters:
- {*} x
- Target object.
- Returns:
- {Boolean} Return true if argument is TypedArray object.
<static>
{Function}
Pot.isWindow(x)
Check whether the argument object is Window.
debug(isWindow(null)); // false
debug(isWindow((void 0))); // false
debug(isWindow({foo: 1, bar: 2, baz: 3})); // false
debug(isWindow('hoge')); // false
debug(isWindow(window)); // true
debug(isWindow(document)); // false
debug(isWindow(document.body)); // false
debug(isWindow(document.getElementById('container'))); // false
debug(isWindow(document.getElementsByTagName('div'))); // false
- Parameters:
- {Document|Element|Node|*} x
- The target object.
- Returns:
- {Boolean} Return true if the argument object is Window, otherwise return false.
<static>
{Function}
Pot.isWords(c)
Checks whether a token is words.
debug(isWords(' ')); // false
debug(isWords('abc')); // true
debug(isWords('ほげ')); // true
debug(isWords('\r\n')); // false
debug(isWords(' \n')); // false
debug(isWords(' abc')); // false
debug(isWords('abc ')); // false
debug(isWords('_')); // true
debug(isWords(false)); // false
debug(isWords(true)); // false
debug(isWords(void 0)); // false
debug(isWords({})); // false
debug(isWords(['ABC'])); // false
debug(isWords('$hoge')); // true
debug(isWords('$_')); // true
- Parameters:
- {String} c
- A string token.
- Returns:
- {Boolean} Returns whether a token is words.
<static>
{Function}
Pot.isWorkeroid(x)
Check whether the argument object is an instance of Pot.Workeroid.
var o = {hoge: 1};
var w = new Pot.Workeroid();
debug(isWorkeroid(o)); // false
debug(isWorkeroid(w)); // true
- Parameters:
- {Object|*} x
- The target object to test.
- Returns:
- {Boolean} Return true if the argument object is an instance of Pot.Workeroid, otherwise return false.
<static>
{Function}
Pot.joinTokens(tokens)
Joins the tokenized array.
var hoge = function() {
var a = 1, b = 0.5, c = '"hoge"', $d = /'\/'/g;
return $d.test(c) ? a : b;
};
var tokens = Pot.tokenize(hoge);
var result = Pot.joinTokens(tokens);
// @results
// 'function(){\n' +
// 'var a=1,b=0.5,c=\'"hoge"\',$d=/\'\\/\'/g;\n' +
// 'return $d.test(c)?a:b;\n' +
// '}'
- Parameters:
- {Array} tokens
- The tokenized array.
- Returns:
- {String} Returns a string that joined from tokens.
<static>
{Function}
Pot.keys(o)
Collect the object key names like ES5's Object.keys().
var obj = {foo: 1, bar: 2, baz: 3};
debug(keys(obj));
// @results ['foo', 'bar', 'baz']
var array = [10, 20, 30, 40, 50];
debug(keys(array));
// @results [0, 1, 2, 3, 4]
delete array[2];
debug(keys(array));
// @results [0, 1, 3, 4]
{@link https://developer.mozilla.org/en/JavaScript/
Reference/Global_Objects/Object/keys }
- Parameters:
- {Object|Function|*} o
- The target object.
- Returns:
- {Array} The collected key names as an array.
<static>
Pot.lastIndexOf(object, subject, (from))
Returns the last index at which a
given element can be found in the object, or -1 if it is not present.
This method like Array.prototype.lastIndexOf
debug('array');
var index, array = [2, 5, 9, 2];
index = Pot.lastIndexOf(array, 2);
debug('index is 3 : result = ' + index); // 3
index = Pot.lastIndexOf(array, 7);
debug('index is -1 : result = ' + index); // -1
index = Pot.lastIndexOf(array, 2, 3);
debug('index is 3 : result = ' + index); // 3
index = Pot.lastIndexOf(array, 2, 2);
debug('index is 0 : result = ' + index); // 0
index = Pot.lastIndexOf(array, 2, -2);
debug('index is 0 : result = ' + index); // 0
index = Pot.lastIndexOf(array, 2, -1);
debug('index is 3 : result = ' + index); // 3
debug('object');
var object = {a: 2, b: 5, c: 9, d: 2};
index = Pot.lastIndexOf(object, 2);
debug('index is d : result = ' + index); // 'd'
index = Pot.lastIndexOf(object, 7);
debug('index is -1 : result = ' + index); // -1
index = Pot.lastIndexOf(object, 2, 'd'); // 'd'
debug('index is d : result = ' + index);
index = Pot.lastIndexOf(object, 2, 'c'); // 'a'
debug('index is a : result = ' + index);
- Parameters:
- {Array|Object|*} object
- A target object.
- {*} subject
- A subject object.
- {*} (from)
- (Optional) The index at which to start searching backwards. Defaults to the array's length.
- Returns:
- Return the index of result, or -1.
<static>
{Function}
Pot.listPlugin()
List the Pot.Plugin function names.
Pot.addPlugin('foo', function() { alert('foo!') });
Pot.addPlugin('bar', function() { alert('bar!') });
debug( Pot.listPlugin() ); // ['foo', 'bar']
- Returns:
- {Array} Returns an array of function names.
<static>
{Function}
Pot.localEval(code, (scope))
Evaluates a script in a anonymous context.
localEval('function hoge() { return "hoge"; }');
debug(hoge());
// @results (Error: hoge is undefined)
- Parameters:
- {String} code
- The code to evaluate.
- {Object|*} (scope)
- (Optional) The evaluation scope.
- Returns:
- {*} The value of evaluated result.
<static>
{Function}
Pot.noop()
Noop function.
<static>
{Function}
Pot.now()
Get the current time as milliseconds.
var time = now(); // equals (new Date()).getTime(); debug(time); // e.g. 1323446177282
- Returns:
- {Number} Return the current time as milliseconds.
<static>
{Function}
Pot.override(object, properties, converters/overrider, overrider/converters)
Override the method of the object.
That enable replace the return value and the arguments variables.
var Hoge = {
addHoge : function(value) {
return value + 'hoge';
}
};
debug(Hoge.addHoge('fugafuga'));
// @results 'fugafugahoge'
override(Hoge, 'addHoge', function(inherits, args, self, prop) {
var value = args[0];
var modify = '{{Modified:' + value + '}}';
args[0] = '';
return modify + inherits(args);
});
var result = Hoge.addHoge('fugafuga');
debug(result);
// @results '{{Modified:fugafuga}}hoge'
var Numbers = {
NAME : 'Numbers',
logAdd : function(a, b) {
return this.NAME + ':' + (a + b);
}
};
debug(Numbers.logAdd(1, 2));
// @results 'Numbers:3'
//
override(Numbers, 'logAdd', [[
/\bthis\.NAME\b/,
'"Result"'
], [
/(["']):(['"])/,
'$1 = $2'
], [
/\ba\s*[+]\s*b\b/,
'(a * b * 100)'
]]);
debug(Numbers.logAdd(1, 2));
// @results 'Result = 200'
var Numbers = {
NAME : 'Numbers',
logAdd : function(a, b) {
return this.NAME + ':' + (a + b);
}
};
debug(Numbers.logAdd(1, 2));
// @results 'Numbers:3'
//
override(Numbers, 'logAdd', [
/this\.NAME\s*[+]\s*([()])?\s*["']:['"]\s*[+]/,
'"(*l_l)/"+$1'
], function(inherits, args, self, prop) {
var a = args[0], b = args[1];
return '{{' + inherits(a + 100, b + 100) + '}}';
});
debug(Numbers.logAdd(1, 2));
// @results '{{(*l_l)/203}}'
- Parameters:
- {Object} object
- The target object.
- {String|RegExp|Array} properties
- The method name. (can be multiple). That can also be specified by regular expressions, and arrays.
- {Array|RegExp|String} converters/overrider
- (Optional) The converters to replace the function source code by RegExp patterns. e.g. [/\breturn\b\s*([^;]+);/, 'throw $1;']
- {Function} overrider/converters
- (Optional) The processing function.
The 4 arguments are passed.
function(inherits, args, self, prop) - inherits : {Function} Inherits function for the original method. - args : {Arguments} The original arguments. - self : {Object} The original object self. - prop : {String} The target method name.
- Returns:
- {Object} Return the first argument `object`.
<static>
{Array}
Pot.range(end/begin, (end), (step))
Create continuously array that
has numbers between start number and end number.
First argument can given an object that has "begin, end, step" any keys.
This function can be a letter rather than just numbers.
var numbers = Pot.range(1, 5);
debug(numbers); // @results [1, 2, 3, 4, 5]
var chars = Pot.range('a', 'f');
debug(chars); // @results ['a', 'b', 'c', 'd', 'e', 'f']
var ranges = Pot.range({begin: 0, step: 10, end: 50});
debug(ranges); // @results [0, 10, 20, 30, 40, 50]
- Parameters:
- {Number|Object} end/begin
- The end number or object.
- {Number} (end)
- (optinal) The end number.
- {Number} (step)
- (optinal) The step number.
- Returns:
- {Array} Return an array result.
<static>
{Function}
Pot.removePlugin(name)
Removes Pot.Plugin's function.
Pot.addPlugin('hoge', function() {});
debug( Pot.removePlugin('hoge') ); // true
Pot.hoge(); // (Error: hoge is undefined)
- Parameters:
- {String|Array} name
- A name of Plugin function. or Array.
- Returns:
- {Boolean} Returns success or failure.
<static>
{Function}
Pot.rescape(s)
Escape RegExp patterns.
var pattern = '*[hoge]*';
var regex = new RegExp('^(' + rescape(pattern) + ')$', 'g');
debug(regex.toString());
// @results /^(\*\[hoge\]\*)$/g
- Parameters:
- {String} s
- A target string.
- Returns:
- {String} The escaped string.
<static>
{Function}
Pot.stringify(x, (ignoreBoolean))
Evaluate a string can be a scalar value only.
Return "1" when argument was passed as true.
This function can treat XML object that
will be string by toString method.
debug(stringify({}));
// @results ''
debug(stringify([]));
// @results ''
debug(stringify(0));
// @results '0'
debug(stringify(-100.02));
// @results '-100.02'
debug(stringify(new Date()));
// @results ''
debug(stringify(null));
// @results ''
debug(stringify(void 0));
// @results ''
debug(stringify(false));
// @results ''
debug(stringify(true));
// @results '1'
debug(stringify(''));
// @results ''
debug(stringify('hoge'));
// @results 'hoge'
debug(stringify(new String('hoge')));
// @results 'hoge'
debug(stringify(new Boolean(false)));
// @results ''
debug(stringify(new Boolean(true)));
// @results '1'
debug(stringify([100]));
// @results ''
- Parameters:
- {*} x
- Any value.
- {Boolean} (ignoreBoolean)
- Optional, Ignores Boolean value.
- Returns:
- {String} Value as a string.
<static>
{Function}
Pot.tokenize(func)
Tokenize a function code simply.
var hoge = function() {
var a = 1, b = 0.5, c = '"hoge"', $d = /'\/'/g;
return $d.test(c) ? a : b;
};
debug( Pot.tokenize(hoge) );
// @results
// [
// 'function', '(', ')', '{', '\n',
// 'var', 'a', '=', '1', ',', 'b', '=', '0.5', ',',
// 'c', '=', '\'"hoge"\'', ',',
// '$d', '=', '/\'\\/\'/g', ';', '\n',
// 'return', '$d', '.', 'test', '(', 'c', ')', '?',
// 'a', ':', 'b', ';', '\n',
// '}'
// ]
- Parameters:
- {Function|String} func
- The code or function to tokenize.
- Returns:
- {Array} Tokens as an array.
<static>
{Function}
Pot.toString()
toString.
- Returns:
- Return formatted string of object.
<static>
{Function}
Pot.trim(s, (chars), (ignoreCase))
Trim the white spaces including em (U+3000).
White spaces will not removed when specified the second argument.
debug( trim(' hoge ') );
// @results 'hoge'
//
// White spaces will not removed when
// specified the second argument.
//
debug( trim('abbbcc cc ', 'ab') );
// @results 'cc cc '
- Parameters:
- {String} s
- A target string.
- {String} (chars)
- (Optional) Removing characters.
- {Boolean} (ignoreCase)
- (Optional) Whether ignore case on RegExp.
- Returns:
- {String} A result string.
<static>
{String}
Pot.typeLikeOf(o)
Get the object type like of array or any types.
The return types: 'boolean', 'number', 'string', 'function', 'array', 'date', 'regexp', 'object', 'error', 'null', 'undefined'
(function() {
debug( Pot.typeLikeOf(arguments) );
// @results 'array'
})();
- Parameters:
- {*} o
- A target object.
- Returns:
- {String} Return the type of object.
<static>
{String}
Pot.typeOf(o)
Get the object type as string.
The return types: 'boolean', 'number', 'string', 'function', 'array', 'date', 'regexp', 'object', 'error', 'null', 'undefined'
debug( Pot.typeOf([1, 2, 3]) ); // @results 'array'
- Parameters:
- {*} o
- A target object.
- Returns:
- {String} Return the type of object.
<static>
{Object}
Pot.update(target)
Extend target object from arguments.
var obj = {foo: 'v1', bar: 'v2'};
var src = {baz: 'v3'};
update(obj, src);
debug(obj);
// @results obj = {foo: 'v1', bar: 'v2', baz: 'v3'}
- Parameters:
- {Object} target
- Target object.
- {...Object} (...)
- Subject objects.
- Returns:
- {Object} Updated object. (first argument).