Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dilbert Oracle #9

Merged
merged 8 commits into from
Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
run: yarn test
- name: Check Code Style
run: yarn lint
- name: Lint .d.ts
run: yarn dtslint

- name: Report Coverage
uses: coverallsapp/github-action@master
Expand Down
3 changes: 3 additions & 0 deletions algorithms/dilbert-oracle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Troll: Nine nine nine nine nine nine
const random = () => 9
module.exports = random
3 changes: 3 additions & 0 deletions algorithms/fair-dice-roll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// chosen by fair dice roll. guaranteed to be random.
const random = () => 4
module.exports = random
10 changes: 7 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
declare module '@rschmidmeister/random.js' {
declare namespace random {
// Troll: Nine nine nine nine nine nine
function dilbertOracle(): number;
// chosen by fair dice roll. guaranteed to be random.
function random(): number;
export = random;
function fairDiceRoll(): number;
}
// Legacy default export
declare function random(): number;
export = random;
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// chosen by fair dice roll.
// guaranteed to be random.
module.exports = () => 4
const fairDiceRoll = require('./algorithms/fair-dice-roll')
const dilbertOracle = require('./algorithms/dilbert-oracle')
module.exports = Object.assign(fairDiceRoll, { fairDiceRoll, dilbertOracle })
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
"mocha": "^7.0.0",
"nyc": "^15.0.0",
"standard": "^14.3.1"
},
"dependencies": {
"dtslint": "^2.0.5"
}
}
20 changes: 12 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,28 @@
[![devDependencies Status](https://david-dm.org/bash/random.js/dev-status.svg)](https://david-dm.org/bash/random.js?type=dev)
![gluten free](https://img.shields.io/badge/gluten-free-green.svg)


A [deterministic random number](https://www.xkcd.com/221/) generator for node.
A *deterministic random number* generator for node.
This module has some important advantages over other modules:

- Only **82 bytes** in size (without gzip)!
- Only **400 bytes** in size (without gzip)!
- **O(1)** complexity
- **100%** test coverage

Install with:
## Supported algorithms

- [Fair Dice Roll](https://www.xkcd.com/221/)
- [Dilbert Oracle](https://dilbert.com/strip/2001-10-25)

## Installation

```bash
npm i --save @rschmidmeister/random.js
```

Usage:
## Usage

```js
const random = require('@rschmidmeister/random.js')

console.log(random())
const { fairDiceRoll, dilbertOracle } = require('@rschmidmeister/random.js')
console.log(fairDiceRoll())
console.log(dilbertOracle())
```
10 changes: 10 additions & 0 deletions test/dilbert-oracle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

const assert = require('assert')
const { dilbertOracle } = require('../index')

describe('dilbert oracle', () => {
it('always returns the same number', () => {
assert.equal(9, dilbertOracle())
})
})
10 changes: 10 additions & 0 deletions test/fair-dice-roll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

const assert = require('assert')
const { fairDiceRoll } = require('../index')

describe('fair dice roll', () => {
it('always returns the same number', () => {
assert.equal(4, fairDiceRoll())
})
})
10 changes: 10 additions & 0 deletions test/legacy-export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

const assert = require('assert')
const random = require('../index')

describe('legacy default export', () => {
it('should be the same as fair dice roll', () => {
assert.equal(random.fairDiceRoll, random)
})
})
14 changes: 0 additions & 14 deletions test/test.js

This file was deleted.

22 changes: 22 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"@rschmidmeister/random.js": [
"."
]
}
},
"files": [
"index.d.ts"
]
}