diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d47e11e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,20 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Jest Current File", + "program": "${workspaceFolder}/node_modules/.bin/jest", + "args": ["${relativeFile}"], + "console": "integratedTerminal", + "internalConsoleOptions": "neverOpen", + "windows": { + "program": "${workspaceFolder}/node_modules/jest/bin/jest" + } + } + ] +} diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..8671812 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,6 @@ +module.exports = { + transform: { '^.+\\.ts?$': 'ts-jest' }, + testEnvironment: 'node', + testRegex: '/tests/.*\\.(test|spec)?\\.(ts|tsx)$', + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'] +}; diff --git a/package.json b/package.json index ac0c21d..8c26c12 100644 --- a/package.json +++ b/package.json @@ -1,25 +1,30 @@ { - "name": "cubetiq-ts-utils", - "version": "1.0.0", - "description": "CUBETIQ TypeScript Utils", - "main": "index.ts", - "repository": "https://github.com/CUBETIQ/cubetiq-ts-utils.git", - "author": "Sambo Chea", - "license": "MIT", - "private": false, - "dependencies": {}, - "devDependencies": { - "@typescript-eslint/eslint-plugin": "^4.17.0", - "@typescript-eslint/parser": "^4.17.0", - "eslint": "^7.21.0", - "eslint-config-prettier": "^8.1.0", - "eslint-plugin-prettier": "^3.3.1", - "prettier": "^2.2.1", - "typescript": "^4.2.3" - }, - "scripts": { - "build": "tsc -p tsconfig.json", - "lint": "eslint . --ext .ts", - "prettier": "prettier --config .prettierrc 'src/**/*.ts' --write" - } + "name": "cubetiq-ts-utils", + "version": "1.0.0", + "description": "CUBETIQ TypeScript Utils", + "main": "index.ts", + "repository": "https://github.com/CUBETIQ/cubetiq-ts-utils.git", + "author": "Sambo Chea", + "license": "MIT", + "private": false, + "dependencies": {}, + "devDependencies": { + "@types/jest": "^26.0.20", + "@typescript-eslint/eslint-plugin": "^4.17.0", + "@typescript-eslint/parser": "^4.17.0", + "eslint": "^7.21.0", + "eslint-config-prettier": "^8.1.0", + "eslint-plugin-prettier": "^3.3.1", + "jest": "^26.6.3", + "prettier": "^2.2.1", + "ts-jest": "^26.5.3", + "typescript": "^4.2.3" + }, + "scripts": { + "build": "tsc -p tsconfig.json", + "lint": "eslint . --ext .ts", + "prettier": "prettier --config .prettierrc 'src/**/*.ts' --write", + "test": "jest", + "coverage": "jest --coverage" + } } diff --git a/src/log/Log.ts b/src/log/Log.ts new file mode 100644 index 0000000..9ecba17 --- /dev/null +++ b/src/log/Log.ts @@ -0,0 +1,31 @@ +import { Loggable } from "./interfaces"; + +class Log { + static log(loggable: Loggable): void { + switch (loggable.type) { + case 'error': + this.error(loggable.from, loggable.data) + break; + case 'warn': + this.warn(loggable.from, loggable.data) + break; + default: + this.info(loggable.from, loggable.data) + break; + } + } + + static info(...data: any[]): void { + console.log(data); + } + + static error(...data: any[]): void { + console.error(data) + } + + static warn(...data: any[]): void { + console.warn(data) + } +} + +export default Log; diff --git a/src/log/interfaces.ts b/src/log/interfaces.ts new file mode 100644 index 0000000..05d3331 --- /dev/null +++ b/src/log/interfaces.ts @@ -0,0 +1,7 @@ +type LogType = 'info' | 'error' | 'warn' + +export interface Loggable { + type: LogType; + from?: string; + data?: any; +} \ No newline at end of file diff --git a/tests/log.test.ts b/tests/log.test.ts new file mode 100644 index 0000000..8fd7e57 --- /dev/null +++ b/tests/log.test.ts @@ -0,0 +1,23 @@ +import Log from '../src/log/Log'; + +describe('loggin into console', function () { + it('info', function () { + Log.info('I am an info!'); + }); + + it('warn', function () { + Log.info('I am a warn!'); + }); + + it('error', function () { + Log.info('I am an error!'); + }); + + it('loggable', function () { + Log.log({ + type: 'info', + from: 'log.test.ts', + data: 'I am loggable called' + }); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index cefe09a..e8c669f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,11 +11,11 @@ "module": "commonjs", "moduleResolution": "node", "resolveJsonModule": true, - "isolatedModules": true, "noEmit": true, "declaration": true, "outDir": "dist", - "rootDir": "src" + "rootDir": "src", }, - "include": ["src/**/*"] + "include": ["src/**/*"], + "exclude": ["node_modules"] }