Comparing version 0.9.6 to 0.10.0
/*jslint node: true */ | ||
'use strict'; | ||
var forms = require('./forms'), | ||
tag = require('./tag'), | ||
is = require('is'), | ||
async = require('async'), | ||
validators = require('./validators'), | ||
coerceArray = function (arr) { | ||
return Array.isArray(arr) && arr.length > 0 ? arr : []; | ||
}, | ||
copy = function (original) { | ||
return Object.keys(original).reduce(function (copy, key) { | ||
copy[key] = original[key]; | ||
return copy; | ||
}, {}); | ||
}, | ||
nameSeparatorRegExp = /[_-]/g; | ||
var forms = require('./forms'); | ||
var tag = require('./tag'); | ||
var is = require('is'); | ||
var async = require('async'); | ||
var validators = require('./validators'); | ||
var coerceArray = function (arr) { | ||
return Array.isArray(arr) && arr.length > 0 ? arr : []; | ||
}; | ||
var assign = require('object.assign'); | ||
var nameSeparatorRegExp = /[_-]/g; | ||
@@ -24,3 +19,3 @@ | ||
var f = copy(opt); | ||
var f = assign({}, opt); | ||
f.widget = f.widget || forms.widgets.text(opt.attrs || {}); | ||
@@ -35,3 +30,3 @@ | ||
f.bind = function (raw_data) { | ||
var b = copy(f); // clone field object: | ||
var b = assign({}, f); // clone field object: | ||
b.value = raw_data; | ||
@@ -122,6 +117,6 @@ b.data = b.parse(raw_data); | ||
exports.boolean = function (opt) { | ||
if (!opt) { opt = {}; } | ||
var f = exports.string(opt); | ||
var opts = assign({}, opt); | ||
var f = exports.string(opts); | ||
f.widget = opt.widget || forms.widgets.checkbox(opt.attrs || {}); | ||
f.widget = opts.widget || forms.widgets.checkbox(opts.attrs || {}); | ||
f.parse = function (raw_data) { | ||
@@ -134,3 +129,3 @@ return !!raw_data; | ||
exports.email = function (opt) { | ||
var opts = opt ? copy(opt) : {}; | ||
var opts = assign({}, opt); | ||
if (!opts.widget) { opts.widget = forms.widgets.email(opts.attrs || {}); } | ||
@@ -147,3 +142,3 @@ var f = exports.string(opts); | ||
exports.tel = function (opt) { | ||
var opts = opt ? copy(opt) : {}; | ||
var opts = assign({}, opt); | ||
if (!opts.widget) { opts.widget = forms.widgets.tel(opts.attrs || {}); } | ||
@@ -154,5 +149,5 @@ return exports.string(opts); | ||
exports.password = function (opt) { | ||
if (!opt) { opt = {}; } | ||
var f = exports.string(opt); | ||
f.widget = opt.widget || forms.widgets.password(opt.attrs || {}); | ||
var opts = assign({}, opt); | ||
var f = exports.string(opts); | ||
f.widget = opts.widget || forms.widgets.password(opts.attrs || {}); | ||
return f; | ||
@@ -162,4 +157,4 @@ }; | ||
exports.url = function (opt) { | ||
if (!opt) { opt = {}; } | ||
var f = exports.string(opt); | ||
var opts = assign({}, opt); | ||
var f = exports.string(opts); | ||
if (f.validators) { | ||
@@ -174,4 +169,4 @@ f.validators.unshift(forms.validators.url()); | ||
exports.array = function (opt) { | ||
if (!opt) { opt = {}; } | ||
var f = exports.string(opt); | ||
var opts = assign({}, opt); | ||
var f = exports.string(opts); | ||
f.parse = function (raw_data) { | ||
@@ -185,4 +180,4 @@ if (typeof raw_data === 'undefined') { return []; } | ||
exports.date = function (opt) { | ||
if (!opt) { opt = {}; } | ||
var f = exports.string(opt); | ||
var opts = assign({}, opt); | ||
var f = exports.string(opts); | ||
if (f.validators) { | ||
@@ -197,4 +192,4 @@ f.validators.unshift(forms.validators.date()); | ||
exports.object = function (fields, opts) { | ||
return forms.create(fields || {}); | ||
return forms.create(fields || {}, opts); | ||
}; | ||
/*jslint node: true */ | ||
'use strict'; | ||
var async = require('async'), | ||
is = require('is'), | ||
http = require('http'), | ||
querystring = require('qs'), | ||
parse = require('url').parse, | ||
formidable = require('formidable'); | ||
var async = require('async'); | ||
var is = require('is'); | ||
var http = require('http'); | ||
var querystring = require('qs'); | ||
var parse = require('url').parse; | ||
var formidable = require('formidable'); | ||
exports.widgets = require('./widgets'); | ||
@@ -13,0 +12,0 @@ exports.fields = require('./fields'); |
@@ -7,8 +7,8 @@ /* | ||
var rAmp = /&/g, | ||
rLt = /</g, | ||
rGt = />/g, | ||
rApos = /\'/g, | ||
rQuot = /\"/g, | ||
hChars = /[&<>\"\']/; | ||
var rAmp = /&/g; | ||
var rLt = /</g; | ||
var rGt = />/g; | ||
var rApos = /\'/g; | ||
var rQuot = /\"/g; | ||
var hChars = /[&<>\"\']/; | ||
@@ -15,0 +15,0 @@ var coerceToString = function (val) { |
@@ -67,4 +67,4 @@ /*jslint node: true */ | ||
var validator = function (form, field, callback) { | ||
var alternateBlank = trim(form.fields[alternate_field].data).length === 0, | ||
fieldBlank = trim(field.data).length === 0; | ||
var alternateBlank = trim(form.fields[alternate_field].data).length === 0; | ||
var fieldBlank = trim(field.data).length === 0; | ||
if (alternateBlank && fieldBlank) { | ||
@@ -192,5 +192,5 @@ callback(format(message, field.name, alternate_field)); | ||
return function (form, field, callback) { | ||
var parts = field.data ? field.data.split('-') : [], | ||
allNumbers = parts.every(function (part) { return numberRegex.test(part); }), | ||
date = allNumbers && parts.length === 3 ? new Date(parts[0], parts[1] - 1, parts[2]) : invalidDate; | ||
var parts = field.data ? field.data.split('-') : []; | ||
var allNumbers = parts.every(function (part) { return numberRegex.test(part); }); | ||
var date = allNumbers && parts.length === 3 ? new Date(parts[0], parts[1] - 1, parts[2]) : invalidDate; | ||
if (!isNaN(date.getTime())) { | ||
@@ -197,0 +197,0 @@ callback(); |
@@ -7,14 +7,14 @@ /*jslint node: true */ | ||
var dataRegExp = /^data-[a-z]+([-][a-z]+)*$/, | ||
ariaRegExp = /^aria-[a-z]+$/, | ||
legalAttrs = ['autocomplete', 'autocorrect', 'autofocus', 'autosuggest', 'checked', 'dirname', 'disabled', 'tabindex', 'list', 'max', 'maxlength', 'min', 'multiple', 'novalidate', 'pattern', 'placeholder', 'readonly', 'required', 'size', 'step'], | ||
ignoreAttrs = ['id', 'name', 'class', 'classes', 'type', 'value'], | ||
getUserAttrs = function (opt) { | ||
return Object.keys(opt).reduce(function (attrs, k) { | ||
if ((ignoreAttrs.indexOf(k) === -1 && legalAttrs.indexOf(k) > -1) || dataRegExp.test(k) || ariaRegExp.test(k)) { | ||
attrs[k] = opt[k]; | ||
} | ||
return attrs; | ||
}, {}); | ||
}; | ||
var dataRegExp = /^data-[a-z]+([-][a-z]+)*$/; | ||
var ariaRegExp = /^aria-[a-z]+$/; | ||
var legalAttrs = ['autocomplete', 'autocorrect', 'autofocus', 'autosuggest', 'checked', 'dirname', 'disabled', 'tabindex', 'list', 'max', 'maxlength', 'min', 'multiple', 'novalidate', 'pattern', 'placeholder', 'readonly', 'required', 'size', 'step']; | ||
var ignoreAttrs = ['id', 'name', 'class', 'classes', 'type', 'value']; | ||
var getUserAttrs = function (opt) { | ||
return Object.keys(opt).reduce(function (attrs, k) { | ||
if ((ignoreAttrs.indexOf(k) === -1 && legalAttrs.indexOf(k) > -1) || dataRegExp.test(k) || ariaRegExp.test(k)) { | ||
attrs[k] = opt[k]; | ||
} | ||
return attrs; | ||
}, {}); | ||
}; | ||
@@ -21,0 +21,0 @@ // used to generate different input elements varying only by type attribute |
@@ -6,3 +6,3 @@ { | ||
"author": "Caolan McMahon", | ||
"version": "0.9.6", | ||
"version": "0.10.0", | ||
"repository": { | ||
@@ -24,12 +24,14 @@ "type": "git", | ||
"async": "~0.9.0", | ||
"qs": "~2.2.2", | ||
"qs": "~2.2.4", | ||
"formidable": "~1.0.15", | ||
"is": "~2.0.1" | ||
"is": "~2.0.1", | ||
"object.assign": "~1.0.1" | ||
}, | ||
"devDependencies": { | ||
"tape": "~2.14.0", | ||
"testling": "~1.7.0", | ||
"tape": "~3.0.0", | ||
"testling": "~1.7.1", | ||
"covert": "~1.0.0", | ||
"jscs": "~1.6.1" | ||
"jscs": "~1.6.2" | ||
}, | ||
"license": "MIT", | ||
"licenses": [ | ||
@@ -36,0 +38,0 @@ { |
@@ -1,6 +0,10 @@ | ||
# Forms <sup>[![Version Badge][9]][8]</sup> | ||
# Forms <sup>[![Version Badge][npm-version-svg]][npm-url]</sup> | ||
[![Build Status][1]][2] [![dependency status][3]][4] [![dev dependency status][5]][6] | ||
[![Build Status][travis-svg]][travis-url] | ||
[![dependency status][deps-svg]][deps-url] | ||
[![dev dependency status][dev-deps-svg]][dev-deps-url] | ||
[![License][license-image]][license-url] | ||
[![Downloads][downloads-image]][downloads-url] | ||
[![npm badge][7]][8] | ||
[![npm badge][npm-badge-png]][npm-url] | ||
@@ -387,11 +391,15 @@ Constructing a good form by hand is a lot of work. Popular frameworks like | ||
[1]: https://travis-ci.org/caolan/forms.svg | ||
[2]: https://travis-ci.org/caolan/forms | ||
[3]: https://david-dm.org/caolan/forms.svg | ||
[4]: https://david-dm.org/caolan/forms | ||
[5]: https://david-dm.org/caolan/forms/dev-status.svg | ||
[6]: https://david-dm.org/caolan/forms#info=devDependencies | ||
[7]: https://nodei.co/npm/forms.png?downloads=true&stars=true | ||
[8]: https://npmjs.org/package/forms | ||
[9]: http://vb.teelaun.ch/caolan/forms.svg | ||
[travis-svg]: https://travis-ci.org/caolan/forms.svg | ||
[travis-url]: https://travis-ci.org/caolan/forms | ||
[deps-svg]: https://david-dm.org/caolan/forms.svg | ||
[deps-url]: https://david-dm.org/caolan/forms | ||
[dev-deps-svg]: https://david-dm.org/caolan/forms/dev-status.svg | ||
[dev-deps-url]: https://david-dm.org/caolan/forms#info=devDependencies | ||
[npm-badge-png]: https://nodei.co/npm/forms.png?downloads=true&stars=true | ||
[npm-url]: https://npmjs.org/package/forms | ||
[npm-version-svg]: http://vb.teelaun.ch/caolan/forms.svg | ||
[license-image]: http://img.shields.io/npm/l/forms.svg | ||
[license-url]: LICENSE | ||
[downloads-image]: http://img.shields.io/npm/dm/forms.svg | ||
[downloads-url]: http://npm-stat.com/charts.html?package=forms | ||
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
162217
405
5
3924
+ Addedobject.assign@~1.0.1
+ Addedobject-keys@1.0.12(transitive)
+ Addedobject.assign@1.0.3(transitive)
Updatedqs@~2.2.4