Skip to content

Commit 37b0445

Browse files
authored
Merge pull request #37 from mmdapl/docs/github-ci
feat: 新增一些文档,grpc、es6相关,优化ci配置
2 parents 4d15d85 + 28d3738 commit 37b0445

40 files changed

+1497
-167
lines changed

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm run lintfix && git add .

code/algorithm/shell/shell-1.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
##
4+
## 统计文件的行数
5+
6+
read -a arr
7+
while [ ${#arr[@]} -eq 2 ]
8+
do
9+
sum=$((${arr[0]} + ${arr[1]}))
10+
echo $sum
11+
read -a arr
12+
done
13+
exit 0

code/node/dayjs/demo-1.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* dayjs 解析操作
3+
*/
4+
5+
const dayjs = require('dayjs')
6+
7+
console.log(dayjs().format())
8+
// 输出: 2023-03-13T22:28:34+08:00
9+
10+
// 解析
11+
console.log(dayjs('2018-04-04T16:00:00.000Z'))
12+
// 输出:
13+
// {
14+
// '$L': 'en',
15+
// '$d': 2018-04-04T16:00:00.000Z,
16+
// '$x': {},
17+
// '$y': 2018,
18+
// '$M': 3,
19+
// '$D': 5,
20+
// '$W': 4,
21+
// '$H': 0,
22+
// '$m': 0,
23+
// '$s': 0,
24+
// '$ms': 0
25+
// }
26+
27+
// 解析毫秒级时间戳,返回解析后的对象
28+
console.log(dayjs(1318781876406))
29+
30+
// 解析秒级时间戳,返回解析后的对象
31+
console.log(dayjs.unix(1318781876))
32+
console.log(dayjs.unix(1318781876.721))
33+
34+
35+
// Date对象
36+
const date = new Date(2022, 8, 18)
37+
console.log(dayjs(date))
38+
39+
40+
// 对象复制
41+
const a = dayjs()
42+
const b = a.clone()
43+
console.log(a, b)
44+
// a 和 b 是两个独立的 Day.js 对象
45+
// 在 dayjs() 里传入一个 Day.js 对象也会返回一个复制的对象。
46+
const c = dayjs()
47+
const d = dayjs(c)
48+
console.log(c, d)
49+
50+
51+
// 校验是否为日期
52+
console.log(dayjs('2022-01-33').isValid())
53+
// true, parsed to 2022-02-02
54+
console.log(dayjs('some invalid string').isValid())
55+
// false
56+

code/node/dayjs/demo-2.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* dayjs 的取值|赋值操作
3+
*/
4+
const dayjs = require('dayjs')
5+
6+
// 获取或设置毫秒
7+
console.log(dayjs().millisecond())
8+
console.log(dayjs().millisecond(1))
9+
10+
// 获取或设置秒
11+
console.log(dayjs().second())
12+
console.log(dayjs().second(1))
13+
14+
// 获取或设置小时
15+
console.log(dayjs().hour())
16+
console.log(dayjs().hour(12))
17+
18+
/**
19+
* dayjs.date 是该月的日期。 dayjs.day 是星期几
20+
*/
21+
22+
// 获取或设置月份里的日期
23+
console.log(dayjs().date())
24+
console.log(dayjs().date(10))
25+
26+
// 获取或设置星期几
27+
console.log(dayjs().day())
28+
console.log(dayjs().day(3))
29+
30+
31+
// 获取或设置月份
32+
console.log(dayjs().month())
33+
console.log(dayjs().month(0))
34+
35+
// 获取或设置年份
36+
console.log(dayjs().year())
37+
console.log(dayjs().year(2023))
38+
39+
40+
// get方法获取
41+
console.log(dayjs().get('year'))
42+
console.log(dayjs().get('month'))
43+
console.log(dayjs().get('date'))
44+
console.log(dayjs().get('hour'))
45+
console.log(dayjs().get('minute'))
46+
console.log(dayjs().get('second'))
47+
console.log(dayjs().get('millisecond'))
48+
49+
// set方法设置
50+
console.log(dayjs().set('date', 1))
51+
console.log(dayjs().set('month', 6)) // 5月
52+
console.log(dayjs().set('second', 30))
53+
// 支持链式调用
54+
console.log(dayjs().set('hour', 8).set('minute', 35).set('second', 15))

code/node/dayjs/demo-3.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* 操作dayjs对象
3+
*/
4+
const dayjs = require('dayjs')
5+
6+
// 支持链式调用
7+
console.log(dayjs('2019-01-25').add(1, 'day').subtract(1, 'year').year(2009).toString())
8+
9+
// 增加一定时间 参考:https://dayjs.gitee.io/docs/zh-CN/manipulate/add
10+
console.log(dayjs().add(7, 'day'))
11+
console.log(dayjs().add(10, 'hour'))
12+
13+
// 减去一定时间 , 同上
14+
console.log(dayjs().subtract(7, 'year'))
15+
console.log(dayjs().subtract(2, 'month'))
16+
17+
18+
// 设置到一个时间的开始
19+
console.log(dayjs().startOf('year'))
20+
// 设置到一个时间的末尾
21+
console.log(dayjs().endOf('month'))

code/node/dayjs/demo-4.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* 展示 Day.js 对象的操作
3+
* api参考:https://dayjs.gitee.io/docs/zh-CN/display/format
4+
*/
5+
6+
const dayjs = require('dayjs')
7+
8+
// 将字符串格式化为日期
9+
console.log(dayjs().format('YYYY-MM-DD HH:mm:ss'))
10+
// 默认返回的是 ISO8601 格式字符串 '2020-04-02T08:02:17-05:00'
11+
console.log(dayjs('2019-01-25').format('[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]'))
12+
// 'YYYYescape 2019-01-25T00:00:00-02:00Z'
13+
console.log(dayjs('2019-01-25').format('DD/MM/YYYY')) // '25/01/2019'
14+
15+
16+
// 时间戳 毫秒 13位
17+
console.log(dayjs('2022-01-25').valueOf())
18+
// 时间戳 秒 10位
19+
console.log(dayjs('2022-01-25').unix())
20+
21+
// 获取当前月份包含的天数
22+
console.log(dayjs('2019-01-25').daysInMonth())
23+
24+
25+
// 原生Date对象
26+
console.log(dayjs('2019-01-25').toDate())

code/node/dayjs/demo-5.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* dayjs的查询操作
3+
* api参考:https://dayjs.gitee.io/docs/zh-CN/query/query
4+
*/
5+
6+
const dayjs = require('dayjs')
7+
8+
9+
// 是否在一个日期之前
10+
console.log(dayjs().isBefore(dayjs('2021-01-01')))
11+
// 比较年份
12+
console.log(dayjs().isBefore('2024-01-01', 'year'))
13+
14+
// 日期是否相同
15+
console.log(dayjs().isSame(dayjs('2011-01-01')))
16+
console.log(dayjs().isSame('2023-3-13', 'year'))
17+
18+
// 是否在一个日期之后面
19+
console.log(dayjs().isAfter(dayjs('2021-01-01')))
20+
// 比较年份
21+
console.log(dayjs().isAfter('2024-01-01', 'year'))
22+
23+
24+
// 是否为dayjs对象
25+
console.log(dayjs.isDayjs(dayjs()))
26+
console.log(dayjs.isDayjs(new Date()))

code/node/es6/demo-1.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* ES6声明相关操作
3+
*/
4+
5+

docs/.vuepress/config/navbar.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
export default [
22
{
3-
text: "首页", link: "/",
3+
text: "首页",
4+
link: "/",
45
},
56
{
6-
text: "前端", link: "/manuscript/front-end",
7+
text: "前端",
8+
link: "/manuscript/front-end",
79
},
810
{
9-
text: "Node后端", link: "/manuscript/server-end",
11+
text: "Node后端",
12+
link: "/manuscript/server-end",
1013
},
1114
{
12-
text: "Solo算法", link: "/manuscript/solo-algorithm",
15+
text: "Solo算法",
16+
link: "/manuscript/solo-algorithm",
1317
},
1418
{
1519
text: '微服务',
@@ -20,13 +24,16 @@ export default [
2024
link: "/manuscript/battle-interview",
2125
},
2226
{
23-
text: "开发技巧", link: "/manuscript/develop-skill",
27+
text: "开发技巧",
28+
link: "/manuscript/develop-skill",
2429
},
2530
{
26-
text: "读书整理", link: "/manuscript/read-books",
31+
text: "读书整理",
32+
link: "/manuscript/read-books",
2733
},
2834

2935
{
30-
text: "其他", link: "/manuscript/other",
36+
text: "其他",
37+
link: "/manuscript/other",
3138
},
3239
];

docs/.vuepress/config/theme.config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ export default {
6262
copyright: false,
6363

6464
// 主题色选择器
65-
themeColor: {
66-
blue: "#2196f3",
67-
red: "#f26d6d",
68-
green: "#3eaf7c",
69-
orange: "#fb9b5f",
70-
},
65+
// themeColor: {
66+
// blue: "#2196f3",
67+
// red: "#f26d6d",
68+
// green: "#3eaf7c",
69+
// orange: "#fb9b5f",
70+
// },
7171

7272
plugins: {
7373
readingTime: {

0 commit comments

Comments
 (0)