Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 0e0cbf19
authored
Nov 09, 2013
by
Sascha Depold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parameter validator supports optional parameters
1 parent
2bf4ea51
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
4 deletions
lib/utils/parameter-validator.js
test/utils.test.js
lib/utils/parameter-validator.js
View file @
0e0cbf1
...
...
@@ -3,9 +3,14 @@ var ParameterValidator = module.exports = {
options
=
Utils
.
_
.
extend
({
throwError
:
true
,
deprecated
:
false
,
onDeprecated
:
console
.
log
onDeprecated
:
console
.
log
,
optional
:
false
},
options
||
{})
if
(
options
.
optional
&&
(
value
===
undefined
))
{
return
true
}
if
(
value
===
undefined
)
{
throw
new
Error
(
'No value has been passed.'
)
}
...
...
@@ -14,9 +19,9 @@ var ParameterValidator = module.exports = {
throw
new
Error
(
'No expectation has been passed.'
)
}
validateDeprication
(
value
,
expectation
,
options
)
return
validate
(
value
,
expectation
,
options
)
return
false
||
validateDeprication
(
value
,
expectation
,
options
)
||
validate
(
value
,
expectation
,
options
)
}
}
...
...
@@ -32,6 +37,7 @@ var validateDeprication = function(value, expectation, options) {
if
(
options
.
deprecated
)
{
if
(
matchesExpectation
(
value
,
options
.
deprecated
))
{
options
.
onDeprecated
(
"Deprecated!"
)
return
true
}
}
}
...
...
test/utils.test.js
View file @
0e0cbf1
...
...
@@ -169,6 +169,12 @@ describe(Support.getTestDialectTeaser("Utils"), function() {
}).
to
.
throw
(
'No value has been passed.'
)
})
it
(
'does not throw an error if the value is not defined and the parameter is optional'
,
function
()
{
expect
(
function
()
{
Utils
.
validateParameter
(
undefined
,
Object
,
{
optional
:
true
})
}).
to
.
not
.
throw
()
})
it
(
'throws an error if the expectation is not defined'
,
function
()
{
expect
(
function
()
{
Utils
.
validateParameter
(
1
)
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment