ts-axios-yhysir v1.0.0
TypeScript library starter
A starter project that makes creating a TypeScript library extremely easy.
Usage
git clone https://github.com/alexjoverm/typescript-library-starter.git YOURFOLDERNAME
cd YOURFOLDERNAME
# Run npm install and write your library name when asked. That's all!
npm install
Start coding! package.json
and entry files are already set up for you, so don't worry about linking to your main file, typings, etc. Just keep those files with the same name.
Features
- Zero-setup. After running
npm install
things will setup for you :wink: - RollupJS for multiple optimized bundles following the standard convention and Tree-shaking
- Tests, coverage and interactive watch mode using Jest
- Prettier and TSLint for code formatting and consistency
- Docs automatic generation and deployment to
gh-pages
, using TypeDoc - Automatic types
(*.d.ts)
file generation - Travis integration and Coveralls report
- (Optional) Automatic releases and changelog, using Semantic release, Commitizen, Conventional changelog and Husky (for the git hooks)
Importing library
You can import the generated bundle to use the whole library generated by this starter:
import myLib from 'mylib'
Additionally, you can import the transpiled modules from dist/lib
in case you have a modular library:
import something from 'mylib/dist/lib/something'
NPM scripts
npm t
: Run test suitenpm start
: Runnpm run build
in watch modenpm run test:watch
: Run test suite in interactive watch modenpm run test:prod
: Run linting and generate coveragenpm run build
: Generate bundles and typings, create docsnpm run lint
: Lints codenpm run commit
: Commit using conventional commit style (husky will tell you to use it if you haven't :wink:)
Excluding peerDependencies
On library development, one might want to set some peer dependencies, and thus remove those from the final bundle. You can see in Rollup docs how to do that.
Good news: the setup is here for you, you must only include the dependency name in external
property within rollup.config.js
. For example, if you want to exclude lodash
, just write there external: ['lodash']
.
Automatic releases
Prerequisites: you need to create/login accounts and add your project to:
Prerequisite for Windows: Semantic-release uses node-gyp so you will need to install Microsoft's windows-build-tools using this command:
npm install --global --production windows-build-tools
Setup steps
Follow the console instructions to install semantic release and run it (answer NO to "Do you want a .travis.yml
file with semantic-release setup?").
Note: make sure you've setup repository.url
in your package.json
file
npm install -g semantic-release-cli
semantic-release-cli setup
# IMPORTANT!! Answer NO to "Do you want a `.travis.yml` file with semantic-release setup?" question. It is already prepared for you :P
From now on, you'll need to use npm run commit
, which is a convenient way to create conventional commits.
Automatic releases are possible thanks to semantic release, which publishes your code automatically on github and npm, plus generates automatically a changelog. This setup is highly influenced by Kent C. Dodds course on egghead.io
Git Hooks
There is already set a precommit
hook for formatting your code with Prettier :nail_care:
By default, there are two disabled git hooks. They're set up when you run the npm run semantic-release-prepare
script. They make sure:
- You follow a conventional commit message
- Your build is not going to fail in Travis (or your CI server), since it's runned locally before
git push
This makes more sense in combination with automatic releases
FAQ
Array.prototype.from
, Promise
, Map
... is undefined?
TypeScript or Babel only provides down-emits on syntactical features (class
, let
, async/await
...), but not on functional features (Array.prototype.find
, Set
, Promise
...), . For that, you need Polyfills, such as core-js
or babel-polyfill
(which extends core-js
).
For a library, core-js
plays very nicely, since you can import just the polyfills you need:
import "core-js/fn/array/find"
import "core-js/fn/string/includes"
import "core-js/fn/promise"
...
What is npm install
doing on first run?
It runs the script tools/init
which sets up everything for you. In short, it:
- Configures RollupJS for the build, which creates the bundles
- Configures
package.json
(typings file, main file, etc) - Renames main src and test files
What if I don't want git-hooks, automatic releases or semantic-release?
Then you may want to:
- Remove
commitmsg
,postinstall
scripts frompackage.json
. That will not use those git hooks to make sure you make a conventional commit - Remove
npm run semantic-release
from.travis.yml
What if I don't want to use coveralls or report my coverage?
Remove npm run report-coverage
from .travis.yml
Resources
- Write a library using TypeScript library starter by @alexjoverm
- 📺 Create a TypeScript Library using typescript-library-starter by @alexjoverm
- Introducing TypeScript Library Starter Lite by @tonysneed
Projects using typescript-library-starter
Here are some projects that use typescript-library-starter
:
- NOEL - A universal, human-centric, replayable event emitter
- droppable - A library to give file dropping super-powers to any HTML element.
- redis-messaging-manager - Pubsub messaging library, using redis and rxjs
Credits
Made with :heart: by @alexjoverm and all these wonderful contributors (emoji key):
This project follows the all-contributors specification. Contributions of any kind are welcome!
xmlhttp.readyState的值及解释: 0:请求未初始化(还没有调用 open())。 1:请求已经建立,但是还没有发送(还没有调用 send())。 2:请求已发送,正在处理中(通常现在可以从响应中获取内容头)。 3:请求在处理中;通常响应中已有部分数据可用了,但是服务器还没有完成响应的生成。 4:响应已完成;您可以获取并使用服务器的响应了。
########################################################################################################################
xmlhttp.status的值及解释: 100——客户必须继续发出请求 101——客户要求服务器根据请求转换HTTP协议版本
200——交易成功 201——提示知道新文件的URL 202——接受和处理、但处理未完成 203——返回信息不确定或不完整 204——请求收到,但返回信息为空 205——服务器完成了请求,用户代理必须复位当前已经浏览过的文件 206——服务器已经完成了部分用户的GET请求
300——请求的资源可在多处得到 301——删除请求数据 302——在其他地址发现了请求数据 303——建议客户访问其他URL或访问方式 304——客户端已经执行了GET,但文件未变化 305——请求的资源必须从服务器指定的地址得到 306——前一版本HTTP中使用的代码,现行版本中不再使用 307——申明请求的资源临时性删除
400——错误请求,如语法错误 401——请求授权失败 402——保留有效ChargeTo头响应 403——请求不允许 404——没有发现文件、查询或URl 405——用户在Request-Line字段定义的方法不允许 406——根据用户发送的Accept拖,请求资源不可访问 407——类似401,用户必须首先在代理服务器上得到授权 408——客户端没有在用户指定的饿时间内完成请求 409——对当前资源状态,请求不能完成 410——服务器上不再有此资源且无进一步的参考地址 411——服务器拒绝用户定义的Content-Length属性请求 412——一个或多个请求头字段在当前请求中错误 413——请求的资源大于服务器允许的大小 414——请求的资源URL长于服务器允许的长度 415——请求资源不支持请求项目格式 416——请求中包含Range请求头字段,在当前请求资源范围内没有range指示值,请求也不包含If-Range请求头字段 417——服务器不满足请求Expect头字段指定的期望值,如果是代理服务器,可能是下一级服务器不能满足请求
合起来
500——服务器产生内部错误 501——服务器不支持请求的函数 502——服务器暂时不可用,有时是为了防止发生系统过载 503——服务器过载或暂停维修 504——关口过载,服务器使用另一个关口或服务来响应用户,等待时间设定值较长 505——服务器不支持或拒绝支请求头中指定的HTTP版本
1xx:信息响应类,表示接收到请求并且继续处理 2xx:处理成功响应类,表示动作被成功接收、理解和接受 3xx:重定向响应类,为了完成指定的动作,必须接受进一步处理 4xx:客户端错误,客户请求包含语法错误或者是不能正确执行 5xx:服务端错误,服务器不能正确执行一个正确的请求
2 years ago