Skip to content

Commit 18a3b65

Browse files
committed
code compiled to ES2015
1 parent f9b1496 commit 18a3b65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+893
-4
lines changed

dist/module-2/alias.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use strict";
2+
const crush1 = {
3+
name: "Lisa Pakhi",
4+
age: 25,
5+
profession: "Artist",
6+
address: "South Korea",
7+
};
8+
const crush2 = {
9+
name: "Rosie Pakhi",
10+
age: 27,
11+
profession: "Artist",
12+
address: "South Korea",
13+
};
14+
const isCrushMarried = false;
15+
const calculate = (n1, // 10
16+
n2, // 20
17+
operation // (x, y) => x + y
18+
) => {
19+
return operation(n1, n2);
20+
};
21+
calculate(10, 20, (x, y) => x + y);
22+
calculate(10, 20, (x, y) => x + y);
23+
calculate(10, 20, (x, y) => x - y);
24+
// console.log(calculate(10, 20, (x, y) => x - y));
25+
// console.log(calculate(10, 20, (x, y) => x * y));
26+
// console.log(calculate(10, 20, (x, y) => x * y));

dist/module-2/array.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
const jennie = ["abul", "kabul", "habul"];
3+
const lisa = [1, 3, 4];
4+
// tuple
5+
const stars = [12, "lisa"];
6+
const couple = ["lisa", "fans"];

dist/module-2/function.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use strict";
2+
// normal function // default parameter
3+
function addNumber(n1, n2, n3 = 10) {
4+
return n1 + n2 + n3;
5+
}
6+
addNumber(30, 20);
7+
// -------------
8+
// spread operator
9+
const myFriends = ["abul", "babul", "kabul"];
10+
const newFriends = ["orina", "jorina", "karina"];
11+
myFriends.push(...newFriends);
12+
// console.log(myFriends);
13+
// -------------
14+
// rest parameter
15+
const greetFriends = (...friends) => friends.forEach((friend) => console.log(`Hi ${friend}`));
16+
greetFriends("hashem", "kashem", "batashen", "ashen", "boshen");
17+
// -------------
18+
// array and object destructuring
19+
// -------------
20+
const addArrow = (n1, n2) => n1 + n2;
21+
// -------------
22+
const arr = [1, 2, 3, 4];
23+
const newArr = arr.map((elem) => elem * elem);
24+
// -------------
25+
const person = {
26+
name: "Saad",
27+
balance: 5,
28+
addBalance(money) {
29+
console.log(`My new balance is ${this.balance + money}`);
30+
},
31+
};

dist/module-2/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
let x = undefined;
3+
x = "a";
4+
x = 1;
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use strict";
2+
const searchName = (value) => {
3+
if (value === null)
4+
console.log("There is nothing to search");
5+
else
6+
console.log("Searching...");
7+
};
8+
// searchName(null);
9+
// ---------------
10+
const getMyCarSpeed = (speed) => {
11+
if (typeof speed === "number") {
12+
const convertedSpeed = (speed * 1000) / 3600; // kmh^-1 to ms^-1
13+
console.log(`My speed is ${convertedSpeed.toFixed(2)}`);
14+
}
15+
else if (typeof speed === "string") {
16+
const value = parseFloat(speed.split(" ")[0]);
17+
const convertedSpeed = (value * 1000) / 3600;
18+
console.log(`My speed is ${convertedSpeed.toFixed(2)}`);
19+
}
20+
else {
21+
console.log("Wrong Type");
22+
}
23+
};
24+
// getMyCarSpeed(10);
25+
// getMyCarSpeed("10 kmh^-1");
26+
// getMyCarSpeed(true);
27+
// ---------------
28+
function throwError(message) {
29+
throw new Error(message);
30+
}
31+
// throwError("Abort abort");

dist/module-2/object.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
const user = {
3+
company: "Programming Hero",
4+
name: "Montu mia",
5+
age: 52,
6+
isMarried: true,
7+
};
8+
//
9+
const user2 = {
10+
company: "Programming Hero",
11+
name: "Montu mia",
12+
age: 52,
13+
isMarried: true,
14+
};
15+
// user2.company = "Programming Hero";

dist/module-2/question-marks.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
var _a, _b;
3+
// ternary operator
4+
const age = 19;
5+
const isAdult = age >= 18 ? "Yes" : "No";
6+
// ------------
7+
// Nullish Coalescing Operator
8+
// Null and Undefined
9+
const isAuthenticatedUser = "demo";
10+
const userName = isAuthenticatedUser !== null && isAuthenticatedUser !== void 0 ? isAuthenticatedUser : "Guest";
11+
const manush = {
12+
name: "Boltu",
13+
age: 16,
14+
address: {
15+
city: "No city",
16+
road: "No road",
17+
},
18+
};
19+
const home = (_b = (_a = manush === null || manush === void 0 ? void 0 : manush.address) === null || _a === void 0 ? void 0 : _a.home) !== null && _b !== void 0 ? _b : "No home";
20+
console.log({ home });

dist/module-2/quiz.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
function generateAdder(a) {
3+
return function (b) {
4+
return a + b;
5+
};
6+
}
7+
const addTwo = generateAdder(2);
8+
console.log(addTwo(3));
9+
console.log(addTwo(5));

dist/module-2/union-intersection.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict";
2+
// Union
3+
const newDeveloper = {
4+
name: "Moznu Ali",
5+
expertise: "Javascript",
6+
experience: 6,
7+
};
8+
// intersection
9+
const developer = {
10+
name: "Super vai",
11+
expertise: "Typescript",
12+
experience: 2,
13+
leaderShipExperience: 1,
14+
level: "mid",
15+
};
16+
console.log(developer);

dist/module-3/asynchronus.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"use strict";
2+
// Mocking
3+
// Promise with different data types
4+
// Promise of string
5+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7+
return new (P || (P = Promise))(function (resolve, reject) {
8+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11+
step((generator = generator.apply(thisArg, _arguments || [])).next());
12+
});
13+
};
14+
const makePromiseString = () => {
15+
return new Promise((resolve, reject) => {
16+
const data = "Data fetched";
17+
if (data) {
18+
resolve(data);
19+
}
20+
else {
21+
reject("Failed to fetch data");
22+
}
23+
});
24+
};
25+
const getPromiseString = () => __awaiter(void 0, void 0, void 0, function* () {
26+
const data = yield makePromiseString();
27+
console.log(data);
28+
});
29+
// getPromise();
30+
// ----------------
31+
// Promise of boolean
32+
const makePromiseBoolean = () => {
33+
return new Promise((resolve, reject) => {
34+
const data = true;
35+
if (data)
36+
resolve(data);
37+
else
38+
reject("Failed to fetch data");
39+
});
40+
};
41+
const getPromiseBoolean = () => __awaiter(void 0, void 0, void 0, function* () {
42+
const data = yield makePromiseBoolean();
43+
console.log(data);
44+
});
45+
const makePromiseObject = () => {
46+
return new Promise((resolve, reject) => {
47+
const data = { data: "Data is fetched" };
48+
if (data)
49+
resolve(data);
50+
else
51+
reject("Failed to fetch data");
52+
});
53+
};
54+
const getPromiseObject = () => __awaiter(void 0, void 0, void 0, function* () {
55+
const data = yield makePromiseObject();
56+
console.log(data);
57+
return data;
58+
});
59+
const getTodo = () => __awaiter(void 0, void 0, void 0, function* () {
60+
const response = yield fetch("https://jsonplaceholder.typicode.com/todos/1");
61+
return yield response.json();
62+
});
63+
const getTodoData = () => __awaiter(void 0, void 0, void 0, function* () {
64+
const data = yield getTodo();
65+
console.log(data);
66+
return data;
67+
});
68+
getTodoData();

dist/module-3/conditional-type.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"use strict";

dist/module-3/generic-constraints.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict";
2+
const myInfo1 = {
3+
name: "Saad",
4+
age: 22,
5+
salary: 100000000,
6+
other1: false,
7+
other2: null,
8+
};
9+
const addMeToMyCrushMind1 = (myInfo) => {
10+
const crush = "Kate Winslet";
11+
const newData = Object.assign(Object.assign({}, myInfo), { crush });
12+
return newData;
13+
};
14+
// const result6 = addMeToMyCrushMind1<MyInfoType>(myInfo1);
15+
const result6 = addMeToMyCrushMind1(myInfo1);
16+
// result6.

dist/module-3/generic-function.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"use strict";
2+
const createArray1 = (param) => {
3+
return [param];
4+
};
5+
// const createArray2 = <T>(param: T): T[] => {
6+
// return [param];
7+
// };
8+
// using tuple
9+
// arrow function
10+
const createArray2 = (param1, param2) => {
11+
return [param1, param2];
12+
};
13+
// normal function
14+
function createArray3(param1, param2) {
15+
return [param1, param2];
16+
}
17+
const result1 = createArray2("Japan", "I love Bangladesh");
18+
const result2 = createArray2(false, ["USA"]);
19+
const result3 = createArray2({ name: "India" }, "I love Bangladesh");
20+
const result4 = createArray2({ name: "India" }, true);
21+
// ------------------
22+
// spread operator
23+
const myInfo = {
24+
name: "Saad",
25+
age: 22,
26+
salary: 100000000,
27+
};
28+
// adding a object and a variable
29+
const addMeToMyCrushMind = (myInfo) => {
30+
const crush = "Kate Winslet";
31+
const newData = Object.assign(Object.assign({}, myInfo), { crush });
32+
return newData;
33+
};
34+
const result5 = addMeToMyCrushMind(myInfo);
35+
result5.age = 21;
36+
console.log(result5);

dist/module-3/generic-interface.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use strict";
2+
// ------------------------
3+
const crush01 = {
4+
name: "lalalalisa",
5+
husband: 0,
6+
};
7+
// ------------------------
8+
const crush02 = {
9+
name: "lalalalisa",
10+
husband: false,
11+
};
12+
const crush03 = {
13+
name: "lalalalisa",
14+
husband: {
15+
name: "Thakur",
16+
salary: 1000000,
17+
},
18+
kids: 3,
19+
};
20+
const crush04 = {
21+
name: "Jenny",
22+
husband: {
23+
name: "Thakur",
24+
age: 22,
25+
},
26+
kids: {
27+
name: "Nezuko",
28+
age: 21,
29+
},
30+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use strict";
2+
const a = "address";
3+
const b = "address";
4+
// ------------
5+
function getProperty(obj, key) {
6+
console.log(obj[key]);
7+
}
8+
const result7 = getProperty({ name: "Mr. X", age: 100 }, "age");
9+
// Y extends keyof X means Y = "name" | "age"

dist/module-3/generic-type.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use strict";
2+
/*
3+
const rollNumbers1: Array<number> = [1, 2, 3];
4+
const rollNumbers2: Array<string> = ["1", "2", "3"];
5+
const rollNumbers3: Array<boolean> = [true, false, true];
6+
const userNameAndRollNumbers: Array<{ name: string; roll: number }> = [
7+
{ name: "somir", roll: 34 },
8+
{ name: "jomir", roll: 40 },
9+
];
10+
*/
11+
const rollNumbers1 = [1, 2, 3];
12+
const rollNumbers2 = ["1", "2", "3"];
13+
const rollNumbers3 = [true, false, true];
14+
const userNameAndRollNumbers = [
15+
{ name: "somir", roll: 34 },
16+
{ name: "jomir", roll: 40 },
17+
];
18+
const relation = ["Thakur", "Kate Winslet"];
19+
const relationWithSalary = [
20+
{ name: "123", salary: 200000 },
21+
"lalalalisa",
22+
];
23+
const relationWithSalary2 = [
24+
{ name: "thakur", salary: 200000 },
25+
"lalalalisa",
26+
];

dist/module-3/interface.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use strict";
2+
// --------------------------
3+
// Object
4+
// --------------------------
5+
const userWithTypeAlias = {
6+
name: "Type alias",
7+
age: 23,
8+
};
9+
const userWithExtendedTypeAlias = {
10+
name: "Extend Type Alias",
11+
age: 5000,
12+
role: "devourer",
13+
};
14+
const userWithInterface = {
15+
name: "Interface",
16+
age: 4000,
17+
};
18+
const userWithExtendedInterface = {
19+
name: "Extended Interface",
20+
age: 3020,
21+
role: "dumb",
22+
};
23+
// const addNumbers: AddNumbersType = (n1, n2) => n1 + n2;
24+
const addNumbers = (n1, n2) => n1 + n2;
25+
// const rollNumbers: RollNumbersType = [1, 2, 3, 4];
26+
const rollNumbers = [1, 2, 3, 4];

0 commit comments

Comments
 (0)