Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Commit

Permalink
Added README and package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
laktek committed Oct 4, 2012
1 parent e25a052 commit 4bd8cdf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
37 changes: 37 additions & 0 deletions Readme.md
@@ -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)
21 changes: 21 additions & 0 deletions package.json
@@ -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"
}
4 changes: 3 additions & 1 deletion tests.js
Expand Up @@ -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++) {
Expand Down

0 comments on commit 4bd8cdf

Please sign in to comment.