Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Parse objects #7

Merged
merged 1 commit into from over 1 year ago

2 participants

Arnout Kazemier TJ Holowaychuk
Arnout Kazemier
Collaborator

Instead of strings only, see #6

TJ Holowaychuk visionmedia merged commit 0bb42bc into from
TJ Holowaychuk visionmedia closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
4  lib/Parser.js
@@ -75,6 +75,8 @@ Parser.prototype.parse = function(str){
75 75
   var self = this
76 76
     , plugins = this.plugins;
77 77
 
  78
+  if (typeof str !== 'string') str = JSON.stringify(str);
  79
+
78 80
   return JSON.parse(str, function(key, val){
79 81
     var plugin, ret;
80 82
     if ('' === key) return val;
@@ -85,4 +87,4 @@ Parser.prototype.parse = function(str){
85 87
     }
86 88
     return val;
87 89
   });
88  
-};
  90
+};
9  test/parser.js
@@ -70,5 +70,12 @@ describe('Parser', function(){
70 70
       parser.parse('{ "foo": "bar" }')
71 71
         .should.eql({ foo: 'hey' });
72 72
     })
  73
+
  74
+    it('should also parse objects', function(){
  75
+      var parser = new Parser
  76
+        , data = { foo: 'bar' };
  77
+
  78
+      parser.parse(data).should.eql(data);
  79
+    })
73 80
   })
74  
-})
  81
+})
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.