commit 27cd5e213c473d5abae1bd7e4cdc5405b1257383 Author: saman Date: Fri Dec 3 00:24:17 2021 -0500 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8cdcaea --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +dist/ +node_modules/ \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..6248932 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,10 @@ +{ + "singleQuote": true, + "printWidth": 200, + "proseWrap": "always", + "tabWidth": 4, + "useTabs": false, + "trailingComma": "none", + "bracketSpacing": true, + "semi": true +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8c898d7 --- /dev/null +++ b/.vscode/settings.json @@ -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 +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..7625f02 --- /dev/null +++ b/package.json @@ -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" + } +} diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..4c47620 --- /dev/null +++ b/rollup.config.js @@ -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()] + } +]; diff --git a/src/hooks/index.ts b/src/hooks/index.ts new file mode 100644 index 0000000..882812e --- /dev/null +++ b/src/hooks/index.ts @@ -0,0 +1 @@ +export * from './useLogging'; diff --git a/src/hooks/useLogging.ts b/src/hooks/useLogging.ts new file mode 100644 index 0000000..48e5891 --- /dev/null +++ b/src/hooks/useLogging.ts @@ -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]; +}; diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..391d5bf --- /dev/null +++ b/src/index.ts @@ -0,0 +1 @@ +export * from './hooks'; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..4e717a5 --- /dev/null +++ b/tsconfig.json @@ -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 + } +}