Skip to content
Browse files

suspended support of 'style' format

  • Loading branch information...
1 parent 027dfd0 commit cd7ac6fa2b0770cb83cc16aa9669c08e8cda5692 @oferei committed Nov 7, 2012
Showing with 18 additions and 21 deletions.
  1. +0 −2 README.md
  2. +16 −17 lib/formats.js
  3. +1 −1 package.json
  4. +1 −1 test/object-format-test.js
View
2 README.md
@@ -447,8 +447,6 @@ Example: `'09:13:24'`.
Example: `'^[0-9]{5}-[0-9]{4}$'`.
* color - A string containing a CSS color, based on CSS 2.1 [W3C.CR-CSS21-20070719].
Examples: `'red'`, `'#FF9900'`, `'f90'`, `'rgb(64, 224, 208)'`, `'rgb(100%, 0%, 25%)'`.
-* style - A string containing a CSS style definition, based on CSS 2.1 [W3C.CR-CSS21-20070719].
-Example: `'color: red; background-color:#FFF'`. This format is only partially supported: any string passes validation.
* phone - A string containing a national or international phone number, based on E.123.
No hypens allows, only spaces.
Examples: `'(42) 123 4567'`, `'+31 42 123 4567'`.
View
33 lib/formats.js
@@ -25,11 +25,6 @@ function validateFormatColor(obj) {
|| obj.match(colorsReRgbNum) || obj.match(colorsReRgbPerc);
}
-function validateFormatStyle(obj) {
- // TODO: enfore style-sheet declaration (W3C.CR-CSS21-20070719)
- return true;
-}
-
var phoneReNational = /^(\(\d+\)|\d+)( \d+)*$/;
var phoneReInternational = /^\+\d+( \d+)*$/;
@@ -42,34 +37,38 @@ var formats = {
types: ['string'],
regex: /^\d{4}-\d{2}-\d{2}T[0-2]\d:[0-5]\d:[0-5]\dZ$/
},
- 'date': {
+ 'date': { // YYYY-MM-DD
types: ['string'],
regex: /^\d{4}-\d{2}-\d{2}$/
- }, // YYYY-MM-DD
- 'time': {
+ },
+ 'time': { // hh:mm:ss
types: ['string'],
regex: /^[0-2]\d:[0-5]\d:[0-5]\d$/
- }, // hh:mm:ss
+ },
'utc-millisec': {
types: ['number', 'integer'],
func: validateFormatUtcMillisec
},
- 'regex': {
+ 'regex': { // ECMA 262/Perl 5
types: ['string'],
func: validateFormatRegExp
- }, // ECMA 262/Perl 5
- 'color': {
+ },
+ 'color': { // W3C.CR-CSS21-20070719
types: ['string'],
func: validateFormatColor
- }, // W3C.CR-CSS21-20070719
- 'style': {
+ },
+ /* TODO: support style
+ * style - A string containing a CSS style definition, based on CSS 2.1 [W3C.CR-CSS21-20070719].
+ Example: `'color: red; background-color:#FFF'`.
+
+ 'style': { // W3C.CR-CSS21-20070719
types: ['string'],
func: validateFormatStyle
- }, // W3C.CR-CSS21-20070719
- 'phone': {
+ },*/
+ 'phone': { // E.123
types: ['string'],
func: validateFormatPhone
- }, // E.123
+ },
'uri': {
types: ['string'],
regex: RegExp("^([a-z][a-z0-9+.-]*):(?://(?:((?:[a-z0-9-._~!$&'()*+,;=:]|%[0-9A-F]{2})*)@)?((?:[a-z0-9-._~!$&'()*+,;=]|%[0-9A-F]{2})*)(?::(\\d*))?(/(?:[a-z0-9-._~!$&'()*+,;=:@/]|%[0-9A-F]{2})*)?|(/?(?:[a-z0-9-._~!$&'()*+,;=:@]|%[0-9A-F]{2})+(?:[a-z0-9-._~!$&'()*+,;=:@/]|%[0-9A-F]{2})*)?)(?:\\?((?:[a-z0-9-._~!$&'()*+,;=:/?@]|%[0-9A-F]{2})*))?(?:#((?:[a-z0-9-._~!$&'()*+,;=:/?@]|%[0-9A-F]{2})*))?$", 'i')
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "json-gate",
"description": "A friendly, fast JSON schema validator",
- "version": "0.8.16",
+ "version": "0.8.17",
"author": {
"name": "Ofer Reichman",
"email": "oferei@gmail.com"
View
2 test/object-format-test.js
@@ -316,7 +316,7 @@ vows.describe('Object Format').addBatch({
'when a numeric rgb color is passed for a color': objectShouldBeValid(objColorRgbNum, schemaColor),
'when a percentile rgb color is passed for a color': objectShouldBeValid(objColorRgbPerc, schemaColor),
'when trying to pass a style for a color': objectShouldBeInvalid(objInvalidColor, schemaColor, { errMsg: 'JSON object property \'color\' does not conform to the \'color\' format' }),
- 'when a style is passed for a style': objectShouldBeValid(objStyle, schemaStyle),
+ //'when a style is passed for a style': objectShouldBeValid(objStyle, schemaStyle),
//'when trying to pass a phone for a style': objectShouldBeInvalid(objInvalidStyle, schemaStyle, { errMsg: 'JSON object property \'style\' does not conform to the \'style\' format' }),
'when a national phone is passed for a phone': objectShouldBeValid(objPhoneNational, schemaPhone),
'when a internation phone is passed for a phone': objectShouldBeValid(objPhoneInternational, schemaPhone),

0 comments on commit cd7ac6f

Please sign in to comment.
Something went wrong with that request. Please try again.