mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
Add type definition for valdr (https://www.npmjs.com/package/valdr)
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/// <reference path="valdr-message.d.ts" />
|
||||
|
||||
function ValdrMessageTests() {
|
||||
var valdrMessage: valdr.message.IValdrMessage;
|
||||
|
||||
valdrMessage.templateUrl = 'valdrMesssageTemplate.html';
|
||||
valdrMessage.translateAvailable = true;
|
||||
valdrMessage.angularMessagesEnabled = true;
|
||||
valdrMessage.setTemplate('<div class="valdr-message">{{ violation.message }}</div>');
|
||||
valdrMessage.addMessages({
|
||||
'required': 'This field is required.',
|
||||
'number': 'Not a valid number.'
|
||||
});
|
||||
var message = valdrMessage.getMessage("person", "lastName", "required");
|
||||
}
|
||||
|
||||
function ValdrMessageProviderTests() {
|
||||
var valdrMessageProvider: valdr.message.IValdrMessageProvider;
|
||||
valdrMessageProvider.setTemplate('<div class="valdr-message" > {{ violation.message }}</div>');
|
||||
valdrMessageProvider.setTemplateUrl('valdrMesssageTemplate.html');
|
||||
valdrMessageProvider.addMessages({
|
||||
'person.lastName.required': 'This last name is required.',
|
||||
'person.age.number': 'The age has to be a number.'
|
||||
});
|
||||
var message = valdrMessageProvider.getMessage("person", "lastName", "required");
|
||||
}
|
||||
Vendored
+74
@@ -0,0 +1,74 @@
|
||||
// Type definitions for valdr.js v1.1.5 (valdr-message)
|
||||
// Project: https://github.com/netceteragroup/valdr
|
||||
// Definitions by: Kai Ilbertz <https://github.com/ilbertz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace valdr.message {
|
||||
|
||||
interface IValdrMessage {
|
||||
/**
|
||||
* Default message template URL.
|
||||
*/
|
||||
templateUrl: string;
|
||||
|
||||
/**
|
||||
* A boolean that shows if Angular-translate is available.
|
||||
*/
|
||||
translateAvailable: boolean;
|
||||
|
||||
/**
|
||||
* A boolean that allows to show messages for the AngularJS built-in validators like 'required' or 'number'.
|
||||
*/
|
||||
angularMessagesEnabled: boolean;
|
||||
|
||||
/**
|
||||
* Sets the default message template.
|
||||
* @param template the default message template (eg "<div class="valdr-message">{{ violation.message }}</div>").
|
||||
*/
|
||||
setTemplate(template: string): void;
|
||||
|
||||
/**
|
||||
* Adds messages for AngularJS build-in validators (eg "required" and "number") or for specific fields (eg "Person.lastName.required").
|
||||
* @param messages the list of key/value pairs.
|
||||
*/
|
||||
addMessages(messages: any): void;
|
||||
|
||||
/**
|
||||
* Gets the validator message.
|
||||
* @param typeName the name of the type.
|
||||
* @param fieldName the name of the field.
|
||||
* @param validatorName the name of the validator.
|
||||
* @returns {string} the message.
|
||||
*/
|
||||
getMessage(typeName: string, fieldName: string, validatorName: string): string;
|
||||
}
|
||||
|
||||
interface IValdrMessageProvider {
|
||||
/**
|
||||
* Sets the default message template.
|
||||
* @param template the default message template (eg "<div class="valdr-message">{{ violation.message }}</div>").
|
||||
*/
|
||||
setTemplate(template: string): void;
|
||||
|
||||
/**
|
||||
* Sets the URL for the default message template (eg "/partials/valdrMesssageTemplate.html").
|
||||
* @param url the URL of the default message template.
|
||||
*/
|
||||
setTemplateUrl(url: string): void;
|
||||
|
||||
/**
|
||||
* Adds messages for AngularJS build-in validators (eg "required" and "number") or for specific fields (eg "Person.lastName.required").
|
||||
* @param messages the list of key/value pairs.
|
||||
*/
|
||||
addMessages(messages: any): void;
|
||||
|
||||
/**
|
||||
* Gets the validator message.
|
||||
* @param typeName the name of the type.
|
||||
* @param fieldName the name of the field.
|
||||
* @param validatorName the name of the validator.
|
||||
* @returns {string} the message.
|
||||
*/
|
||||
getMessage(typeName: string, fieldName: string, validatorName: string): string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/// <reference path="valdr.d.ts" />
|
||||
|
||||
function ValdrTests() {
|
||||
var valdr: valdr.IValdr;
|
||||
var validation = valdr.validate('person', 'lastName', 'test');
|
||||
valdr.addConstraints({
|
||||
'person': {
|
||||
'lastName': {
|
||||
'required': {
|
||||
'message': 'Last name is required.'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
valdr.removeConstraints('person');
|
||||
var constraints = valdr.getConstraints();
|
||||
valdr.setClasses({
|
||||
valid: 'demo-is-valid',
|
||||
invalid: 'demo-is-invalid'
|
||||
});
|
||||
}
|
||||
|
||||
function ValdrProviderTests() {
|
||||
var valdrProvider: valdr.IValdrProvider;
|
||||
valdrProvider.addConstraints({
|
||||
'person': {
|
||||
'lastName': {
|
||||
'required': {
|
||||
'message': 'Last name is required.'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
valdrProvider.removeConstraints('person');
|
||||
valdrProvider.setConstraintUrl('/api/constraints');
|
||||
valdrProvider.addValidator('customValidator');
|
||||
valdrProvider.addConstraintAlias('customValidator', 'customValidatorAlias');
|
||||
}
|
||||
Vendored
+75
@@ -0,0 +1,75 @@
|
||||
// Type definitions for valdr.js v1.1.5
|
||||
// Project: https://github.com/netceteragroup/valdr
|
||||
// Definitions by: Kai Ilbertz <https://github.com/ilbertz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace valdr {
|
||||
|
||||
interface IValdr {
|
||||
/**
|
||||
* Validates the value of the given type with the constraints for the given field name.
|
||||
* @param typeName the type name.
|
||||
* @param fieldName the field name.
|
||||
* @param value the value to validate.
|
||||
* @returns {*} the validation result.
|
||||
*/
|
||||
validate(typeName: string, fieldName: string, value: string): any;
|
||||
|
||||
/**
|
||||
* Adds a new list of constraints (JSON Object).
|
||||
* @param newConstraints the list of constraints (JSON Object).
|
||||
*/
|
||||
addConstraints(newConstraints: any): void;
|
||||
|
||||
/**
|
||||
* Removes one or many contraints.
|
||||
* @param constraintNames the name or array of constraint names.
|
||||
*/
|
||||
removeConstraints(constraintNames: string | string[]): void;
|
||||
|
||||
/**
|
||||
* Gets the list of constraints (JSON Object).
|
||||
* @returns the list of constraints.
|
||||
*/
|
||||
getConstraints(): any;
|
||||
|
||||
/**
|
||||
* Sets custom classes on the surrounding elements.
|
||||
* @param newClasses the new classes.
|
||||
*/
|
||||
setClasses(newClasses: { valid: string, invalid: string }): void;
|
||||
}
|
||||
|
||||
interface IValdrProvider {
|
||||
/**
|
||||
* Adds a new list of constraints (JSON Object).
|
||||
* @param newConstraints the list of constraints (JSON Object).
|
||||
*/
|
||||
addConstraints(newConstraints: any): void;
|
||||
|
||||
/**
|
||||
* Removes one or many contraints.
|
||||
* @param constraintNames the name or array of constraint names.
|
||||
*/
|
||||
removeConstraints(constraintNames: string | string[]): void;
|
||||
|
||||
/**
|
||||
* Sets the constraint URL (eg "/api/constraints").
|
||||
* @param url the URL of the contraints.
|
||||
*/
|
||||
setConstraintUrl(url: string): void;
|
||||
|
||||
/**
|
||||
* Adds a custom validator.
|
||||
* @param validatorName the name of the custom validator.
|
||||
*/
|
||||
addValidator(validatorName: string): void;
|
||||
|
||||
/**
|
||||
* Adds a constraint validator alias.
|
||||
* @param valdrName the validator name.
|
||||
* @param alias the validator alias name.
|
||||
*/
|
||||
addConstraintAlias(valdrName: string, alias: string): void;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user