├── .gitignore
├── README.md
├── project00_Calculator
├── addition.ts
├── division.ts
├── main.ts
├── multiplication.ts
├── package.json
├── substraction.js
├── substraction.ts
└── tsconfig.json
├── project01_number_guessing_game
├── guessNumber.ts
├── package.json
└── tsconfig.json
└── project02_Atom
├── .gitignore
├── index.ts
├── package.json
└── tsconfig.json
/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore Node.js development dependencies
2 | node_modules/
3 | npm-debug.log
4 |
5 | # Ignore yarn.lock and package-lock.json files
6 | yarn.lock
7 | package-lock.json
8 | *.js
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
TypeScript Node Projects
2 |
3 | TypeScript Node CLI Projects
4 |
5 |
6 |
7 |
8 |
9 |
10 | ## Table of Contents
11 | - [About](#about)
12 | - [Features](#features)
13 |
14 | ## About
15 |
16 | This repository is a treasure of TypeScript-based Node CLI projects, each designed to showcase a different aspect of programming and problem-solving. Inside, you'll discover a diverse array of applications, including a calculator for mathematical tasks, a number guessing game that challenges your intuition, an ATM simulator for financial interactions, a to-do list manager for keeping your tasks organized, a currency converter for global financial conversions, a word counter to analyze text, a student management system for educational institutions, an adventure game to embark on exciting quests, a quiz app to test your knowledge, a countdown timer to keep track of time, a bank application for financial management, and an array of other fascinating creations. These projects are not only excellent learning resources but also serve as a testament to the versatility of TypeScript and Node.js in building real-world command-line applications.
17 |
18 | ## Features
19 |
20 | 1. **Interactive Command Line**: Use the `inquirer` library to create interactive command-line prompts, making it easy for users to input data and make selections within the CLI.
21 | 2. **Styling and Coloring**: Integrate `chalk` for adding colors and styles to text in the terminal, making your CLI tool visually appealing and easy to read.
22 | 3. **Command Line Argument Parsing**: Utilize libraries like `yargs` or TypeScript's built-in `process.argv` to parse command-line arguments and options, allowing users to customize the behavior of your CLI.
23 | 4. **File System Manipulation**: TypeScript provides built-in support for file system operations, allowing you to create, read, write, and manipulate files and directories as needed for your CLI projects.
24 | 5. **External APIs**: Connect to external APIs using libraries like `axios` to fetch data from the internet, making your CLI tools dynamic and data-driven.
25 | 6. **Error Handling**: Implement robust error handling using TypeScript's exception handling or libraries like `try-catch-finally` to gracefully handle errors and provide meaningful error messages to users.
26 | 7. **Unit Testing**: Use testing frameworks like `Jest` or `Mocha` along with assertion libraries like `Chai` to ensure the reliability and stability of your CLI projects.
27 | 8. **Logging**: Implement a logging mechanism using libraries like `winston` to capture and store logs for debugging and troubleshooting purposes.
28 | 9. **Configuration Management**: Manage configuration settings using libraries like `dotenv` to keep sensitive information secure and allow users to customize your CLI's behavior via configuration files.
29 | 10. **Promises and Async/Await**: Leverage TypeScript's native support for Promises and Async/Await to handle asynchronous operations efficiently, such as making HTTP requests or reading files.
30 | 11. **Data Validation**: Use libraries like `validator` to validate user input and data, ensuring data integrity and security in your CLI applications.
31 | 12. **CLI Testing**: Employ CLI testing frameworks like `cypress` or `jest` with simulated user input to automate testing of your CLI projects.
32 | 13. **Documentation**: Provide clear and comprehensive documentation for your CLI projects, including a well-structured README file, to help users understand how to use your tool effectively.
33 |
34 |
35 |
--------------------------------------------------------------------------------
/project00_Calculator/addition.ts:
--------------------------------------------------------------------------------
1 | export function sum (a:number,b:number): number {
2 | return a+b;
3 | }
4 |
--------------------------------------------------------------------------------
/project00_Calculator/division.ts:
--------------------------------------------------------------------------------
1 | export function div(a: number, b: number): number {
2 | if (b === 0) {
3 | throw new Error("Division by zero is not allowed.");
4 | }
5 | return a / b;
6 | }
7 |
--------------------------------------------------------------------------------
/project00_Calculator/main.ts:
--------------------------------------------------------------------------------
1 | import { sum } from "./addition.js";
2 | import { sub } from "./substraction.js";
3 | import { mul } from "./multiplication.js";
4 | import { div } from "./division.js";
5 | import inquirer from "inquirer";
6 | import chalk from "chalk";
7 | import showBanner from "node-banner";
8 | import { error } from "console";
9 | async function main()
10 | {
11 | try {
12 | await showBanner('Calculator', 'A modular calculator program with Inquirer, chalk, and node-banner.');
13 |
14 | let answers = await inquirer.prompt([
15 | {
16 | name:"a",
17 | type:"number",
18 | message:chalk.bgMagenta.white("Please Enter First Number")
19 | },
20 | {
21 | name:"b",
22 | type:"number",
23 | message:chalk.bgMagenta.white("Please Enter Second Number")
24 | },
25 | {
26 | name:"operation",
27 | type:"list",
28 | message:chalk.bgMagenta("Choose an operation:"),
29 | choices:['Addition','Substraction','Multiplication','Division']
30 | }
31 | ]);
32 | const {a,b,operation} = answers;
33 | switch (operation) {
34 | case 'Addition':
35 | console.log(chalk.bgGreen.black(`The Addition of ${a} + ${b} = `,sum(a,b)));
36 | break;
37 | case 'Substraction':
38 | console.log(chalk.bgGreen.black(`The Addition of ${a} - ${b} = `,sub(a,b)));
39 | break;
40 | case 'Multiplication':
41 | console.log(chalk.bgGreen.black(`The Addition of ${a} * ${b} = `,mul(a,b)));
42 | break;
43 | case 'Division':
44 | console.log(chalk.bgGreen.black(`The Addition of ${a} / ${b} = `,div(a,b)));
45 | break;
46 |
47 | default:
48 | console.error(chalk.bgRed.black('Invalid operation.'))
49 | break;
50 | }
51 | }
52 | catch(error)
53 | {
54 | console.error('An error occurred:', error);
55 | }
56 | }
57 | main();
--------------------------------------------------------------------------------
/project00_Calculator/multiplication.ts:
--------------------------------------------------------------------------------
1 | export function mul (a:number,b:number): number {
2 | return a*b;
3 | }
4 |
--------------------------------------------------------------------------------
/project00_Calculator/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "calculator-assignment",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "type": "module",
7 | "scripts": {
8 | "test": "echo \"Error: no test specified\" && exit 1"
9 | },
10 | "keywords": [],
11 | "author": "",
12 | "license": "ISC",
13 | "devDependencies": {
14 | "@types/node": "^20.4.10"
15 | },
16 | "dependencies": {
17 | "chalk": "^5.3.0",
18 | "inquirer": "^9.2.10",
19 | "node-banner": "^1.4.0"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/project00_Calculator/substraction.js:
--------------------------------------------------------------------------------
1 | export function sub(a, b) {
2 | return a - b;
3 | }
4 |
--------------------------------------------------------------------------------
/project00_Calculator/substraction.ts:
--------------------------------------------------------------------------------
1 | export function sub (a:number,b:number): number {
2 | return a-b;
3 | }
4 |
--------------------------------------------------------------------------------
/project00_Calculator/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | /* Visit https://aka.ms/tsconfig to read more about this file */
4 |
5 | /* Projects */
6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12 |
13 | /* Language and Environment */
14 | "target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16 | // "jsx": "preserve", /* Specify what JSX code is generated. */
17 | // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26 |
27 | /* Modules */
28 | "module": "NodeNext", /* Specify what module code is generated. */
29 | // "rootDir": "./", /* Specify the root folder within your source files. */
30 | "moduleResolution": "NodeNext", /* Specify how TypeScript looks up a file from a given module specifier. */
31 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38 | // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
39 | // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
40 | // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
41 | // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42 | // "resolveJsonModule": true, /* Enable importing .json files. */
43 | // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
44 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */
45 |
46 | /* JavaScript Support */
47 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
48 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
49 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
50 |
51 | /* Emit */
52 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
53 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */
54 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
55 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
56 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
57 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
58 | // "outDir": "./", /* Specify an output folder for all emitted files. */
59 | // "removeComments": true, /* Disable emitting comments. */
60 | // "noEmit": true, /* Disable emitting files from a compilation. */
61 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
62 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
63 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
64 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
65 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
66 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
67 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
68 | // "newLine": "crlf", /* Set the newline character for emitting files. */
69 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
70 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
71 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
72 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
73 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
74 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
75 |
76 | /* Interop Constraints */
77 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
78 | // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
79 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
80 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
81 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
82 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
83 |
84 | /* Type Checking */
85 | "strict": true, /* Enable all strict type-checking options. */
86 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
87 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
88 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
89 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
90 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
91 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
92 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
93 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
94 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
95 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
96 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
97 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
98 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
99 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
100 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
101 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
102 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
103 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
104 |
105 | /* Completeness */
106 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107 | "skipLibCheck": true /* Skip type checking all .d.ts files. */
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/project01_number_guessing_game/guessNumber.ts:
--------------------------------------------------------------------------------
1 | import readline from 'readline'
2 | import chalk from 'chalk'
3 | import inquirer from 'inquirer'
4 | const r1 = readline.createInterface({
5 | input:process.stdin,
6 | output:process.stdout
7 | });
8 | function getRandomNumber(min:number, max:number):number
9 | {
10 | return Math.floor(Math.random()*(max-min+1))+min;
11 | }
12 | async function playGame()
13 | {
14 | const min = 1;
15 | const max = 100;
16 | const secretNumber = getRandomNumber(min,max)
17 | let attempts = 0;
18 | console.log(chalk.blue.bold('Welcome to the Guess the Number Game!'));
19 | console.log(`I'm thinking of a number between ${min} and ${max}.`);
20 | async function askForGuess()
21 | {
22 | const input = await inquirer.prompt([
23 | {
24 | type:'number',
25 | name:'guess',
26 | message:'Take a guess',
27 | validate:(value)=>{
28 | if(isNaN(value)|| value < min || value > max)
29 | {
30 | return 'Please enter a valid number between 1 and 100 ';
31 | }
32 | return true;
33 | },
34 | },
35 | ]);
36 | const guess = input.guess;
37 | attempts++;
38 | if(guess === secretNumber)
39 | {
40 | console.log(chalk.green.bold(`Congratulations! You guessed the number ${secretNumber} in ${attempts} attempts.`));
41 | }
42 | else if(guess < secretNumber)
43 | {
44 | console.log(chalk.red('Too low. Try again.'));
45 | askForGuess();
46 | }
47 | else
48 | {
49 | console.log(chalk.red('Too high. Try again.'));
50 | askForGuess();
51 | }
52 | }
53 | askForGuess();
54 | }
55 | // Display a banner
56 | console.log(chalk.yellow.bold('--------------------------------------'));
57 | console.log(chalk.yellow.bold(' Welcome to Guess the Number '));
58 | console.log(chalk.yellow.bold('--------------------------------------'));
59 | playGame();
--------------------------------------------------------------------------------
/project01_number_guessing_game/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "project01_number_guessing_game",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "guessNumber.js",
6 | "type": "module",
7 | "scripts": {
8 | "test": "echo \"Error: no test specified\" && exit 1"
9 | },
10 | "keywords": [],
11 | "author": "",
12 | "license": "ISC",
13 | "devDependencies": {
14 | "@types/chalk": "^2.2.0",
15 | "@types/inquirer": "^9.0.3",
16 | "@types/node": "^20.5.6"
17 | },
18 | "dependencies": {
19 | "chalk": "^5.3.0",
20 | "inquirer": "^9.2.10"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/project01_number_guessing_game/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | /* Visit https://aka.ms/tsconfig to read more about this file */
4 |
5 | /* Projects */
6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12 |
13 | /* Language and Environment */
14 | "target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16 | // "jsx": "preserve", /* Specify what JSX code is generated. */
17 | // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26 |
27 | /* Modules */
28 | "module": "NodeNext", /* Specify what module code is generated. */
29 | // "rootDir": "./", /* Specify the root folder within your source files. */
30 | "moduleResolution": "NodeNext", /* Specify how TypeScript looks up a file from a given module specifier. */
31 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38 | // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
39 | // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
40 | // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
41 | // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42 | // "resolveJsonModule": true, /* Enable importing .json files. */
43 | // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
44 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */
45 |
46 | /* JavaScript Support */
47 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
48 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
49 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
50 |
51 | /* Emit */
52 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
53 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */
54 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
55 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
56 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
57 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
58 | // "outDir": "./", /* Specify an output folder for all emitted files. */
59 | // "removeComments": true, /* Disable emitting comments. */
60 | // "noEmit": true, /* Disable emitting files from a compilation. */
61 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
62 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
63 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
64 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
65 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
66 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
67 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
68 | // "newLine": "crlf", /* Set the newline character for emitting files. */
69 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
70 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
71 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
72 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
73 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
74 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
75 |
76 | /* Interop Constraints */
77 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
78 | // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
79 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
80 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
81 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
82 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
83 |
84 | /* Type Checking */
85 | "strict": true, /* Enable all strict type-checking options. */
86 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
87 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
88 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
89 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
90 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
91 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
92 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
93 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
94 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
95 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
96 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
97 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
98 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
99 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
100 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
101 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
102 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
103 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
104 |
105 | /* Completeness */
106 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107 | "skipLibCheck": true /* Skip type checking all .d.ts files. */
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/project02_Atom/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore the node_modules directory
2 | node_modules/
3 |
4 | # Ignore .js files
5 | *.js
6 |
--------------------------------------------------------------------------------
/project02_Atom/index.ts:
--------------------------------------------------------------------------------
1 | import inquirer from 'inquirer';
2 | // Function to generate random alphanumeric string of a specified length
3 | const generateRandomAlphaNumeric = (length: number): string => {
4 | const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
5 | let result = '';
6 | for (let i = 0; i < length; i++) {
7 | const randomIndex = Math.floor(Math.random() * characters.length);
8 | result += characters.charAt(randomIndex);
9 | }
10 | return result;
11 | };
12 | // Function to generate a random number within a specified range
13 | const generateRandomNumber = (min: number, max: number): number => {
14 | return Math.floor(Math.random() * (max - min + 1)) + min;
15 | };
16 | // Function to generate a random financial amount as a string
17 | const generateRandomAccountBalance = (): string => {
18 | const minBalance = 100;
19 | const maxBalance = 10000;
20 | const decimalPlaces = 2;
21 | const randomBalance = (Math.random() * (maxBalance - minBalance) + minBalance).toFixed(decimalPlaces);
22 | return randomBalance;
23 | };
24 | // Function to generate random user data
25 | const generateRandomUser = () => ({
26 | userId: generateRandomAlphaNumeric(6),
27 | userPin: generateRandomNumber(1000,9999),
28 | accountBalance: generateRandomAccountBalance(),
29 | });
30 | // Generate a random user
31 | const randomUser = generateRandomUser();
32 | // Function for user authentication
33 | const authenticateUser = async () => {
34 | console.log('Welcome to the ATM.');
35 |
36 | const { userId, userPin } = await inquirer.prompt([
37 | {
38 | type: 'input',
39 | name: 'userId',
40 | message: 'Enter your User ID:',
41 | },
42 | {
43 | type: 'input',
44 | name: 'userPin',
45 | message: 'Enter your User PIN:',
46 | },
47 | ]);
48 |
49 | if (userId === randomUser.userId && parseInt(userPin) === randomUser.userPin) {
50 | console.log('Authentication successful!');
51 | // Proceed to ATM functionalities
52 | showAccountBalance(randomUser.accountBalance);
53 | } else {
54 | console.log('Authentication failed. Please try again.');
55 | }
56 | };
57 |
58 | // Function to display account balance
59 | const showAccountBalance = (balance: string) => {
60 | console.log(`Your account balance is $${balance}`);
61 | };
62 |
63 | // Call the authentication function to start the process
64 | authenticateUser();
65 |
--------------------------------------------------------------------------------
/project02_Atom/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "project02_atom",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "type": "module",
7 | "compilerOptions": {
8 | "esModuleInterop": true,
9 | "allowSyntheticDefaultImports": true
10 | },
11 | "scripts": {
12 | "test": "echo \"Error: no test specified\" && exit 1"
13 | },
14 | "keywords": [],
15 | "author": "",
16 | "license": "ISC",
17 | "dependencies": {
18 | "inquirer": "^9.2.11"
19 | },
20 | "devDependencies": {
21 | "@types/inquirer": "^9.0.3"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/project02_Atom/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | /* Visit https://aka.ms/tsconfig to read more about this file */
4 |
5 | /* Projects */
6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7 | // "composite": true,
8 | /* Enable constraints that allow a TypeScript project to be used with project references. */
9 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
10 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
11 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
12 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
13 |
14 | /* Language and Environment */
15 | "target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
16 | // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
17 | // "jsx": "preserve", /* Specify what JSX code is generated. */
18 | // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
19 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
20 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
21 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
22 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
23 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
24 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
25 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
26 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
27 |
28 | /* Modules */
29 | "module": "NodeNext", /* Specify what module code is generated. */
30 | // "rootDir": "./", /* Specify the root folder within your source files. */
31 | "moduleResolution": "NodeNext", /* Specify how TypeScript looks up a file from a given module specifier. */
32 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
33 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
34 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
35 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
36 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */
37 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
38 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
39 | // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
40 | // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
41 | // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
42 | // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
43 | // "resolveJsonModule": true, /* Enable importing .json files. */
44 | // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
45 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */
46 |
47 | /* JavaScript Support */
48 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
49 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
50 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
51 |
52 | /* Emit */
53 | // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
54 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */
55 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
56 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
57 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
58 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
59 | // "outDir": "./", /* Specify an output folder for all emitted files. */
60 | // "removeComments": true, /* Disable emitting comments. */
61 | // "noEmit": true, /* Disable emitting files from a compilation. */
62 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
63 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
64 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
65 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
66 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
67 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
68 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
69 | // "newLine": "crlf", /* Set the newline character for emitting files. */
70 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
71 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
72 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
73 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
74 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
75 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
76 |
77 | /* Interop Constraints */
78 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
79 | // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
80 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
81 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
82 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
83 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
84 |
85 | /* Type Checking */
86 | "strict": true, /* Enable all strict type-checking options. */
87 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
88 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
89 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
90 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
91 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
92 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
93 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
94 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
95 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
96 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
97 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
98 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
99 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
100 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
101 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
102 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
103 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
104 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
105 |
106 | /* Completeness */
107 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
108 | "skipLibCheck": true /* Skip type checking all .d.ts files. */
109 | }
110 | }
111 |
--------------------------------------------------------------------------------