@geeebe/common
This library has tiny bit of useful code, plus a util for setting up a `typescript` project with some common useful settings including `ts-node`, `tslint` and `jest`.
Last updated 3 months ago by gregbacchus .
ISC · Original npm · Tarball · package.json
$ cnpm install @geeebe/common 
SYNC missed versions from official npm registry.

@geeebe/common

This library has tiny bit of useful code, plus a util for setting up a typescript project with some common useful settings including ts-node, tslint and jest.

Getting Started

In empty project directory.

npm init
# fill in details asked (defaults will do)
npm i @geeebe/common
npx geeebe init

This will do the following for your project

  • create .editorconfig, .gitignore and .npmignore
  • install typescript and ts-node
  • install and configure tslint
  • install jest with ts-jest and create a starter config
  • install and configure nodemon

To get started, write some typescript code in src/index.ts and run it.

To run, either use:

  • npm start to run one-off using ts-node
  • npm run watch to run and watch for changes using nodemon and ts-node
  • npm run build to build output to dist/ using tsc

Also useful:

  • npm test to run jest tests in the test/ directory (looking for *.test.ts files)
  • npm run lint to run tslint

Included Code

Not too much here...

HTTP response status

import { Statuses } from '@geeebe/common';

// ...

if (status === Statuses.NOT_FOUND) {} // 404

Some simple functions for time and duration

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

Methods:

  • ms(ms: number): Duration
  • seconds(s: number): Duration
  • minutes(m: number): Duration
  • hours(h: number): Duration
  • days(d: number): Duration
  • toMs(d: Duration): number
  • toSeconds(d: Duration): number
  • toMinutes(d: Duration): number
  • toHours(d: Duration): number
  • toDays(d: Duration): number
  • past(interval: Duration): Date
  • future(interval: Duration): Date

Constants:

  • SECOND = 1000
  • MINUTE = 60 * Time.SECOND
  • HOUR = 60 * Time.MINUTE
  • DAY = 24 * Time.HOUR

Async sleep function

await sleep(Time.seconds(45));

Current Tags

  • 1.0.75                                ...           latest (3 months ago)

69 Versions

  • 1.0.75                                ...           3 months ago
  • 1.0.74                                ...           3 months ago
  • 1.0.73                                ...           3 months ago
  • 1.0.72                                ...           3 months ago
  • 1.0.71                                ...           4 months ago
  • 1.0.70                                ...           4 months ago
  • 1.0.69                                ...           4 months ago
  • 1.0.68                                ...           4 months ago
  • 1.0.67                                ...           4 months ago
  • 1.0.66                                ...           4 months ago
  • 1.0.65                                ...           4 months ago
  • 1.0.64                                ...           4 months ago
  • 1.0.63                                ...           4 months ago
  • 1.0.62                                ...           7 months ago
  • 1.0.61                                ...           7 months ago
  • 1.0.60                                ...           7 months ago
  • 1.0.59                                ...           7 months ago
  • 1.0.58                                ...           7 months ago
  • 1.0.57                                ...           7 months ago
  • 1.0.56                                ...           7 months ago
  • 1.0.55                                ...           7 months ago
  • 1.0.54                                ...           7 months ago
  • 1.0.53                                ...           7 months ago
  • 1.0.52                                ...           7 months ago
  • 1.0.51                                ...           7 months ago
  • 1.0.50                                ...           8 months ago
  • 1.0.49                                ...           9 months ago
  • 1.0.48                                ...           a year ago
  • 1.0.47                                ...           a year ago
  • 1.0.46                                ...           2 years ago
  • 1.0.45                                ...           2 years ago
  • 1.0.44                                ...           2 years ago
  • 1.0.42                                ...           2 years ago
  • 1.0.41                                ...           2 years ago
  • 1.0.40                                ...           2 years ago
  • 1.0.39                                ...           2 years ago
  • 1.0.38                                ...           2 years ago
  • 1.0.37                                ...           2 years ago
  • 1.0.36                                ...           2 years ago
  • 1.0.35                                ...           2 years ago
  • 1.0.34                                ...           2 years ago
  • 1.0.33                                ...           2 years ago
  • 1.0.32                                ...           2 years ago
  • 1.0.31                                ...           2 years ago
  • 1.0.30                                ...           2 years ago
  • 1.0.29                                ...           2 years ago
  • 1.0.28                                ...           2 years ago
  • 1.0.26                                ...           2 years ago
  • 1.0.25                                ...           2 years ago
  • 1.0.24                                ...           2 years ago
  • 1.0.23                                ...           2 years ago
  • 1.0.21                                ...           2 years ago
  • 1.0.20                                ...           2 years ago
  • 1.0.19                                ...           2 years ago
  • 1.0.18                                ...           2 years ago
  • 1.0.17                                ...           2 years ago
  • 1.0.16                                ...           2 years ago
  • 1.0.15                                ...           2 years ago
  • 1.0.14                                ...           2 years ago
  • 1.0.13                                ...           2 years ago
  • 1.0.12                                ...           2 years ago
  • 1.0.11                                ...           2 years ago
  • 1.0.10                                ...           2 years ago
  • 1.0.9                                ...           2 years ago
  • 1.0.8                                ...           2 years ago
  • 1.0.7                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 71
Last Day 0
Last Week 69
Last Month 1
Dependencies (1)
Dev Dependencies (7)

Copyright 2014 - 2017 © taobao.org |