Skip to content

Commit a9261e3

Browse files
authored
Merge pull request #40 from 142vip/next
feat: 侧边栏优化,新增一些文档
2 parents 828315c + 23bbaff commit a9261e3

File tree

104 files changed

+4373
-255
lines changed

Some content is hidden

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

104 files changed

+4373
-255
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+

code/node/lodash/demo-array.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Lodash数组相关操作
3+
* @private
4+
*/
5+
6+
const _ = require('lodash')
7+
8+
9+
// chunk: 分片 ,指定长度切割
10+
console.log(_.chunk(['a', 'b', 'c', 'd'], 2))
11+
// => [['a', 'b'], ['c', 'd']]
12+
console.log(_.chunk(['a', 'b', 'c', 'd'], 3))
13+
// => [['a', 'b', 'c'], ['d']]
14+
15+
16+
// compact: 过滤假值(false, null,0, "", undefined,NaN)
17+
// concat: 拼接
18+
// difference: 过滤给定数组中的值(来源于数组)
19+
// drop: 创建切片数组
20+
// fill: 指定元素填充
21+
// head: 获取头部元素
22+
// last:获取尾部元素
23+
// indexOf:查找目标元素第一个索引
24+
// lastIndexOf: 查找目标元素最后一个索引
25+
// initial:排除最后一个元素
26+
// intersection: 查找多数组的交集元素
27+
// join: 指定符号连接数组元素
28+
// nth: 返回数组的第n个元素
29+
// pull:移除数组中所有和给定值相等的元素
30+
// remove:移除元素
31+
// reverse:元素反转
32+
// slice: 指定索引裁剪元素
33+
// sortedIndex:排序插入返回索引
34+
// tail:去除第一个元素
35+
// take:提取元素(指定个数)
36+
// union: 创建一个按顺序排列的唯一值的数组
37+
// uniq: 数组去重,第一次出现的元素保留
38+
// without: 提出所有给定值,返回新数组
39+
// xor: 创建给点数组唯一值的数组
40+
// zip: 创建一个分组元素的数组,数组的第一个元素包含所有给定数组的第一个元素,数组的第二个元素包含所有给定数组的第二个元素,以此类推

code/node/lodash/demo-num.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Lodash数字相关操作
3+
* @private
4+
*/
5+
6+
const _ = require('lodash')
7+
8+
// inRange: 判断是否在范围中
9+
console.log(_.inRange(3, 2, 4))
10+
// => true
11+
console.log(_.inRange(4, 8))
12+
// => true
13+
console.log(_.inRange(4, 2))
14+
// => false
15+
console.log(_.inRange(2, 2))
16+
// => false
17+
console.log(_.inRange(1.2, 2))
18+
// => true
19+
console.log(_.inRange(5.2, 4))
20+
// => false
21+
console.log(_.inRange(-3, -2, -6))
22+
// => true
23+
24+
25+
// random: 返回指定范围随机值
26+
console.log(_.random(0, 5))
27+
// => an integer between 0 and 5
28+
console.log(_.random(5))
29+
// => also an integer between 0 and 5
30+
console.log(_.random(5, true))
31+
// => a floating-point number between 0 and 5
32+
console.log(_.random(1.2, 5.2))
33+
// => a floating-point number between 1.2 and 5.2
34+
35+
// add : 相加
36+
console.log(_.add(6, 4))
37+
// => 10
38+
39+
40+
// divide: 相除
41+
console.log(_.divide(6, 4))
42+
// => 1.5
43+
44+
45+
// multiply: 相乘
46+
console.log(_.multiply(6, 4))
47+
// => 24
48+
49+
50+
// subtract: 相减
51+
_.subtract(6, 4)
52+
// => 2
53+
54+
// sum: 求和
55+
_.sum([4, 2, 8, 6])
56+
// => 20
57+
58+
59+
// ceil: 向上取整
60+
console.log(_.ceil(4.006))
61+
// => 5
62+
console.log(_.ceil(6.004, 2))
63+
// => 6.01
64+
console.log(_.ceil(6040, -2))
65+
// => 6100
66+
67+
// floor: 向下取整
68+
console.log(_.floor(4.006))
69+
// => 4
70+
console.log(_.floor(0.046, 2))
71+
// => 0.04
72+
console.log(_.floor(4060, -2))
73+
// => 4000
74+
75+
76+
// round: 四舍五入
77+
console.log(_.round(4.006))
78+
// => 4
79+
console.log(_.round(4.006, 2))
80+
// => 4.01
81+
console.log(_.round(4060, -2))
82+
// => 4100
83+
84+
85+
// max: 最大值
86+
console.log(_.max([4, 2, 8, 6]))
87+
// => 8
88+
console.log(_.max([]))
89+
// => undefined
90+
91+
92+
// mean: 求平均值
93+
console.log(_.mean([4, 2, 8, 6]))
94+
// => 5
95+
96+
97+
// min: 最小值
98+
console.log(_.min([4, 2, 8, 6]))
99+
// => 2
100+
console.log(_.min([]))
101+
// => undefined

0 commit comments

Comments
 (0)