Skip to content

Commit

Permalink
dojox/validate: api doc comment cleanup, refs #13101 !strict
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.dojotoolkit.org/src/dojox/trunk@28888 560b804f-0ae3-0310-86f3-f6aa0a117693
  • Loading branch information
wkeese committed Jun 17, 2012
1 parent 45fe4b1 commit a064dc9
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 251 deletions.
64 changes: 28 additions & 36 deletions validate/_base.js
Expand Up @@ -5,21 +5,18 @@ define([
"./regexp" // additional expressions
], function(lang, regexp, number, xregexp) {

var validate = lang.getObject("dojox.validate", true);
/*=====
validate = dojox.validate;
=====*/
var validate = lang.getObject("dojox.validate", true);

validate.isText = function(/*String*/value, /*Object?*/flags){
validate.isText = function(value, flags){
// summary:
// Checks if a string has non whitespace characters.
// Parameters allow you to constrain the length.
//
// value: A string
// flags: {length: Number, minlength: Number, maxlength: Number}
// flags.length If set, checks if there are exactly flags.length number of characters.
// flags.minlength If set, checks if there are at least flags.minlength number of characters.
// flags.maxlength If set, checks if there are at most flags.maxlength number of characters.
// Checks if a string has non whitespace characters.
// Parameters allow you to constrain the length.
// value: String
// flags: Object?
// {length: Number, minlength: Number, maxlength: Number}
// - flags.length If set, checks if there are exactly flags.length number of characters.
// - flags.minlength If set, checks if there are at least flags.minlength number of characters.
// - flags.maxlength If set, checks if there are at most flags.maxlength number of characters.

flags = (typeof flags == "object") ? flags : {};

Expand All @@ -36,16 +33,16 @@ validate.isText = function(/*String*/value, /*Object?*/flags){
};

validate._isInRangeCache = {};
validate.isInRange = function(/*String*/value, /*Object?*/flags){
validate.isInRange = function(value, flags){
// summary:
// Validates whether a string denoting a number
// is between a max and min.
//
// value: A string
// flags: {max:Number, min:Number, decimal:String}
// flags.max A number, which the value must be less than or equal to for the validation to be true.
// flags.min A number, which the value must be greater than or equal to for the validation to be true.
// flags.decimal The character used for the decimal point. Default is ".".
// Validates whether a string denoting a number
// is between a max and min.
// value: String
// flags: Object?
// {max:Number, min:Number, decimal:String}
// - flags.max A number, which the value must be less than or equal to for the validation to be true.
// - flags.min A number, which the value must be greater than or equal to for the validation to be true.
// - flags.decimal The character used for the decimal point. Default is ".".

value = number.parse(value, flags);
if(isNaN(value)){
Expand All @@ -70,9 +67,9 @@ validate.isInRange = function(/*String*/value, /*Object?*/flags){

};

validate.isNumberFormat = function(/* String */value, /* Object? */flags){
// summary: Validates any sort of number based format
//
validate.isNumberFormat = function(value, flags){
// summary:
// Validates any sort of number based format
// description:
// Validates any sort of number based format. Use it for phone numbers,
// social security numbers, zip-codes, etc. The value can be validated
Expand All @@ -89,18 +86,12 @@ validate.isNumberFormat = function(/* String */value, /* Object? */flags){
// | "###-##-####" -> 506-82-1089 i.e. social security number
// | "#####-####" -> 98225-1649 i.e. zip code
//
// value: A string
//
// value: String
// flags: Object?
// FIXME: make pseudo-object for this
// format: String
//
// flags.format A string or an Array of strings for multiple formats.
//
// - flags.format A string or an Array of strings for multiple formats.
// example:
// | // returns true:
// | dojox.validate.isNumberFormat("123-45", { format:"###-##" });
//
// | // returns true:
// | dojox.validate.isNumberFormat("123-45", { format:"###-##" });
// example:
// Check Multiple formats:
// | dojox.validate.isNumberFormat("123-45", {
Expand All @@ -113,7 +104,8 @@ validate.isNumberFormat = function(/* String */value, /* Object? */flags){
};

validate.isValidLuhn = function(/* String */value){
// summary: Validate a String value against the Luhn algorithm.
// summary:
// Validate a String value against the Luhn algorithm.
// description:
// Validate a String value against the Luhn algorithm to verify
// its integrity.
Expand Down
10 changes: 4 additions & 6 deletions validate/br.js
Expand Up @@ -4,7 +4,6 @@ var br = lang.getObject("br", true, validate);
br.isValidCnpj = function(/*String*/value){
// summary:
// Validates a CNPJ/CGC number
//
// value: String
// The CNPJ/CGC number in ##.###.###/####-##, ########/####-##,
// ############-## or ############## format
Expand Down Expand Up @@ -78,9 +77,10 @@ br.isValidCnpj = function(/*String*/value){
};

br.computeCnpjDv = function(/*String*/value){
// summary: Generate the DV code (checksum part) for a Cnpj number
//
// value: The CGC number in ##.###.###/#### or ############ format
// summary:
// Generate the DV code (checksum part) for a Cnpj number
// value:
// The CGC number in ##.###.###/#### or ############ format
if(!lang.isString(value)){
if(!value){
return "";
Expand Down Expand Up @@ -141,7 +141,6 @@ br.computeCnpjDv = function(/*String*/value){
br.isValidCpf = function(/*String*/value){
// summary:
// Validates a CPF number
//
// value: String
// The CPF number in #########-## or ###########,
// format
Expand Down Expand Up @@ -216,7 +215,6 @@ br.isValidCpf = function(/*String*/value){
br.computeCpfDv = function(/*String*/value){
// summary:
// Generate the DV code (checksum part) for a CPF number
//
// value: String
// The CPF number in ######### format
if(!lang.isString(value)){
Expand Down
28 changes: 14 additions & 14 deletions validate/ca.js
@@ -1,49 +1,49 @@
define(["dojo/_base/lang", "./_base", "./regexp", "./us"],
function(lang, validate, xregexp, us){
/*=====
dojox.validate.ca = {
// summary: Module which includes Canadian-specific methods for dojox.validate
}

var ca = lang.getObject("ca", true, validate);
/*=====
ca = {
// summary:
// Module which includes Canadian-specific methods for dojox.validate
};
=====*/

var ca = lang.getObject("ca", true, validate);
lang.mixin(ca, {

isPhoneNumber: function(/* String */value){
// summary: Validates Canadian 10-digit phone number for several common formats
// summary:
// Validates Canadian 10-digit phone number for several common formats
return us.isPhoneNumber(value); // Boolean
},

isProvince: function(/* String[2] */value) {
// summary: Validates Canadian province abbreviations (2 characters)
// summary:
// Validates Canadian province abbreviations (2 characters)
var re = new RegExp("^" + xregexp.ca.province() + "$", "i");
return re.test(value); // Boolean
},

isSocialInsuranceNumber: function(/* String */value) {
// summary: Validates Canadian 9 digit social insurance number for several
// summary:
// Validates Canadian 9 digit social insurance number for several
// common formats
//
// description:
// Validates Canadian 9 digit social insurance number for several
// common formats. This routine only pattern matches and does not
// use the Luhn Algorithm to validate number.
//
var flags = { format: [ "###-###-###", "### ### ###", "#########" ]};
return validate.isNumberFormat(value, flags); // Boolean
},

isPostalCode: function(value) {
// summary: Validates Canadian 6 digit postal code
//
// summary:
// Validates Canadian 6 digit postal code
// description:
// Validates Canadian 6 digit postal code.
// Canadian postal codes are in the format ANA NAN,
// where A is a letter and N is a digit, with a space
// separating the third and fourth characters.
//
var re = new RegExp("^" + xregexp.ca.postalCode() + "$", "i");
return re.test(value); // Boolean
}
Expand Down
55 changes: 27 additions & 28 deletions validate/check.js
Expand Up @@ -2,11 +2,6 @@ define(["dojo/_base/kernel", "dojo/_base/lang", "./_base"],
function(kernel, lang, validate){
kernel.experimental("dojox.validate.check");

/*=====
validate = dojox.validate;
=====*/
/**
FIXME: How much does this overlap with dojox.form.Manager and friends?
Expand Down Expand Up @@ -75,15 +70,16 @@ kernel.experimental("dojox.validate.check");
*/

validate.check = function(/*HTMLFormElement*/form, /*Object*/profile){
// summary: validates user input of an HTML form based on input profile
//
// summary:
// validates user input of an HTML form based on input profile
// description:
// returns an object that contains several methods summarizing the results of the validation
//
// form: form to be validated
// profile: specifies how the form fields are to be validated
// {trim:Array, uppercase:Array, lowercase:Array, ucfirst:Array, digit:Array,
// required:Array, dependencies:Object, constraints:Object, confirm:Object}
// returns an object that contains several methods summarizing the results of the validation
// form:
// form to be validated
// profile:
// specifies how the form fields are to be validated
// {trim:Array, uppercase:Array, lowercase:Array, ucfirst:Array, digit:Array,
// required:Array, dependencies:Object, constraints:Object, confirm:Object}

// Essentially private properties of results object
var missing = [];
Expand Down Expand Up @@ -300,24 +296,27 @@ validate.check = function(/*HTMLFormElement*/form, /*Object*/profile){
//TODO: evaluateConstraint doesn't use profile or fieldName args?
validate.evaluateConstraint=function(profile, /*Array*/constraint, fieldName, elem){
// summary:
// Evaluates dojo.validate.check() constraints that are specified as array
// arguments
//
// description: The arrays are expected to be in the format of:
// constraints:{
// fieldName: [functionToCall, param1, param2, etc.],
// fieldName: [[functionToCallFirst, param1],[functionToCallSecond,param2]]
// }
// Evaluates dojo.validate.check() constraints that are specified as array
// arguments
// description:
// The arrays are expected to be in the format of:
// | constraints:{
// | fieldName: [functionToCall, param1, param2, etc.],
// | fieldName: [[functionToCallFirst, param1],[functionToCallSecond,param2]]
// | }
//
// This function evaluates a single array function in the format of:
// This function evaluates a single array function in the format of:
// [functionName, argument1, argument2, etc]
//
// The function will be parsed out and evaluated against the incoming parameters.
//
// profile: The dojo.validate.check() profile that this evaluation is against.
// constraint: The single [] array of function and arguments for the function.
// fieldName: The form dom name of the field being validated.
// elem: The form element field.
// The function will be parsed out and evaluated against the incoming parameters.
// profile:
// The dojo.validate.check() profile that this evaluation is against.
// constraint:
// The single [] array of function and arguments for the function.
// fieldName:
// The form dom name of the field being validated.
// elem:
// The form element field.

var isValidSomething = constraint[0];
var params = constraint.slice(1);
Expand Down
30 changes: 9 additions & 21 deletions validate/creditCard.js
@@ -1,21 +1,17 @@
define(["dojo/_base/lang", "./_base"], function(lang, validate){
/*=====

dojox.validate.creditCard = {
/*=====
return {
// summary:
// Module provides validation functions for Credit Cards, using account number
// rules in conjunction with the Luhn algorigthm, with a plugable card info database.
// rules in conjunction with the Luhn algorigthm, with a pluggable card info database.
};
validate = dojox.validate;
=====*/

validate._cardInfo = {
// summary: A dictionary list of credit card abbreviations
//
// summary:
// A dictionary list of credit card abbreviations
// description:
//
// A hash of valid CC abbreviations and regular expressions
//
// mc: Mastercard
Expand All @@ -28,7 +24,7 @@ validate._cardInfo = {
// jcb: JCB
// er: Enroute
//
// example:
// example:
// Define your own card, gift-card, whatever. Starts with 7,
// is 15 total length.
// | dojo.mixin(dojox.validate._cardInfo, {
Expand All @@ -47,19 +43,16 @@ validate._cardInfo = {
};

validate.isValidCreditCard = function(value, ccType){
// summary: Validate a credit card number by type with Luhn checking.
//
// summary:
// Validate a credit card number by type with Luhn checking.
// description:
// Checks if a credit card type matches the # scheme in a passed value, and if
// the Luhn checksum is accurate (unless its an Enroute card, in which case
// the checkSum is skipped), returning a Boolean to check against.
//
// value: String|Int
// A Value (credit card number) to validate
//
// ccType: String
// A credit-card abbreviation.
//
// example:
// | if(dojox.validate.isValidCreditCard("12345", "mc")){
// | console.log('inconceivable');
Expand All @@ -72,10 +65,8 @@ validate.isValidCreditCard = function(value, ccType){
validate.isValidCreditCardNumber = function(value, ccType){
// summary:
// Checks if value matches the pattern for that card or any card types if none is specified
//
// value: String|Int
// CC #, white spaces and dashes are ignored
//
// ccType: String?
// One of the abbreviation values in `dojox.validate._cardInfo` --
// if Omitted, function returns a `|` delimited string of matching card types,
Expand All @@ -100,10 +91,6 @@ validate.isValidCreditCardNumber = function(value, ccType){
validate.isValidCvv = function(/* String|Int */value, /* String */ccType) {
// summary:
// Validate the security code (CCV) for a passed credit-card type.
//
// description:
//
// value:

if(!lang.isString(value)){
value = String(value);
Expand All @@ -124,5 +111,6 @@ validate.isValidCvv = function(/* String|Int */value, /* String */ccType) {
return !!format && value.length && validate.isNumberFormat(value, { format: format }); // Boolean
};

// TODO: return functions defined in this module, rather than sticking them into "validate"
return validate;
});
11 changes: 2 additions & 9 deletions validate/isbn.js
@@ -1,15 +1,8 @@
define(["dojo/_base/lang", "./_base"], function(lang, validate){
// summary: Provides ISBN validation functions in `dojox.validate`
//

/*=====
validate = dojox.validate;
=====*/

validate.isValidIsbn = function(/* String */value) {
// summary: Validate ISBN-10 or ISBN-13 based on the length of value
// summary:
// Validate ISBN-10 or ISBN-13 based on the length of value
// value: String
// An ISBN to validate
// returns: Boolean
Expand Down

0 comments on commit a064dc9

Please sign in to comment.