typescript demo step by step
This commit is contained in:
16
04_lint/eslint.config.mjs
Normal file
16
04_lint/eslint.config.mjs
Normal 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
8
04_lint/example.ts
Normal 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
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
18
04_lint/package.json
Normal 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
6
04_lint/src/index.ts
Normal 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);
|
||||
12
04_lint/src/model/enums.ts
Normal file
12
04_lint/src/model/enums.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Тип сообщения.
|
||||
*
|
||||
* WARNING - Предупреждение.
|
||||
* ERROR - Ошибка.
|
||||
* SUCCESS - Успешно.
|
||||
*/
|
||||
export enum MESSAGE_TYPE {
|
||||
WARNING = '#EA9325',
|
||||
ERROR = '#FF3532',
|
||||
SUCCESS = '#449D2C'
|
||||
}
|
||||
2
04_lint/src/model/index.ts
Normal file
2
04_lint/src/model/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { MESSAGE_TYPE } from './enums';
|
||||
export { TMessage } from './types';
|
||||
4
04_lint/src/model/types.ts
Normal file
4
04_lint/src/model/types.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Сообщение.
|
||||
*/
|
||||
export type TMessage = string | number;
|
||||
1
04_lint/src/utils/index.ts
Normal file
1
04_lint/src/utils/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { logger } from './logUtils';
|
||||
14
04_lint/src/utils/logUtils.ts
Normal file
14
04_lint/src/utils/logUtils.ts
Normal 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;
|
||||
`);
|
||||
};
|
||||
Reference in New Issue
Block a user