Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit 10095b3

Browse files
authored
Refactor article (#17)
* Start refactor page * Start writing refactor article * Add emojis * Wordsmith * Finish intro * Start tip 1 * Wordsmith * Wordsmith * Slide 2 start * Refactor * Continue w/ slide 2 * Wordsmith * Wordsmith * Wordsmith * Simplify * Slide 2 * Finish tip 1 * Rewrite 1 * Improve slide 2 * Start slide 3 * Remove run button text and simplify * Rewrite 1 again * Simplify the conclusion * Simplify slide 2 * Add prettier * Finish slide 2 * Simplify slide 1 * Wordsmith * Change slide 3 * Fix cursor: pointer * Keep text decoration on read more * Wordsmith * ScaryCat * Wordsmith * Finish slide 3 * Wordsmith, left align emojiSeparator * Wordsmith * Wordsmith, add remaining titles * Make emojis clickable * Add remaining cards * Wordsmith * Wordsmith * Wordsmith * Extra credit * Revert "Extra credit" This reverts commit f5aa813. * Add all emojis * Update bad example icon * Start slide 3 * Update description * Wordsmith * Simplify * Add official website doc * Start slide 3 * Test slide 3 * Continue with slide 3 * Wordsmith * Wordsmith * Add comment * Adjust spacing * Finish slide 3 * Add rocket * Update og image * Highlight refactor * Highlight text * Continue with tip 3 * Continue with tip 3 * Continue with tip 3 * Wordsmith * Add total number of tips * Remove part 7 * Finish tip 3 * Enhance paddingLeftCss * Add monkeys * Revert "Add monkeys" This reverts commit cc40ce7. * Start slide 6 * Finish tip 5 * White70 * Wordsmith * Wordsmith * Wordsmith * Continue with tip 6 * Continue with slide 7 * Finish tip 6 * Done with first draft * Add hr * Add a note about translation * Update README.md * Wordsmith * Finish tip 4 * Add blockquote * Move ... * Wordsmith conclusion * Wordsmith tip 6 * Wordsmith tip 3 * Finish wordsmith * Adjust spacing
1 parent a71cd8b commit 10095b3

Some content is hidden

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

72 files changed

+2793
-206
lines changed

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
"options": {
1414
"printWidth": 53
1515
}
16+
},
17+
{
18+
"files": ["snippets/snippets/**/ignoreWidth/*.ts"],
19+
"options": {
20+
"printWidth": 120
21+
}
1622
}
1723
]
1824
}

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
# [TypeScript for Beginner Programmers](https://ts.chibicode.com)
22

3-
### This is the repository for the TypeScript tutorial website called **[TypeScript for Beginner Programmers](https://ycombinator.chibicode.com/)**.
3+
This is the repository for the TypeScript tutorial website called **[TypeScript for Beginner Programmers](https://ycombinator.chibicode.com/)**.
44

55
<p>
66
<a href="https://ts.chibicode.com/"><img src="public/images/og-index.png" width="600" /></a>
77
</p>
88

9+
## Article 3: [Your Coding Tutorial Might Need Some Refactoring](https://ts.chibicode.com/refactor)
10+
11+
<p>
12+
<a href="https://ts.chibicode.com/refactor"><img src="public/images/og-refactor.png" width="600" /></a>
13+
</p>
14+
15+
## Article 2: [TypeScript Tutorial for JS Programmers Who Know How to Build a Todo App](https://ts.chibicode.com/todo)
16+
17+
<p>
18+
<a href="https://ts.chibicode.com/todo"><img src="public/images/og-todo-v2.png" width="600" /></a>
19+
</p>
20+
21+
## Article 1: [TypeScript Generics for People Who Gave Up on Understanding Generics](https://ts.chibicode.com/generics)
22+
23+
<p>
24+
<a href="https://ts.chibicode.com/generics"><img src="public/images/og-generics.png" width="600" /></a>
25+
</p>
26+
927
## License & Credits
1028

1129
- For emojis, I’m using [Twemoji](https://github.com/twitter/twemoji) by Twitter (CC-BY 4.0 license).
@@ -16,6 +34,6 @@
1634

1735
**Shu Uesugi**
1836

19-
- Twitter: [@chibicode](https://twitter.com/chibicode)
2037
- [Website](https://chibicode.com)
38+
- Twitter: [@chibicode](https://twitter.com/chibicode)
2139
- Email: [shu@chibicode.com](mailto:shu@chibicode.com)

public/images/og-refactor.png

86.1 KB
Loading
171 KB
Loading

public/images/refactor/tsdoc.gif

484 KB
Loading

snippets/bin/generateSnippetsBundle.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,29 @@ const glob = require('glob')
22
const fs = require('fs')
33
const chokidar = require('chokidar')
44

5+
const filePathToKey = (file: string) =>
6+
file
7+
.replace(/\.\/snippets\/snippets\/\w+\//, '')
8+
.replace(/longerWidth\//, '')
9+
.replace(/ignoreWidth\//, '')
10+
.replace(/\.ts/, '')
11+
512
const regenerate = () => {
613
glob('./snippets/snippets/**/*.ts', (_: any, files: readonly string[]) => {
14+
if (
15+
new Set(files.map(filePathToKey)).size !== files.map(filePathToKey).length
16+
) {
17+
throw new Error('Duplicate file name')
18+
}
19+
720
const result = files
821
.map(file => {
922
const contents = fs.readFileSync(file, 'utf8')
10-
return `export const ${file
11-
.replace(/\.\/snippets\/snippets\/\w+\//, '')
12-
.replace(/longerWidth\//, '')
13-
.replace(/\.ts/, '')} = \`${contents
23+
return `export const ${filePathToKey(file)} = \`${contents
1424
.trim()
1525
.replace(/^;/m, '')
16-
.replace(/`/g, '\\`')}\``
26+
.replace(/`/g, '\\`')
27+
.replace(/\$/g, '\\$')}\``
1728
})
1829
.join('\n\n')
1930

snippets/snippets/refactor/bxzx.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// It could have been useful if you could pass
2+
// both number AND string, and have it repeat
3+
// the string the specified number of times
4+
padLeft('Hello world', 4, '#')
5+
// → "####Hello world"

snippets/snippets/refactor/crgn.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// If the second parameter is string, then
2+
// that string is appended to the left side
3+
padLeft('Hello world', 'Jim: ')
4+
// → "Jim: Hello world"
5+
6+
// Ask yourself: Would you EVER do this?

snippets/snippets/refactor/hfdq.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function paddingLeftCss(val: number | string) {
2+
if (typeof val === 'number') {
3+
return `padding-left: ${val * 0.25}rem;`
4+
} else {
5+
return `padding-left: ${val};`
6+
}
7+
}
8+
9+
// padding-left: 0.25rem;
10+
paddingLeftCss(1)
11+
12+
// padding-left: 0.5rem;
13+
paddingLeftCss(2)
14+
15+
// padding-left: 10%;
16+
paddingLeftCss('10%')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function makePair<F extends number | string, S extends boolean | F>() {}

0 commit comments

Comments
 (0)