ProgrammingNotes
  • README
  • accounting会计学
  • Apache
  • ar
  • asciidoc
  • AssemblyLanguage汇编语言
  • authorization授权
    • 1.jwt
    • 2.oauth
  • C语言
    • C++
  • cache
  • Computer计算机相关
    • 1.reinstallSystem重装系统
    • 2.vhd
    • 3.bulidWeb建站
    • 4.computerOrganization计算机原理
  • config配置文件相关
  • ContainerTechnology
    • 1.docker
    • 2.kubernetes
  • cs计算机科学
    • 1.api
      • 1.1.restful
      • 1.2.graphQL
      • 1.3.openAPI
      • 1.4.swagger
    • 10.blockchain区块链
      • 10.1.bitCoin比特币
    • 11.characterEncoding字符编码
    • 12.map
      • 12.1.百度地图
      • 12.2.qgis
      • 12.3.openLayers3
      • 12.4.postGIS
    • 13.ai人工智能
    • 14.machineLearning机器学习
    • 15.ioT物联网
    • 16.microservices微服务
    • 17.serverless无服务架构
    • 2.uml
    • 3.designPattern
    • 33.compilation_tool编译工具
      • 33.1.gradle
      • 33.2.maven
    • 4.devOps
      • 4.1.ci
        • 4.1.1.jenkins
        • 4.1.2.github_actions
        • 4.1.3.team_city
      • 4.2.argoCD
    • 6.dataVisualization数据可视化
    • 7.abandonTechnology可放弃的技术
    • 8.bigData大数据
      • 8.1.streamComputing流计算
      • 8.2.edgeComputing边缘计算
    • 9.deepLearning
  • C#
  • db数据库
    • 1.sql
    • 2.noSQL
      • 2.1.redis
      • 2.2.mongoDB
      • 2.3.hbase
      • 2.4.etcd
    • 3.fileSystem文件系统
      • 3.1.fastDFS
      • 3.2.hdfs
    • 4.postgreSQL
    • 5.sqlserver
    • 6.MySQL
    • 7.oracle
    • 8.oceanBase
    • 9.influxDB
    • DatabaseSecurity数据库安全
    • pl/sql
  • Delphi
  • dorado
  • education
  • english
  • frontEnd前端
    • 1.html
      • 1.1.h5
      • 1.2.webSocket
      • 1.3.html2pdf
    • 10.1.wonder
    • 10.webGL
    • 2.w3C规范
      • 2.1.webAPIs
    • 3.css
    • 4.dom
    • 5.xhtml
    • 6.webAssembly
    • 7.ajax
    • 8.fetch
    • 9.picture
  • git
    • 1.gitbook
    • 2.svn
    • 3.github
    • 4.travis_ci
  • golang
    • go_cloud
    • go_crawler
    • goroutine
    • hydra
  • hardware
  • ios
  • java
    • 1.jvm
    • 2.java高级特性之多线程
    • 3.javafx
    • 4.java网络编程
    • 5.java类加载和反射
    • 6.jms
    • 7.java_cloud
    • 8.jsp
    • 9.spring
  • js
    • 1.npm
    • 13.mockJS
    • 19.bootstrap
    • 2.nodeJS
    • 25.echarts
    • 3.angular
      • 3.1.angularCLI
      • 3.2.angularMaterial
    • 4.react
      • 4.3.reactNative
      • 4.4.next
    • 5.vue
      • 5.1.vue-CLI
      • 5.2.vuex
      • 5.3.axios
      • 5.4.vue-router
      • 5.5.element-ui
      • 5.6.vueCore
      • 5.7.nuxt
    • 6.compilation_tool编译工具
      • 6.1.webpack
      • 6.2.parcel
      • 6.3.grunt
    • 7.lib第三方库
      • 7.1.jQuery
      • 7.2.lodash
    • TypeScript
      • 8.1.tslint
    • Deno
    • JS设计模式
    • ECMAScript
    • JS
    • JS6
    • NativeScript
    • RXJS
    • V8
  • linux
    • 1.vim
    • 2.shell
    • 3.shellScript
    • 4.ubuntu
    • 5.makefile
    • 6.centOS
  • markdown
  • markup_lang
    • JSON
    • YAML
  • math
    • 1.algorithm算法
    • 2.cryptology密码学
    • 3.computerGraphics计算机图形学
    • 4.dataStructure数据结构
  • MC消息通信
    • MQ消息队列
      • 1.kafka
      • 2.rabbitMQ
      • 3.redis
      • 4.activeMQ
      • 5.rocketMQ
      • 6.nats
    • MQTT
      • EMQ
    • RPC
      • gRPC
  • mobile
    • android
      • 1.kotlin
      • 2.weixin
      • 3.miniProgram
    • cordova
    • dart
    • flutter
    • ios
      • xcode
    • ReactNative
  • network网络
    • 2.ss
    • 3.http
    • 4.kcp
    • 5.nmap
    • 5G
    • 6.webCrawler
  • news重要新闻
  • Philosophy哲学
    • AnCoderPrepares程序员的自我修养
    • 软件工程的语录
  • php
  • popularizationOfScience科普
  • protocol
    • 1.rpc
  • python
  • readingNotes读书笔记
    • 1.profession专业笔记
    • 2.sql_Antipatterns
    • 3.unix_Network_Programming
    • 4.the_Docker_Book
  • rust
  • scriptingLanguage
    • 2.lua
    • 3.regularExpression正则表达式
    • 4.julia
    • 5.ruby
  • security安全
  • server服务器相关
    • nginx
    • OpenResty
  • software&tool软件和工具
    • 1.vscode
    • 11.plsqldev
    • 17.androidStudio
    • 3.虚拟机VirtualMachine
    • 4.jetBrains
    • 5.eclipse
    • 7.visualStudio
    • 8.office系列
  • softwaretest软件测试
    • JUnit
  • ssh&ssm
    • 2.hibernate
    • 1.spring
  • unix
    • hackintosh
    • mac
  • vr
  • windows
    • terminal&DOS
    • windows10
    • Wine
  • word一些术语
  • zztemp草稿
    • temp
    • temp4study
    • temp4studyLater以后再学的
Powered by GitBook
On this page
  • 7.lib第三方库
  • 一 概述
  • 三 基础
  • 常见测试框架
  • 参数校验
  • 加解密
  • uuid
  • assert
  • Babel(待补充)
  • chai
  • core-js
  • dotenv
  • flow
  • hotkeys-js
  • http-server
  • jsvu
  • Mocha
  • qs
  • 五 经验

Was this helpful?

  1. js

7.lib第三方库

7.lib第三方库

一 概述

js常用库(包括工具库、测试框架等)的笔记,大型的单独一个笔记,简单的就记录本笔记里。

三 基础

常见测试框架

Mocha、Jasmine、Karma、Tape

参数校验

ajv

https://www.npmjs.com/package/ajv

// 简单使用示例
// 导入包

// 定义校验规则
const schema = {
  type: "object",
  properties: {
    foo: {type: "integer"},
    bar: {type: "string"}
  },
  required: ["foo"],
  additionalProperties: false,
}

// 参数
const data = {
  foo: 1,
  bar: "abc"
}

const validate = ajv.compile(schema) // schema也可以是文件
const valid = validate(data)
if (!valid) console.log(validate.errors)

async-validator

加解密

crypto-js

import cryptojs from 'crypto-js';

// sha256加密
console.log(cryptojs.SHA256("abc" + "tom").toString());

uuid

import {v4} from 'uuid';

console.log(v4());

assert

断言

Babel(待补充)

npm install babel-core babel-preset-es2015 babel-polyfill

新建一个.babelrc配置文件:

{
  "presets": [ "es2015" ]
}

chai

断言库

core-js

https://github.com/zloirock/core-js

dotenv

https://www.npmjs.com/package/dotenv

虽然不借助库也可以管理环境变量,但借助该库可以更方便地从文件或Buffer中读取环境变量。(但现在更常见的做法是容器来做这个工作)

可以用来读取.env文件,.env文件的格式是key=value,value是字符串,如下

MONGODB_HOST=localhost
MONGODB_PORT=27017

使用:

  1. 加载配置文件:实测它不能一次加载多个配置文件

    require('dotenv').config(); // 默认会自动读取项目下名称为.env的配置文件
    require('dotenv').config({ path: '/custom/path/to/.env' }); // 手动指定.env文件路径
  2. 预加载dotenv(todo)

适合的场景:

  1. allows you to separate secrets from your source code:代码仓库中不存放敏感的配置信息(将.env文件写入.gitignore),而是在部署的地方手动创建配置文件。

flow

参考

  1. 官方

    1. github:https://github.com/facebook/flow

    2. https://flowtype.org/

  2. 译者:https://zhenyong.github.io/flowtype/

Adds static typing to JavaScript to improve developer productivity and code quality。通过注解的方式来使用。

hotkeys-js

https://www.npmjs.com/package/hotkeys-js

input capture library,快捷键

http-server

jsvu

https://github.com/GoogleChromeLabs/jsvu

它是JavaScript(引擎)版本更新程序。jsvu可以轻松安装各种JavaScript引擎的最新版本,而无需从源代码编译它们。

Mocha

js测试框架

qs

更好的处理url参数的库,更多信息见:https://www.npmjs.com/package/qs

  1. parse(string[, options]):allows you to create nested objects within your query strings, by surrounding the name of sub-keys with square brackets [].

    // 1. 
    assert.deepEqual(qs.parse('foo[bar]=baz'), {
        foo: {
            bar: 'baz'
        }
    });
    // 2. 忽略前面的问号
    var prefixed = qs.parse('?a=b&c=d', { ignoreQueryPrefix: true });
    assert.deepEqual(prefixed, { a: 'b', c: 'd' });
    // 3. 处理数组
    var withArray = qs.parse('a[]=b&a[]=c');
    assert.deepEqual(withArray, { a: ['b', 'c'] });
    ...
  2. qs.stringify(object[, options])

    var qs = require('qs');
    var assert = require('assert');
    
    var obj = qs.parse('a=c');
    assert.deepEqual(obj, { a: 'c' });
    
    var str = qs.stringify(obj);
    assert.equal(str, 'a=c');
    // 1. 处理数组
    console.log(qs.stringify({a: ['b', 'c', 'd']})) // 'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d'
    console.log(qs.stringify({a: ['b', 'c', 'd']}, {encode: false})) // a[0]=b&a[1]=c&a[2]=d
    console.log(qs.stringify({a: ['b', 'c', 'd']}, {indices: false})) // 'a=b&a=c&a=d'

五 经验

Previous6.3.gruntNext7.1.jQuery

Last updated 3 years ago

Was this helpful?