refactor: rebuild logger to be static

Fixes #4
This commit is contained in:
Karl-Philipp Wulfert
2019-03-27 16:37:25 +01:00
committed by Karl-Philipp Wulfert
parent 7ef29ef56d
commit 1ae3beb347
4 changed files with 193 additions and 312 deletions

View File

@@ -13,15 +13,17 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* A recursive partial object
*
* Copied from https://stackoverflow.com/a/51365037
*/
/**
* A recursive partial object
*
* Copied from https://stackoverflow.com/a/51365037
*/
import {Transport, VerifiableTransport} from './Transport';
export type RecursivePartial<T> = {
[P in keyof T]?: T[P] extends Array<infer U> ?
Array<RecursivePartial<U>> :
T[P] extends object ? RecursivePartial<T[P]> : T[P];
Array<RecursivePartial<U>> :
T[P] extends object ? RecursivePartial<T[P]> : T[P];
};
/**
@@ -47,3 +49,35 @@ export function deleteUndefinedProperties(obj: any) {
return obj;
}
/**
* Checks if environment is Node.js
*/
export function isNodeEnvironment(): boolean {
return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
}
/**
* Checks if environment is productive
*/
export function isProductiveEnvironment(): boolean {
return typeof process.env === 'object'
&& typeof process.env.NODE_ENV !== 'undefined'
&& process.env.NODE_ENV === 'production';
}
/**
* Checks if environment is Node.js and productive
*/
export function isProductiveNodeEnvironment(): boolean {
return isNodeEnvironment() && isProductiveEnvironment();
}
/**
* Check if a transport is a verifiable transport
*
* @param transport Transport to check
*/
export function isTransportWithVerification(transport: Transport): transport is VerifiableTransport {
return transport instanceof VerifiableTransport;
}