Moving class to library

This commit is contained in:
saman
2021-12-03 11:05:35 -05:00
parent 4e92faf56b
commit 8d790378b9
5 changed files with 53 additions and 51 deletions

View File

@ -1,5 +1,5 @@
{
"name": "@nc/component-library",
"name": "@nerdy-canuck/component-library",
"repository": {
"type": "git",
"url": "https://github.com/joeythelantern/Component-Library.git"
@ -12,7 +12,7 @@
"dist"
],
"scripts": {
"build": "rm -rf dist/ && npm run build:esm && npm run build:cjs",
"build": "rm -rf dist/ && prettier --write src/ && npm run build:esm && npm run build:cjs",
"build:esm": "tsc",
"build:cjs": "tsc --module CommonJS --outDir dist/cjs"
},

View File

@ -1 +1 @@
export * from './useLogging';
export * from './useLogging';

View File

@ -1,47 +1,8 @@
import { useRef } from 'react';
class Logging {
private namespace = 'Client';
constructor(namespace?: string) {
if (namespace) this.namespace = namespace;
}
public info = (message: any) => {
if (typeof message === 'string') {
console.log(`[${this.getDate()}] [${this.namespace}] [INFO] ${message}`);
} else {
console.log(`[${this.getDate()}] [${this.namespace}] [INFO]`, message);
}
};
public warn = (message: any) => {
if (typeof message === 'string') {
console.log(`[${this.getDate()}] [${this.namespace}] [WARN] ${message}`);
} else {
console.log(`[${this.getDate()}] [${this.namespace}] [WARN]`, message);
}
};
public error = (message: any) => {
if (typeof message === 'string') {
console.log(`[${this.getDate()}] [${this.namespace}] [ERROR] ${message}`);
} else {
console.log(`[${this.getDate()}] [${this.namespace}] [ERROR]`, message);
}
};
public getDate = () => {
return new Date().toISOString();
};
public setNamespace = (namespace: string) => {
this.namespace = namespace;
};
}
export const useLogging = (namespace?: string): [Logging] => {
const { current: logging } = useRef(new Logging(namespace));
return [logging];
};
import { useRef } from 'react';
import Logging from '../library/Logging';
export const useLogging = (namespace?: string): [Logging] => {
const { current: logging } = useRef(new Logging(namespace));
return [logging];
};

View File

@ -1 +1 @@
export * from './hooks';
export * from './hooks';

41
src/library/Logging.ts Normal file
View File

@ -0,0 +1,41 @@
class Logging {
private namespace = 'Default';
constructor(namespace?: string) {
if (namespace) this.namespace = namespace;
}
public info = (message: any) => {
if (typeof message === 'string') {
console.log(`[${this.getDate()}] [${this.namespace}] [INFO] ${message}`);
} else {
console.log(`[${this.getDate()}] [${this.namespace}] [INFO]`, message);
}
};
public warn = (message: any) => {
if (typeof message === 'string') {
console.log(`[${this.getDate()}] [${this.namespace}] [WARN] ${message}`);
} else {
console.log(`[${this.getDate()}] [${this.namespace}] [WARN]`, message);
}
};
public error = (message: any) => {
if (typeof message === 'string') {
console.log(`[${this.getDate()}] [${this.namespace}] [ERROR] ${message}`);
} else {
console.log(`[${this.getDate()}] [${this.namespace}] [ERROR]`, message);
}
};
public getDate = () => {
return new Date().toISOString();
};
public setNamespace = (namespace: string) => {
this.namespace = namespace;
};
}
export default Logging;