typescript demo step by step

This commit is contained in:
Primakov Alexandr Alexandrovich
2024-10-09 00:16:12 +03:00
commit 14bd95b5ae
31 changed files with 2012 additions and 0 deletions

16
04_lint/eslint.config.mjs Normal file
View File

@@ -0,0 +1,16 @@
import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
export default [
{files: ['**/*.{js,mjs,cjs,ts}']},
{languageOptions: { globals: globals.browser }},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
rules: {
quotes: ['error', 'single'],
}
}
];

8
04_lint/example.ts Normal file
View File

@@ -0,0 +1,8 @@
const boys = 32;
const girls = 25;
const summ = (a, b) => {
return a + b;
}
const boysAndGirls = summ(boys, girls);

1597
04_lint/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

18
04_lint/package.json Normal file
View File

@@ -0,0 +1,18 @@
{
"name": "04_lint",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"@eslint/js": "^9.12.0",
"eslint": "^9.12.0",
"globals": "^15.10.0",
"typescript-eslint": "^8.8.1"
}
}

6
04_lint/src/index.ts Normal file
View File

@@ -0,0 +1,6 @@
import { logger } from './utils';
import { MESSAGE_TYPE } from "./model";
logger('good');
logger("something is wrong", MESSAGE_TYPE.WARNING)
logger('something is very wrong', MESSAGE_TYPE.ERROR);

View File

@@ -0,0 +1,12 @@
/**
* Тип сообщения.
*
* WARNING - Предупреждение.
* ERROR - Ошибка.
* SUCCESS - Успешно.
*/
export enum MESSAGE_TYPE {
WARNING = '#EA9325',
ERROR = '#FF3532',
SUCCESS = '#449D2C'
}

View File

@@ -0,0 +1,2 @@
export { MESSAGE_TYPE } from './enums';
export { TMessage } from './types';

View File

@@ -0,0 +1,4 @@
/**
* Сообщение.
*/
export type TMessage = string | number;

View File

@@ -0,0 +1 @@
export { logger } from './logUtils';

View File

@@ -0,0 +1,14 @@
import { TMessage, MESSAGE_TYPE } from '../model';
/**
* Логирует цветное сообщение в консоль.
*
* @param {TMessage} message Сообщение.
* @param {MESSAGE_TYPE} type Тип сообщения.
*/
export const logger = (message: TMessage, type: MESSAGE_TYPE = MESSAGE_TYPE.SUCCESS): void => {
console.info(`%c ${message}`, `
color: ${type};
font-size: 25px;
`);
};