Comparing version 0.0.2 to 0.0.3
@@ -17,4 +17,5 @@ /// <reference types="bignumber.js" /> | ||
isHttpUrl(variableName: string, value: any): void; | ||
isUri(variableName: string, value: any): void; | ||
assert(condition: boolean, message: string): void; | ||
typeAssertionMessage(variableName: string, type: string, value: any): string; | ||
}; |
@@ -57,5 +57,9 @@ "use strict"; | ||
isHttpUrl: function (variableName, value) { | ||
var isValidUrl = validUrl.isHttpsUri(value) || validUrl.isHttpUri(value); | ||
var isValidUrl = validUrl.isWebUri(value); | ||
this.assert(isValidUrl, this.typeAssertionMessage(variableName, 'http url', value)); | ||
}, | ||
isUri: function (variableName, value) { | ||
var isValidUri = validUrl.isUri(value); | ||
this.assert(isValidUri, this.typeAssertionMessage(variableName, 'uri', value)); | ||
}, | ||
assert: function (condition, message) { | ||
@@ -62,0 +66,0 @@ if (!condition) { |
@@ -295,2 +295,32 @@ "use strict"; | ||
}); | ||
describe('#isUri', function () { | ||
it('should not throw for valid input', function () { | ||
var validInputs = [ | ||
'http://www.google.com', | ||
'https://api.example-relayer.net', | ||
'https://api.radarrelay.com/0x/v0/', | ||
'https://zeroex.beta.radarrelay.com:8000/0x/v0/', | ||
'ws://www.api.example-relayer.net', | ||
'wss://www.api.example-relayer.net', | ||
'user:password@api.example-relayer.net', | ||
]; | ||
validInputs.forEach(function (input) { | ||
return expect(index_1.assert.isUri.bind(index_1.assert, variableName, input)).to.not.throw(); | ||
}); | ||
}); | ||
it('should throw for invalid input', function () { | ||
var invalidInputs = [ | ||
42, | ||
{ random: 'test' }, | ||
undefined, | ||
new bignumber_js_1.BigNumber(45), | ||
'www.google.com', | ||
'api.example-relayer.net', | ||
'//api.example-relayer.net', | ||
]; | ||
invalidInputs.forEach(function (input) { | ||
return expect(index_1.assert.isUri.bind(index_1.assert, variableName, input)).to.throw(); | ||
}); | ||
}); | ||
}); | ||
describe('#assert', function () { | ||
@@ -297,0 +327,0 @@ var assertMessage = 'assert not satisfied'; |
{ | ||
"name": "0x-assert", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Provides a standard way of performing type and schema validation across 0x projects", | ||
@@ -5,0 +5,0 @@ "main": "lib/src/index.js", |
@@ -69,5 +69,9 @@ import {BigNumber} from 'bignumber.js'; | ||
isHttpUrl(variableName: string, value: any): void { | ||
const isValidUrl = validUrl.isHttpsUri(value) || validUrl.isHttpUri(value); | ||
const isValidUrl = validUrl.isWebUri(value); | ||
this.assert(isValidUrl, this.typeAssertionMessage(variableName, 'http url', value)); | ||
}, | ||
isUri(variableName: string, value: any): void { | ||
const isValidUri = validUrl.isUri(value); | ||
this.assert(isValidUri, this.typeAssertionMessage(variableName, 'uri', value)); | ||
}, | ||
assert(condition: boolean, message: string): void { | ||
@@ -74,0 +78,0 @@ if (!condition) { |
@@ -293,2 +293,32 @@ import 'mocha'; | ||
}); | ||
describe('#isUri', () => { | ||
it('should not throw for valid input', () => { | ||
const validInputs = [ | ||
'http://www.google.com', | ||
'https://api.example-relayer.net', | ||
'https://api.radarrelay.com/0x/v0/', | ||
'https://zeroex.beta.radarrelay.com:8000/0x/v0/', | ||
'ws://www.api.example-relayer.net', | ||
'wss://www.api.example-relayer.net', | ||
'user:password@api.example-relayer.net', | ||
]; | ||
validInputs.forEach(input => | ||
expect(assert.isUri.bind(assert, variableName, input)).to.not.throw(), | ||
); | ||
}); | ||
it('should throw for invalid input', () => { | ||
const invalidInputs = [ | ||
42, | ||
{ random: 'test' }, | ||
undefined, | ||
new BigNumber(45), | ||
'www.google.com', | ||
'api.example-relayer.net', | ||
'//api.example-relayer.net', | ||
]; | ||
invalidInputs.forEach(input => | ||
expect(assert.isUri.bind(assert, variableName, input)).to.throw(), | ||
); | ||
}); | ||
}); | ||
describe('#assert', () => { | ||
@@ -295,0 +325,0 @@ const assertMessage = 'assert not satisfied'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54067
854