Skip to content
Newer
Older
100644 50 lines (29 sloc) 1.59 KB
4bd8cdf @laktek Added README and package.json
authored
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
7bf0bb6 @laktek Updated the examples
authored
15 extractValues("from 4th October to 10th October", "from `from` to `to`", { whitespace: 1, delimeters: ["`", "`"] })
16 >> {"from": "4th October", "to": "10th October" }
20619f2 @laktek Add the option to change the string to lowercase
authored
17
18 extractValues("Convert 1500 Grams to Kilograms", "convert {quantity} {from_unit} to {to_unit}", { lowercase: true })
19 >> {"quantity": "1500", "from_unit": "grams", "to_unit": "kilograms" }]
20
4bd8cdf @laktek Added README and package.json
authored
21 ```
22
23 ### How to Use
24
25 * Install as a NPM package
26
27 ```
28 npm install extract-values
29 ```
30
31 * Then `require` in your project.
32
33 ```javascript
7d22a37 @laktek Handle mismatches
authored
34 var extractValues = require("extract-values");
4bd8cdf @laktek Added README and package.json
authored
35 ```
36
37 * For client-side use, simply copy and paste the function (`extract_values.js`) in to your source.
38
20619f2 @laktek Add the option to change the string to lowercase
authored
39 ### Options
40
41 **whitespace** - normalizes the whitespace in the input string, so it can be aligned with the given pattern. You can define the number of continous whitespaces to contain in the string. Making it zero (0) will remove all whitespaces.
42
43 **lowercase** - coverts the input string to lowercase before matching.
44
45 **delimeters** - If specify the delimeters used in the pattern to define the values. Default delimeters are `{` and `}`.
46
4bd8cdf @laktek Added README and package.json
authored
47 ### Licence
48
49 [MIT LICENSE](https://github.com/laktek/punch/blob/master/LICENSE)
Something went wrong with that request. Please try again.