From 161a175f8584bb9fb242fde066fcd02afac0c8b4 Mon Sep 17 00:00:00 2001 From: Guido Zuidhof Date: Wed, 12 Nov 2014 20:53:16 +0100 Subject: [PATCH] Add minilog typings --- CONTRIBUTORS.md | 3 +- minilog/minilog-tests.ts | 63 ++++++++++++++++++++++++++ minilog/minilog.d.ts | 98 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 minilog/minilog-tests.ts create mode 100644 minilog/minilog.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index e10ca14d4ca596..c45542a9f3dfe2 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -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)) diff --git a/minilog/minilog-tests.ts b/minilog/minilog-tests.ts new file mode 100644 index 00000000000000..3a9bb0f4dea67f --- /dev/null +++ b/minilog/minilog-tests.ts @@ -0,0 +1,63 @@ +// Type definitions for minilog v2 +// Project: https://github.com/mixu/minilog +// Definitions by: Guido +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + + +//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); + + diff --git a/minilog/minilog.d.ts b/minilog/minilog.d.ts new file mode 100644 index 00000000000000..d9d1695bf29d8f --- /dev/null +++ b/minilog/minilog.d.ts @@ -0,0 +1,98 @@ +// Type definitions for minilog v2 +// Project: https://github.com/mixu/minilog +// Definitions by: Guido +// 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; + } + +} \ No newline at end of file