Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
ember-functional-validation
Advanced tools
Yet another validation library for EmberJS, this one takes a much more functional approach
An functional approach to object validations for emberjs.
This is just like Dockyard's ember validation library, except instead it builds a bunch of functions instead of being a bunch of object mixins that are advertised to work on all Ember.Objects, but actually only work on things with the container.
Suppose you have a comment model Declare your validating function somewhere
# app/validators/comment
import FunctionalValidation from 'ember-functional-validation'
commentValidator = FunctionalValidation.create
postName:
presence: true
opEmail:
format: /\w+@\w+\.com/
length:
min: 5
content:
presence: true
export default commentValidator
Then, because commentValidator is just a function, use it wherever you please.
# app/controller/posts/new
import commentValidator from 'app/validators/comment'
PostsNewController = Ember.Controller.extend
actions
newComment: (comment) ->
commentValidator comment
.then (validComment) ->
validComment.save()
...
.catch (errors) ->
@displayErrors errors
Note that the commentValidator always returns a promise
Because of the functional nature of your validator, you can compose them: (admittedly, although this feature is useful for building this library, I can't really think of an use-case for it in a real application)
import californianValidator from '../validators/californian'
import droughtVictimValidator from '../validators/drought-victim'
import compose from 'ember-functional-validation/utils/compose'
socalValidator = compose californianValidator, droughtVictomValidator
resident = store.createRecord "socalResident",
lowPayingJob: true
noWater: true
traffic: true
atLeastNotSF: true
socalValidator resident
.then (validResident) ->
validResident.save()
...
.catch (errors) ->
# do stuff with errors
The below is lifted almost bodily from dockyard's validation library:
https://raw.githubusercontent.com/dockyard/ember-validations/master/README.md
The sections not yet implemented are noted. (This is beta software, after all, and I'm writing this only because I actually need it, not because I'm trying to sell it to others)
Validates the property has a value that is null
, undefined
, or ''
true
- Passing just true
will activate validation and use default messagemessage
- Any string you wish to be the error message. Overrides i18n
.// Examples
absence: true
absence: { message: 'must be blank' }
not implemented yet
By default the values '1'
, 1
, and true
are the acceptable values
true
- Passing just true
will activate validation and use default messagemessage
- Any string you wish to be the error message. Overrides i18n
.accept
- the value for acceptance// Examples
acceptance: true
acceptance: { message: 'you must accept', accept: 'yes' }
not implemented yet
Expects a propertyConfirmation
to have the same value as
property
. The validation must be applied to the property
, not the propertyConfirmation
(otherwise it would expect a propertyConfirmationConfirmation
).
true
- Passing just true
will activate validation and use default messagemessage
- Any string you wish to be the error message. Overrides i18n
.// Examples
confirmation: true
confirmation: { message: 'you must confirm' }
not implemented yet A list of values that are not allowed
message
- Any string you wish to be the error message. Overrides i18n
.allowBlank
- If true
skips validation if value is emptyin
- An array of values that are excludedrange
- an array with the first element as the lower bound the and second element as the upper bound. Any value that falls within the range will be considered excluded// Examples
exclusion: { in: ['Yellow', 'Black', 'Red'] }
exclusion: { range: [5, 10], allowBlank: true, message: 'cannot be between 5 and 10' }
not implemented yet A regular expression to test with the value
message
- Any string you wish to be the error message. Overrides i18n
.allowBlank
- If true
skips validation if value is emptywith
- The regular expression to test with// Examples
format: { with: /^([a-zA-Z]|\d)+$/, allowBlank: true, message: 'must be letters and numbers only' }
not implemented yet A list of the only values allowed
message
- Any string you wish to be the error message. Overrides i18n
.allowBlank
- If true
skips validation if value is emptyin
- An array of values that are allowedrange
- an array with the first element as the lower bound the and
second element as the upper bound. Only values that fall within the range will be considered allowed// Examples
inclusion: { in: ['Yellow', 'Black', 'Red'] }
inclusion: { range: [5, 10], allowBlank: true, message: 'must be between 5 and 10' }
not implemented yet Define the lengths that are allowed
number
- Alias for is
array
- Will expand to minimum
and maximum
. First element is the lower bound, second element is the upper bound.allowBlank
- If true
skips validation if value is emptyminimum
- The minimum length of the value allowedmaximum
- The maximum length of the value allowedis
- The exact length of the value allowedtokenizer
- A function that should return a object that responds to length
tooShort
- the message used when the minimum
validation fails. Overrides i18n
tooLong
- the message used when the maximum
validation fails. Overrides i18n
wrongLength
- the message used when the is
validation fails. Overrides i18n
// Examples
length: 5
length: [3, 5]
length: { is: 10, allowBlank: true }
length: { minimum: 3, maximum: 5, messages: { tooShort: 'should be more than 3 characters', tooLong: 'should be less than 5 characters' } }
length: { is: 5, tokenizer: function(value) { return value.split(''); } }
not implemented yet Will ensure the value is a number
true
- Passing just true
will activate validation and use default messageallowBlank
- If true
skips validation if value is emptyonlyInteger
- Will only allow integersgreaterThan
- Ensures the value is greater thangreaterThanOrEqualTo
- Ensures the value is greater than or equal toequalTo
- Ensures the value is equal tolessThan
- Ensures the value is less thanlessThanOrEqualTo
- Ensures the value is less than or equal toodd
- Ensures the value is oddeven
- Ensures the value is evengreaterThan
- Message used when value failes to be greater than. Overrides i18n
greaterThanOrEqualTo
- Message used when value failes to be greater than or equal to. Overrides i18n
equalTo
- Message used when value failes to be equal to. Overrides i18n
lessThan
- Message used when value failes to be less than. Overrides i18n
lessThanOrEqualTo
- Message used when value failes to be less than or equal to. Overrides i18n
odd
- Message used when value failes to be odd. Overrides i18n
even
- Message used when value failes to be even. Overrides i18n
// Examples
numericality: true
numericality: { odd: true, messages: { odd: 'must be an odd number' } }
numericality: { onlyInteger: true, greaterThan: 5, lessThanOrEqualTo : 10 }
Validates the property has a value that is not null
, undefined
, or ''
true
- Passing just true
will activate validation and use default messagemessage
- Any string you wish to be the error message. Overrides i18n
.// Examples
presence: true
presence: { message: 'must not be blank' }
Not yet implemented.
not implemented yet
Each validator can take an if
or an unless
in its options
hash.
The value of the conditional can be an inline function, a string that
represents a property on the object, or a string that represents a
function on the object. The result should be a boolean.
note that if
is considered a keyword in IE8 and so you should put it
in quotes
// function form
firstName: {
presence: {
'if': function(object, validator) {
return true;
}
}
}
// string form
// if 'canValidate' is a function on the object it will be called
// if 'canValidate' is a property object.get('canValidate') will be called
firstName: {
presence: {
unless: 'canValidate'
}
}
Custom (or inline) validators take an arbitrary function which allow you to decide how to validate your model.
Have your custom function return null or a promise resolving to a null if validation passes.
have your function return a string or a promise to a string if validation fails.
email:
inline: (model) ->
store.find "user", Ember.get(model, "email")
.then (user) ->
return if user.get("isMasterrace")
"not master-race"
.catch ->
"cannot be found"
git clone
this repositorynpm install
bower install
ember server
ember test
ember test --server
ember build
For more information on using ember-cli, visit http://www.ember-cli.com/.
FAQs
Yet another validation library for EmberJS, this one takes a much more functional approach
The npm package ember-functional-validation receives a total of 0 weekly downloads. As such, ember-functional-validation popularity was classified as not popular.
We found that ember-functional-validation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.