Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update module 'props'

  • Loading branch information...
commit 188a02e99dd42c0c72af1c17b49e5b207f9dc0b6 1 parent df25033
@pvorb authored
View
1  node_modules/props/.npmignore
@@ -1 +1,2 @@
+node_modules/
test/
View
28 node_modules/props/README.mkd
@@ -1,10 +1,15 @@
-**props** is a module for node that is able to extract either JSON or YAML from
-the beginning of a string.
+# props
-Usage
-=====
+a module for node that is able to extract either JSON or YAML from the beginning
+of a string
-```javascript
+## Installation
+
+`npm install props` or `npm install -g props`
+
+## Usage
+
+```js
var props = require("props");
// Use JSON
@@ -28,7 +33,7 @@ var yaml =
date: 2011-08-09T17:56:00\n\
tags:\n\
- example\n\
- - node.js\
+ - node.js\n\
\n\
\n\
Node.js is a new technology...';
@@ -41,7 +46,7 @@ same object:
_JSON_:
-```javascript
+```js
{ title: 'How to use node.js',
date: '2011-08-09T17:56:00',
tags: [ 'example', 'node.js' ],
@@ -51,7 +56,7 @@ _JSON_:
_YAML_:
-```javascript
+```js
{ title: 'How to use node.js',
date: Tue, 09 Aug 2011 15:56:00 GMT,
tags: [ 'example', 'node.js' ],
@@ -64,8 +69,11 @@ YAML version.
The JSON/YAML part has to be **always** seperated from the content by three
newline characters (`\n\n\n` or `\r\n\r\n\r\n`).
+## Bugs and Issues
+
+If you encounter any bugs or issues, feel free to open an issue at
+[github](//github.com/pvorb/node-props/issues).
-License
-=======
+## License
The [MIT license](http://vorb.de/license/mit.html).
View
28 node_modules/props/lib/props.js
@@ -1,28 +0,0 @@
-var yaml = require("yamlparser");
-
-module.exports = function(str) {
- // `str` must be a string
- if (typeof str !== 'string')
- str = str.toString();
-
- var split, result = {}, content;
-
- // If the string starts with "{", look for JSON
- if (str.match(/^{/)
- && (split = str.split(/\r?\n\r?\n\r?\n/, 2)).length > 0) {
- result = JSON.parse(split[0]);
- }
- // If not, look for YAML
- else if ((split = str.split(/\n\n\n|\r\n\r\n\r\n/, 2)).length > 0) {
- result = yaml.eval(split[0]);
- }
- // If no match was found, the whole string is the content
- else {
- return { __content: str };
- }
-
- // The second part of the array is the content string
- result["__content"] = split[1];
-
- return result;
-};
View
6 node_modules/props/package.json
@@ -2,8 +2,8 @@
"name": "props",
"description": "extract json/yaml from the beginning of text files",
"author": "Paul Vorbach <paul@vorb.de> (http://vorb.de)",
- "version": "0.1.1",
- "main": "lib/props.js",
+ "version": "0.2.2",
+ "main": "./props.js",
"repository": {
"type": "git",
"url": "git://github.com/pvorb/node-props.git"
@@ -18,7 +18,7 @@
"url": "http://github.com/pvorb/node-props/issues"
},
"dependencies": {
- "yamlparser": ">= 0.0.2"
+ "yamlparser": ">=0.0.2"
},
"devDependencies": {},
"engines": {
View
42 node_modules/props/props.js
@@ -0,0 +1,42 @@
+;(function() {
+
+var yaml = require('yamlparser');
+
+module.exports = function(str, div) {
+ div = div || /\n\n\n|\r\n\r\n\r\n/;
+
+ // `str` must be a string
+ if (typeof str != 'string')
+ str = str.toString();
+
+ // trim string
+ str = str.trim();
+
+ var split;
+ var result = {};
+ var content;
+
+ // If a match was found
+ if ((split = str.split(div)).length > 0)
+ try {
+ // JSON
+ if (split[0].charAt(0) == '{')
+ result = JSON.parse(split[0]);
+ // YAML
+ else
+ result = yaml.eval(split[0]);
+ } catch (e) {
+ return { __content: str };
+ }
+ else
+ return { __content: str };
+
+ delete split[0];
+ // Join remaining
+ str = split.join('\n\n\n');
+
+ result.__content = str;
+ return result;
+};
+
+}).call(this);
Please sign in to comment.
Something went wrong with that request. Please try again.