Merge remote-tracking branch 'refs/remotes/borisyankov/master' into bootstrap-switch-release

This commit is contained in:
johnmbaughman
2015-10-26 23:15:00 -06:00
15 changed files with 1076 additions and 265 deletions
+102
View File
@@ -0,0 +1,102 @@
/// <reference path="./decorum.d.ts" />
import {Required} from 'decorum';
import {Email} from 'decorum';
import {MinLength} from 'decorum';
import {MaxLength} from 'decorum';
import {Length} from 'decorum';
import {FieldName} from 'decorum';
import {Validation} from 'decorum';
import {Pattern} from 'decorum';
import {Validator} from 'decorum';
import {BaseValidator} from 'decorum';
class MyModel {
@FieldName('User name')
@Required()
@MaxLength(50)
username = '';
@FieldName('Email address')
@Email()
@Required('Your email address will be used to send you a confirmation email. You must fill it out')
emailAddress = '';
@Required()
@MinLength(10)
@MaxLength(30)
password = '';
@FieldName('Confirm password')
@Validation<MyModel>(
'The passwords do not match.',
(pwd, model) => model.password === pwd
)
confirmPassword = '';
@Pattern(/^[a-z0-9-]+$/i, 'Must be a valid slug tag')
slug = 'foo';
@Length(6, 'Alias must be 6 characters long')
alias: string;
}
// ES6-style
class MyController {
model = new MyModel();
validator = Validator.new(this.model);
doStuff(): void {
var opts = this.validator.getValidationOptions('alias');
var fieldName = opts.getFieldName();
var errs = opts.validateValue('foo', this.model);
opts.setFieldName('Foo');
opts.addValidator(null);
var validators = opts.getValidators();
}
validate(): void {
var result = this.validator.validate();
if (!result.isValid) {
for(var i = 0; i < result.errors.length; i++) {
var current = result.errors[i];
console.error(current.fieldName, current.errors);
}
}
}
}
// ES5-style
function MyOtherModel() {
this.foo = '';
this.bar = '';
}
Validator.decorate(MyOtherModel, {
foo: [
Required()
],
bar: [
Pattern(/^[a-z][0-9]$/i)
]
});
var otherValidator = Validator.new(new MyOtherModel());
otherValidator.validateField('foo', '');
// Custom validator
class MyValidator extends BaseValidator {
validatesEmptyValue(): boolean {
return false;
}
getMessage(fieldName: string, fieldValue: any): string {
return 'No!';
}
isValid(value: any, model: any): boolean {
return false;
}
}
+2
View File
@@ -0,0 +1,2 @@
--experimentalDecorators
--target ES5
+292
View File
@@ -0,0 +1,292 @@
// Type definitions for Decorum JS v0.1.2
// Project: https://github.com/dflor003/decorum
// Definitions by: Danil Flores <https://github.com/dflor003>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module 'decorum' {
/**
* A generic custom validation. Takes a predicate that will receive the proposed value as the first parameter and the
* current model state as the second.
* @param message The message to display when the predicate fails.
* @param predicate A lambda expression/function that determines if the value is valid. If it returns a falsy value, the
* field will be considered invalid and will return the passed error message upon validation.
* @returns {function(Object, string): void} A field validation decorator.
*/
export function Validation<TModel>(message: string, predicate: (value: any, model: TModel) => boolean): PropertyDecorator;
/**
* Validate's that the field is a valid email address. The format used is the same as the webkit browser's internal
* email validation format. For looser or stricter formats, use your own validation based on the @Pattern decorator.
* @param message [Optional] Overrides the default validation error message.
* @returns {function(Object, string): void} A field validation decorator.
*/
export function Email(message?: string): PropertyDecorator;
/**
* Sets the field's "friendly" name in validation error messages.
* @param name The field's friendly name
* @returns {function(Object, string): void} A field validation decorator.
*/
export function FieldName(name: string): PropertyDecorator;
/**
* Validate's a field's EXACT length. Validation fails if the field is not EXACTLY the length passed.
* @param length The exact length the field must be.
* @param message [Optional] Overrides the default validation error message.
* @returns {function(Object, string): void} A field validation decorator.
*/
export function Length(length: number, message?: string): PropertyDecorator;
/**
* Validates a field's maximum length.
* @param maxLength The field's maximum length. Must be a positive integer greater than 1.
* @param message [Optional] Overrides the default validation error message.
* @returns {function(Object, string): void} A field validation decorator.
*/
export function MaxLength(maxLength: number, message?: string): PropertyDecorator;
/**
* Validates the field's minimum length.
* @param minLength The field's minimum length. Must be a positive integer greater than 0
* @param message [Optional] Overrides the default validation error message.
* @returns {function(Object, string): void} A field validation decorator.
*/
export function MinLength(minLength: number, message?: string): PropertyDecorator;
/**
* Validates the field against a regular expression pattern.
* @param regex The regex to validate against. Should be a valid JavaScript {RegExp} instance.
* @param message [Optional] Overrides the default validation error message.
* @returns {function(Object, string): void} A field validation decorator.
*/
export function Pattern(regex: RegExp, message?: string): PropertyDecorator;
/**
* Marks the field as required.
* @param message [Optional] Overrides the default validation error message.
* @returns {function(Object, string): void} A field validation decorator.
*/
export function Required(message?: string): PropertyDecorator;
/**
* A map from field name to array of field validation decorators.
*/
export type ValidationDefinitions = {
[field: string]: PropertyDecorator[];
};
/**
* Static container for convenience methods related to field validation.
*/
export class Validator {
/**
* Creates a new model validator for the given model. Model should be a valid class that has a valid constructor
* and a prototype.
* @param model The model to create the validator for.
* @returns {ModelValidator} An instance of {ModelValidator}
*/
static new(model: any): ModelValidator;
/**
* Decorates the passed class with model validations. Use this when you do not have access to ES7 decorators.
* The object passed should be a valid class (ES6 class or ES5 function constructor).
* @param objectType The class to decorate.
* @param definitions One or more field validation definitions of the form { "fieldName": [ decorators ] }.
*/
static decorate(objectType: any, definitions: ValidationDefinitions): void;
/**
* Creates an anonymous validator, immediately validates the model, and returns any validation errors on the model
* as a result.
* @param model The model to validate.
*/
static validate(model: any): IValidationResult;
}
/**
* Details about validation errors on a field.
*/
export interface IFieldValidationError {
/**
* The property name of the field on the model.
*/
field: string;
/**
* The "friendly" name of the field. If not set on the model via @FieldName(...), it will default to "Field".
*/
fieldName: string;
/**
* One or more field validation errors. Empty if no errors.
*/
errors: string[];
}
/**
* Result returned when a model is validated.
*/
export interface IValidationResult {
/**
* Whether or not the model is valid.
*/
isValid: boolean;
/**
* A map of field name to validation errors.
*/
errors: IFieldValidationError[];
}
/**
* Wraps a model to allow the consuming class to call validation methods.
*/
export class ModelValidator {
/**
* Creates a new model validator.
* @param model The model to validate. Should be a class that has a valid constructor function and prototype.
*/
constructor(model: any);
/**
* Gets the validation options for the given field name.
* @param fieldKey The name of the field to get options for.
* @returns {FieldOptions} The field options associated with that field or null if no validations defined
* for the field.
*/
getValidationOptions(fieldKey: string): FieldOptions;
/**
* Validates the given field on this {ModelValidator}'s model. If a proposed value is passed, validate
* against that passed value; otherwise, use the field's current value on the model.
* @param fieldKey The name of the field to validate.
* @param proposedValue [Optional] The proposed value to set on the field.
* @returns {string[]} An array of field validation error messages if the field is invalid; otherwise,
* an empty array.
*/
validateField(fieldKey: string, proposedValue?: any): string[];
/**
* Validate the entire model and return a result that indicates whether the model is valid or not and any errors
* that have occurred in an object indexed by field name on the model.
* @returns {IValidationResult} An object that contains whether the model is valid or not and errors by field name.
*/
validate(): IValidationResult;
}
/**
* Callback invoked when a validation needs to return an error. Parameters include field name,
* field value, and any other properties relating to the field validation itself.
*/
export type MessageHandler = (fieldName: string, fieldValue: any, ...args: any[]) => string;
/**
* A map of validation "key" (unique name for a given type of validation) to message handler callback.
*/
export interface IMessageHandlerMap {
[key: string]: MessageHandler;
}
/**
* Mechanism for overriding validation errors to provide for custom or localized error messages.
* @type {{IMessageHandlerMap}}
*/
let MessageHandlers: IMessageHandlerMap;
/**
* Validation options for a given field including actual validators and meta data such as the field name.
*/
export class FieldOptions {
/**
* Gets the "friendly" name of the field for use in validation error messages. Defaults to just "Field".
* @returns {string}
*/
getFieldName(): string;
/**
* Sets the "friendly" name of the field for use in validation error messages. This name will be used in the text
* of validation errors.
* @param name The new name to set.
*/
setFieldName(name: string): void;
/**
* Add a validator to the list of validators for this field.
* @param validator The validator to add. Should be a class that extends from {BaseValidator}.
*/
addValidator(validator: BaseValidator): void;
/**
* Gets the validators assigned to this field.
* @returns {BaseValidator[]} The validators for this field.
*/
getValidators(): BaseValidator[];
/**
* Runs through all of the validators for the field given a particular value and returns any validation errors that
* may have occurred.
* @param value The value to validate.
* @param model The rest of the model. Used in custom cross-field validations.
* @returns {string[]} Any validation errors that may have occurred or an empty array if the value passed is valid
* for the field.
*/
validateValue(value: any, model: any): string[];
}
/**
* Base abstract class for all validators. Methods that must be overridden:
* getMessage(...) - Get error message to return when field is invalid.
* isValid(...) - Check validity of field given proposed value and the rest of the model.
*/
abstract class BaseValidator {
/**
* Initializes the {BaseValidator}
* @param validatorKey A unique "key" by which to identify this field validator i.e. length, maxlength, required.
* Should be a valid JS property name.
* @param message A custom error message to return. Should be passed down from concrete class' constructors to enable
* customizing error messages.
*/
constructor(validatorKey: string, message: string);
/**
* Returns true if the validator instance was passed a custom error message.
*/
hasCustomMessage: boolean;
/**
* Check whether this validator should process an "empty" value (i.e. null, undefined, empty string). Override
* this in derived classes to skip validators if the field value hasn't been set. Things like email, min/max length,
* and pattern should return false for this to ensure they don't get fired when the model is initially empty
* before a user has had a chance to input a value. Things like required should override this to true so that
* they are fired for empty values. Base implementation defaults to false
* @returns {boolean}
*/
validatesEmptyValue(): boolean;
/**
* Gets the custom error message set on this validator.
* @returns {string} The custom error message or null if none has been set.
*/
getCustomMessage(): string;
/**
* Gets the unique name for this validator.
* @returns {string} The unique name for this validator.
*/
getKey(): string;
/**
* [Abstract] Gets the error message to display when a field fails validation by this validator.
* @param fieldName The "friendly" name set for the field.
* @param fieldValue The field's current value.
*/
abstract getMessage(fieldName: string, fieldValue: any): string;
/**
* [Abstract] Checks the passed value for validity.
* @param value The field's proposed value.
* @param model The rest of the model if cross-field validity checks are necessary.
*/
abstract isValid(value: any, model: any): boolean;
}
}
+72 -60
View File
@@ -1,4 +1,4 @@
// Type definitions for Durandal 2.1.0
// Type definitions for Durandal 2.1.0
// Project: http://durandaljs.com
// Definitions by: Blue Spire <https://github.com/BlueSpire>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
@@ -12,6 +12,18 @@
/// <reference path="../jquery/jquery.d.ts" />
/// <reference path="../knockout/knockout.d.ts" />
// By default, Durandal uses JQuery's Defer/Promise implementation, but durandal supports injecting/configuring
// usage of different JavaScript Defer/Promise libraries (f.ex. Q or ES6 Promise polyfills).
// You might therefore want to use a different interface from a community typings file or your custom unified interface.
// When using f.ex. Q as Defer/Promise library replace the lines below with:
// <reference path="../q/Q.d.ts" />
// interface DurandalPromise<T> extends Q.Promise<T>
// interface DurandalDeferred<T> extends Q.Deferred<T>
interface DurandalPromise<T> extends JQueryPromise<T> { }
interface DurandalDeferred<T> extends JQueryDeferred<T> { }
/**
* The system module encapsulates the most basic features used by other modules.
* @requires require
@@ -45,7 +57,7 @@ interface DurandalSystemModule {
* @param {object} obj The object whose module id you wish to set.
* @param {string} id The id to set for the specified object.
*/
setModuleId(obj, id: string): void;
setModuleId(obj: any, id: string): void;
/**
* Resolves the default object instance for a module. If the module is an object, the module is returned. If the module is a function, that function is called with `new` and it's result is returned.
@@ -89,9 +101,9 @@ interface DurandalSystemModule {
/**
* Creates a deferred object which can be used to create a promise. Optionally pass a function action to perform which will be passed an object used in resolving the promise.
* @param {function} [action] The action to defer. You will be passed the deferred object as a paramter.
* @returns {JQueryDeferred} The deferred object.
* @returns {Deferred} The deferred object.
*/
defer<T>(action?: (dfd: JQueryDeferred<T>) => void): JQueryDeferred<T>;
defer<T>(action?: (dfd: DurandalDeferred<T>) => void): DurandalDeferred<T>;
/**
* Creates a simple V4 UUID. This should not be used as a PK in your database. It can be used to generate internal, unique ids. For a more robust solution see [node-uuid](https://github.com/broofa/node-uuid).
@@ -102,23 +114,23 @@ interface DurandalSystemModule {
/**
* Uses require.js to obtain a module. This function returns a promise which resolves with the module instance.
* @param {string} moduleId The id of the module to load.
* @returns {JQueryPromise} A promise for the loaded module.
* @returns {Promise} A promise for the loaded module.
*/
acquire(moduleId: string): JQueryPromise<any>;
acquire(moduleId: string): DurandalPromise<any>;
/**
* Uses require.js to obtain an array of modules. This function returns a promise which resolves with the modules instances in an array.
* @param {string[]} moduleIds The ids of the modules to load.
* @returns {JQueryPromise} A promise for the loaded module.
* @returns {Promise} A promise for the loaded module.
*/
acquire(modules: string[]): JQueryPromise<any[]>;
acquire(modules: string[]): DurandalPromise<any[]>;
/**
* Uses require.js to obtain multiple modules. This function returns a promise which resolves with the module instances in an array.
* @param {string} moduleIds* The ids of the modules to load.
* @returns {JQueryPromise} A promise for the loaded module.
* @returns {Promise} A promise for the loaded module.
*/
acquire(...moduleIds: string[]): JQueryPromise<any[]>;
acquire(...moduleIds: string[]): DurandalPromise<any[]>;
/**
* Extends the first object with the properties of the following objects.
@@ -130,9 +142,9 @@ interface DurandalSystemModule {
/**
* Uses a setTimeout to wait the specified milliseconds.
* @param {number} milliseconds The number of milliseconds to wait.
* @returns {JQueryPromise}
* @returns {Promise}
*/
wait(milliseconds: number): JQueryPromise<any>;
wait(milliseconds: number): DurandalPromise<any>;
/**
* Gets all the owned keys of the specified object.
@@ -295,14 +307,14 @@ interface DurandalViewEngineModule {
* @param {string} id The view id whose view should be cached.
* @param {DOMElement} view The view to cache.
*/
putViewInCache(id: string, view: HTMLElement);
putViewInCache(id: string, view: HTMLElement): void;
/**
* Creates the view associated with the view id.
* @param {string} viewId The view id whose view should be created.
* @returns {JQueryPromise<HTMLElement>} A promise of the view.
* @returns {DurandalPromise<HTMLElement>} A promise of the view.
*/
createView(viewId: string): JQueryPromise<HTMLElement>;
createView(viewId: string): DurandalPromise<HTMLElement>;
/**
* Called when a view cannot be found to provide the opportunity to locate or generate a fallback view. Mainly used to ease development.
@@ -311,7 +323,7 @@ interface DurandalViewEngineModule {
* @param {Error} requirePath The error that was returned from the attempt to locate the default view.
* @returns {Promise} A promise for the fallback view.
*/
createFallbackView(viewId: string, requirePath: string, err: Error): JQueryPromise<HTMLElement>;
createFallbackView(viewId: string, requirePath: string, err: Error): DurandalPromise<HTMLElement>;
}
/**
@@ -439,7 +451,7 @@ interface DurandalViewLocatorModule {
* @param {DOMElement[]} [elementsToSearch] An existing set of elements to search first.
* @returns {Promise} A promise of the view.
*/
locateViewForObject(obj: any, area: string, elementsToSearch?: HTMLElement[]): JQueryPromise<HTMLElement>;
locateViewForObject(obj: any, area: string, elementsToSearch?: HTMLElement[]): DurandalPromise<HTMLElement>;
/**
* Converts a module id into a view id. By default the ids are the same.
@@ -470,7 +482,7 @@ interface DurandalViewLocatorModule {
* @param {DOMElement[]} [elementsToSearch] An existing set of elements to search first.
* @returns {Promise} A promise of the view.
*/
locateView(view: HTMLElement, area?: string, elementsToSearch?: HTMLElement[]): JQueryPromise<HTMLElement>;
locateView(view: HTMLElement, area?: string, elementsToSearch?: HTMLElement[]): DurandalPromise<HTMLElement>;
/**
* Locates the specified view.
@@ -479,7 +491,7 @@ interface DurandalViewLocatorModule {
* @param {DOMElement[]} [elementsToSearch] An existing set of elements to search first.
* @returns {Promise} A promise of the view.
*/
locateView(viewUrlOrId: string, area?: string, elementsToSearch?: HTMLElement[]): JQueryPromise<HTMLElement>;
locateView(viewUrlOrId: string, area?: string, elementsToSearch?: HTMLElement[]): DurandalPromise<HTMLElement>;
}
/**
@@ -514,7 +526,7 @@ declare module 'durandal/composition' {
area?: string;
preserveContext?: boolean;
activate?: boolean;
strategy?: (context: CompositionContext) => JQueryPromise<HTMLElement>;
strategy?: (context: CompositionContext) => DurandalPromise<HTMLElement>;
composingNewView: boolean;
child: HTMLElement;
binding?: (child: HTMLElement, parent: HTMLElement, context: CompositionContext) => void;
@@ -547,7 +559,7 @@ declare module 'durandal/composition' {
* @param {object} [config] The binding handler instance. If none is provided, the name will be used to look up an existing handler which will then be converted to a composition handler.
* @param {function} [initOptionsFactory] If the registered binding needs to return options from its init call back to knockout, this function will server as a factory for those options. It will receive the same parameters that the init function does.
*/
export function addBindingHandler(name, config?: KnockoutBindingHandler, initOptionsFactory?: (element?: HTMLElement, valueAccessor?: any, allBindingsAccessor?: any, viewModel?: any, bindingContext?: KnockoutBindingContext) => any);
export function addBindingHandler(name: string, config?: KnockoutBindingHandler, initOptionsFactory?: (element?: HTMLElement, valueAccessor?: any, allBindingsAccessor?: any, viewModel?: any, bindingContext?: KnockoutBindingContext) => any): void;
/**
* Gets an object keyed with all the elements that are replacable parts, found within the supplied elements. The key will be the part name and the value will be the element itself.
@@ -568,7 +580,7 @@ declare module 'durandal/composition' {
* @param {object} context The composition context containing the model and possibly existing viewElements.
* @returns {promise} A promise for the view.
*/
export var defaultStrategy: (context: CompositionContext) => JQueryPromise<HTMLElement>;
export var defaultStrategy: (context: CompositionContext) => DurandalPromise<HTMLElement>;
/**
* Initiates a composition.
@@ -663,13 +675,13 @@ declare module 'plugins/dialog' {
* In this function, you are expected to add a DOM element to the tree which will serve as the "host" for the modal's composed view. You must add a property called host to the modalWindow object which references the dom element. It is this host which is passed to the composition module.
* @param {Dialog} theDialog The dialog model.
*/
addHost(theDialog: Dialog);
addHost(theDialog: Dialog): void;
/**
* This function is expected to remove any DOM machinery associated with the specified dialog and do any other necessary cleanup.
* @param {Dialog} theDialog The dialog model.
*/
removeHost(theDialog: Dialog);
removeHost(theDialog: Dialog): void;
/**
* This function is called after the modal is fully composed into the DOM, allowing your implementation to do any final modifications, such as positioning or animation. You can obtain the original dialog object by using `getDialog` on context.model.
@@ -677,14 +689,14 @@ declare module 'plugins/dialog' {
* @param {DOMElement} parent The parent view.
* @param {object} context The composition context.
*/
compositionComplete(child: HTMLElement, parent: HTMLElement, context: composition.CompositionContext);
compositionComplete(child: HTMLElement, parent: HTMLElement, context: composition.CompositionContext): void;
}
interface Dialog {
owner: any;
context: DialogContext;
activator: DurandalActivator<any>;
close(): JQueryPromise<any>;
close(): DurandalPromise<any>;
settings: composition.CompositionContext;
}
@@ -745,7 +757,7 @@ declare module 'plugins/dialog' {
* @param {string} [context] The name of the dialog context to use. Uses the default context if none is specified.
* @returns {Promise} A promise that resolves when the dialog is closed and returns any data passed at the time of closing.
*/
export function show(obj: any, activationData?: any, context?: string): JQueryPromise<any>;
export function show(obj: any, activationData?: any, context?: string): DurandalPromise<any>;
/**
* Shows a message box.
@@ -756,7 +768,7 @@ declare module 'plugins/dialog' {
* @param {Object} [settings] Custom settings for this instance of the messsage box, used to change classes and styles.
* @returns {Promise} A promise that resolves when the message box is closed and returns the selected option.
*/
export function showMessage(message: string, title?: string, options?: string[], autoclose?: boolean, settings?: Object): JQueryPromise<string>;
export function showMessage(message: string, title?: string, options?: string[], autoclose?: boolean, settings?: Object): DurandalPromise<string>;
/**
* Shows a message box.
@@ -767,7 +779,7 @@ declare module 'plugins/dialog' {
* @param {Object} [settings] Custom settings for this instance of the messsage box, used to change classes and styles.
* @returns {Promise} A promise that resolves when the message box is closed and returns the selected option.
*/
export function showMessage(message: string, title?: string, options?: DialogButton[], autoclose?: boolean, settings?: Object): JQueryPromise<any>;
export function showMessage(message: string, title?: string, options?: DialogButton[], autoclose?: boolean, settings?: Object): DurandalPromise<any>;
/**
* Installs this module into Durandal; called by the framework. Adds `app.showDialog` and `app.showMessage` convenience methods.
@@ -890,7 +902,7 @@ declare module 'plugins/http' {
* @param {object} [headers] The data to add to the request header. It will be converted to JSON. If the data contains Knockout observables, they will be converted into normal properties before serialization.
* @returns {Promise} A promise of the get response data.
*/
export function get(url: string, query?: Object, headers?: Object): JQueryPromise<any>;
export function get(url: string, query?: Object, headers?: Object): DurandalPromise<any>;
/**
* Makes an JSONP request.
@@ -900,7 +912,7 @@ declare module 'plugins/http' {
* @param {object} [headers] The data to add to the request header. It will be converted to JSON. If the data contains Knockout observables, they will be converted into normal properties before serialization.
* @returns {Promise} A promise of the response data.
*/
export function jsonp(url: string, query?: Object, callbackParam?: string, headers?: Object): JQueryPromise<any>;
export function jsonp(url: string, query?: Object, callbackParam?: string, headers?: Object): DurandalPromise<any>;
/**
* Makes an HTTP POST request.
@@ -909,7 +921,7 @@ declare module 'plugins/http' {
* @param {object} [headers] The data to add to the request header. It will be converted to JSON. If the data contains Knockout observables, they will be converted into normal properties before serialization.
* @returns {Promise} A promise of the response data.
*/
export function post(url: string, data: Object, headers?: Object): JQueryPromise<any>;
export function post(url: string, data: Object, headers?: Object): DurandalPromise<any>;
/**
* Makes an HTTP PUT request.
@@ -919,7 +931,7 @@ declare module 'plugins/http' {
* @param {object} [headers] The data to add to the request header. It will be converted to JSON. If the data contains Knockout observables, they will be converted into normal properties before serialization.
* @return {Promise} A promise of the response data.
*/
export function put(url: string, data: Object, headers?: Object): JQueryPromise<any>;
export function put(url: string, data: Object, headers?: Object): DurandalPromise<any>;
/**
* Makes an HTTP DELETE request.
@@ -929,7 +941,7 @@ declare module 'plugins/http' {
* @param {object} [headers] The data to add to the request header. It will be converted to JSON. If the data contains Knockout observables, they will be converted into normal properties before serialization.
* @return {Promise} A promise of the get response data.
*/
export function remove(url: string, query?: Object, headers?: Object): JQueryPromise<any>;
export function remove(url: string, query?: Object, headers?: Object): DurandalPromise<any>;
}
/**
@@ -964,7 +976,7 @@ declare module 'plugins/observable' {
* @param {function|object} evaluatorOrOptions The Knockout computed function or computed options object.
* @returns {KnockoutComputed} The underlying computed observable.
*/
export function defineProperty<T>(obj: any, propertyName: string, evaluatorOrOptions?: KnockoutComputedDefine<T>);
export function defineProperty<T>(obj: any, propertyName: string, evaluatorOrOptions?: KnockoutComputedDefine<T>): KnockoutComputed<T>;
/**
* Installs the plugin into the view model binder's `beforeBind` hook so that objects are automatically converted before being bound.
@@ -1046,7 +1058,7 @@ declare module 'plugins/serializer' {
* @param {object} [settings] Settings can specify a replacer or space to override the serializer defaults.
* @returns {string} The JSON string.
*/
export function serialize(object: any, settings?: string);
export function serialize(object: any, settings?: string): string;
/**
* Serializes the object.
@@ -1054,7 +1066,7 @@ declare module 'plugins/serializer' {
* @param {object} [settings] Settings can specify a replacer or space to override the serializer defaults.
* @returns {string} The JSON string.
*/
export function serialize(object: any, settings?: number);
export function serialize(object: any, settings?: number): string;
/**
* Serializes the object.
@@ -1062,7 +1074,7 @@ declare module 'plugins/serializer' {
* @param {object} [settings] Settings can specify a replacer or space to override the serializer defaults.
* @returns {string} The JSON string.
*/
export function serialize(object: any, settings?: SerializerOptions);
export function serialize(object: any, settings?: SerializerOptions): string;
/**
* Gets the type id for an object instance, using the configured `typeAttribute`.
@@ -1081,7 +1093,7 @@ declare module 'plugins/serializer' {
* @param {string} typeId The type id.
* @param {function} constructor The constructor.
*/
export function registerType(typeId: string, constructor: () => any);
export function registerType(typeId: string, constructor: () => any): void;
/**
* The default reviver function used during deserialization. By default is detects type properties on objects and uses them to re-construct the correct object using the provided constructor mapping.
@@ -1091,7 +1103,7 @@ declare module 'plugins/serializer' {
* @param {object} getConstructor A custom function used to get the constructor function associated with a type id.
* @returns {object} The value.
*/
export function reviver(key: string, value: any, getTypeId: (value: any) => string, getConstructor: (string) => () => any): any;
export function reviver(key: string, value: any, getTypeId: (value: any) => string, getConstructor: (id: string) => () => any): any;
/**
* Deserialize the JSON.
@@ -1128,7 +1140,7 @@ declare module 'plugins/widget' {
* Creates a ko binding handler for the specified kind.
* @param {string} kind The kind to create a custom binding handler for.
*/
export function registerKind(kind: string);
export function registerKind(kind: string): void;
/**
* Maps views and module to the kind identifier if a non-standard pattern is desired.
@@ -1136,7 +1148,7 @@ declare module 'plugins/widget' {
* @param {string} [viewId] The unconventional view id to map the kind to.
* @param {string} [moduleId] The unconventional module id to map the kind to.
*/
export function mapKind(kind: string, viewId?: string, moduleId?: string);
export function mapKind(kind: string, viewId?: string, moduleId?: string): void;
/**
* Maps a kind name to it's module id. First it looks up a custom mapped kind, then falls back to `convertKindToModulePath`.
@@ -1172,7 +1184,7 @@ declare module 'plugins/widget' {
* @param {object} settings The widget settings.
* @param {object} [bindingContext] The current binding context.
*/
export function create(element: HTMLElement, settings: WidgetSettings, bindingContext?: KnockoutBindingContext);
export function create(element: HTMLElement, settings: WidgetSettings, bindingContext?: KnockoutBindingContext): void;
}
/**
@@ -1279,14 +1291,14 @@ interface DurandalAppModule extends DurandalEventSupport<DurandalAppModule> {
* @param {string} [context] The name of the dialog context to use. Uses the default context if none is specified.
* @returns {Promise} A promise that resolves when the dialog is closed and returns any data passed at the time of closing.
*/
showDialog(obj: any, activationData?: any, context?: string): JQueryPromise<any>;
showDialog(obj: any, activationData?: any, context?: string): DurandalPromise<any>;
/**
* Closes the dialog associated with the specified object. via the dialog plugin.
* @param {object} obj The object whose dialog should be closed.
* @param {object} results* The results to return back to the dialog caller after closing.
*/
closeDialog(obj: any, ...results);
closeDialog(obj: any, ...results: any[]): void;
/**
* Shows a message box via the dialog plugin.
@@ -1297,7 +1309,7 @@ interface DurandalAppModule extends DurandalEventSupport<DurandalAppModule> {
* @param {Object} [settings] Custom settings for this instance of the messsage box, used to change classes and styles.
* @returns {Promise} A promise that resolves when the message box is closed and returns the selected option.
*/
showMessage(message: string, title?: string, options?: string[], autoclose?: boolean, settings?: Object): JQueryPromise<string>;
showMessage(message: string, title?: string, options?: string[], autoclose?: boolean, settings?: Object): DurandalPromise<string>;
/**
* Shows a message box.
@@ -1308,7 +1320,7 @@ interface DurandalAppModule extends DurandalEventSupport<DurandalAppModule> {
* @param {Object} [settings] Custom settings for this instance of the messsage box, used to change classes and styles.
* @returns {Promise} A promise that resolves when the message box is closed and returns the selected option.
*/
showMessage(message: string, title?: string, options?: DialogButton[], autoclose?: boolean, settings?: Object): JQueryPromise<any>;
showMessage(message: string, title?: string, options?: DialogButton[], autoclose?: boolean, settings?: Object): DurandalPromise<any>;
/**
* Configures one or more plugins to be loaded and installed into the application.
@@ -1322,7 +1334,7 @@ interface DurandalAppModule extends DurandalEventSupport<DurandalAppModule> {
* Starts the application.
* @returns {promise}
*/
start(): JQueryPromise<any>;
start(): DurandalPromise<any>;
/**
* Sets the root module/view for the application.
@@ -1404,7 +1416,7 @@ interface DurandalActivator<T> extends KnockoutComputed<T> {
* @param {boolean} close Whether or not to check if close is possible.
* @returns {promise}
*/
canDeactivateItem(item: T, close: boolean): JQueryPromise<boolean>;
canDeactivateItem(item: T, close: boolean): DurandalPromise<boolean>;
/**
* Deactivates the specified item.
@@ -1412,7 +1424,7 @@ interface DurandalActivator<T> extends KnockoutComputed<T> {
* @param {boolean} close Whether or not to close the item.
* @returns {promise}
*/
deactivateItem(item: T, close: boolean): JQueryPromise<boolean>;
deactivateItem(item: T, close: boolean): DurandalPromise<boolean>;
/**
* Determines whether or not the specified item can be activated.
@@ -1420,7 +1432,7 @@ interface DurandalActivator<T> extends KnockoutComputed<T> {
* @param {object} activationData Data associated with the activation.
* @returns {promise}
*/
canActivateItem(newItem: T, activationData?: any): JQueryPromise<boolean>;
canActivateItem(newItem: T, activationData?: any): DurandalPromise<boolean>;
/**
* Activates the specified item.
@@ -1428,31 +1440,31 @@ interface DurandalActivator<T> extends KnockoutComputed<T> {
* @param {object} newActivationData Data associated with the activation.
* @returns {promise}
*/
activateItem(newItem: T, activationData?: any): JQueryPromise<boolean>;
activateItem(newItem: T, activationData?: any): DurandalPromise<boolean>;
/**
* Determines whether or not the activator, in its current state, can be activated.
* @returns {promise}
*/
canActivate(): JQueryPromise<boolean>;
canActivate(): DurandalPromise<boolean>;
/**
* Activates the activator, in its current state.
* @returns {promise}
*/
activate(): JQueryPromise<boolean>;
activate(): DurandalPromise<boolean>;
/**
* Determines whether or not the activator, in its current state, can be deactivated.
* @returns {promise}
*/
canDeactivate(close: boolean): JQueryPromise<boolean>;
canDeactivate(close: boolean): DurandalPromise<boolean>;
/**
* Deactivates the activator, in its current state.
* @returns {promise}
*/
deactivate(close: boolean): JQueryPromise<boolean>;
deactivate(close: boolean): DurandalPromise<boolean>;
/**
* Adds canActivate, activate, canDeactivate and deactivate functions to the provided model which pass through to the corresponding functions on the activator.
@@ -1462,7 +1474,7 @@ interface DurandalActivator<T> extends KnockoutComputed<T> {
/**
* Sets up a collection representing a pool of objects which the activator will activate. See below for details. Activators without an item bool always close their values on deactivate. Activators with an items pool only deactivate, but do not close them.
*/
forItems(items): DurandalActivator<T>;
forItems(items: any[]): DurandalActivator<T>;
}
interface DurandalHistoryOptions {
@@ -1509,7 +1521,7 @@ interface DurandalRouteConfiguration {
title?: any;
moduleId?: string;
hash?: string;
route?: string|string[];
route?: string | string[];
routePattern?: RegExp;
isActive?: KnockoutComputed<boolean>;
nav?: any;
@@ -1765,7 +1777,7 @@ interface DurandalRouterBase<T> extends DurandalEventSupport<T> {
* @param {object} instruction The route instruction. The instruction object has config, fragment, queryString, params and queryParams properties.
* @returns {Promise|Boolean|String} If a boolean, determines whether or not the route should activate or be cancelled. If a string, causes a redirect to the specified route. Can also be a promise for either of these value types.
*/
guardRoute?: (instance: Object, instruction: DurandalRouteInstruction) => JQueryPromise<boolean|string>|boolean|string;
guardRoute?: (instance: Object, instruction: DurandalRouteInstruction) => DurandalPromise<boolean | string> | boolean | string;
/**
* Parent router of the current child router.
@@ -1785,7 +1797,7 @@ interface DurandalRootRouter extends DurandalRouterBase<DurandalRootRouter> {
* Activates the router and the underlying history tracking mechanism.
* @returns {Promise} A promise that resolves when the router is ready.
*/
activate(options?: DurandalHistoryOptions): JQueryPromise<any>;
activate(options?: DurandalHistoryOptions): DurandalPromise<any>;
/**
* Disable history, perhaps temporarily. Not useful in a real app, but possibly useful for unit testing Routers.
+8 -6
View File
@@ -2101,12 +2101,14 @@ declare module "hapi" {
Returns a server object with connections set to the requested subset. Selecting again on a selection operates as a logic AND statement between the individual selections.
var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({ port: 80, labels: ['a', 'b'] });
server.connection({ port: 8080, labels: ['a', 'c'] });
server.connection({ port: 8081, labels: ['b', 'c'] });
var a = server.select('a'); // 80, 8080
var ac = a.select('c'); // 8080*/
select(labels: string|string[]): void;
server.connection({ port: 80, labels: ['a'] });
server.connection({ port: 8080, labels: ['b'] });
server.connection({ port: 8081, labels: ['c'] });
server.connection({ port: 8082, labels: ['c','d'] });
var a = server.select('a'); // The server with port 80
var ab = server.select(['a','b']); // A list of servers containing the server with port 80 and the server with port 8080
var c = server.select('c'); // A list of servers containing the server with port 8081 and the server with port 8082 */
select(labels: string|string[]): Server|Server[];
/** server.start([callback])
Starts the server connections by listening for incoming requests on the configured port of each listener (unless the connection was configured with autoListen set to false), where:
callback - optional callback when server startup is completed or failed with the signature function(err) where:
+8 -6
View File
@@ -2104,12 +2104,14 @@ declare module "hapi" {
Returns a server object with connections set to the requested subset. Selecting again on a selection operates as a logic AND statement between the individual selections.
var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({ port: 80, labels: ['a', 'b'] });
server.connection({ port: 8080, labels: ['a', 'c'] });
server.connection({ port: 8081, labels: ['b', 'c'] });
var a = server.select('a'); // 80, 8080
var ac = a.select('c'); // 8080*/
select(labels: string|string[]): void;
server.connection({ port: 80, labels: ['a'] });
server.connection({ port: 8080, labels: ['b'] });
server.connection({ port: 8081, labels: ['c'] });
server.connection({ port: 8082, labels: ['c','d'] });
var a = server.select('a'); // The server with port 80
var ab = server.select(['a','b']); // A list of servers containing the server with port 80 and the server with port 8080
var c = server.select('c'); // A list of servers containing the server with port 8081 and the server with port 8082 */
select(labels: string|string[]): Server|Server[];
/** server.start([callback])
Starts the server connections by listening for incoming requests on the configured port of each listener (unless the connection was configured with autoListen set to false), where:
callback - optional callback when server startup is completed or failed with the signature function(err) where:
@@ -0,0 +1,26 @@
/// <reference path="jquery.highlight-bartaz.d.ts" />
$('#content').highlight('lorem');
// search for and highlight more terms at once
// so you can save some time on traversing DOM
$('#content').highlight(['lorem', 'ipsum']);
$('#content').highlight('lorem ipsum');
// search only for entire word 'lorem'
$('#content').highlight('lorem', { wordsOnly: true });
// don't ignore case during search of term 'lorem'
$('#content').highlight('lorem', { caseSensitive: true });
// wrap every occurrance of term 'ipsum' in content
// with <em class='important'>
$('#content').highlight('ipsum', { element: 'em', className: 'important' });
// remove default highlight
$('#content').unhighlight();
// remove custom highlight
$('#content').unhighlight({ element: 'em', className: 'important' });
+20
View File
@@ -0,0 +1,20 @@
// Type definitions for jquery.highlight.js
// Project: https://github.com/bartaz/sandbox.js/blob/master/jquery.highlight.js
// Definitions by: Stefan Profanter <https://github.com/Pro/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///<reference path="../jquery/jquery.d.ts" />
interface JQuery {
unhighlight(options?: {
element?: string,
className?: string
}): JQuery;
highlight(words: string | string[], options?: {
element?: string,
className?: string
caseSensitive?: boolean,
wordsOnly?: boolean
}): JQuery;
}
+73
View File
@@ -0,0 +1,73 @@
/// <reference path="../jquery/jquery.d.ts"/>
/// <reference path="jquery.qrcode.d.ts"/>
// Examples from website (note: the examples use color instead of fill, which is not supported)
$('.container').qrcode();
$('.container').qrcode({
"size": 100,
"fill": "#3a3",
"text": "http://larsjung.de/qrcode"
});
$('.container').qrcode({
"render": "div",
"size": 100,
"fill": "#3a3",
"text": "http://larsjung.de/qrcode"
});
// defaults
$('.container').qrcode({
// render method: `'canvas'`, `'image'` or `'div'`
render: 'canvas',
// version range somewhere in 1 .. 40
minVersion: 1,
maxVersion: 40,
// error correction level: `'L'`, `'M'`, `'Q'` or `'H'`
ecLevel: 'L',
// offset in pixel if drawn onto existing canvas
left: 0,
top: 0,
// size in pixel
size: 200,
// code color or image element
fill: '#000',
// background color or image element, `null` for transparent background
background: null,
// content
text: 'no text',
// corner radius relative to module width: 0.0 .. 0.5
radius: 0,
// quiet zone in modules
quiet: 0,
// modes
// 0: normal
// 1: label strip
// 2: label box
// 3: image strip
// 4: image box
mode: JQueryQRCode.Mode.NORMAL,
mSize: 0.1,
mPosX: 0.5,
mPosY: 0.5,
label: 'no label',
fontname: 'sans',
fontcolor: '#000',
image: null
});
+127
View File
@@ -0,0 +1,127 @@
// Type definitions for jQuery.qrcode v0.12.0
// Project: https://github.com/lrsjng/jquery-qrcode
// Definitions by: Dan Manastireanu <https://github.com/danmana>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts" />
declare module JQueryQRCode {
/**
* One of the possible mode types.
*/
export const enum Mode {
NORMAL,
LABEL_STRIP,
LABEL_BOX,
IMAGE_STRIP,
IMAGE_BOX
}
interface Options {
/**
* Render method: 'canvas', 'image' or 'div'
* @default 'canvas'
*/
render?: string,
/**
* Start of version range, somewhere in 1 .. 40
* @default 1
*/
minVersion?: number,
/**
* End of version range, somewhere in 1 .. 40
* @default 40
*/
maxVersion?: number,
/**
* Error correction level: 'L', 'M', 'Q' or 'H'
* @default 'L'
*/
ecLevel?: string,
/**
* Left offset in pixels, if drawn onto existing canvas
* @default 0
*/
left?: number,
/**
* Top offset in pixels, if drawn onto existing canvas
* @default 0
*/
top?: number,
/**
* Size in pixel
* @default 200
*/
size?: number,
/**
* Code color or image element
* @default '#000'
*/
fill?: string,
/**
* Background color or image element, null for transparent background
* @default null
*/
background?: string,
/**
* The text content of the QR code.
* @default 'no text'
*/
text?: string,
/**
* Corner radius relative to module width: 0.0 .. 0.5
* @default 0
*/
radius?: number,
/**
* Quiet zone in modules
* @default 0
*/
quiet?: number,
/**
* Mode
* @default Mode.NORMAL
*/
mode?: Mode,
/** @default 0.1 */
mSize?: number,
/** @default 0.5 */
mPosX?: number,
/** @default 0.5 */
mPosY?: number,
/** @default 'no label' */
label?: string,
/** @default 'sans' */
fontname?: string,
/** @default '#000' */
fontcolor?: string,
/** @default null */
image?: string
}
}
interface JQuery {
/**
* Create a QR Code inside the selected container.
* @param options
*/
qrcode(options?: JQueryQRCode.Options): JQuery;
}
+18 -5
View File
@@ -53,11 +53,11 @@ declare module 'karma' {
}
interface Runner {
run(options?: Config, callback?: ServerCallback): void;
run(options?: ConfigOptions|ConfigFile, callback?: ServerCallback): void;
}
interface Server extends NodeJS.EventEmitter {
new(options?: Config, callback?: ServerCallback): Server;
new(options?: ConfigOptions|ConfigFile, callback?: ServerCallback): Server;
/**
* Start the server
*/
@@ -82,8 +82,21 @@ declare module 'karma' {
interface ServerCallback {
(exitCode: number): void;
}
interface Config {
set: (config: ConfigOptions) => void;
LOG_DISABLE: string;
LOG_ERROR: string;
LOG_WARN: string;
LOG_INFO: string;
LOG_DEBUG: string;
}
interface ConfigFile {
configFile: string;
}
interface Config {
interface ConfigOptions {
/**
* @description Enable or disable watching files and executing the tests whenever one of these files changes.
* @default true
@@ -163,7 +176,7 @@ declare module 'karma' {
* </p>
*/
captureTimeout?: number;
client?: ClientConfig;
client?: ClientOptions;
/**
* @default true
* @description Enable or disable colors in the output (reporters and logs).
@@ -308,7 +321,7 @@ declare module 'karma' {
urlRoot?: string;
}
interface ClientConfig {
interface ClientOptions {
/**
* @default undefined
* @description When karma run is passed additional arguments on the command-line, they
+93 -34
View File
@@ -2102,20 +2102,6 @@ module TestMap {
}
}
// _.floor
result = <number>_.floor(4.006);
// → 4
result = <number>_.floor(0.046, 2);
// → 0.04
result = <number>_.floor(4060, -2);
// → 4000
result = <number>_(4.006).floor();
// → 4
result = <number>_(0.046).floor(2);
// → 0.04
result = <number>_(4060).floor(-2);
// → 4000
result = <number>_.sum([4, 2, 8, 6]);
result = <number>_.sum([4, 2, 8, 6], function(v) { return v; });
result = <number>_.sum({a: 2, b: 4});
@@ -2992,8 +2978,20 @@ module TestToPlainObject {
********/
// _.add
result = <number>_.add(1, 1);
result = <number>_(1).add(1);
module TestAdd {
{
let result: number;
result = _.add(1, 1);
result = _(1).add(1);
}
{
let result: _.LoDashExplicitWrapper<number>;
result = _(1).chain().add(1);
}
}
// _.ceil
module TestCeil {
@@ -3015,6 +3013,29 @@ module TestCeil {
}
}
// _.floor
module TestFloor {
{
let result: number;
result = _.floor(4.006);
result = _.floor(0.046, 2);
result = _.floor(4060, -2);
result = _(4.006).floor();
result = _(0.046).floor(2);
result = _(4060).floor(-2);
}
{
let result: _.LoDashExplicitWrapper<number>;
result = _(4.006).chain().floor();
result = _(0.046).chain().floor(2);
result = _(4060).chain().floor(-2);
}
}
// _.max
module TestMax {
let array: number[];
@@ -3157,20 +3178,32 @@ module TestInRange {
// _.random
module TestRandom {
let result: number;
{
let result: number;
result = _.random();
result = _.random(1);
result = _.random(1, 2);
result = _.random(1, 2, true);
result = _.random(1, true);
result = _.random(true);
result = _.random();
result = _.random(1);
result = _.random(1, 2);
result = _.random(1, 2, true);
result = _.random(1, true);
result = _.random(true);
result = _(1).random();
result = _(1).random(2);
result = _(1).random(2, true);
result = _(1).random(true);
result = _(true).random();
result = _(1).random();
result = _(1).random(2);
result = _(1).random(2, true);
result = _(1).random(true);
result = _(true).random();
}
{
let result: _.LoDashExplicitWrapper<number>;
result = _(1).chain().random();
result = _(1).chain().random(2);
result = _(1).chain().random(2, true);
result = _(1).chain().random(true);
result = _(true).chain().random();
}
}
/*********
@@ -3711,8 +3744,20 @@ class Mage {
*********/
// _.camelCase
result = <string>_.camelCase('Foo Bar');
result = <string>_('Foo Bar').camelCase();
module TestCamelCase {
{
let result: string;
result = _.camelCase('Foo Bar');
result = _('Foo Bar').camelCase();
}
{
let result: _.LoDashExplicitWrapper<string>;
result = _('Foo Bar').chain().camelCase();
}
}
// _.capitalize
module TestCapitalize {
@@ -3988,10 +4033,24 @@ result = <string>_.unescape('fred, barney, &amp; pebbles');
result = <string>_('fred, barney, &amp; pebbles').unescape();
// _.words
result = <string[]>_.words('fred, barney, & pebbles');
result = <string[]>_.words('fred, barney, & pebbles', /[^, ]+/g);
result = <string[]>_('fred, barney, & pebbles').words();
result = <string[]>_('fred, barney, & pebbles').words(/[^, ]+/g);
module TestWords {
{
let result: string[];
result = _.words('fred, barney, & pebbles');
result = _.words('fred, barney, & pebbles', /[^, ]+/g);
result = _('fred, barney, & pebbles').words();
result = _('fred, barney, & pebbles').words(/[^, ]+/g);
}
{
let result: _.LoDashExplicitArrayWrapper<string>;
result = _('fred, barney, & pebbles').chain().words();
result = _('fred, barney, & pebbles').chain().words(/[^, ]+/g);
}
}
/***********
* Utility *
+76 -20
View File
@@ -4538,24 +4538,6 @@ declare module _ {
): LoDashImplicitArrayWrapper<boolean>;
}
//_.floor
interface LoDashStatic {
/**
* Calculates n rounded down to precision.
* @param n The number to round down.
* @param precision The precision to round down to.
* @return Returns the rounded down number.
*/
floor(n: number, precision?: number): number;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.floor
*/
floor(precision?: number): number;
}
//_.sum
interface LoDashStatic {
/**
@@ -7447,11 +7429,15 @@ declare module _ {
interface LoDashStatic {
/**
* Adds two numbers.
*
* @param augend The first number to add.
* @param addend The second number to add.
* @return Returns the sum.
*/
add(augend: number, addend: number): number;
add(
augend: number,
addend: number
): number;
}
interface LoDashImplicitWrapper<T> {
@@ -7461,6 +7447,13 @@ declare module _ {
add(addend: number): number;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.add
*/
add(addend: number): LoDashExplicitWrapper<number>;
}
//_.ceil
interface LoDashStatic {
/**
@@ -7490,6 +7483,35 @@ declare module _ {
ceil(precision?: number): LoDashExplicitWrapper<number>;
}
//_.floor
interface LoDashStatic {
/**
* Calculates n rounded down to precision.
*
* @param n The number to round down.
* @param precision The precision to round down to.
* @return Returns the rounded down number.
*/
floor(
n: number,
precision?: number
): number;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.floor
*/
floor(precision?: number): number;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.floor
*/
floor(precision?: number): LoDashExplicitWrapper<number>;
}
//_.max
interface LoDashStatic {
/**
@@ -7835,6 +7857,21 @@ declare module _ {
random(floating?: boolean): number;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.random
*/
random(
max?: number,
floating?: boolean
): LoDashExplicitWrapper<number>;
/**
* @see _.random
*/
random(floating?: boolean): LoDashExplicitWrapper<number>;
}
/**********
* Object *
**********/
@@ -9098,6 +9135,7 @@ declare module _ {
interface LoDashStatic {
/**
* Converts string to camel case.
*
* @param string The string to convert.
* @return Returns the camel cased string.
*/
@@ -9111,6 +9149,13 @@ declare module _ {
camelCase(): string;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.camelCase
*/
camelCase(): LoDashExplicitWrapper<string>;
}
//_.capitalize
interface LoDashStatic {
capitalize(string?: string): string;
@@ -9638,11 +9683,15 @@ declare module _ {
interface LoDashStatic {
/**
* Splits string into an array of its words.
*
* @param string The string to inspect.
* @param pattern The pattern to match words.
* @return Returns the words of string.
*/
words(string?: string, pattern?: string|RegExp): string[];
words(
string?: string,
pattern?: string|RegExp
): string[];
}
interface LoDashImplicitWrapper<T> {
@@ -9652,6 +9701,13 @@ declare module _ {
words(pattern?: string|RegExp): string[];
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.words
*/
words(pattern?: string|RegExp): LoDashExplicitArrayWrapper<string>;
}
/***********
* Utility *
***********/
+1
View File
@@ -334,6 +334,7 @@ declare module NodeJS {
undefined: typeof undefined;
unescape: (str: string) => string;
gc: () => void;
v8debug?: any;
}
export interface Timer {
+158 -134
View File
@@ -5,163 +5,187 @@
/// <reference path="../node/node.d.ts" />
declare module yo {
export interface IYeomanGenerator {
argument(name: string, config: IArgumentConfig): void;
composeWith(namespace: string, options: any, settings?: IComposeSetting): IYeomanGenerator;
defaultFor(name: string): void;
destinationRoot(rootPath: string): string;
determineAppname(): void;
getCollisionFilter(): (output: any) => void;
hookFor(name: string, config: IHookConfig): void;
option(name: string, config: IYeomanGeneratorOption): void;
rootGeneratorName(): string;
run(args?: any): void;
run(args: any, callback?: Function): void;
runHooks(callback?: Function): void;
sourceRoot(rootPath: string): string;
}
export interface IYeomanGenerator {
argument(name: string, config: IArgumentConfig): void;
composeWith(namespace: string, options: any, settings?: IComposeSetting): IYeomanGenerator;
defaultFor(name: string): void;
destinationRoot(rootPath: string): string;
determineAppname(): void;
getCollisionFilter(): (output: any) => void;
hookFor(name: string, config: IHookConfig): void;
option(name: string, config: IYeomanGeneratorOption): void;
rootGeneratorName(): string;
run(args?: any): void;
run(args: any, callback?: Function): void;
runHooks(callback?: Function): void;
sourceRoot(rootPath: string): string;
export class YeomanGeneratorBase implements IYeomanGenerator, NodeJS.EventEmitter {
argument(name: string, config: IArgumentConfig): void;
composeWith(namespace: string, options: any, settings?: IComposeSetting): IYeomanGenerator;
defaultFor(name: string): void;
destinationRoot(rootPath: string): string;
determineAppname(): void;
getCollisionFilter(): (output: any) => void;
hookFor(name: string, config: IHookConfig): void;
option(name: string, config: IYeomanGeneratorOption): void;
rootGeneratorName(): string;
run(args?: any): void;
run(args: any, callback?: Function): void;
runHooks(callback?: Function): void;
sourceRoot(rootPath: string): string;
addListener(event: string, listener: Function): NodeJS.EventEmitter;
on(event: string, listener: Function): NodeJS.EventEmitter;
once(event: string, listener: Function): NodeJS.EventEmitter;
removeListener(event: string, listener: Function): NodeJS.EventEmitter;
removeAllListeners(event?: string): NodeJS.EventEmitter;
setMaxListeners(n: number): void;
listeners(event: string): Function[];
emit(event: string, ...args: any[]): boolean;
}
export interface IArgumentConfig {
desc: string;
required: boolean;
optional: boolean;
type: any;
defaults: any;
}
}
export interface IComposeSetting {
local?: string;
link?: string;
}
export class YeomanGeneratorBase implements IYeomanGenerator, NodeJS.EventEmitter {
argument(name: string, config: IArgumentConfig): void;
composeWith(namespace: string, options: any, settings?: IComposeSetting): IYeomanGenerator;
defaultFor(name: string): void;
destinationRoot(rootPath: string): string;
determineAppname(): void;
getCollisionFilter(): (output: any) => void;
hookFor(name: string, config: IHookConfig): void;
option(name: string, config?: IYeomanGeneratorOption): void;
rootGeneratorName(): string;
run(args?: any): void;
run(args: any, callback?: Function): void;
runHooks(callback?: Function): void;
sourceRoot(rootPath: string): string;
addListener(event: string, listener: Function): NodeJS.EventEmitter;
on(event: string, listener: Function): NodeJS.EventEmitter;
once(event: string, listener: Function): NodeJS.EventEmitter;
removeListener(event: string, listener: Function): NodeJS.EventEmitter;
removeAllListeners(event?: string): NodeJS.EventEmitter;
setMaxListeners(n: number): void;
listeners(event: string): Function[];
emit(event: string, ...args: any[]): boolean;
export interface IHookConfig {
as: string;
args: any;
options: any;
}
async(): any;
prompt(opt?:IPromptOptions, callback?:(answers:any)=>void) :void;
log(message: string) : void;
npmInstall(packages: string[], options?:any) :void;
export interface IYeomanGeneratorOption {
alias: string;
defaults: any;
desc: string;
hide: boolean;
type: any;
}
appname: string;
gruntfile: IGruntFileStatic;
}
export interface IPromptOptions{
type:string;
name:string;
message:string;
default:string;
}
export interface IGruntFileStatic {
loadNpmTasks(pluginName: string): void;
insertConfig(name:string, config:any):void;
registerTask(name:string, tasks:any):void;
insertVariable(name:string, value:any):void;
prependJavaScript(code:string):void;
}
export interface IQueueProps {
initializing: () => void;
prompting?: () => void;
configuring?: () => void;
default?: () => void;
writing: {
[target: string]: () => void;
};
conflicts?: () => void;
install?: () => void;
end: () => void;
}
export interface IArgumentConfig {
desc: string;
required: boolean;
optional: boolean;
type: any;
defaults: any;
}
export interface INamedBase extends IYeomanGenerator {
}
export interface IComposeSetting {
local?: string;
link?: string;
}
export interface IBase extends INamedBase {
}
export interface IHookConfig {
as: string;
args: any;
options: any;
}
export interface IAssert {
file(path: string): void;
file(paths: string[]): void;
fileContent(file: string, reg: RegExp): void;
export interface IYeomanGeneratorOption {
alias?: string;
defaults?: any;
desc?: string;
hide?: boolean;
type?: any;
}
/** @param {[String, RegExp][]} pairs */
fileContent(pairs: any[][]): void;
export interface IQueueProps {
initializing: () => void;
prompting?: () => void;
configuring?: () => void;
default?: () => void;
writing: {
[target: string]: () => void;
};
conflicts?: () => void;
install?: () => void;
end: () => void;
}
/** @param {[String, RegExp][]|String[]} pairs */
files(pairs: any[]): void;
export interface INamedBase extends IYeomanGenerator {
}
/**
* @param {Object} subject
* @param {Object|Array} methods
*/
implement(subject: any, methods: any): void;
noFile(file: string): void;
noFileContent(file: string, reg: RegExp): void;
export interface IBase extends INamedBase {
}
/** @param {[String, RegExp][]} pairs */
noFileContent(pairs: any[][]): void;
export interface IAssert {
file(path: string): void;
file(paths: string[]): void;
fileContent(file: string, reg: RegExp): void;
/**
* @param {Object} subject
* @param {Object|Array} methods
*/
noImplement(subject: any, methods: any): void;
/** @param {[String, RegExp][]} pairs */
fileContent(pairs: any[][]): void;
textEqual(value: string, expected: string): void;
}
/** @param {[String, RegExp][]|String[]} pairs */
files(pairs: any[]): void;
export interface ITestHelper {
createDummyGenerator(): IYeomanGenerator;
createGenerator(name: string, dependencies: any[], args: any, options: any): IYeomanGenerator;
decorate(context: any, method: string, replacement: Function, options: any): void;
gruntfile(options: any, done: Function): void;
mockPrompt(generator: IYeomanGenerator, answers: any): void;
registerDependencies(dependencies: string[]): void;
restore(): void;
/**
* @param {Object} subject
* @param {Object|Array} methods
*/
implement(subject: any, methods: any): void;
noFile(file: string): void;
noFileContent(file: string, reg: RegExp): void;
/** @param {String|Function} generator */
run(generator: any): IRunContext;
}
/** @param {[String, RegExp][]} pairs */
noFileContent(pairs: any[][]): void;
export interface IRunContext {
async(): Function;
inDir(dirPath: string): IRunContext;
/**
* @param {Object} subject
* @param {Object|Array} methods
*/
noImplement(subject: any, methods: any): void;
/** @param {String|String[]} args */
withArguments(args: any): IRunContext;
withGenerators(dependencies: string[]): IRunContext;
withOptions(options: any): IRunContext;
withPrompts(answers: any): IRunContext;
}
textEqual(value: string, expected: string): void;
}
/** @type file file-utils */
var file: any;
var assert: IAssert;
var test: ITestHelper;
module generators {
export interface ITestHelper {
createDummyGenerator(): IYeomanGenerator;
createGenerator(name: string, dependencies: any[], args: any, options: any): IYeomanGenerator;
decorate(context: any, method: string, replacement: Function, options: any): void;
gruntfile(options: any, done: Function): void;
mockPrompt(generator: IYeomanGenerator, answers: any): void;
registerDependencies(dependencies: string[]): void;
restore(): void;
export class NamedBase extends YeomanGeneratorBase implements INamedBase {
constructor(args: string | string[], options: any);
}
/** @param {String|Function} generator */
run(generator: any): IRunContext;
}
export class Base extends NamedBase implements IBase {
static extend(protoProps: IQueueProps, staticProps?: any): IYeomanGenerator;
}
}
export interface IRunContext {
async(): Function;
inDir(dirPath: string): IRunContext;
/** @param {String|String[]} args */
withArguments(args: any): IRunContext;
withGenerators(dependencies: string[]): IRunContext;
withOptions(options: any): IRunContext;
withPrompts(answers: any): IRunContext;
}
/** @type file file-utils */
var file: any;
var assert: IAssert;
var test: ITestHelper;
module generators {
export class NamedBase extends YeomanGeneratorBase implements INamedBase {
constructor(args: string | string[], options: any);
}
export class Base extends NamedBase implements IBase {
static extend(protoProps: IQueueProps, staticProps?: any): IYeomanGenerator;
}
}
}
declare module "yeoman-generator" {
export = yo;
export = yo;
}