Permalink
Browse files

Fixed the typo in delimiter

  • Loading branch information...
1 parent 0eb998f commit 833fdb8742a3c55aa3b0429b504ccc6cc6c59974 @laktek committed Oct 4, 2012
Showing with 8 additions and 8 deletions.
  1. +2 −2 Readme.md
  2. +3 −3 extract_values.js
  3. +3 −3 tests.js
View
@@ -12,7 +12,7 @@ This is a simple helper to extract values from a string based on a pattern.
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: ["`", "`"] })
+ extractValues("from 4th October to 10th October", "from `from` to `to`", { whitespace: 1, delimiters: ["`", "`"] })
>> {"from": "4th October", "to": "10th October" }
extractValues("Convert 1500 Grams to Kilograms", "convert {quantity} {from_unit} to {to_unit}", { lowercase: true })
@@ -42,7 +42,7 @@ This is a simple helper to extract values from a string based on a pattern.
**lowercase** - coverts the input string to lowercase before matching.
-**delimeters** - If specify the delimeters used in the pattern to define the values. Default delimeters are `{` and `}`.
+**delimiters** - If specify the delimiters used in the pattern to define the values. Default delimiters are `{` and `}`.
### Licence
View
@@ -1,11 +1,11 @@
var extractValues = function(str, pattern, options) {
options = options || {};
- var delimeters = options.delimeters || ["{", "}"];
+ var delimiters = options.delimiters || ["{", "}"];
var lowercase = options.lowercase;
var whitespace = options.whitespace;
var special_chars_regex = /[\\\^\$\*\+\.\?\(\)]/g;
- var token_regex = new RegExp( delimeters[0] + "([^" + delimeters.join("") + "\t\r\n]+)" + delimeters[1], "g");
+ var token_regex = new RegExp( delimiters[0] + "([^" + delimiters.join("") + "\t\r\n]+)" + delimiters[1], "g");
var tokens = pattern.match(token_regex);
var pattern_regex = new RegExp(pattern.replace(special_chars_regex, "\\$&").replace(token_regex, "(\.+)"));
@@ -32,7 +32,7 @@ var extractValues = function(str, pattern, options) {
matches = matches.splice(1);
var output = {};
for (var i=0; i < tokens.length; i++) {
- output[tokens[i].replace( new RegExp( delimeters[0] + "|" + delimeters[1], "g"), "")] = matches[i];
+ output[tokens[i].replace( new RegExp( delimiters[0] + "|" + delimiters[1], "g"), "")] = matches[i];
}
return output;
View
@@ -14,13 +14,13 @@ var cases = [
[["Lakshan Perera <lakshan@web2media.net> (http://laktek.com)", "{name} <{email}> ({url})"], {"name": "Lakshan Perera", "email": "lakshan@web2media.net", "url": "http://laktek.com" }],
- [["a:b,c:d", "a:{{a}},c:{{c}}", { delimeters: ["{{", "}}"] }], { "a": "b", "c": "d" }],
+ [["a:b,c:d", "a:{{a}},c:{{c}}", { delimiters: ["{{", "}}"] }], { "a": "b", "c": "d" }],
[["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" }],
+ [["from 4th October to 10th October", "from `from` to `to`", { whitespace: 1, delimiters: ["`", "`"] }], {"from": "4th October", "to": "10th October" }],
- [["4th October to 10th October", "from `from` to `to`", { whitespace: 1, delimeters: ["`", "`"] }], null],
+ [["4th October to 10th October", "from `from` to `to`", { whitespace: 1, delimiters: ["`", "`"] }], null],
[["Convert 1500 Grams to Kilograms", "convert {quantity} {from_unit} to {to_unit}", { lowercase: true }], {"quantity": "1500", "from_unit": "grams", "to_unit": "kilograms" }]

0 comments on commit 833fdb8

Please sign in to comment.