1.0.79 • Published 3 years ago

@geeebe/common v1.0.79

Weekly downloads
77
License
ISC
Repository
github
Last release
3 years ago

@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));
1.0.77

3 years ago

1.0.79

3 years ago

1.0.78

3 years ago

1.0.76

3 years ago

1.0.75

4 years ago

1.0.73

4 years ago

1.0.74

4 years ago

1.0.72

4 years ago

1.0.71

4 years ago

1.0.70

4 years ago

1.0.66

4 years ago

1.0.65

4 years ago

1.0.64

4 years ago

1.0.63

4 years ago

1.0.69

4 years ago

1.0.68

4 years ago

1.0.67

4 years ago

1.0.62

4 years ago

1.0.61

4 years ago

1.0.60

4 years ago

1.0.59

4 years ago

1.0.58

4 years ago

1.0.57

4 years ago

1.0.56

4 years ago

1.0.55

4 years ago

1.0.54

4 years ago

1.0.53

4 years ago

1.0.52

5 years ago

1.0.51

5 years ago

1.0.50

5 years ago

1.0.49

5 years ago

1.0.48

5 years ago

1.0.47

5 years ago

1.0.46

6 years ago

1.0.45

6 years ago

1.0.44

6 years ago

1.0.42

6 years ago

1.0.41

6 years ago

1.0.40

6 years ago

1.0.39

6 years ago

1.0.38

6 years ago

1.0.37

6 years ago

1.0.36

6 years ago

1.0.35

6 years ago

1.0.34

6 years ago

1.0.33

6 years ago

1.0.32

6 years ago

1.0.31

6 years ago

1.0.30

6 years ago

1.0.29

6 years ago

1.0.28

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago