Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Typings declaration file
Browse files Browse the repository at this point in the history
  • Loading branch information
harrisonhoward committed Oct 4, 2020
1 parent efffc94 commit 6f10b55
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { EventEmitter } from "events";

declare namespace NodeLogger {
type Key = number;
type LoggerPrefixFunction = () => string;
interface LoggerOptions {
prefix?: LoggerPrefixFunction,
dirPath?: string
}

export class Logger extends EventEmitter {
constructor(options?: LoggerOptions, seperator?: string);
private _seperator: string;
private _prefix: string;
private _dirPath: string;
private _history: LogHistory;
private _fileHistory: FileHistory | undefined;
public log(...log: (string | object)[]): Log;
public eventLog(...log: (string | object)[]): Log;
public info(...log: (string | object)[]): Log;
public debug(...log: (string | object)[]): Log;
public warn(...log: (string | object)[]): Log;
public error(...log: (string | object)[]): Log;
public readonly CONFIG: JSON;
public readonly history: LogHistory;
public readonly fileHistory: FileHistory;
public readonly prefix: LoggerPrefixFunction;
public readonly dirPath: string;
public readonly seperator: string;
}

export class Log {
constructor(prefix: string, seperator: string, ...logs: (string | object)[]);
private _prefix: string;
private _dateAdded: number;
private _seperator: string;
private _log: string;
public format(): string;
public clean(): string;
public readonly prefix: string;
public readonly seperator: string;
public readonly log: string;
public readonly dateAdded: number;
public readonly _CODES: string;
}

export class LogHistory extends Map<Key, Log> {
constructor(maxSize: number);
private _maxSize: number;
private _index: number;
public add(log: Log): this;
public _set(key: Key, log: Log): this;
public get(key: Key | Log): Log | undefined;
public getKey(log: Log): Key | undefined;
public find(callbackFn: (value: Log, key: Key, collection: this) => boolean): Log | undefined;
public find<T>(callbackFn: (this: T, value: Log, key: Key, collection: this) => boolean, thisArg: T): Log | undefined;
public filter(callbackFn: (value: Log, key: Key, collection: this) => boolean): this;
public filter<T>(callbackFn: (this: T, value: Log, key: Key, collection: this) => boolean, thisArg: T): this;
public map<T>(callbackFn: (value: Log, key: Key, collection: this) => T): T[];
public map<This, T>(callbackFn: (this: This, value: Log, key: Key, collection: this, thisArg: This) => T);
public delete(key: Key | Log): boolean;
public clear(): void;
public first(): Log;
public first(amount: number): Log[];
public last(): Log;
public last(amount: number): Log[];
public toArray(): Log[];
}

export class ReadWrite {
public static write(pathToFile: string, line: string): Promise<true | Error>;
public static read(pathToFile: string): Promise<string[]>;
public static dirIfNotExists(pathToFile: string): Promise<boolean>;
}

export class FileHistory {
constructor(dirPath: string, Logger: Logger);
private dirPath: string;
private Logger: Logger;
private year: () => number;
private month: () => string;
private day: () => string;
private _handleCatch(err: Error): void;
public getLatestLog(): Promise<string[]>;
}
}

0 comments on commit 6f10b55

Please sign in to comment.