source: trip-planner-front/node_modules/node-forge/lib/debug.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1/**
2 * Debugging support for web applications.
3 *
4 * @author David I. Lehn <dlehn@digitalbazaar.com>
5 *
6 * Copyright 2008-2013 Digital Bazaar, Inc.
7 */
8var forge = require('./forge');
9
10/* DEBUG API */
11module.exports = forge.debug = forge.debug || {};
12
13// Private storage for debugging.
14// Useful to expose data that is otherwise unviewable behind closures.
15// NOTE: remember that this can hold references to data and cause leaks!
16// format is "forge._debug.<modulename>.<dataname> = data"
17// Example:
18// (function() {
19// var cat = 'forge.test.Test'; // debugging category
20// var sState = {...}; // local state
21// forge.debug.set(cat, 'sState', sState);
22// })();
23forge.debug.storage = {};
24
25/**
26 * Gets debug data. Omit name for all cat data Omit name and cat for
27 * all data.
28 *
29 * @param cat name of debugging category.
30 * @param name name of data to get (optional).
31 * @return object with requested debug data or undefined.
32 */
33forge.debug.get = function(cat, name) {
34 var rval;
35 if(typeof(cat) === 'undefined') {
36 rval = forge.debug.storage;
37 } else if(cat in forge.debug.storage) {
38 if(typeof(name) === 'undefined') {
39 rval = forge.debug.storage[cat];
40 } else {
41 rval = forge.debug.storage[cat][name];
42 }
43 }
44 return rval;
45};
46
47/**
48 * Sets debug data.
49 *
50 * @param cat name of debugging category.
51 * @param name name of data to set.
52 * @param data data to set.
53 */
54forge.debug.set = function(cat, name, data) {
55 if(!(cat in forge.debug.storage)) {
56 forge.debug.storage[cat] = {};
57 }
58 forge.debug.storage[cat][name] = data;
59};
60
61/**
62 * Clears debug data. Omit name for all cat data. Omit name and cat for
63 * all data.
64 *
65 * @param cat name of debugging category.
66 * @param name name of data to clear or omit to clear entire category.
67 */
68forge.debug.clear = function(cat, name) {
69 if(typeof(cat) === 'undefined') {
70 forge.debug.storage = {};
71 } else if(cat in forge.debug.storage) {
72 if(typeof(name) === 'undefined') {
73 delete forge.debug.storage[cat];
74 } else {
75 delete forge.debug.storage[cat][name];
76 }
77 }
78};
Note: See TracBrowser for help on using the repository browser.