You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
module.exports = sigmund |
|
function sigmund (subject, maxSessions) { |
|
maxSessions = maxSessions || 10; |
|
var notes = []; |
|
var analysis = ''; |
|
var RE = RegExp; |
|
|
|
function psychoAnalyze (subject, session) { |
|
if (session > maxSessions) return; |
|
|
|
if (typeof subject === 'function' || |
|
typeof subject === 'undefined') { |
|
return; |
|
} |
|
|
|
if (typeof subject !== 'object' || !subject || |
|
(subject instanceof RE)) { |
|
analysis += subject; |
|
return; |
|
} |
|
|
|
if (notes.indexOf(subject) !== -1 || session === maxSessions) return; |
|
|
|
notes.push(subject); |
|
analysis += '{'; |
|
Object.keys(subject).forEach(function (issue, _, __) { |
|
// pseudo-private values. skip those. |
|
if (issue.charAt(0) === '_') return; |
|
var to = typeof subject[issue]; |
|
if (to === 'function' || to === 'undefined') return; |
|
analysis += issue; |
|
psychoAnalyze(subject[issue], session + 1); |
|
}); |
|
} |
|
psychoAnalyze(subject, 0); |
|
return analysis; |
|
} |
|
|
|
// vim: set softtabstop=4 shiftwidth=4:
|
|
|