Skip to content

Commit 7e99002

Browse files
committed
first commit (add files)
1 parent 7557850 commit 7e99002

File tree

12 files changed

+288
-2
lines changed

12 files changed

+288
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.vscode/extensions.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"recommendations": [
3+
"esbenp.prettier-vscode"
4+
]
5+
}

.vscode/settings.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"editor.tabSize": 2,
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"editor.formatOnSave": true,
5+
"editor.formatOnSaveMode": "modifications",
6+
"prettier.printWidth": 150,
7+
"typescript.tsserver.maxTsServerMemory": 8000,
8+
"[json]": {
9+
"editor.defaultFormatter": "vscode.json-language-features"
10+
},
11+
"files.watcherExclude": {
12+
"**/.git/objects/**": true,
13+
"**/.git/subtree-cache/**": true,
14+
"**/node_modules/*/**": true,
15+
"**/.hg/store/**": true,
16+
"**/build/**": true,
17+
"**/.yarn/**": true
18+
}
19+
}

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
1-
# example-of-class-in-typescript
2-
example of class in typescript
1+
## Example of class in typescript
2+
3+
### How to use this ?
4+
5+
#### Requiered
6+
7+
1. Node
8+
2. Yarn
9+
10+
Once the prerequisites are installed you need to clone the repo via the link
11+
`git@github.com:ydainna/example-of-class-in-typescript.git`
12+
13+
Once this is done you just have to open the project then do `yarn install` in the terminal and finally do `yarn start` to run the script.

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "ts-class",
3+
"version": "1.0.0",
4+
"license": "UNLICENSED",
5+
"author": "ydainna",
6+
"private": true,
7+
"scripts": {
8+
"start": "ts-node ./src/app.ts"
9+
},
10+
"dependencies": {
11+
"tslog": "^3.3.4",
12+
"typescript": "^4.8.4"
13+
},
14+
"devDependencies": {
15+
"@tsconfig/node16": "^1.0.3",
16+
"@types/node": "^16.11.7",
17+
"ts-node": "^10.9.1"
18+
}
19+
}

src/Car.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { getLogger } from './utils/getLogger';
2+
import Vehicle from './Vehicle';
3+
4+
class Car extends Vehicle {
5+
6+
private lockDoors: boolean;
7+
8+
constructor(name: string, color: string, wheels: number, lockDoors: boolean = true) {
9+
super(name, color, wheels);
10+
this.lockDoors = lockDoors;
11+
}
12+
public logTypesProps(): void {
13+
const log = getLogger("Car");
14+
log.info(`Information(s): ${this.getPropsString()}, doors ${this.lockDoors ? "locked" : "unlocked"}`);
15+
}
16+
}
17+
18+
export default Car;

src/Motorcycle.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { getLogger } from './utils/getLogger';
2+
import Vehicle from './Vehicle';
3+
4+
class Motorcycle extends Vehicle {
5+
constructor(name: string, color: string, wheels: number) {
6+
super(name, color, wheels);
7+
}
8+
public logTypesProps(): void {
9+
const log = getLogger("Motorcycle");
10+
log.info(`Information(s): ${this.getPropsString()}`);
11+
}
12+
}
13+
14+
export default Motorcycle;

src/Vehicle.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { getLogger } from "./utils/getLogger";
2+
3+
class Vehicle {
4+
private name: string;
5+
private color: string;
6+
private wheels: number;
7+
8+
constructor(name: string, color: string, wheels: number = 4) {
9+
this.name = name;
10+
this.color = color;
11+
this.wheels = wheels;
12+
}
13+
14+
public getPropsString(): string {
15+
return `Name: ${this.name}, Color: ${this.color}, Wheels: ${this.wheels}`;
16+
}
17+
18+
public logTypsProps(): void {
19+
const log = getLogger("Vehicle");
20+
log.info(this.getPropsString());
21+
}
22+
}
23+
24+
export default Vehicle;

src/app.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Vehicl from "./Vehicle";
2+
import Car from "./Car";
3+
import Motorcycle from "./Motorcycle";
4+
5+
const vehicle = new Vehicl("Vehicle", "Red");
6+
vehicle.logTypsProps();
7+
8+
const car = new Car("Car", "Blue", 4, true);
9+
car.logTypesProps();
10+
11+
const motorcycle = new Motorcycle("Motorcycle", "Black", 2);
12+
motorcycle.logTypesProps();

src/utils/getLogger.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Logger } from "tslog";
2+
3+
export function getLogger(name: string): Logger {
4+
return new Logger({
5+
name,
6+
displayFilePath: "hidden",
7+
displayFunctionName: false,
8+
dateTimeTimezone: "Europe/Paris",
9+
dateTimePattern: "hour:minute:second.millisecond ",
10+
});
11+
}

0 commit comments

Comments
 (0)