Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added README and package.json

  • Loading branch information...
commit 4bd8cdf3b9be00b13b0e67d98a5234e260f7371e 1 parent e25a052
Lakshan Perera authored

Showing 3 changed files with 61 additions and 1 deletion. Show diff stats Hide diff stats

  1. +37 0 Readme.md
  2. +21 0 package.json
  3. +3 1 tests.js
37 Readme.md
Source Rendered
... ... @@ -0,0 +1,37 @@
  1 +## ExtractValues
  2 +
  3 +This is a simple helper to extract values from a string based on a pattern.
  4 +
  5 +### Examples
  6 +
  7 +```javascript
  8 +
  9 + extractValues("/2012/08/12/test.html", "/{year}/{month}/{day}/{title}.html")
  10 + >> { "year": "2012", "month": "08", "day": "12", "title": "test" }
  11 +
  12 + extractValues("John Doe <john@example.com> (http://example.com)", "{name} <{email}> ({url})")
  13 + >> {"name": "John Doe", "email": "john@example.com", "url": "http://example.com" }
  14 +
  15 + extractValues"from 4th October to 10th October", "from `from` to `to`", { whitespace: 1, delimeters: ["`", "`"] }])
  16 + >> {"from": "4th October", "to": "10th October" }]
  17 +```
  18 +
  19 +### How to Use
  20 +
  21 +* Install as a NPM package
  22 +
  23 +```
  24 + npm install extract-values
  25 +```
  26 +
  27 +* Then `require` in your project.
  28 +
  29 +```javascript
  30 + var extractValues = require("extractValues");
  31 +```
  32 +
  33 +* For client-side use, simply copy and paste the function (`extract_values.js`) in to your source.
  34 +
  35 +### Licence
  36 +
  37 +[MIT LICENSE](https://github.com/laktek/punch/blob/master/LICENSE)
21 package.json
... ... @@ -0,0 +1,21 @@
  1 +{
  2 + "name": "extract-values",
  3 + "description": "A simple helper to extract values from a string based on a pattern.",
  4 + "keywords": [
  5 + "regex",
  6 + "pattern matching",
  7 + "strings"
  8 + ],
  9 + "version": "0.0.1",
  10 + "homepage": "https://github.com/laktek/extract-values",
  11 + "author": "Lakshan Perera <lakshan@web2media.net> (http://laktek.com)",
  12 + "licenses": "MIT",
  13 + "bugs": {
  14 + "url": "http://github.com/laktek/extract-values/issues"
  15 + },
  16 + "repository": {
  17 + "type": "git",
  18 + "url": "https://github.com/laktek/extract-values.git"
  19 + },
  20 + "main": "./lib/extract_values.js"
  21 +}
4 tests.js
@@ -14,7 +14,9 @@ var cases = [
14 14
15 15 [["a:b,c:d", "a:{{a}},c:{{c}}", { delimeters: ["{{", "}}"] }], { "a": "b", "c": "d" }],
16 16
17   - [["red blue green", "{first} {second} {third}", { whitespace: 1 }], {"first": "red", "second": "blue", "third": "green" }]
  17 + [["red blue green", "{first} {second} {third}", { whitespace: 1 }], {"first": "red", "second": "blue", "third": "green" }],
  18 +
  19 + [["from 4th October to 10th October", "from `from` to `to`", { whitespace: 1, delimeters: ["`", "`"] }], {"from": "4th October", "to": "10th October" }]
18 20 ]
19 21
20 22 for (var i = 0; i < cases.length; i++) {

0 comments on commit 4bd8cdf

Please sign in to comment.
Something went wrong with that request. Please try again.