dresende/node-enforce — pull request #1 by SPARTAN563 (2013-08-14 22:24:29+00:00)
Title: Switch to TypeScript and allow Validator chaining

## Introduction
Obviously this is a rather large change to the way the library is written up, with the entire `lib` folder's contents being rewritten in TypeScript, and then compiled to JavaScript using the TypeScript compiler. The reason behind the switch is two-fold, firstly it allows easy static checking of the code - allowing us to catch bugs which might slip through the test framework while also providing meta information which acts like automated documentation, and secondly because I was interested to see how well TypeScript could be integrated into a Node.js module - and what advantages it would provide.

*This pull request is here to allow us to discuss the merits and disadvantages of the switch, and decide whether it is something we'd like to do for the module.*

## Rationale
Switching to TypeScript gives us the ability to ensure that changes made to interfaces and function signatures do not break existing code, this is done through the use of static checking. It has the added benefit of allowing supported IDEs to display this type information to the user, effectively reducing the amount of times a developer has to consult the documentation for function signatures and object interfaces.

Also added the ability to chain methods onto validators, with an orUndefined() one provided by default. Added tests to ensure that it functions as expected, and with minimal modifications to the tests (only those necessary to adapt to the new chainable Validator object's API) everything functions as expected. External API remains unchanged, except for the addition of an `enforce.Validator` object to ease construction of custom validators.

I have also added a translator between legacy calls to `Enforce.add(property: string, validator: function(value: any, next: (errorMessage?: string) => void, contexts?: ContextMap) => boolean);` and the new Validator objects to help ensure a smooth transition between any software using Enforce already and the new version.

## Chaining Functions
```typescript
interface IValidator {
validate(data: any, done(errors?: Error[]) => void);
validate(data: any, done(errors?: Error[]) => void, contexts: ContextMap);
validate(data: any, done(errors?: Error[]) => void, contexts: ContextMap, thisArg: any);
isDefined(): IValidator;
isNotEmptyString(): IValidator;
isType(type: string): IValidator;
isNotType(type: string): IValidator;
}
```