Comparing version 2.0.2 to 2.1.0
@@ -5,5 +5,5 @@ { | ||
"description": "The definitive type testing library", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"dependencies": {}, | ||
"scripts": ["index.js"] | ||
} |
36
index.js
@@ -23,2 +23,5 @@ | ||
var base64Regex = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/; | ||
var hexRegex = /^[A-Fa-f0-9]+$/; | ||
/** | ||
@@ -711,1 +714,34 @@ * Expose `is` | ||
/** | ||
* Test base64 string. | ||
*/ | ||
/** | ||
* is.base64 | ||
* Test if `value` is a valid base64 encoded string. | ||
* | ||
* @param {Mixed} value value to test | ||
* @return {Boolean} true if 'value' is a base64 encoded string, false otherwise | ||
* @api public | ||
*/ | ||
is.base64 = function (value) { | ||
return is.string(value) && (!value.length || base64Regex.test(value)); | ||
}; | ||
/** | ||
* Test base64 string. | ||
*/ | ||
/** | ||
* is.hex | ||
* Test if `value` is a valid hex encoded string. | ||
* | ||
* @param {Mixed} value value to test | ||
* @return {Boolean} true if 'value' is a hex encoded string, false otherwise | ||
* @api public | ||
*/ | ||
is.hex = function (value) { | ||
return is.string(value) && (!value.length || hexRegex.test(value)); | ||
}; |
{ | ||
"name": "is", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"main": "index.js", | ||
@@ -35,6 +35,6 @@ "scripts": { | ||
"devDependencies": { | ||
"tape": "~3.0.0", | ||
"tape": "~3.0.1", | ||
"foreach": "~2.0.5", | ||
"covert": "~1.0.0", | ||
"jscs": "~1.6.2" | ||
"covert": "1.0.0", | ||
"jscs": "~1.7.3" | ||
}, | ||
@@ -41,0 +41,0 @@ "testling": { |
@@ -111,3 +111,8 @@ # is <sup>[![Version Badge][npm-version-svg]][npm-url]</sup> | ||
### encoded binary | ||
- ``is.base64`` (value) | ||
- ``is.hex`` (value) | ||
## Contributors | ||
@@ -132,2 +137,1 @@ | ||
[downloads-url]: http://npm-stat.com/charts.html?package=is | ||
@@ -575,1 +575,17 @@ var test = require('tape'); | ||
test('is.base64', function (t) { | ||
t.ok(is.base64('wxyzWXYZ/+=='), 'string is base64 encoded'); | ||
t.ok(is.base64(''), 'zero length string is base64 encoded'); | ||
t.notOk(is.base64('wxyzWXYZ123/+=='), 'string length not a multiple of four is not base64 encoded'); | ||
t.notOk(is.base64('wxyzWXYZ1234|]=='), 'string with invalid characters is not base64 encoded'); | ||
t.notOk(is.base64('wxyzWXYZ1234==/+'), 'string with = not at end is not base64 encoded'); | ||
t.notOk(is.base64('wxyzWXYZ1234/==='), 'string ending with === is not base64 encoded'); | ||
t.end(); | ||
}); | ||
test('is.hex', function (t) { | ||
t.ok(is.hex('abcdABCD1234'), 'string is hex encoded'); | ||
t.ok(is.hex(''), 'zero length string is hex encoded'); | ||
t.notOk(is.hex('wxyzWXYZ1234/+=='), 'string with invalid characters is not hex encoded'); | ||
t.end(); | ||
}); |
49240
8
1165
136