2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
8 YUI.add('dump', function(Y) {
11 * Returns a simple string representation of the object or array.
12 * Other types of objects will be returned unprocessed. Arrays
13 * are expected to be indexed. Use object notation for
16 * If included, the dump method is added to the YUI instance.
28 * The following methods are added to the YUI instance
33 * Returns a simple string representation of the object or array.
34 * Other types of objects will be returned unprocessed. Arrays
35 * are expected to be indexed. Use object notation for
38 * This method is in the 'dump' module, which is not bundled with
42 * @param {object} o The object to dump.
43 * @param {int} d How deep to recurse child objects, default 3.
44 * @return {string} the dump result.
46 dump = function(o, d) {
47 var i, len, s = [], type = L.type(o);
49 // Cast non-objects to string
50 // Skip dates because the std toString is what we want
51 // Skip HTMLElement-like objects because trying to dump
52 // an element will cause an unhandled exception in FF 2.x
55 } else if (type == 'date') {
57 } else if (o.nodeType && o.tagName) {
58 return o.tagName + '#' + o.id;
59 } else if (o.document && o.navigator) {
61 } else if (o.location && o.body) {
63 } else if (type == 'function') {
67 // dig into child objects the depth specifed. Default 3
68 d = (L.isNumber(d)) ? d : 3;
71 if (type == 'array') {
73 for (i = 0, len = o.length; i < len; i = i + 1) {
74 if (L.isObject(o[i])) {
75 s.push((d > 0) ? L.dump(o[i], d - 1) : OBJ);
86 } else if (type == 'regexp') {
88 // objects {k1 => v1, k2 => v2}
92 if (o.hasOwnProperty(i)) {
95 if (L.isObject(o[i])) {
96 s.push((d > 0) ? L.dump(o[i], d - 1) : OBJ);
102 s.push('Error: ' + e.message);