sigmund.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. module.exports = sigmund
  2. function sigmund (subject, maxSessions) {
  3. maxSessions = maxSessions || 10;
  4. var notes = [];
  5. var analysis = '';
  6. var RE = RegExp;
  7. function psychoAnalyze (subject, session) {
  8. if (session > maxSessions) return;
  9. if (typeof subject === 'function' ||
  10. typeof subject === 'undefined') {
  11. return;
  12. }
  13. if (typeof subject !== 'object' || !subject ||
  14. (subject instanceof RE)) {
  15. analysis += subject;
  16. return;
  17. }
  18. if (notes.indexOf(subject) !== -1 || session === maxSessions) return;
  19. notes.push(subject);
  20. analysis += '{';
  21. Object.keys(subject).forEach(function (issue, _, __) {
  22. // pseudo-private values. skip those.
  23. if (issue.charAt(0) === '_') return;
  24. var to = typeof subject[issue];
  25. if (to === 'function' || to === 'undefined') return;
  26. analysis += issue;
  27. psychoAnalyze(subject[issue], session + 1);
  28. });
  29. }
  30. psychoAnalyze(subject, 0);
  31. return analysis;
  32. }
  33. // vim: set softtabstop=4 shiftwidth=4: