Comparing version 0.1.0 to 0.2.0
@@ -19,2 +19,14 @@ var isString = arg => typeof arg === 'string' | ||
var isURL = (arg) => { | ||
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol | ||
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.?)+[a-z]{2,}|'+ // domain name | ||
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address | ||
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path | ||
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string | ||
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator | ||
return pattern.test(arg); | ||
} | ||
var isNotURL = (arg) => !isURL(arg) | ||
module.exports = { | ||
@@ -29,3 +41,5 @@ isString: isString, | ||
isVariableName: isVariableName, | ||
isNotVariableName: isNotVariableName | ||
isNotVariableName: isNotVariableName, | ||
isURL: isURL, | ||
isNotURL: isNotURL | ||
} |
{ | ||
"name": "isnot", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "All imaginable type checking utils with negation", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,3 +11,5 @@ var expect = require("chai").expect; | ||
isVariableName, | ||
isNotVariableName | ||
isNotVariableName, | ||
isURL, | ||
isNotURL | ||
} = require("../lib/strings"); | ||
@@ -95,2 +97,14 @@ | ||
}); | ||
describe("isURL", function() { | ||
it("checks correctly", function() { | ||
expect(isURL('a@a.a')).to.equal(false); | ||
expect(isURL('')).to.equal(false); | ||
expect(isURL('localhost')).to.equal(true); | ||
expect(isURL('http://localhost')).to.equal(true); | ||
expect(isURL('https://localhost')).to.equal(true); | ||
expect(isURL('//localhost')).to.equal(false); | ||
expect(isURL('bim.bam')).to.equal(true); | ||
}); | ||
}); | ||
}); |
20016
476