Permalink
Browse files

Added README and package.json

  • Loading branch information...
1 parent e25a052 commit 4bd8cdf3b9be00b13b0e67d98a5234e260f7371e @laktek committed Oct 4, 2012
Showing with 61 additions and 1 deletion.
  1. +37 −0 Readme.md
  2. +21 −0 package.json
  3. +3 −1 tests.js
View
@@ -0,0 +1,37 @@
+## ExtractValues
+
+This is a simple helper to extract values from a string based on a pattern.
+
+### Examples
+
+```javascript
+
+ extractValues("/2012/08/12/test.html", "/{year}/{month}/{day}/{title}.html")
+ >> { "year": "2012", "month": "08", "day": "12", "title": "test" }
+
+ extractValues("John Doe <john@example.com> (http://example.com)", "{name} <{email}> ({url})")
+ >> {"name": "John Doe", "email": "john@example.com", "url": "http://example.com" }
+
+ extractValues"from 4th October to 10th October", "from `from` to `to`", { whitespace: 1, delimeters: ["`", "`"] }])
+ >> {"from": "4th October", "to": "10th October" }]
+```
+
+### How to Use
+
+* Install as a NPM package
+
+```
+ npm install extract-values
+```
+
+* Then `require` in your project.
+
+```javascript
+ var extractValues = require("extractValues");
+```
+
+* For client-side use, simply copy and paste the function (`extract_values.js`) in to your source.
+
+### Licence
+
+[MIT LICENSE](https://github.com/laktek/punch/blob/master/LICENSE)
View
@@ -0,0 +1,21 @@
+{
+ "name": "extract-values",
+ "description": "A simple helper to extract values from a string based on a pattern.",
+ "keywords": [
+ "regex",
+ "pattern matching",
+ "strings"
+ ],
+ "version": "0.0.1",
+ "homepage": "https://github.com/laktek/extract-values",
+ "author": "Lakshan Perera <lakshan@web2media.net> (http://laktek.com)",
+ "licenses": "MIT",
+ "bugs": {
+ "url": "http://github.com/laktek/extract-values/issues"
+ },
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/laktek/extract-values.git"
+ },
+ "main": "./lib/extract_values.js"
+}
View
@@ -14,7 +14,9 @@ var cases = [
[["a:b,c:d", "a:{{a}},c:{{c}}", { delimeters: ["{{", "}}"] }], { "a": "b", "c": "d" }],
- [["red blue green", "{first} {second} {third}", { whitespace: 1 }], {"first": "red", "second": "blue", "third": "green" }]
+ [["red blue green", "{first} {second} {third}", { whitespace: 1 }], {"first": "red", "second": "blue", "third": "green" }],
+
+ [["from 4th October to 10th October", "from `from` to `to`", { whitespace: 1, delimeters: ["`", "`"] }], {"from": "4th October", "to": "10th October" }]
]
for (var i = 0; i < cases.length; i++) {

0 comments on commit 4bd8cdf

Please sign in to comment.