TypeScript Collections 项目教程
1. 项目的目录结构及介绍
TypeScript Collections 项目的目录结构如下:
typescript-collections/
├── dist/
├── examples/
├── lib/
├── src/
├── test/
├── .gitignore
├── .npmignore
├── .travis.yml
├── LICENSE
├── package.json
├── README.md
├── tsconfig.json
└── tslint.json
目录介绍
dist/
: 编译后的 JavaScript 文件存放目录。examples/
: 项目使用示例代码。lib/
: 库文件存放目录。src/
: TypeScript 源代码存放目录。test/
: 测试代码存放目录。.gitignore
: Git 忽略文件配置。.npmignore
: npm 发布时忽略的文件配置。.travis.yml
: Travis CI 配置文件。LICENSE
: 项目许可证。package.json
: 项目依赖和脚本配置。README.md
: 项目说明文档。tsconfig.json
: TypeScript 编译配置文件。tslint.json
: TypeScript 代码风格检查配置文件。
2. 项目的启动文件介绍
TypeScript Collections 项目的启动文件主要是 src/index.ts
,它是项目的入口文件,负责导出所有可供外部使用的模块和类。
// src/index.ts
export * from './lib/Bag';
export * from './lib/BSTree';
export * from './lib/Dictionary';
export * from './lib/LinkedDictionary';
export * from './lib/LinkedList';
export * from './lib/MultiDictionary';
export * from './lib/Queue';
export * from './lib/PriorityQueue';
export * from './lib/Set';
export * from './lib/Stack';
export * from './lib/Heap';
export * from './lib/TreeSet';
3. 项目的配置文件介绍
tsconfig.json
tsconfig.json
文件是 TypeScript 项目的编译配置文件,定义了 TypeScript 编译器的行为。
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"outDir": "./dist",
"rootDir": "./src",
"declaration": true,
"sourceMap": true,
"strict": true,
"esModuleInterop": true
},
"include": [
"src/**/*"
]
}
package.json
package.json
文件定义了项目的依赖、脚本和其他元数据。
{
"name": "typescript-collections",
"version": "1.3.3",
"description": "A complete, fully tested data structure library written in TypeScript.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"test": "jest",
"lint": "tslint -c tslint.json 'src/**/*.ts'"
},
"repository": {
"type": "git",
"url": "git+https://github.com/basarat/typescript-collections.git"
},
"keywords": [
"typescript",
"data",
"structure",
"collection",
"linked",
"list",
"dictionary",
"set",
"stack",
"queue",
"priority",
"tree",
"binary",
"search"
],
"author": "basarat",
"license": "MIT",
"bugs": {
"url": "https://github.com/basarat/typescript-collections/issues"
},
"homepage": "https://github.com/basarat/typescript-collections#readme",
"devDependencies": {
"@types/jest": "^26.0.20",
"jest": "^26.6.3",
"ts-jest": "^26.5.3",
"tslint": "^6.1.3",
"typ