Skip to content

Commit 3ffcde9

Browse files
committed
progress
1 parent 2f24bff commit 3ffcde9

File tree

3 files changed

+65
-134
lines changed

3 files changed

+65
-134
lines changed
Lines changed: 17 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,17 @@
1-
console.log("let's get started")
2-
3-
/**
4-
* Intro
5-
*/
6-
7-
// EcmaScript, JavaScript, Node
8-
9-
/**
10-
* Versions
11-
*/
12-
13-
// Node Versions
14-
// https://nodejs.dev/en/about/releases/
15-
16-
/**
17-
* Globals
18-
*/
19-
20-
// https://nodejs.org/docs/latest/api/globals.html
21-
// console.log(process.versions)
22-
// console.log('process.cwd():', process.cwd())
23-
// console.log('__dirname:', __dirname)
24-
// console.log('__filename:', __filename)
25-
26-
/**
27-
* Modules
28-
*/
29-
30-
// CommonJS
31-
// ESModules
32-
33-
/**
34-
* Env
35-
*/
36-
37-
// require('dotenv').config()
38-
// console.log(process.env.SECRET) // from .env
39-
40-
// // Community standard
41-
// // "lecture-1": "NODE_ENV=development node lessons/01-js-and-node/lecture",
42-
// console.log(process.env.NODE_ENV)
43-
44-
/**
45-
* Scope
46-
*/
47-
48-
// var x = [5, 6, 7]
49-
// function scope() {
50-
// for (var i = 0; i < x.length; i++) {
51-
// var item = x[i]
52-
// console.log(item)
53-
// }
54-
55-
// console.log(i)
56-
// console.log(item)
57-
// }
58-
// scope()
59-
60-
/**
61-
* Object and Array Literals
62-
*/
63-
64-
/**
65-
* Function Types
66-
*/
67-
68-
/**
69-
* Expressions and Expression Chaining
70-
*/
71-
72-
/**
73-
* Map, Filter, Reduce, Find, Includes
74-
*/
75-
76-
/**
77-
* File System
78-
*/
79-
80-
// const fs = require('fs')
81-
// const path = require('path')
82-
// const dataPath = path.join(__dirname, `data.csv`)
83-
// const data = fs.readFileSync(dataPath, 'utf8')
84-
85-
// let json = data
86-
// .split('\n')
87-
// .map((item) => {
88-
// const [id, name] = item.split(',')
89-
// return `{ "id": ${id}, "name": "${name}" }`
90-
// })
91-
// .join(',\n')
92-
93-
// json = `{ "users": [${json}] }`
94-
95-
// console.log(JSON.parse(json))
1+
const fs = require('fs')
2+
const path = require('path')
3+
const dataPath = path.join(__dirname, `data.csv`)
4+
const data = fs.readFileSync(dataPath, 'utf8')
5+
6+
let json = data
7+
.split('\n')
8+
.map((item) => {
9+
const [id, name] = item.split(',')
10+
return id ? `{ "id": ${id}, "name": "${name.trim()}" }` : false
11+
})
12+
.filter(Boolean)
13+
.join(',\n')
14+
15+
json = `{ "users": [${json}] }`
16+
17+
console.log(JSON.parse(json))

lessons/02-promises/lecture/index.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import fs from 'fs'
2-
import path from 'path'
3-
// const fsPromises = require('fs').promises // the way the docs show
4-
// import { promises as fsPromises } from 'fs' // the esm version
5-
// import fetch from 'node-fetch'
62

7-
const dataPath = path.join(__dirname, `data.csv`)
3+
function getVehicle(url: string) {
4+
return fetch(url).then((response) => response.json())
5+
}
86

9-
// Let's make this asynchronous
10-
const data = fs.readFileSync(dataPath, 'utf8')
11-
console.log(data)
7+
function getPersonVehicles(id: number): Promise<string[]> {
8+
return fetch(`https://swapi.dev/api/people/${id}`)
9+
.then((response) => response.json() as Record<string, any>)
10+
.then((data) => data.vehicles)
11+
}
12+
13+
getPersonVehicles(1)
14+
.then((vehicles) => {
15+
const promises = vehicles.map((url) => getVehicle(url))
16+
return Promise.all(promises)
17+
})
18+
.then((allVehicles) => {
19+
console.log(allVehicles)
20+
})

lessons/04-async-await/lecture/index.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,42 @@
44
Part 1
55
*****************************************/
66

7-
function getVehicle(url: string) {
8-
return fetch(url).then((response) => response.json())
9-
}
7+
// async function getVehicle(url: string) {
8+
// return await fetch(url).then((response) => response.json())
9+
// }
1010

11-
function getPersonVehicles(id: number): Promise<string[]> {
12-
return fetch(`https://swapi.dev/api/people/${id}`)
13-
.then((response) => response.json() as Record<string, any>)
14-
.then((data) => data.vehicles)
15-
}
11+
// async function getPersonVehicles(id: number): Promise<string[]> {
12+
// const data = (await fetch(`https://swapi.dev/api/people/${id}`).then((response) =>
13+
// response.json()
14+
// )) as any
15+
16+
// return data.vehicles as string[]
17+
// }
1618

17-
getPersonVehicles(1)
18-
.then((vehicles) => {
19-
const p = vehicles.map((url) => getVehicle(url))
20-
return Promise.all(p)
21-
})
22-
.then((allVehicles) => {
23-
console.log(allVehicles)
24-
})
19+
// async function main() {
20+
// const vehicles = await getPersonVehicles(1)
21+
// const p = vehicles.map((url) => getVehicle(url))
22+
// const data = await Promise.all(p)
23+
// console.log(data)
24+
// }
25+
26+
// main()
2527

2628
/****************************************
2729
Part 2
2830
*****************************************/
2931

30-
// function signup(user: User) {
31-
// return createAccount()
32-
// .then((account) => {
33-
// return addAccountUser(account.accountId, user)
34-
// })
35-
// .then((user) => {
36-
// // emailUser(user)
37-
// // logNewUserStats(account.accountId)
38-
// })
39-
// }
40-
41-
// signup({ name: 'brad' }).then(() => {
42-
// console.log('✅ User Added')
43-
// })
32+
function signup(user: User) {
33+
return createAccount()
34+
.then((account) => {
35+
return addAccountUser(account.accountId, user)
36+
})
37+
.then((user) => {
38+
// emailUser(user)
39+
// logNewUserStats(account.accountId)
40+
})
41+
}
4442

45-
// // Remember "top-level" await
43+
signup({ name: 'brad' }).then(() => {
44+
console.log('✅ User Added')
45+
})

0 commit comments

Comments
 (0)