Class Index | File Index

Classes


Namespace Pot.Serializer


Defined in: <potlite.js>.

Namespace Summary
Constructor Attributes Constructor Name and Description
 
Serializer.
Method Summary
Method Attributes Method Name and Description
<static>  
Pot.Serializer.parseFromJSON(text, (reviver))
`parseFromJSON` will parse a JSON object and convert to any object.
<static>  
Pot.Serializer.parseFromQueryString(queryString, (toObject))
Parse the query-string to the items() format array or the key-value object.
<static>  
Pot.Serializer.serializeToJSON(value, (replacer), (space))
`serializeToJSON` will convert any object to a stringify JSON.
<static>  
Pot.Serializer.serializeToQueryString(params)
Serializes an key-value object to query-string format string.
Namespace Detail
Pot.Serializer
Serializer. Provides the JSON.stringify and the JSON.parse methods. If JSON object is in Built-in then will use native method.
Method Detail
<static> {Function} Pot.Serializer.parseFromJSON(text, (reviver))
`parseFromJSON` will parse a JSON object and convert to any object. Argument `reviver` is unimplemented.
  debug(parseFromJSON('"hoge"'));
  // @results 'hoge'
  debug(parseFromJSON('null'));
  // @results null
  debug(parseFromJSON('true'));
  // @results true
  debug(parseFromJSON('false'));
  // @results false
  debug(parseFromJSON('"Hello\\u000aWorld!\\u000a"'));
  // @results 'Hello\nWorld!\n'
  debug(parseFromJSON('[1,2,3]'));
  // @results [1,2,3]
  debug(parseFromJSON('[1E1,"(///\\"v\\"///)"]'));
  // @results [10,'(///"v"///)']
  debug(parseFromJSON('{"Hello\\u000aWorld!":[1,{"a":"{ABC}"}]}'));
  // @results {'Hello\nWorld!':[1,{a:'{ABC}'}]}
  debug(parseFromJSON('{"key1":"12345","key2":null}'));
  // @results {key1:'12345',key2:null}
Parameters:
{String} text
A target JSON string object.
{*} (reviver)
(Optional) Unimplemented.
Returns:
{*} Return the parsed object.

<static> {Function} Pot.Serializer.parseFromQueryString(queryString, (toObject))
Parse the query-string to the items() format array or the key-value object. The default result will be the items() format array.
  // Default is the items() format.
  var query = 'foo=1&bar=bar2&baz=';
  debug(parseFromQueryString(query));
  // @results [['foo', '1'], ['bar', 'bar2'], ['baz', '']]
  // Specify "toObject".
  var query = 'key1=value1&key2=value2';
  debug(parseFromQueryString(query, true));
  // @results {key1: 'value1', key2: 'value2'}
  // Invalid key names.
  var query = 'prototype=value1&__iterator__=value2';
  debug(parseFromQueryString(query));
  // @results [['prototype', 'value1'], ['__iterator__', 'value2']]
  // Example of needless key.
  var query = 'http%3A%2F%2Fwww.example.com%2F';
  debug(parseFromQueryString(query));
  // @results [['', 'http://www.example.com/']]
  var query = '%40A=16%5E2%262&%40B=(2%2B3%3E%3D1)';
  debug(parseFromQueryString(query, true));
  // @results {'@A': '16^2&2', '@B': '(2+3>=1)'}
  var query = 'foo=bar&baz[]=qux&baz[]=quux&corge=';
  debug(parseFromQueryString(query, true));
  // @results {foo: 'bar', baz: ['qux', 'quux'], corge: ''}
Parameters:
{String} queryString
The query-string to parse.
{Boolean} (toObject)
Whether to return as an key-value object. Note that if invalid key name included then an object will be broken. (e.g., "__iterator__" or "prototype", "hasOwnProperty" etc.).
Returns:
{Array|Object} The parsed array or object.

<static> {Function} Pot.Serializer.serializeToJSON(value, (replacer), (space))
`serializeToJSON` will convert any object to a stringify JSON. Arguments `replacer` and `space` are unimplemented.
  debug(serializeToJSON(100));
  // @results "100"
  debug(serializeToJSON('100'));
  // @results "\"100\""
  debug(serializeToJSON('hoge'));
  // @results "\"hoge\""
  debug(serializeToJSON(null));
  // @results "null"
  debug(serializeToJSON(true));
  // @results "true"
  debug(serializeToJSON(false));
  // @results "false"
  debug(serializeToJSON('Hello\nWorld!\n'));
  // @results "\"Hello\\nWorld!\\n\""
  debug(serializeToJSON([1, 2, 3]));
  // @results "[1,2,3]"
  debug(serializeToJSON([1E1, '(///"v"///)']));
  // @results "[10,\"(///\\\"v\\\"///)\"]"
  debug(serializeToJSON({'Hello\nWorld!': [1, {a: '{ABC}'}]}));
  // @results "{\"Hello\\nWorld!\":[1,{\"a\":\"{ABC}\"}]}"
  debug(serializeToJSON({key1: function() {}, key2: new Date()}));
  // @results "{\"key2\":\"2011-08-30T16:32:28Z\"}"
Parameters:
{*} value
A target object.
{Function} (replacer)
(Optional) Unimplemented.
{Number|String} (space)
(Optional) Indent.
Returns:
{String} Return a JSON object as string.

<static> {Function} Pot.Serializer.serializeToQueryString(params)
Serializes an key-value object to query-string format string.
  var query = {foo: 1, bar: 'bar2', baz: null};
  debug(serializeToQueryString(query));
  // @results 'foo=1&bar=bar2&baz='
  // Example of the items() format.
  var query = [['prototype', 'value1'], ['__iterator__', 'value2']];
  debug(serializeToQueryString(query));
  // @results 'prototype=value1&__iterator__=value2'
  // Example of needless key.
  var query = {'': 'http://www.example.com/'};
  debug(serializeToQueryString(query));
  // @results 'http%3A%2F%2Fwww.example.com%2F'
  var query = 'a=value1&b=value2';
  debug(serializeToQueryString(query));
  // @results 'a=value1&b=value2'
  var query = {foo: 'bar', baz: ['qux', 'quux'], corge: ''};
  debug(serializeToQueryString(query));
  // @results 'foo=bar&baz[]=qux&baz[]=quux&corge='
Parameters:
{Object|Array|*} params
The target object.
Returns:
{String} The query-string of builded result.

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