Comparing version 0.1.1 to 0.1.2
@@ -74,3 +74,3 @@ /*jslint node: true */ | ||
f.toHTML = function (name, iterator) { | ||
return (iterator || forms.render.div)(name, this); | ||
return (iterator || forms.render.div)(name || this.name, this); | ||
}; | ||
@@ -77,0 +77,0 @@ |
@@ -15,2 +15,5 @@ /*jslint node: true */ | ||
exports.create = function (fields) { | ||
Object.keys(fields).forEach(function (k) { | ||
fields[k].name = k; | ||
}); | ||
var f = { | ||
@@ -48,3 +51,3 @@ fields: fields, | ||
handle: function (obj, callbacks) { | ||
if (typeof obj === 'undefined' || obj === null) { | ||
if (typeof obj === 'undefined' || obj === null || (typeof obj === 'object' && Object.keys(obj).length === 0)) { | ||
(callbacks.empty || callbacks.other)(f); | ||
@@ -51,0 +54,0 @@ } else if (obj instanceof http.IncomingMessage) { |
@@ -27,3 +27,3 @@ /*jslint node: true */ | ||
'<tr class="', field.classes().join(' '), '">', | ||
'<th>', field.labelHTML(name), '</th>', | ||
'<th>', field.labelHTML(name, field.id), '</th>', | ||
'<td>', | ||
@@ -30,0 +30,0 @@ field.errorHTML(), |
@@ -90,6 +90,9 @@ /*jslint node: true */ | ||
exports.url = function () { | ||
exports.url = function (include_localhost) { | ||
// regular expression by Scott Gonzalez: | ||
// http://projects.scottsplayground.com/iri/ | ||
return exports.regexp(/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i, 'Please enter a valid URL.'); | ||
var external_regex = /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i, | ||
with_localhost_regex = /^(https?|ftp):\/\/(localhost|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i; | ||
return exports.regexp(include_localhost ? with_localhost_regex : external_regex, 'Please enter a valid URL.'); | ||
}; | ||
@@ -6,3 +6,3 @@ { | ||
"author": "Caolan McMahon", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -185,4 +185,4 @@ var forms = require('../lib/forms'), | ||
exports['handle error'] = function(test){ | ||
test.expect(7); | ||
exports['handle empty object'] = function(test){ | ||
test.expect(3); | ||
var f = forms.create({field1: forms.fields.string()}); | ||
@@ -201,2 +201,38 @@ f.bind = function(raw_data, callback){ | ||
empty: function(form){ | ||
test.ok(true, 'empty called'); | ||
test.equals(form, f); | ||
}, | ||
success: function(form){ | ||
test.ok(false, 'success should not be called'); | ||
}, | ||
error: function(form){ | ||
test.ok(false, 'error should not be called'); | ||
}, | ||
other: function(form){ | ||
test.ok(false, 'other should not be called'); | ||
} | ||
}); | ||
f.handle({}, { | ||
other: function(form){ | ||
test.ok(true, 'other called'); | ||
} | ||
}); | ||
setTimeout(test.done, 50); | ||
}; | ||
exports['handle error'] = function(test){ | ||
test.expect(5); | ||
var f = forms.create({field1: forms.fields.string()}); | ||
f.bind = function(raw_data, callback){ | ||
test.ok(true, 'bind called'); | ||
f.fields.field1.error = 'some error'; | ||
f.isValid = function(){return false;}; | ||
return f; | ||
}; | ||
f.validate = function(callback){ | ||
test.ok(true, 'validate called'); | ||
callback(null, f); | ||
}; | ||
f.handle({foo: 'bar'}, { | ||
empty: function(form){ | ||
test.ok(false, 'empty should not be called'); | ||
@@ -203,0 +239,0 @@ }, |
@@ -87,3 +87,11 @@ var validators = require('../lib/forms').validators, | ||
}); | ||
}) | ||
}); | ||
validators.url(true)('form', {data: 'localhost/test.html'}, function (err) { | ||
test.equals(err, 'Please enter a valid URL.'); | ||
validators.url(true)('form', {data: 'http://localhost/test.html'}, function (err) { | ||
test.equals(err, undefined); | ||
test.done(); | ||
}); | ||
}); | ||
}; | ||
@@ -90,0 +98,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
96469
2428
0
6