mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-06 13:11:46 +00:00
Code formatting with Prettier
This commit is contained in:
Vendored
+39
-39
@@ -6,64 +6,64 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace Validator {
|
||||
|
||||
interface ValidationErrors {
|
||||
[field: string]: string
|
||||
[field: string]: string;
|
||||
}
|
||||
|
||||
interface ErrorMessages {
|
||||
[key: string]: string | ErrorMessages
|
||||
[key: string]: string | ErrorMessages;
|
||||
}
|
||||
|
||||
interface AttributeNames {
|
||||
[attribute: string]: string
|
||||
[attribute: string]: string;
|
||||
}
|
||||
|
||||
type AttributeFormatter = (attribute: any) => any
|
||||
type AttributeFormatter = (attribute: any) => any;
|
||||
|
||||
interface Errors {
|
||||
errors : ValidationErrors
|
||||
add (attribute: string, message: string): void
|
||||
get (attribute: string): Array<string>
|
||||
first (attribute: string): string | boolean
|
||||
all (): ValidationErrors
|
||||
has (attribute: string): boolean
|
||||
errors: ValidationErrors;
|
||||
add(attribute: string, message: string): void;
|
||||
get(attribute: string): Array<string>;
|
||||
first(attribute: string): string | boolean;
|
||||
all(): ValidationErrors;
|
||||
has(attribute: string): boolean;
|
||||
}
|
||||
|
||||
interface ValidatorStatic {
|
||||
new <A>(data: A, rules: any, customMessages?: ErrorMessages): Validator<A>
|
||||
setMessages (lang: string, messages: ErrorMessages): any
|
||||
getMessages (lang: string): ErrorMessages
|
||||
useLang (lang: string): void
|
||||
getDefaultLang (): string
|
||||
setAttributeFormatter (func: AttributeFormatter): void
|
||||
stopOnError (attributes: boolean | Array<string>): void
|
||||
register (name: string, fn: Function, message: string): void
|
||||
registerAsync (name: string, fn: Function, message: string): void
|
||||
new <A>(data: A, rules: any, customMessages?: ErrorMessages): Validator<
|
||||
A
|
||||
>;
|
||||
setMessages(lang: string, messages: ErrorMessages): any;
|
||||
getMessages(lang: string): ErrorMessages;
|
||||
useLang(lang: string): void;
|
||||
getDefaultLang(): string;
|
||||
setAttributeFormatter(func: AttributeFormatter): void;
|
||||
stopOnError(attributes: boolean | Array<string>): void;
|
||||
register(name: string, fn: Function, message: string): void;
|
||||
registerAsync(name: string, fn: Function, message: string): void;
|
||||
}
|
||||
|
||||
interface Validator<A> {
|
||||
lang: string
|
||||
input: A
|
||||
messages: ErrorMessages
|
||||
errors: Errors
|
||||
errorCount: number
|
||||
hasAsync: boolean
|
||||
rules: any
|
||||
numericRules: Array<string>
|
||||
attributeFormatter: AttributeFormatter
|
||||
check (): boolean
|
||||
checkAsync (passes?: Function, fails?: Function): void
|
||||
setAttributeNames (attributes: AttributeNames): void
|
||||
setAttributeFormatter (func: AttributeFormatter): void
|
||||
getRule (name: string): Function
|
||||
stopOnError (passes?: Function): boolean | void
|
||||
passes (passes?: Function): boolean | void
|
||||
fails (fails?: Function): boolean | void
|
||||
lang: string;
|
||||
input: A;
|
||||
messages: ErrorMessages;
|
||||
errors: Errors;
|
||||
errorCount: number;
|
||||
hasAsync: boolean;
|
||||
rules: any;
|
||||
numericRules: Array<string>;
|
||||
attributeFormatter: AttributeFormatter;
|
||||
check(): boolean;
|
||||
checkAsync(passes?: Function, fails?: Function): void;
|
||||
setAttributeNames(attributes: AttributeNames): void;
|
||||
setAttributeFormatter(func: AttributeFormatter): void;
|
||||
getRule(name: string): Function;
|
||||
stopOnError(passes?: Function): boolean | void;
|
||||
passes(passes?: Function): boolean | void;
|
||||
fails(fails?: Function): boolean | void;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
declare const Validator: Validator.ValidatorStatic
|
||||
declare const Validator: Validator.ValidatorStatic;
|
||||
export = Validator;
|
||||
export as namespace Validator;
|
||||
|
||||
@@ -1,41 +1,40 @@
|
||||
import Validator = require("validatorjs");
|
||||
import Validator = require('validatorjs');
|
||||
|
||||
var rules: any = {
|
||||
foo: "required"
|
||||
}
|
||||
foo: 'required'
|
||||
};
|
||||
|
||||
var data: any = {
|
||||
foo: "bar"
|
||||
}
|
||||
foo: 'bar'
|
||||
};
|
||||
|
||||
var validator: Validator.Validator<any> = new Validator(data, rules)
|
||||
var validator: Validator.Validator<any> = new Validator(data, rules);
|
||||
|
||||
var passes: boolean = validator.passes() as boolean
|
||||
validator.passes(() => {})
|
||||
var passes: boolean = validator.passes() as boolean;
|
||||
validator.passes(() => {});
|
||||
|
||||
var fails: boolean = validator.fails() as boolean
|
||||
validator.fails(() => {})
|
||||
var fails: boolean = validator.fails() as boolean;
|
||||
validator.fails(() => {});
|
||||
|
||||
var check: boolean = validator.check()
|
||||
var check: boolean = validator.check();
|
||||
|
||||
var errors: Validator.Errors = validator.errors
|
||||
var all: Validator.ValidationErrors = errors.all()
|
||||
var error: Array<string> = errors.get("foo")
|
||||
var first: string | boolean = errors.first("foo")
|
||||
var has: boolean = errors.has("foo")
|
||||
var errors: Validator.Errors = validator.errors;
|
||||
var all: Validator.ValidationErrors = errors.all();
|
||||
var error: Array<string> = errors.get('foo');
|
||||
var first: string | boolean = errors.first('foo');
|
||||
var has: boolean = errors.has('foo');
|
||||
|
||||
Validator.setMessages("en", {
|
||||
integer: 'The :attribute must be an integer.',
|
||||
min: {
|
||||
numeric: 'The :attribute must be at least :min.',
|
||||
string: 'The :attribute must be at least :min characters.'
|
||||
}
|
||||
Validator.setMessages('en', {
|
||||
integer: 'The :attribute must be an integer.',
|
||||
min: {
|
||||
numeric: 'The :attribute must be at least :min.',
|
||||
string: 'The :attribute must be at least :min characters.'
|
||||
}
|
||||
);
|
||||
var messages: Validator.ErrorMessages = Validator.getMessages("en")
|
||||
Validator.useLang("en")
|
||||
var lang: string = Validator.getDefaultLang()
|
||||
Validator.setAttributeFormatter((attributes: any) => ({}))
|
||||
Validator.stopOnError(true)
|
||||
Validator.register("custom", () => {}, "error.custom")
|
||||
Validator.registerAsync("custom", () => {}, "error.custom")
|
||||
});
|
||||
var messages: Validator.ErrorMessages = Validator.getMessages('en');
|
||||
Validator.useLang('en');
|
||||
var lang: string = Validator.getDefaultLang();
|
||||
Validator.setAttributeFormatter((attributes: any) => ({}));
|
||||
Validator.stopOnError(true);
|
||||
Validator.register('custom', () => {}, 'error.custom');
|
||||
Validator.registerAsync('custom', () => {}, 'error.custom');
|
||||
|
||||
Reference in New Issue
Block a user