tv4-formats
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -9,2 +9,3 @@ (function () { | ||
durationRegExp = require('./src/durationRegExp'), | ||
timeOffsetRegExp = require('./src/timeOffsetRegExp'), | ||
dateRegExp = /^[0-9]{4,}-[0-9]{2}-[0-9]{2}$/, | ||
@@ -78,2 +79,6 @@ guidRegExp = | ||
exports['time-offset'] = function (value) { | ||
return timeOffsetRegExp.test(value) ? null : 'A signed ISO 8601 duration is expected'; | ||
}; | ||
exports.guid = function (value) { | ||
@@ -80,0 +85,0 @@ return guidRegExp.test(value) ? null : 'A valid GUID is expected'; |
{ | ||
"name": "tv4-formats", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Common JSON Schema string format constraints in the form of tv4 validator callbacks", | ||
@@ -31,3 +31,3 @@ "main": "index.js", | ||
"jshint": "^2.8.0", | ||
"mocha": "^2.3.3" | ||
"mocha": "^3.0.0" | ||
}, | ||
@@ -34,0 +34,0 @@ "dependencies": { |
@@ -40,2 +40,3 @@ [![Build Status](https://travis-ci.org/ikr/tv4-formats.svg?branch=master)](https://travis-ci.org/ikr/tv4-formats) | ||
* [duration](http://en.wikipedia.org/wiki/Iso8601#Durations) (for example, P1DT12H for 1.5 days) | ||
* time-offset (same format as duration, but can also be negative: -P7D) | ||
@@ -42,0 +43,0 @@ * [guid](https://en.wikipedia.org/wiki/Globally_unique_identifier) |
(function () { | ||
'use strict'; | ||
var amount = '[\\.,0-9]+'; | ||
var durationRegExpString = require('./durationRegExpString'); | ||
module.exports = new RegExp( | ||
'^P(' + amount + 'Y|)(' + amount + 'M|)(' + amount + 'W|)(' + amount + 'D|)' + | ||
'(T(' + amount + 'H|)(' + amount + 'M|)(' + amount + 'S|))?$' | ||
); | ||
module.exports = new RegExp(durationRegExpString); | ||
}()); |
@@ -162,3 +162,3 @@ describe('tv4-formats', function () { | ||
].forEach(function (validDuration) { | ||
it('validates valid "' + validDuration + '" durantion positively', function () { | ||
it('validates valid "' + validDuration + '" duration positively', function () { | ||
assert.strictEqual(formats.duration(validDuration), null); | ||
@@ -171,8 +171,28 @@ }); | ||
].forEach(function (invalidDuration) { | ||
it('validates invalid "' + invalidDuration + '" durantion negatively', function () { | ||
it('validates invalid "' + invalidDuration + '" duration negatively', function () { | ||
assert(formats.duration(invalidDuration).length); | ||
}); | ||
}); | ||
}); | ||
describe('time-offset', function () { | ||
it('is defined', function () { | ||
assert.strictEqual(typeof formats['time-offset'], 'function'); | ||
}); | ||
[ | ||
'P1Y', '-P1Y3WT24H', 'P0.5Y', '-P0,5Y', 'PT0.5H' | ||
].forEach(function (validTimeOffset) { | ||
it('validates valid "' + validTimeOffset + '" time offset positively', function () { | ||
assert.strictEqual(formats['time-offset'](validTimeOffset), null); | ||
}); | ||
}); | ||
[ | ||
'P1', '-PW', 'P4D2', '-P3Y6M4D12H30M5S' | ||
].forEach(function (invalidTimeOffset) { | ||
it('validates invalid "' + invalidTimeOffset + '" time offset negatively', function () { | ||
assert(formats.duration(invalidTimeOffset).length); | ||
}); | ||
}); | ||
}); | ||
@@ -179,0 +199,0 @@ |
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
27260
15
312
45