Skip to content

Commit 8d8ae8c

Browse files
committed
Prefer function to method as type identifier.
Closes #47.
1 parent 8877fa7 commit 8d8ae8c

File tree

14 files changed

+30
-30
lines changed

14 files changed

+30
-30
lines changed

EXAMPLE.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ schema.validate(source, function(err, res) {
251251
// validate a field length
252252
var Schema = require('async-validate')
253253
, descriptor = {
254-
func: {type: 'method', required: true, len: 1}
254+
func: {type: 'function', required: true, len: 1}
255255
}
256256
, source = {func: function noop(){}}
257257
, schema;
@@ -276,7 +276,7 @@ schema.validate(source, function(err, res) {
276276
// validate a field has a maximum length
277277
var Schema = require('async-validate')
278278
, descriptor = {
279-
func: {type: 'method', required: true, max: 1}
279+
func: {type: 'function', required: true, max: 1}
280280
}
281281
, source = {func: function noop(foo, bar){}}
282282
, schema;
@@ -427,7 +427,7 @@ schema.validate(source, function(err, res) {
427427
// validate a field has a minimum length
428428
var Schema = require('async-validate')
429429
, descriptor = {
430-
func: {type: 'method', required: true, min: 1}
430+
func: {type: 'function', required: true, min: 1}
431431
}
432432
, source = {func: function noop(){}}
433433
, schema;
@@ -584,7 +584,7 @@ schema.validate(source, function(err, res) {
584584
// validate a field has a length within a range
585585
var Schema = require('async-validate')
586586
, descriptor = {
587-
func: {type: 'method', required: true, min: 1, max: 2}
587+
func: {type: 'function', required: true, min: 1, max: 2}
588588
}
589589
, source = {func: function noop(foo, bar, qux){}}
590590
, schema;
@@ -701,7 +701,7 @@ schema.validate(source, opts, function(err, res) {
701701
```
702702

703703
```
704-
[ { [Error: email: could not resolve dns for domain 1442394138490.com] field: 'email' } ]
704+
[ { [Error: email: could not resolve dns for domain 1442468604548.com] field: 'email' } ]
705705
```
706706

707707
#### type
@@ -761,4 +761,5 @@ Generated by [mdp(1)](https://github.com/freeformsystems/mdp).
761761
[mdp]: https://github.com/freeformsystems/mdp
762762
[browserify]: http://browserify.org/
763763
[jshint]: http://jshint.com/
764+
[jscs]: http://jscs.info/
764765
[zephyr]: https://github.com/socialally/zephyr

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ Recognised type values are:
312312
* `string`: Must be of type `string`.
313313
* `number`: Must be of type `number`.
314314
* `boolean`: Must be of type `boolean`.
315-
* `method`: Must be of type `function`.
315+
* `function`: Must be of type `function`.
316316
* `null`: Must strictly equal `null`.
317317
* `regexp`: Must be an instance of `RegExp` or a valid string regexp.
318318
* `integer`: Must be of type `number` and an integer.

doc/example/len.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// validate a field length
22
var Schema = require('../..')
33
, descriptor = {
4-
func: {type: 'method', required: true, len: 1}
4+
func: {type: 'function', required: true, len: 1}
55
}
66
, source = {func: function noop(){}}
77
, schema;

doc/example/max.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// validate a field has a maximum length
22
var Schema = require('../..')
33
, descriptor = {
4-
func: {type: 'method', required: true, max: 1}
4+
func: {type: 'function', required: true, max: 1}
55
}
66
, source = {func: function noop(foo, bar){}}
77
, schema;

doc/example/min.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// validate a field has a minimum length
22
var Schema = require('../..')
33
, descriptor = {
4-
func: {type: 'method', required: true, min: 1}
4+
func: {type: 'function', required: true, min: 1}
55
}
66
, source = {func: function noop(){}}
77
, schema;

doc/example/range.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// validate a field has a length within a range
22
var Schema = require('../..')
33
, descriptor = {
4-
func: {type: 'method', required: true, min: 1, max: 2}
4+
func: {type: 'function', required: true, min: 1, max: 2}
55
}
66
, source = {func: function noop(foo, bar, qux){}}
77
, schema;

doc/readme/guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Recognised type values are:
196196
* `string`: Must be of type `string`.
197197
* `number`: Must be of type `number`.
198198
* `boolean`: Must be of type `boolean`.
199-
* `method`: Must be of type `function`.
199+
* `function`: Must be of type `function`.
200200
* `null`: Must strictly equal `null`.
201201
* `regexp`: Must be an instance of `RegExp` or a valid string regexp.
202202
* `integer`: Must be of type `number` and an integer.

messages.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var messages = {
1414
types: {
1515
string: '%s is not a %s',
1616
null: '%s is not %s',
17-
method: '%s is not a %s',
17+
function: '%s is not a %s',
1818
instance: '%s is not an instance of %s',
1919
array: '%s is not an %s',
2020
object: '%s is not an %s',

plugin/all.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ rule.plugin([
66
require('./enum'),
77
require('./float'),
88
require('./integer'),
9-
require('./method'),
9+
require('./function'),
1010
require('./null'),
1111
require('./number'),
1212
require('./object'),

plugin/method.js renamed to plugin/function.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = function() {
55
*
66
* @param cb The callback function.
77
*/
8-
this.main.method = function method(cb) {
8+
this.main.function = function method(cb) {
99
if(this.validates()) {
1010
this.required();
1111
this.type();

plugin/util/type.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module.exports = function() {
7777
this.type();
7878
}
7979

80-
invalid = (this.errors.length - length) === types.length;
80+
invalid = (this.errors.length - length) === list.length;
8181
// remove raised errors
8282
this.errors = this.errors.slice(0, length);
8383

@@ -87,7 +87,7 @@ module.exports = function() {
8787
this.reasons.type,
8888
this.messages.types.multiple,
8989
this.field,
90-
types.map(function(type) {
90+
list.map(function(type) {
9191
if(typeof(type) === 'function') {
9292
return type.name || 'function (anonymous)';
9393
}

test/spec/method.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ var expect = require('chai').expect
44
describe('async-validate:', function() {
55

66
var descriptor = {
7-
mock: {type: 'method'},
7+
mock: {type: 'function'},
88
}
99

1010
it('should error on value that is not a function', function(done) {
1111
var schema = new Schema(descriptor);
1212
schema.validate({mock: 80}, function(err, res) {
1313
expect(res.errors.length).to.eql(1);
14-
expect(res.errors[0].message).to.eql('mock is not a method');
14+
expect(res.errors[0].message).to.eql('mock is not a function');
1515
done();
1616
});
1717
});
1818

1919
it('should error on invalid arity (len: 1)', function(done) {
2020
var descriptor = {
21-
mock: {type: 'method', len: 1},
21+
mock: {type: 'function', len: 1},
2222
}
2323
var schema = new Schema(descriptor);
2424
schema.validate({mock: function(){}}, function(err, res) {
@@ -32,7 +32,7 @@ describe('async-validate:', function() {
3232

3333
it('should error on invalid arity (min: 1)', function(done) {
3434
var descriptor = {
35-
mock: {type: 'method', min: 1},
35+
mock: {type: 'function', min: 1},
3636
}
3737
var schema = new Schema(descriptor);
3838
schema.validate({mock: function(){}}, function(err, res) {
@@ -45,7 +45,7 @@ describe('async-validate:', function() {
4545

4646
it('should error on invalid arity (max: 0)', function(done) {
4747
var descriptor = {
48-
mock: {type: 'method', max: 0},
48+
mock: {type: 'function', max: 0},
4949
}
5050
var schema = new Schema(descriptor);
5151
schema.validate({mock: function(foo){}}, function(err, res) {
@@ -58,7 +58,7 @@ describe('async-validate:', function() {
5858

5959
it('should error on invalid arity (min: 0, max: 1)', function(done) {
6060
var descriptor = {
61-
mock: {type: 'method', min: 0, max: 1},
61+
mock: {type: 'function', min: 0, max: 1},
6262
}
6363
var schema = new Schema(descriptor);
6464
schema.validate({mock: function(foo, bar){}}, function(err, res) {
@@ -69,7 +69,6 @@ describe('async-validate:', function() {
6969
});
7070
});
7171

72-
7372
it('should validate function type', function(done) {
7473
var schema = new Schema(descriptor);
7574
schema.validate({mock: function(){}}, function(err, res) {

test/spec/source.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -160,22 +160,22 @@ describe("async-validate:", function() {
160160
});
161161
});
162162

163-
it("should error on source as method type", function(done) {
164-
var descriptor = {type: 'method'}
163+
it("should error on source as function type", function(done) {
164+
var descriptor = {type: 'function'}
165165
, validator = new schema(descriptor)
166166
, source = 'foo';
167167

168168
validator.validate(source, function(err, res) {
169169
expect(err).to.eql(null);
170170
expect(res.errors.length).to.eql(1);
171171
expect(res.errors[0].message).to.eql(
172-
'source is not a method');
172+
'source is not a function');
173173
done();
174174
});
175175
});
176176

177-
it("should validate on source as method type", function(done) {
178-
var descriptor = {type: 'method'}
177+
it("should validate on source as function type", function(done) {
178+
var descriptor = {type: 'function'}
179179
, validator = new schema(descriptor)
180180
, source = function noop(){};
181181

test/spec/undef.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ describe('async-validate:', function() {
123123
});
124124
});
125125

126-
it('should allow undefined method field if not required', function(done) {
126+
it('should allow undefined function field if not required', function(done) {
127127
var descriptor = {
128-
mock: {type: 'method', required: false}
128+
mock: {type: 'function', required: false}
129129
}
130130
var schema = new Schema(descriptor);
131131
var source = {mock: undefined};

0 commit comments

Comments
 (0)