Skip to content

Commit 1690af5

Browse files
committed
feat: update docs -> design pattern function array object math primitive types utils
1 parent cc4532e commit 1690af5

File tree

44 files changed

+982
-64
lines changed

Some content is hidden

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

44 files changed

+982
-64
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<template>
2+
<SWUpdatePopup v-slot="{ enabled, reload, message, buttonText }">
3+
<div
4+
v-if="enabled"
5+
class="my-sw-update-popup">
6+
{{ message }}<br>
7+
<button @click="reload">{{ buttonText }}</button>
8+
</div>
9+
</SWUpdatePopup>
10+
</template>
11+
12+
<script>
13+
import SWUpdatePopup from '@vuepress/plugin-pwa/lib/SWUpdatePopup.vue'
14+
15+
export default {
16+
components: { SWUpdatePopup }
17+
}
18+
</script>
19+
20+
<style>
21+
.my-sw-update-popup {
22+
text-align: right;
23+
position: fixed;
24+
bottom: 20px;
25+
right: 20px;
26+
background-color: #fff;
27+
font-size: 20px;
28+
padding: 10px;
29+
border: 5px solid #3eaf7c;
30+
}
31+
32+
.my-sw-update-popup button {
33+
border: 1px solid #fefefe;
34+
}
35+
</style>

docs/.vuepress/config.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ const plugins = require('./utils/plugins');
33
const { sidebarHelper } = require('./utils/sidebarHelper');
44
const nav = require('./utils/nav');
55

6+
/**
7+
* @description [guide, how-to-write-docs, ...]
8+
*/
9+
const docs = sidebarHelper();
10+
const sidebar = [];
11+
docs.map(item => {
12+
if (item.path.includes('guide') || item.path.includes('how-to-write-docs')) {
13+
sidebar.unshift(item)
14+
} else {
15+
sidebar.push(item)
16+
}
17+
});
18+
[sidebar[1], sidebar[0]] = [sidebar[0], sidebar[1]];
19+
20+
621
module.exports = {
722
// base: '/awesome-javascript-code-implementation/',
823
base: '',
@@ -12,7 +27,15 @@ module.exports = {
1227
head: [
1328
['link', { rel: 'icon', href: '/logo.png' }],
1429
['link', { rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css' }],
15-
['link', { rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css' }]
30+
['link', { rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css' }],
31+
['link', { rel: 'manifest', href: '/manifest.json' }],
32+
['meta', { name: 'theme-color', content: '#3eaf7c' }],
33+
['meta', { name: 'apple-mobile-web-app-capable', content: 'yes' }],
34+
['meta', { name: 'apple-mobile-web-app-status-bar-style', content: 'black' }],
35+
['link', { rel: 'apple-touch-icon', href: '/icons/apple-touch-icon-152x152.png' }],
36+
['link', { rel: 'mask-icon', href: '/icons/safari-pinned-tab.svg', color: '#3eaf7c' }],
37+
['meta', { name: 'msapplication-TileImage', content: '/icons/msapplication-icon-144x144.png' }],
38+
['meta', { name: 'msapplication-TileColor', content: '#000000' }],
1639
],
1740
configureWebpack: {
1841
resolve: {
@@ -48,7 +71,7 @@ module.exports = {
4871
repoLabel: 'Repo',
4972

5073
displayAllHeaders: true,
51-
sidebar: sidebarHelper(),
74+
sidebar,
5275
nav,
5376

5477
// polyfill IE
@@ -69,8 +92,8 @@ module.exports = {
6992
search: true,
7093
searchMaxSuggestions: 10,
7194
// algolia: {
72-
// apiKey: '<API_KEY>',
73-
// indexName: '<INDEX_NAME>'
95+
// apiKey: '',
96+
// indexName: ''
7497
// },
7598

7699
// PWA

docs/.vuepress/utils/alias.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,51 @@
22
* @Author: Rainy
33
* @Date: 2020-01-31 11:42:43
44
* @LastEditors : Rainy
5-
* @LastEditTime : 2020-02-01 14:09:54
5+
* @LastEditTime : 2020-02-02 14:41:02
66
*/
77

88
const alias = {
99
'guide': '介绍',
1010
'how-to-write-docs': '如何写文档?',
11+
12+
// math
1113
'math': '数学',
1214
'factorial': '阶乘',
1315
'fibonacci': '斐波那契数列',
1416
'gcd': '最大公约数',
1517
'lcm': '最小公倍数',
18+
'binary': '二进制',
19+
20+
// primitive
21+
'primitive': '原生 Javascript',
22+
23+
// function
24+
'function': '函数',
25+
'debounce': '防抖',
26+
'throttle': '节流',
27+
28+
// Array
29+
'array': 'Array(MDN + Function)',
30+
31+
// Object
32+
'object': 'Object(MDN + Function)',
33+
34+
// types
35+
'types': 'Types',
36+
37+
// utils
38+
'utils': 'Utils',
39+
40+
// design-pattern
41+
'design-pattern': '设计模式',
42+
'adapter-pattern': '适配器模式',
43+
'decorator-pattern': '装饰器模式',
44+
'factory-pattern': '工厂模式',
45+
'facade-pattern': '外观模式',
46+
'iterator-pattern': '迭代器模式',
47+
'proxy-pattern': '代理模式',
48+
'observer-pattern': '观察者模式',
49+
'singleton-pattern': '单例模式',
1650
};
1751

1852
module.exports = {

docs/.vuepress/utils/nav.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
module.exports = [
2-
{ text: 'Home', link: '/' },
32
{
4-
text: 'Languages',
5-
ariaLabel: 'Language Menu',
6-
items: [
7-
{ text: 'Chinese', link: '/zh/guide/' },
8-
{ text: 'English', link: '/en/guide/' }
9-
]
3+
text: 'Study Notes',
4+
link: 'https://rain120.github.io/study-notes/',
5+
target: '_blank'
106
},
11-
{ text: 'Github', link: 'https://github.com/rain120', target: '_blank' }
7+
// {
8+
// text: 'Languages',
9+
// ariaLabel: 'Language Menu',
10+
// items: [
11+
// { text: 'Chinese', link: '/zh/guide/' },
12+
// { text: 'English', link: '/en/guide/' }
13+
// ]
14+
// },
15+
{
16+
text: 'Github',
17+
link: 'https://github.com/rain120',
18+
target: '_blank'
19+
}
1220
];

docs/.vuepress/utils/plugins.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const moment = require('moment');
2+
13
module.exports = [
24
['@vuepress/back-to-top'],
35
[
@@ -9,10 +11,36 @@ module.exports = [
911
[
1012
'@vuepress/medium-zoom',
1113
{
12-
selector: 'img.zoom-custom-imgs',
14+
// selector: 'img.zoom-custom-imgs',
1315
options: {
1416
margin: 16
1517
}
1618
}
19+
],
20+
['@vuepress/pwa',
21+
{
22+
serviceWorker: true,
23+
popupComponent: 'MySWUpdatePopup',
24+
updatePopup: {
25+
'/': {
26+
message: "New content is available.",
27+
buttonText: "Refresh"
28+
},
29+
'/zh/': {
30+
message: "发现新内容可用",
31+
buttonText: "刷新"
32+
}
33+
}
34+
}
35+
],
36+
['@vuepress/blog'],
37+
[
38+
'@vuepress/last-updated',
39+
{
40+
transformer: (timestamp, lang) => {
41+
moment.locale(lang)
42+
return moment(timestamp).fromNow()
43+
}
44+
}
1745
]
1846
];

docs/.vuepress/utils/sidebarHelper.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ function helper({ dir, fPath }) {
4444
}
4545

4646
function sidebarHelper(dir = filePath) {
47-
4847
return syncDirPath(dir)
4948
.filter(fPath => !isFile({ fPath }) && !ignore.includes(fPath))
5049
.map((fPath, dirIndex) => {

docs/zh/array/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Array(MDN + Function)
2+
3+
::: tip
4+
主要是对 `MDN` 和一些常见的 `Array` 方法进行讲解及实现
5+
:::
6+
7+
## 目录
8+
9+
- [x] [arrayMove](./arrayMove/README.md)
10+
11+
- [x] [Array.find](./find/README.md)
12+
13+
- [x] [Array.isArray](./isArray/README.md)

docs/zh/array/arrayMove/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## 原理
2+
3+
通过 `splice`方法去复制需要移动的数组元素,并拼接新数组。
4+
5+
## 实现代码
6+
7+
<<< @/src/Array/arrayMove/index.ts
8+
9+
## 参考
10+
11+
[splice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice)

docs/zh/array/find/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
> 为了不污染原生的 Array 对象, 实现通过 function 来实现
2+
>
3+
> Eg:
4+
5+
```javascript
6+
// prototype
7+
Array.prototype.find = function(predicate, /* thisArg*/) {}
8+
9+
// ours
10+
function (collection, predicate) {}
11+
```
12+
13+
## 原理
14+
15+
`find` 方法对数组中的每一项元素执行一次 `predicate` 函数, 直至有一个 `predicate` 返回 `true`. 当找到了这样一个元素后, 该方法会立即返回这个元素的值, 否则返回 `undefined`. 注意`predicate` 函数会为数组中的每个索引调用即从 0 到 `length - 1`, 而不仅仅是那些被赋值的索引, 这意味着对于稀疏数组来说, 该方法的效率要低于那些只遍历有值的索引的方法.
16+
17+
- 把传入的 `this` 转换成 `Object`对象, 需要`null`值处理 -> `O`
18+
19+
- 取出 `Object``length` -> `len`
20+
21+
- 判断传入 `predicate` 的是否是 `function`, 抛出异常 `TypeError exception`
22+
23+
- 设置计数器 `k = 0`
24+
25+
- `while k < len`
26+
- `kValue = O[k]`
27+
- `testResult = predicate(thisArg, kValue, k, O)` -> `Boolean`
28+
- `testResult is true, return kValue`
29+
- `Set k to k + 1`
30+
- `Return undefined`
31+
32+
## 实现代码
33+
34+
<<< @/src/Array/find/index.ts
35+
36+
## 参数
37+
38+
- `predicate`
39+
40+
在数组每一项上执行的函数, 接收 3 个参数:
41+
42+
- `element`
43+
44+
当前遍历到的元素
45+
46+
- `index` 可选
47+
48+
当前遍历到的索引
49+
50+
- `array` 可选
51+
52+
数组本身
53+
54+
- `thisArg` 可选
55+
56+
执行回调时用作`this`的对象
57+
58+
## 返回值
59+
60+
返回数组中满足提供的测试函数的第一个元素的值. 否则返回 `undefined`
61+
62+
## 参考
63+
64+
[Find MDN](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
65+
66+
[TC39 Find](https://tc39.es/ecma262/#sec-array.prototype.find)

docs/zh/array/isArray/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## 原理
2+
3+
使用 `Object.prototype.toString` 取得对象的一个内部属性 `[[Class]]`,然后依据这个属性,返回 `'[object Array]'` 字符串作为结果(`ECMA`标准中使用`[[]]`来表示语言内部用到的、外部不可直接访问的属性,称为`内部属性`)。利用这 个方法,再配合 `call`,我们可以取得任何对象的内部属性 `[[Class]]`,然后把类型检测转化为字符串比较,以达到我们的目的。
4+
5+
## 实现代码
6+
7+
<<< @/src/Array/isArray/index.ts
8+
9+
## 参考
10+
11+
[绝对准确地确定JavaScript对象是否为数组](http://web.mit.edu/jwalden/www/isArray.html)

0 commit comments

Comments
 (0)