+10
-3
@@ -100,7 +100,9 @@ var types = { | ||
| let o, arr2; | ||
| let o, arr2, | ||
| p = /^[\w]+\s*,\s*[\w]+/i; | ||
| if (/,/.test(value)) { | ||
| if (p.test(value)) { | ||
| var arr = value.split(',').map(v => type(v).type); | ||
| arr = Array.from(new Set(arr.map(a => a.data_type))); | ||
| // console.log(arr); | ||
| return arr.length == 1 ? value : null; | ||
@@ -112,2 +114,7 @@ } | ||
| }, | ||
| markup : function (value) { | ||
| let p = /<([A-Z][A-Z0-9]*)\b[^>]*>(.*?)<\/\1>/i | ||
| return p.test(value) ? value : null; | ||
| }, | ||
| color: function (value) { | ||
@@ -135,3 +142,3 @@ let p = /(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d\.]+%?\))/i | ||
| data_types: ['undefined', 'infinity', 'integer', 'float', 'date_time', 'date', 'boolean', 'string'], | ||
| string_types: [ 'remote_file', 'file', 'url', 'email', 'color', 'emoji', 'list'] | ||
| string_types: [ 'remote_file', 'file', 'url', 'email', 'color', 'emoji', 'list', 'markup'] | ||
| } | ||
@@ -138,0 +145,0 @@ |
+1
-1
| { | ||
| "name": "typize", | ||
| "version": "0.0.2", | ||
| "version": "0.0.3", | ||
| "description": "Dynamic type detection for Javascript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+1
-0
@@ -93,2 +93,3 @@ | ||
| - remote file | ||
| - markup | ||
@@ -95,0 +96,0 @@ ## Check out the tests |
+50
-10
@@ -173,2 +173,3 @@ const util = require('util'), | ||
| { | ||
@@ -311,5 +312,46 @@ val: 'http://www.foo.com/abc/def?a=2&b=3', | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| val: 'pencil, PEN, ruler, blackboard', | ||
| type: { | ||
| data_type: 'string', | ||
| string_type: 'list' | ||
| } | ||
| }, | ||
| { | ||
| val: 'pencil, pen, ruler, black board', | ||
| type: { | ||
| data_type: 'string', | ||
| string_type: 'list' | ||
| } | ||
| }, | ||
| { | ||
| val: 'pencil, PEN, ruler, black-board', | ||
| type: { | ||
| data_type: 'string', | ||
| string_type: 'list' | ||
| } | ||
| }, | ||
| { | ||
| val: 'pencil, PEN, ruler, blackBoard', | ||
| type: { | ||
| data_type: 'string', | ||
| string_type: 'list' | ||
| } | ||
| }, | ||
| { | ||
| val: '<p>pencil, pen, ruler, black board</p>', | ||
| type: { | ||
| data_type: 'string', | ||
| string_type: 'markup' | ||
| } | ||
| }, | ||
| ]; | ||
@@ -325,21 +367,19 @@ | ||
| describe(util.format("Data type tests for %s", chalk.blue(test.val.toString())) , function () { | ||
| describe(util.format("Data type tests for %s", chalk.blue(test.val.toString())), function () { | ||
| it(util.format("It should be a %s", test.type.data_type), function () { | ||
| it(util.format("It should be a %s", test.type.data_type), function () { | ||
| assert.equal(res.type.data_type, test.type.data_type); | ||
| }); | ||
| if (test.type.string_type) { | ||
| describe(util.format("string_type = %s?", test.type.string_type ), function () { | ||
| describe(util.format("string_type test", test.type.string_type), function () { | ||
| it(util.format("Yes, its string_type = %s", test.type.string_type ), function () { | ||
| it(util.format("It's string_type should be %s", test.type.string_type), function () { | ||
| assert.equal(res.type.string_type, test.type.string_type, res); | ||
| assert.equal(res.type.string_type, test.type.string_type, res.type.string_type); | ||
| }) | ||
| }) | ||
| } | ||
| }) | ||
| }); | ||
@@ -346,0 +386,0 @@ |
23111
4.75%495
8.55%105
0.96%