diff --git a/package.json b/package.json index 9a5550d..c4d4c8e 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 882812e..a1e2dab 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -1 +1 @@ -export * from './useLogging'; +export * from './useLogging'; diff --git a/src/hooks/useLogging.ts b/src/hooks/useLogging.ts index 48e5891..c686fa0 100644 --- a/src/hooks/useLogging.ts +++ b/src/hooks/useLogging.ts @@ -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]; +}; diff --git a/src/index.ts b/src/index.ts index 391d5bf..4cc90d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -export * from './hooks'; +export * from './hooks'; diff --git a/src/library/Logging.ts b/src/library/Logging.ts new file mode 100644 index 0000000..6ad2930 --- /dev/null +++ b/src/library/Logging.ts @@ -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;