@geeebe/common
这个库有一点点有用的代码, 加上用于设置一个 typescript 包含一些共同有用设置的工程 ts-node, (中文(简体) ), tslint 财务报告和审定财务报表 jest。 。 。 .
开始
在空工程目录中 .
npm init
# fill in details asked (defaults will do)
npm i @geeebe/common
npx geeebe init
这将为您的工程做以下工作
- 创建
.editorconfig, (中文(简体) ),.gitignore财务报告和审定财务报表.npmignore - 安装
typescript财务报告和审定财务报表ts-node - 安装和配置
tslint - 安装
jest与ts-jest创建启动配置 - 安装和配置
nodemon
要开始,写一些 typescript 代码在 src/index.ts 运行它.
要运行,请使用:
npm start使用ts-nodenpm run watch使用nodemon财务报告和审定财务报表ts-nodenpm run build输出到dist/使用tsc
还有用:
npm test要运行jest试验test/目录( 查找)*.test.ts文档)npm run lint要运行tslint
包含代码
这里不多...
HTTP 响应状态
import { Statuses } from '@geeebe/common';
// ...
if (status === Statuses.NOT_FOUND) {} // 404
一些时间和期间的简单功能
import { Time } from '@geeebe/common';
const fiveMinutes = Time.minutes(5); // 5 min in ms = 5 * 60 * 1000
const sevenHours = Time.hours(7); // 7 hours in ms
const someTime = Time.days(2) + Time.hours(3) + Time.seconds(2);
// and then
const hours = Time.toHours(sevenHours);
// etc
// also
const fourHoursAgo = Time.past(Time.hours(4)); // Date() of 4 hours ago
const future = Time.future(Time.seconds(45)); // or in the future
方法:
ms(ms: number): Durationseconds(s: number): Durationminutes(m: number): Durationhours(h: number): Durationdays(d: number): DurationtoMs(d: Duration): numbertoSeconds(d: Duration): numbertoMinutes(d: Duration): numbertoHours(d: Duration): numbertoDays(d: Duration): numberpast(interval: Duration): Datefuture(interval: Duration): Date
常数 :
SECOND = 1000MINUTE = 60 * Time.SECONDHOUR = 60 * Time.MINUTEDAY = 24 * Time.HOUR
Async 睡眠函数
await sleep(Time.seconds(45));