first commit
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
dist/
|
||||||
|
node_modules/
|
10
.prettierrc
Normal file
10
.prettierrc
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"singleQuote": true,
|
||||||
|
"printWidth": 200,
|
||||||
|
"proseWrap": "always",
|
||||||
|
"tabWidth": 4,
|
||||||
|
"useTabs": false,
|
||||||
|
"trailingComma": "none",
|
||||||
|
"bracketSpacing": true,
|
||||||
|
"semi": true
|
||||||
|
}
|
8
.vscode/settings.json
vendored
Normal file
8
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||||
|
"editor.bracketPairColorization.enabled": true,
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"editor.formatOnPaste": true,
|
||||||
|
"editor.wordWrap": "on",
|
||||||
|
"git.ignoreLimitWarning": true
|
||||||
|
}
|
33
package.json
Normal file
33
package.json
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"name": "nerdy-canuck-component-library",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "",
|
||||||
|
"main": "dist/cjs/index.js",
|
||||||
|
"module": "dist/esm/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"types": "dist/index.d.ts",
|
||||||
|
"scripts": {
|
||||||
|
"rollup": "rm -rf dist/ && rollup -c"
|
||||||
|
},
|
||||||
|
"author": "The Nerdy Canuck",
|
||||||
|
"license": "MIT",
|
||||||
|
"devDependencies": {
|
||||||
|
"@rollup/plugin-commonjs": "^21.0.1",
|
||||||
|
"@rollup/plugin-node-resolve": "^13.0.6",
|
||||||
|
"@rollup/plugin-typescript": "^8.3.0",
|
||||||
|
"@types/react": "^17.0.37",
|
||||||
|
"@types/react-dom": "^17.0.11",
|
||||||
|
"react": "^17.0.2",
|
||||||
|
"react-dom": "^17.0.2",
|
||||||
|
"rollup": "^2.60.2",
|
||||||
|
"rollup-plugin-dts": "^4.0.1",
|
||||||
|
"rollup-plugin-flat-dts": "^1.4.0",
|
||||||
|
"tslib": "^2.3.1",
|
||||||
|
"typescript": "^4.5.2"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^17.0.2"
|
||||||
|
}
|
||||||
|
}
|
30
rollup.config.js
Normal file
30
rollup.config.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import resolve from '@rollup/plugin-node-resolve';
|
||||||
|
import commonjs from '@rollup/plugin-commonjs';
|
||||||
|
import typescript from '@rollup/plugin-typescript';
|
||||||
|
import dts from 'rollup-plugin-dts';
|
||||||
|
|
||||||
|
const packageJson = require('./package.json');
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
input: 'src/index.ts',
|
||||||
|
output: [
|
||||||
|
{
|
||||||
|
file: packageJson.main,
|
||||||
|
format: 'cjs',
|
||||||
|
sourcemap: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
file: packageJson.module,
|
||||||
|
format: 'esm',
|
||||||
|
sourcemap: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
plugins: [resolve(), commonjs(), typescript({ tsconfig: './tsconfig.json' })]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: 'dist/esm/types/index.d.ts',
|
||||||
|
output: [{ file: 'dist/index.d.ts', format: 'esm' }],
|
||||||
|
plugins: [dts()]
|
||||||
|
}
|
||||||
|
];
|
1
src/hooks/index.ts
Normal file
1
src/hooks/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './useLogging';
|
47
src/hooks/useLogging.ts
Normal file
47
src/hooks/useLogging.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
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];
|
||||||
|
};
|
1
src/index.ts
Normal file
1
src/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './hooks';
|
21
tsconfig.json
Normal file
21
tsconfig.json
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
// Default
|
||||||
|
"target": "ES6",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
// Added"
|
||||||
|
"jsx": "react",
|
||||||
|
"module": "ESNext",
|
||||||
|
"declaration": true,
|
||||||
|
"declarationDir": "types",
|
||||||
|
"sourceMap": true,
|
||||||
|
"outDir": "lib",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"emitDeclarationOnly": true
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user