Skip to content

Commit

Permalink
Removed Obj suffix from class names; typings added
Browse files Browse the repository at this point in the history
  • Loading branch information
dex4er committed Oct 24, 2017
1 parent 8fb5657 commit 66e1383
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage/**
ts-node-*/**
**/*.d.ts
**/*-ts.js
22 changes: 22 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// npm i -g eslint eslint-config-standard eslint-plugin-import eslint-plugin-node eslint-plugin-promise eslint-plugin-standard

module.exports = {
env: { node: true },
extends: 'standard',
globals: {
And: true,
After: true,
Before: true,
Feature: true,
Given: true,
Scenario: true,
Then: true,
When: true
},
rules: {
indent: ['error', 2, { flatTernaryExpressions: true, MemberExpression: 0, SwitchCase: 1 }],
'no-cond-assign': [2, 'except-parens'],
'no-multi-spaces': ['error', { ignoreEOLComments: true }],
'one-var-declaration-per-line': 2
}
}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
*-ts.js

*.tgz

ts-node-*

/coverage/
/node_modules/

/.nyc_output/

/.tags
/.tern-project

/package-lock.json
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!/index.js
!/tsconfig.json
!/lib/*
4 changes: 3 additions & 1 deletion .taprc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"nodeArgs": ["--harmony"],
"color": false,
"nodeArgs": [],
"reporter": "classic"
}
27 changes: 24 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
sudo: false

language: node_js

matrix:
include:
- node_js: "8"
env:
- TAP_RCFILE=./.taprc

- node_js: "7"
env:
- TAP_RCFILE=./.taprc

- node_js: "6"
env:
- TAP_RCFILE=./.taprc

- node_js: "5"
env: TAP_RCFILE=./.taprc
env:
- TAP_ARGS="--strict --harmony"
- TAP_RCFILE=./.taprc

- node_js: "4"
env: TAP_RCFILE=./.taprc
env:
- TAP_ARGS="--strict --harmony"
- TAP_RCFILE=./.taprc

install:
- npm install
- if [ -n "$NPM_INSTALL_PACKAGES" ]; then npm install $NPM_INSTALL_PACKAGES; fi
- npm install typescript tslint tslint-config-standard

script:
- npm run ${NPM_RUN_SCRIPT:-test}
- npm run ${NPM_RUN_SCRIPT:-test} -- $TAP_ARGS
- node_modules/.bin/tsc
- node_modules/.bin/tslint -t stylish -p .
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v0.1.0 2017-10-24

* Removed `Obj` suffix from class names.
* Typescript: typings added.

## v0.0.4 2017-06-22

* Minor refactoring for tests
Expand Down
25 changes: 25 additions & 0 deletions lib/timers-obj.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/// <reference types="node" />

export type TimerCallback = (...args: any[]) => void

export class Immediate {
readonly timer: NodeJS.Timer
constructor (callback: TimerCallback, ...args: any[])
remove (): void
}

export class Interval {
readonly timer: NodeJS.Timer
constructor (delay: number, callback: TimerCallback, ...args: any[])
remove (): void
}

export class Timeout {
readonly timer: NodeJS.Timer
constructor (delay: number, callback: TimerCallback, ...args: any[])
remove (): void
}

export function immediate (callback: TimerCallback, ...args: any[]): Immediate
export function interval (delay: number, callback: TimerCallback, ...args: any[]): Interval
export function timeout (delay: number, callback: TimerCallback, ...args: any[]): Timeout
15 changes: 9 additions & 6 deletions lib/timers-obj.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

class ImmediateObj {
class Immediate {
constructor (callback, ...args) {
this.timer = setImmediate(callback, ...args)
}
Expand All @@ -13,7 +13,7 @@ class ImmediateObj {
}
}

class IntervalObj {
class Interval {
constructor (delay, callback, ...args) {
this.timer = setInterval(callback, delay, ...args)
}
Expand All @@ -26,7 +26,7 @@ class IntervalObj {
}
}

class TimeoutObj {
class Timeout {
constructor (delay, callback, ...args) {
this.timer = setTimeout(callback, delay, ...args)
}
Expand All @@ -40,18 +40,21 @@ class TimeoutObj {
}

function immediate (callback, ...args) {
return new ImmediateObj(callback, ...args)
return new Immediate(callback, ...args)
}

function interval (delay, callback, ...args) {
return new IntervalObj(delay, callback, ...args)
return new Interval(delay, callback, ...args)
}

function timeout (delay, callback, ...args) {
return new TimeoutObj(delay, callback, ...args)
return new Timeout(delay, callback, ...args)
}

module.exports = {
Immediate: Immediate,
Interval: Interval,
Timeout: Timeout,
immediate: immediate,
interval: interval,
timeout: timeout
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "timers-obj",
"version": "0.0.4",
"version": "0.1.0",
"description": "Timers as objects",
"main": "lib/timers-obj.js",
"repository": {
Expand All @@ -22,6 +22,7 @@
},
"dependencies": {},
"devDependencies": {
"@types/node": "^8.0.46",
"chai": "^4.0.2",
"dirty-chai": "^2.0.0",
"snazzy": "^7.0.0",
Expand Down
10 changes: 10 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"target": "ES2017"
}
}
11 changes: 11 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": [
"tslint:recommended",
"tslint-config-standard"
],
"rules": {
"max-line-length": false,
"no-console": [true, "log"],
"no-unused-variable": false
}
}

0 comments on commit 66e1383

Please sign in to comment.