Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
77e6a40261 | |||
3deb536323 | |||
f6b0e63751 | |||
d52f9cfdc3 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/js-utilities",
|
"name": "@ztimson/js-utilities",
|
||||||
"version": "0.3.5",
|
"version": "0.3.8",
|
||||||
"description": "JavaScript Utility library",
|
"description": "JavaScript Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -4,7 +4,6 @@ export * from './errors';
|
|||||||
export * from './logger';
|
export * from './logger';
|
||||||
export * from './misc';
|
export * from './misc';
|
||||||
export * from './objects';
|
export * from './objects';
|
||||||
// export * from './redis';
|
|
||||||
export * from './string';
|
export * from './string';
|
||||||
export * from './time';
|
export * from './time';
|
||||||
export * from './xhr';
|
export * from './xhr';
|
||||||
|
@ -43,9 +43,11 @@ export const CliBackground = {
|
|||||||
|
|
||||||
export enum LOG_LEVEL {
|
export enum LOG_LEVEL {
|
||||||
VERBOSE,
|
VERBOSE,
|
||||||
INFO,
|
DEBUG = 0,
|
||||||
WARN,
|
LOG = 1,
|
||||||
ERROR
|
INFO = 2,
|
||||||
|
WARN = 3,
|
||||||
|
ERROR = 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LoggerEvents = TypedEvents & {
|
export type LoggerEvents = TypedEvents & {
|
||||||
@ -70,7 +72,6 @@ export class Logger extends TypedEmitter<LoggerEvents> {
|
|||||||
return !end ? padding + t : t + padding;
|
return !end ? padding + t : t + padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private format(...text: string[]): string {
|
private format(...text: string[]): string {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const timestamp = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()} ${this.pad(now.getHours().toString(), 2, '0')}:${this.pad(now.getMinutes().toString(), 2, '0')}:${this.pad(now.getSeconds().toString(), 2, '0')}.${this.pad(now.getMilliseconds().toString(), 3, '0', true)}`;
|
const timestamp = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()} ${this.pad(now.getHours().toString(), 2, '0')}:${this.pad(now.getMinutes().toString(), 2, '0')}:${this.pad(now.getSeconds().toString(), 2, '0')}.${this.pad(now.getMilliseconds().toString(), 3, '0', true)}`;
|
||||||
@ -78,42 +79,37 @@ export class Logger extends TypedEmitter<LoggerEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
debug(...args: string[]) {
|
debug(...args: string[]) {
|
||||||
if(Logger.LOG_LEVEL >= LOG_LEVEL.VERBOSE) {
|
if(Logger.LOG_LEVEL > LOG_LEVEL.VERBOSE) return;
|
||||||
const str = this.format(...args);
|
const str = this.format(...args);
|
||||||
Logger.emit(LOG_LEVEL.VERBOSE, str);
|
Logger.emit(LOG_LEVEL.VERBOSE, str);
|
||||||
console.debug(CliForeground.LIGHT_GREY + str + CliEffects.CLEAR);
|
console.debug(CliForeground.LIGHT_GREY + str + CliEffects.CLEAR);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
error(...args: string[]) {
|
|
||||||
if(Logger.LOG_LEVEL >= LOG_LEVEL.ERROR) {
|
|
||||||
const str = this.format(...args);
|
|
||||||
Logger.emit(LOG_LEVEL.ERROR, str);
|
|
||||||
console.error(CliForeground.RED + str + CliEffects.CLEAR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
info(...args: string[]) {
|
|
||||||
if(Logger.LOG_LEVEL >= LOG_LEVEL.INFO) {
|
|
||||||
const str = this.format(...args);
|
|
||||||
Logger.emit(LOG_LEVEL.INFO, str);
|
|
||||||
console.info(CliForeground.BLUE + str + CliEffects.CLEAR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log(...args: string[]) {
|
log(...args: string[]) {
|
||||||
if(Logger.LOG_LEVEL >= LOG_LEVEL.INFO) {
|
if(Logger.LOG_LEVEL > LOG_LEVEL.INFO) return;
|
||||||
const str = this.format(...args);
|
const str = this.format(...args);
|
||||||
Logger.emit(LOG_LEVEL.INFO, str);
|
Logger.emit(LOG_LEVEL.INFO, str);
|
||||||
console.log(CliEffects.CLEAR + str);
|
console.log(CliEffects.CLEAR + str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info(...args: string[]) {
|
||||||
|
if(Logger.LOG_LEVEL > LOG_LEVEL.INFO) return;
|
||||||
|
const str = this.format(...args);
|
||||||
|
Logger.emit(LOG_LEVEL.INFO, str);
|
||||||
|
console.info(CliForeground.BLUE + str + CliEffects.CLEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
warn(...args: string[]) {
|
warn(...args: string[]) {
|
||||||
if(Logger.LOG_LEVEL >= LOG_LEVEL.WARN) {
|
if(Logger.LOG_LEVEL > LOG_LEVEL.WARN) return;
|
||||||
const str = this.format(...args);
|
const str = this.format(...args);
|
||||||
Logger.emit(LOG_LEVEL.WARN, str);
|
Logger.emit(LOG_LEVEL.WARN, str);
|
||||||
console.warn(CliForeground.YELLOW + str + CliEffects.CLEAR);
|
console.warn(CliForeground.YELLOW + str + CliEffects.CLEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error(...args: string[]) {
|
||||||
|
if(Logger.LOG_LEVEL > LOG_LEVEL.ERROR) return;
|
||||||
|
const str = this.format(...args);
|
||||||
|
Logger.emit(LOG_LEVEL.ERROR, str);
|
||||||
|
console.error(CliForeground.RED + str + CliEffects.CLEAR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,12 @@ export function formEncode(data: any): string {
|
|||||||
* Get profile image from Gravatar
|
* Get profile image from Gravatar
|
||||||
*
|
*
|
||||||
* @param {string} email Account email address
|
* @param {string} email Account email address
|
||||||
|
* @param {string} def Default image, can be a link or '404', see: https://docs.gravatar.com/general/images/
|
||||||
* @returns {string} Gravatar URL
|
* @returns {string} Gravatar URL
|
||||||
*/
|
*/
|
||||||
export function gravatar(email: string) {
|
export function gravatar(email: string, def='mp') {
|
||||||
if(!email) return '';
|
if(!email) return '';
|
||||||
return `https://www.gravatar.com/avatar/${md5(email)}`;
|
return `https://www.gravatar.com/avatar/${md5(email)}?d=${def}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Parts of a URL */
|
/** Parts of a URL */
|
||||||
|
Reference in New Issue
Block a user