随记笔记

260 阅读3分钟

rimraf 以包的形式包装rm -rf命令,用来删除文件和文件夹的,不管文件夹是否为空,都可删除

fs-extra是 fs 的扩展,继承了 fs 所有方法并为这些方法添加了 promise 语法

art-template 是一个简约、超快的模板引擎。它采用作用域预声明的技术来优化模板渲染速度,从而获得接近 JavaScript 极限的运行性能,并且同时支持 NodeJS 和浏览器。

cac 构建cli类型的app的命令行工具库

chalk 可以美化你控制台输出的语句,包括加粗字体、修改字体颜色、改变字体背景色等。主要用来美化相关控制台工具的输出消息和语句。

chokidar 极简高效的跨平台文件监视库

cross-spawn 编写跨平台 Node.js命令

minimist 一个做参数解析的工具包,这个工具可以用来解析process.argv的参数,例如在使用vue create命令时,官方的要求是create后面只能接一个参数,也就是app的名字,如果你输入过多参数,cli就会把之后多输入的给过滤掉并给出提示,这儿给大家符上vue cli的源码看看

if (minimist(process.argv.slice(3))._.length > 1) {
  console.log(chalk.yellow('\n Info: You provided more than one argument. The first one will be used as the app\'s name, the rest are ignored.'))
}

superAgent 是一个轻量级、灵活的、易读的、低学习曲线的客户端请求代理模块,使用在NodeJS环境中,替代 request

inquirer prompts slash2:将Windows反斜杠路径转换为斜杠路径: foo\bar ➔ foo/bar

validate-npm-package-name 验证是否是合法的包名

execa 执行命令行工具的库

const code = `
    const _Vue = vue
    return function render()
`
new Function(code)() // 得到真正的code里return render函数
  • react:React框架的核心
  • react-dom:React视图渲染的核心[基于React构建WebApp(HTML页面)]
  • exlintConfig:对webpack中ESLint词法检测

cross-env:修改环境变量,如process.evn.PORT,"cross-env PORT=8080 node script/start.js"

1、Partial 将对象中的所有属性更改为可选的。

interface Point {

  x: number;

  y: number;

}

let pointPart: Partial = {}; // Partial allows x and y to be optional

pointPart.x = 10;

2、Required将更改所需对象中的所有属性。

interface Car {

  make: string;

  model: string;

  mileage?: number;

}

let myCar: Required = {

  make: 'Ford',

  model: 'Focus',

  mileage: 12000 // Required forces mileage to be defined

};

3、Record是定义具有特定键类型和值类型的对象类型的快捷方式。

const nameAgeMap: Record<string, number> = {

  'Alice': 21,

  'Bob': 25

};

Record<string, number> is equivalent to { [key: string]: number }

4、Omit省略从对象类型中删除键。

interface Person {

  name: string;

  age: number;

  location?: string;

}

const bob: Omit<Person, 'age' | 'location'> = {

  name: 'Bob'

  // Omit has removed age and location from the type and they can't be defined here(“省略”从类型中删除了年龄和位置,因此无法在这里定义它们)

};

5、Pick从对象类型中删除除指定键外的所有键。

interface Person {

  name: string;

  age: number;

  location?: string;

}

const bob: Pick<Person, 'name'> = {

  name: 'Bob'

  // Pick has only kept name, so age and location were removed from the type and they can't be defined here(“Pick”只保留了名字,因此年龄和位置从类型中删除,因此无法在这里定义)

};

6、Exclude从联合中删除类型。

type Primitive = string | number | boolean

const value: Exclude<Primitive, string> = true; // a string cannot be used here since Exclude removed it from the type.(此处不能使用字符串,因为Exclude将其从类型中删除。)

7、ReturnType提取函数类型的返回类型。

type PointGenerator = () => { x: number; y: number; };

const point: ReturnType = {

  x: 10,

  y: 20

};

8、Parameters将函数类型的参数类型提取为数组。

type PointPrinter = (p: { x: number; y: number; }) => void;

const point: Parameters[0] = {

  x: 10,

  y: 20

};

9、Readonly用于创建一个新类型,其中所有属性都是只读的,这意味着一旦赋值就不能修改它们。

interface Person {

  name: string;

  age: number;

}

const person: Readonly = {

  name: "Dylan",

  age: 35,

};

person.name = 'Israel'; // prog.ts(11,8): error TS2540: Cannot assign to 'name' because it is a read-only property.(progs .ts(11,8):错误TS2540:不能分配给'name',因为它是一个只读属性。)