Skip to content

Commit ae195fe

Browse files
authored
feat: add boolean topic (#37)
* feat: add boolean topic * build: add semantic-release
1 parent 91cd3ea commit ae195fe

File tree

8 files changed

+5197
-81
lines changed

8 files changed

+5197
-81
lines changed

.github/workflows/lint.yaml

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: lint
1+
name: ci
22
on:
33
push:
44
branches:
@@ -30,3 +30,31 @@ jobs:
3030
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/yarn.lock') }}
3131
- run: yarn
3232
- run: yarn lint
33+
release:
34+
name: release
35+
runs-on: ubuntu-latest
36+
if: github.ref == 'refs/heads/master'
37+
needs:
38+
- lint
39+
steps:
40+
- uses: actions/checkout@v1
41+
- name: setup yarn-cache
42+
id: yarn-cache
43+
run: echo "::set-output name=dir::$(yarn cache dir)"
44+
- name: cache yarn global cache
45+
uses: actions/cache@v1
46+
with:
47+
path: ${{ steps.yarn-cache.outputs.dir }}
48+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
49+
restore-keys: |
50+
${{ runner.os }}-yarn-
51+
- name: cache node_modules
52+
uses: actions/cache@v1
53+
with:
54+
path: node_modules
55+
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/yarn.lock') }}
56+
- run: yarn
57+
- run: yarn semantic-release
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.releaserc.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"plugins": [
3+
"@semantic-release/commit-analyzer",
4+
"@semantic-release/release-notes-generator",
5+
"@semantic-release/changelog",
6+
"@semantic-release/npm",
7+
"@semantic-release/github"
8+
]
9+
}

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ let me know and we can see how to get it working on your IDE.
4141
- [Arrow Function](/pages/02-javascript-syntax/arrow-function.md)
4242
- [Assignment](/pages/02-javascript-syntax/assignment.md)
4343
- [Async Await](/pages/02-javascript-syntax/async-await.md)
44+
- [Boolean](/pages/02-javascript-syntax/boolean.md)
4445
- [Class](/pages/02-javascript-syntax/class.md)
4546
- [Declaration Statements](/pages/02-javascript-syntax/declaration-statements.md)
4647
- [Decorator](/pages/02-javascript-syntax/decorator.md)

commitlint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ['@commitlint/config-conventional'] }

package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "typescript-style",
3-
"version": "0.0.3",
3+
"version": "0.0.0-development",
44
"description": "A mostly reasonable approach to TypeScript.",
55
"keywords": [
66
"lint",
77
"style guide",
88
"ts",
9-
"tslint",
9+
"eslint",
1010
"typescript",
1111
"unional"
1212
],
@@ -23,11 +23,21 @@
2323
"scripts": {
2424
"lint": "ts-node scripts/lint.ts"
2525
},
26+
"husky": {
27+
"hooks": {
28+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
29+
}
30+
},
2631
"devDependencies": {
32+
"@commitlint/cli": "^8.3.5",
33+
"@commitlint/config-conventional": "^8.3.4",
34+
"@semantic-release/changelog": "^5.0.1",
2735
"@types/glob": "^7.1.1",
2836
"chalk": "^3.0.0",
2937
"glob": "^7.1.6",
38+
"husky": "^4.2.3",
3039
"markdownlint": "^0.19.0",
40+
"semantic-release": "^17.0.4",
3141
"ts-node": "^8.8.1",
3242
"type-plus": "^1.35.1",
3343
"typescript": "^3.8.3"

pages/02-javascript-syntax/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and how to work with them in TypeScript environment.
1010
- [Arrow Function](/pages/02-javascript-syntax/arrow-function.md)
1111
- [Assignment](/pages/02-javascript-syntax/assignment.md)
1212
- [Async Await](/pages/02-javascript-syntax/async-await.md)
13+
- [Boolean](/pages/02-javascript-syntax/boolean.md)
1314
- [Class](/pages/02-javascript-syntax/class.md)
1415
- [Declaration Statements](/pages/02-javascript-syntax/declaration-statements.md)
1516
- [Decorator](/pages/02-javascript-syntax/decorator.md)

pages/02-javascript-syntax/boolean.md

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Boolean
2+
3+
The type of boolean in TypeScript is `boolean`.
4+
It also have boolean literal types `true` and `false`
5+
6+
---
7+
8+
Predicate functions **should** return `boolean`.
9+
10+
```ts
11+
// bad
12+
function hasValue(value: any) {
13+
return value
14+
}
15+
16+
// good
17+
function hasValue(value: any) {
18+
return value !== undefined
19+
}
20+
```
21+
22+
> Why?
23+
24+
Relying on implicit conversion is dangerous.
25+
Always be explicit.
26+
27+
```ts
28+
hasValue(0) ? true : false // false
29+
hasValue(false) ? true : false // false
30+
hasValue('') ? true : false // false
31+
hasValue(Symbol()) ? true : false // false
32+
hasValue(Infinity) ? true : false // false
33+
// but
34+
new Boolean(Infinity) // true !!
35+
```
36+
37+
---
38+
39+
When converting value to boolean, you **should** use double not (`!!`) operator.
40+
41+
```ts
42+
const value = false
43+
// bad
44+
const b = new Boolean(value)
45+
if (b) { /* executed! */ }
46+
47+
// so so
48+
const c = Boolean(value)
49+
if (c) { /* not executed */ }
50+
51+
// good
52+
const d = !!value
53+
if (d) { /* not executed */ }
54+
```
55+
56+
> Why?
57+
58+
In 99.99999% of the time,
59+
you do not even know the existence of the boolean object wrapper `Boolean`.
60+
It is different then the `boolean` you use days in days out.
61+
62+
So don't confuse yourself and your reader by mentioning it in your code when not necessary.
63+
64+
## References
65+
66+
- <https://www.typescriptlang.org/docs/handbook/basic-types.html#boolean>
67+
- <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean>

0 commit comments

Comments
 (0)