Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update README

  • Loading branch information...
commit fb3a5e6a69c7a5fc2f06fe7738db2f155cc427d1 1 parent caef57a
@pvorb authored
Showing with 50 additions and 35 deletions.
  1. +50 −35 README.mkd
View
85 README.mkd
@@ -1,7 +1,6 @@
# props
-a module for node that is able to extract either JSON or YAML from the beginning
-of a string
+parse either JSON or YAML from the beginning of a string
## Installation
@@ -9,42 +8,58 @@ of a string
## Usage
+Imagine you had these two files:
+
+text1.txt:
+
+```
+{
+ "title", "How to use node.js",
+ "date", "2011-08-09T17:56:00",
+ "tags", [ "example", "node.js" ]
+}
+
+
+Node.js is a new technology...
+```
+
+text2.txt:
+
+```
+title: How to use node.js
+date: 2011-08-09T17:56:00
+tags: [ example, node.js ]
+
+
+Node.js is a new technology...
+```
+
+parse.js:
+
```js
-var props = require("props");
-
-// Use JSON
-
-var json =
-'{\n\
- "title": "How to use node.js",\n\
- "date": "2011-08-09T17:56:00",\n\
- "tags": [ "example", "node.js" ]\n\
-}\n\
-\n\
-\n\
-Node.js is a new technology...';
-
-console.log(props(json));
-
-// or YAML
-
-var yaml =
-'title: How to use node.js\n\
-date: 2011-08-09T17:56:00\n\
-tags:\n\
- - example\n\
- - node.js\n\
-\n\
-\n\
-Node.js is a new technology...';
-
-console.log(props(yaml));
+var props = require('props');
+var fs = require('fs');
+
+// --- text1 ---
+
+var text1 = fs.readFileSync('text1.txt', 'utf8'); // read first text file
+
+var parsedText1 = props(text1); // parse json
+
+console.log(parsedText1);
+
+// --- text2 ---
+
+var text2 = fs.readFileSync('text2.txt', 'utf8'); // read second text file
+
+var parsedText2 = props(text2); // parse YAML
+
+console.log(parsedText2);
```
-This will print nearly the same object twice, since `json` and `yaml` define the
-same object:
+The output will be:
-_JSON_:
+text1:
```js
{ title: 'How to use node.js',
@@ -54,7 +69,7 @@ _JSON_:
```
-_YAML_:
+text2:
```js
{ title: 'How to use node.js',
Please sign in to comment.
Something went wrong with that request. Please try again.