Skip to content

Commit 3d576bc

Browse files
committed
feat: add doc and jest
1 parent 9220e6d commit 3d576bc

30 files changed

+10613
-1
lines changed

.editorconfig

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 2
8+
indent_style = space
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
max_line_length = 100
12+
13+
[*.{ts, tsx}]
14+
ij_typescript_enforce_trailing_comma = keep
15+
ij_typescript_use_double_quotes = false
16+
ij_typescript_force_quote_style = true
17+
ij_typescript_align_imports = false
18+
ij_typescript_align_multiline_ternary_operation = false
19+
ij_typescript_align_multiline_parameters_in_calls = false
20+
ij_typescript_align_multiline_parameters = false
21+
ij_typescript_align_multiline_chained_methods = false
22+
ij_typescript_else_on_new_line = false
23+
ij_typescript_catch_on_new_line = false
24+
ij_typescript_spaces_within_interpolation_expressions = false
25+
26+
[*.md]
27+
max_line_length = 100
28+
trim_trailing_whitespace = false
29+
30+
[COMMIT_EDITMSG]
31+
max_line_length = 80

.eslintrc.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"extends": [
3+
"eslint:recommended",
4+
"plugin:prettier/recommended",
5+
"plugin:@typescript-eslint/recommended",
6+
"plugin:mdx/recommended"
7+
],
8+
"env": {
9+
"browser": true,
10+
"node": true
11+
},
12+
"parser": "@typescript-eslint/parser",
13+
"plugins": [
14+
"@typescript-eslint",
15+
"prettier",
16+
"jest"
17+
],
18+
"rules": {
19+
"no-unused-vars": "off",
20+
"@typescript-eslint/no-unused-vars": 0,
21+
"@typescript-eslint/consistent-type-imports": [
22+
1,
23+
{
24+
"prefer": "type-imports",
25+
"fixStyle": "inline-type-imports"
26+
}
27+
],
28+
"@typescript-eslint/ban-ts-comment": "off",
29+
"@typescript-eslint/no-explicit-any": "off"
30+
}
31+
}

.gitignore

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.DS_Store
2+
3+
.pnp
4+
.pnp.js
5+
.env.local
6+
.env.*.local
7+
.history
8+
.rts*
9+
*.log*
10+
*.pid
11+
*.pid.*
12+
*.report
13+
*.lcov
14+
lib-cov
15+
16+
node_modules/
17+
.npm
18+
.lock-wscript
19+
.yarn-integrity
20+
.node_repl_history
21+
.nyc_output
22+
*.tsbuildinfo
23+
.eslintcache
24+
.sonarlint
25+
26+
dist/
27+
coverage/
28+
release/
29+
output/
30+
output_resource/
31+
log/
32+
33+
.vscode/**/*
34+
!.vscode/settings.json
35+
!.vscode/extensions.json
36+
.idea/
37+
38+
**/*/typings/auto-generated
39+
40+
.changeset/pre.json
41+
42+
.pnpm-store/
43+
44+
modern.config.local.ts
45+
modern.config.local.js
46+
modern.config.local.mjs
47+
48+
doc_build/
49+

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
strict-peer-dependencies=false

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/gallium

.prettierrc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "es5",
4+
"tabWidth": 2,
5+
"printWidth": 100,
6+
"semicolons": true,
7+
"quoteProps": "as-needed",
8+
"jsxSingleQuote": false,
9+
"bracketSpacing": true,
10+
"jsxBracketSameLine": true,
11+
"arrowParens": "always",
12+
"endOfLine": "lf"
13+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

docs/public/.gitkeep

Whitespace-only changes.

http/http.md renamed to docs/zh/guide/http/http.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## http 常见状态码
1+
# http 常见状态码
22

33
1. 1xx
44

docs/zh/guide/introduction.mdx

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# 前端面试手册
2+
3+
4+
Todo List
File renamed without changes.
File renamed without changes.

docs/zh/index.mdx

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
pageType: home
3+
4+
hero:
5+
name: 前端面试手册
6+
text:
7+
tagline:
8+
actions:
9+
- theme: brand
10+
text: 介绍
11+
link: /zh/guide/introduction
12+
- theme: alt
13+
text: 快速开始
14+
link: /zh/guide/javascript
15+
features:
16+
- title: '常见面试题解'
17+
details: 收集网络上和自己遇到的常见题。
18+
icon: 📦
19+
- title: '进阶修炼'
20+
details: 从基础到进阶,知识点一网打尽。
21+
icon: 🚀
22+
- title: '开扩视野'
23+
details: 帮你在平时CRUD的基础上拓宽知识面。
24+
icon: 🎨
25+
---

index.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// algorithm 算法 algorithm
2+
3+
// 复杂度分为: O(1) O(n) O(n^2) O(logN) O(nlogN)
4+
5+
// 复杂度为 O(n) 线性阶
6+
function main(n) {
7+
while (--n > 0) {
8+
console.log(n);
9+
}
10+
}
11+
12+
13+
// O(n^2) 平方阶
14+
function N2(n) {
15+
for (let index = 0; index < n; index++) {
16+
for (let j = 0; j < index; j++) {
17+
console.log('j is', j);
18+
}
19+
20+
}
21+
}
22+
23+
// main(5)
24+
25+
// O(logN) 对数阶
26+
function logN(n) {
27+
let i = 1;
28+
while (i < n) {
29+
console.log(i);
30+
i = i * 2;
31+
}
32+
console.log('end');
33+
}
34+
35+
// O(nlogn) 线性对数阶
36+
function nlogN(n) {
37+
for (let i = 0; i < n; i++) {
38+
let j = i;
39+
while(j < n) {
40+
console.log(i);
41+
j = j * 2;
42+
}
43+
44+
}
45+
}

jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
};

modern.config.ts

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { defineConfig, docTools } from '@modern-js/doc-tools';
2+
import path from 'path';
3+
4+
const isProd = () => process.env.NODE_ENV === 'production';
5+
6+
function getI18nHelper(lang: 'zh' | 'en') {
7+
const cn = lang === 'zh';
8+
// 默认语言为中文,如果是英文,需要加上 /en 前缀
9+
// The default language is Chinese, if it is English, you need to add the /en prefix
10+
const prefix = cn ? '' : '/en';
11+
const getLink = (str: string) => `${prefix}${str}`;
12+
const getText = (cnText: string, enText: string) => (cn ? cnText : enText);
13+
return { getText, getLink };
14+
}
15+
16+
function getNavConfig(lang: 'zh' | 'en') {
17+
const { getText, getLink } = getI18nHelper(lang);
18+
return [
19+
{
20+
text: getText('首页', 'Home'),
21+
link: getLink('/'),
22+
},
23+
];
24+
}
25+
26+
function getSidebarConfig(lang: 'zh' | 'en') {
27+
const { getText, getLink } = getI18nHelper(lang);
28+
// 注: 侧边栏配置可以嵌套,子菜单字段为 items
29+
// Note: The sidebar configuration can be nested, and the sub-menu field is items
30+
return {
31+
[getLink('/guide')]: [
32+
{
33+
collapsed: false,
34+
collapsible: false,
35+
text: getText('开始', 'Getting Started'),
36+
items: [getLink('/guide/introduction')],
37+
},
38+
{
39+
collapsed: false,
40+
collapsible: false,
41+
text: getText('网络协议', 'http'),
42+
items: [getLink('/guide/http/http')],
43+
},
44+
{
45+
text: getText('Javascript相关', 'javascript'),
46+
link: getLink('/guide/javascript/javascript'),
47+
},
48+
{
49+
text: getText('手写代码', 'write-code'),
50+
link: getLink('/guide/write-code/write-code'),
51+
},
52+
],
53+
};
54+
}
55+
56+
export default defineConfig({
57+
doc: {
58+
// https://modernjs.dev/doc-tools/zh/api/config/config-basic.html
59+
base: isProd() ? '/front-end-interview/' : '/',
60+
root: path.join(__dirname, 'docs'),
61+
head: [],
62+
// 默认语言
63+
// Default language
64+
lang: 'zh',
65+
themeConfig: {
66+
footer: {
67+
// 页脚的文案
68+
// Footer text
69+
message: '© 2023 JavaSwing Reserved.',
70+
},
71+
// 不同语言的配置
72+
// Configuration for different languages
73+
locales: [
74+
{
75+
lang: 'zh',
76+
title: '前端面试手册',
77+
description: '前端面试手册',
78+
// nav: getNavConfig('zh'),
79+
sidebar: getSidebarConfig('zh'),
80+
// 语言切换按钮的文案
81+
// Language switch button text
82+
label: '简体中文',
83+
},
84+
],
85+
},
86+
},
87+
plugins: [docTools()],
88+
});

package.json

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "front-end-interview",
3+
"version": "1.0.0",
4+
"description": "前端面试整理知识点",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "jest --maxWorkers 2",
8+
"test:watch": "jest --watch",
9+
"test:ssr": "jest --maxWorkers 2 --config ./jest.config.node.ts",
10+
"test:coverage": "jest --coverage",
11+
"lint": "eslint \"{code,tests,stories}/**/*.{ts,js}\"",
12+
"lint:fix": "npm run lint --fix",
13+
"lint:types": "tsc --noEmit",
14+
"dev": "modern dev",
15+
"build": "modern build",
16+
"preview": "modern preview"
17+
},
18+
"license": "ISC",
19+
"repository": {
20+
"type": "git",
21+
"url": "git+https://github.com/javaswing/Front-End-Interview.git"
22+
},
23+
"author": "javaswing",
24+
"devDependencies": {
25+
"@babel/core": "^7.22.5",
26+
"@types/jest": "^29.0.3",
27+
"@types/node": "^20.3.1",
28+
"@typescript-eslint/eslint-plugin": "^5.60.0",
29+
"@typescript-eslint/parser": "^5.60.0",
30+
"babel-jest": "^29.5.0",
31+
"eslint": "^8.43.0",
32+
"eslint-config-prettier": "^8.8.0",
33+
"eslint-plugin-jest": "^27.2.2",
34+
"eslint-plugin-mdx": "^2.1.0",
35+
"eslint-plugin-prettier": "^4.2.1",
36+
"jest": "^29.0.3",
37+
"prettier": "2.8.8",
38+
"ts-jest": "^29.0.2",
39+
"ts-node": "^10.9.1",
40+
"tslib": "^2.5.3",
41+
"typescript": "^4.8.3"
42+
},
43+
"dependencies": {
44+
"@modern-js/doc-tools": "^2.25.1",
45+
"tailwindcss": "^3.2.7"
46+
}
47+
}

0 commit comments

Comments
 (0)