Add minilog typings

This commit is contained in:
Guido Zuidhof 2014-11-12 20:53:16 +01:00
parent 41840d0049
commit 161a175f85
3 changed files with 163 additions and 1 deletions

View File

@ -1,4 +1,4 @@
# Contributors
# Contributors
This is a non-exhaustive list of definitions and their creators. If you created a definition but are not listed then feel free to send a pull request on this file with your name and url.
@ -280,6 +280,7 @@ All definitions files include a header with the author and editors, so at some p
* [md5.js](http://labs.cybozu.co.jp/blog/mitsunari/2007/07/md5js_1.html) (by [MIZUNE Pine](https://github.com/pine613))
* [Microsoft Ajax](http://msdn.microsoft.com/en-us/library/ee341002(v=vs.100).aspx) (by [Patrick Magee](https://github.com/pjmagee))
* [Microsoft Live Connect](http://msdn.microsoft.com/en-us/library/live/hh243643.aspx) (by [John Vilk](https://github.com/jvilk))
* [minilog](http://mixu.net/minilog/index.html) (by [Guido Zuidhof](https://github.com/Rahazan))
* [Minimatch](https://github.com/isaacs/minimatch) (by [vvakame](https://github.com/vvakame))
* [minimist](https://github.com/substack/minimist) (by [Bart van der Schoor](https://github.com/Bartvds))
* [Mithril](http://lhorie.github.io/mithril) (by [Leo Horie](https://github.com/lhorie) and [Chris Bowdon](https://github.com/cbowdon))

63
minilog/minilog-tests.ts Normal file
View File

@ -0,0 +1,63 @@
// Type definitions for minilog v2
// Project: https://github.com/mixu/minilog
// Definitions by: Guido <http://guido.io>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="minilog.d.ts"/>
//Following are example snippets from mixu.net/minilog
var log = Minilog('app');
Minilog.enable();
log
.debug('debug message')
.info('info message')
.warn('warning')
.error('this is an error message');
Minilog.pipe(Minilog.backends.console.formatWithStack)
.pipe(Minilog.backends.console);
Minilog
// formatter
.pipe(Minilog.backends.console.formatClean)
// backend
.pipe(Minilog.backends.console);
Minilog.pipe(Minilog.suggest) // filter
.pipe(Minilog.defaultFormatter) // formatter
.pipe(Minilog.defaultBackend); // backend - e.g. the console
Minilog.suggest.deny(/mymodule\/.*/, 'warn');
Minilog
.suggest
.clear()
.deny('foo', 'warn');
Minilog.enable();
Minilog.suggest.defaultResult = false;
Minilog
.suggest
.clear()
.allow('bar', 'info');
Minilog.enable();
var myFilter = new Minilog.Filter();
// allow any logs from the namespace/module "foo", level >= 'info
myFilter.allow('foo', 'debug');
// deny any logs where the module name matches "bar.*", level < 'warn'
// e.g. only let through "warn" and "error"
myFilter.deny(new RegExp('bar.*', 'warn'));
// now, create a custom pipe
Minilog.pipe(myFilter)
.pipe(Minilog.defaultFormatter)
.pipe(Minilog.defaultBackend);

98
minilog/minilog.d.ts vendored Normal file
View File

@ -0,0 +1,98 @@
// Type definitions for minilog v2
// Project: https://github.com/mixu/minilog
// Definitions by: Guido <http://guido.io>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
//These type definitions are not complete, although basic usage should be typed.
interface Minilog {
debug(msg: any): Minilog;
info(msg: any): Minilog;
log(msg: any): Minilog;
warn(msg: any): Minilog;
error(msg: any): Minilog;
}
declare function Minilog(namespace: string): Minilog;
declare module Minilog {
export function enable(): Minilog;
export function disable() : Minilog;
export function pipe(dest: any): Transform;
export var suggest: Filter;
export var backends: Minilog.MinilogBackends;
export var defaultBackend: any;
export var defaultFormatter: string;
export class Filter extends Transform{
/**
* Adds an entry to the whitelist
* Returns this filter
*/
allow(name: any, level?: any): Filter;
/**
* Adds an entry to the blacklist
* Returns this filter
*/
deny(name: any, level?: any): Filter;
/**
* Empties the whitelist and blacklist
* Returns this filter
*/
clear(): Filter;
test(name:any, level:any): boolean;
/**
* specifies the behavior when a log line doesn't match either the whitelist or the blacklist.
The default is true (= "allow by default") - lines that do not match the whitelist or the blacklist are not filtered (e.g. ).
If you want to flip the default so that lines are filtered unless they are on the whitelist, set this to false (= "deny by default").
*/
defaultResult: boolean;
/**
* controls whether the filter is enabled. Default: true
*/
enabled: boolean;
}
export interface MinilogBackends {
array: any;
browser: any;
console: Console;
localstorage: any;
jQuery: any;
}
export class Console extends Transform{
/**
* List of available formatters
*/
formatters: string[];
//Only available on client
color: Transform;
minilog: Transform;
//Only available on backend
formatClean: Transform;
formatColor: Transform;
formatNpm: Transform;
formatLearnboost: Transform;
formatMinilog: Transform;
formatWithStack: Transform;
}
export class Transform {
write(name: any, level: any, args: any): void;
pipe(dest: any): any;
unpipe(from: any): Transform;
mixin(dest: any): void;
}
}