Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit 0897aad

Browse files
author
Ruben Schmidmeister
authored
Merge pull request #9 from bash/dilbert-oracle
Dilbert Oracle
2 parents 367700d + eaad5c3 commit 0897aad

File tree

12 files changed

+85
-28
lines changed

12 files changed

+85
-28
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
run: yarn test
2222
- name: Check Code Style
2323
run: yarn lint
24+
- name: Lint .d.ts
25+
run: yarn dtslint
2426

2527
- name: Report Coverage
2628
uses: coverallsapp/github-action@master

algorithms/dilbert-oracle.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Troll: Nine nine nine nine nine nine
2+
const random = () => 9
3+
module.exports = random

algorithms/fair-dice-roll.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// chosen by fair dice roll. guaranteed to be random.
2+
const random = () => 4
3+
module.exports = random

index.d.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
declare module '@rschmidmeister/random.js' {
1+
declare namespace random {
2+
// Troll: Nine nine nine nine nine nine
3+
function dilbertOracle(): number;
24
// chosen by fair dice roll. guaranteed to be random.
3-
function random(): number;
4-
export = random;
5+
function fairDiceRoll(): number;
56
}
7+
// Legacy default export
8+
declare function random(): number;
9+
export = random;

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// chosen by fair dice roll.
2-
// guaranteed to be random.
3-
module.exports = () => 4
1+
const fairDiceRoll = require('./algorithms/fair-dice-roll')
2+
const dilbertOracle = require('./algorithms/dilbert-oracle')
3+
module.exports = Object.assign(fairDiceRoll, { fairDiceRoll, dilbertOracle })

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@
2626
"mocha": "^7.0.0",
2727
"nyc": "^15.0.0",
2828
"standard": "^14.3.1"
29+
},
30+
"dependencies": {
31+
"dtslint": "^2.0.5"
2932
}
3033
}

readme.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,28 @@
1010
[![devDependencies Status](https://david-dm.org/bash/random.js/dev-status.svg)](https://david-dm.org/bash/random.js?type=dev)
1111
![gluten free](https://img.shields.io/badge/gluten-free-green.svg)
1212

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

17-
- Only **82 bytes** in size (without gzip)!
16+
- Only **400 bytes** in size (without gzip)!
1817
- **O(1)** complexity
1918
- **100%** test coverage
2019

21-
Install with:
20+
## Supported algorithms
21+
22+
- [Fair Dice Roll](https://www.xkcd.com/221/)
23+
- [Dilbert Oracle](https://dilbert.com/strip/2001-10-25)
24+
25+
## Installation
2226

2327
```bash
2428
npm i --save @rschmidmeister/random.js
2529
```
2630

27-
Usage:
31+
## Usage
2832

2933
```js
30-
const random = require('@rschmidmeister/random.js')
31-
32-
console.log(random())
34+
const { fairDiceRoll, dilbertOracle } = require('@rschmidmeister/random.js')
35+
console.log(fairDiceRoll())
36+
console.log(dilbertOracle())
3337
```

test/dilbert-oracle.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict'
2+
3+
const assert = require('assert')
4+
const { dilbertOracle } = require('../index')
5+
6+
describe('dilbert oracle', () => {
7+
it('always returns the same number', () => {
8+
assert.equal(9, dilbertOracle())
9+
})
10+
})

test/fair-dice-roll.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict'
2+
3+
const assert = require('assert')
4+
const { fairDiceRoll } = require('../index')
5+
6+
describe('fair dice roll', () => {
7+
it('always returns the same number', () => {
8+
assert.equal(4, fairDiceRoll())
9+
})
10+
})

test/legacy-export.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict'
2+
3+
const assert = require('assert')
4+
const random = require('../index')
5+
6+
describe('legacy default export', () => {
7+
it('should be the same as fair dice roll', () => {
8+
assert.equal(random.fairDiceRoll, random)
9+
})
10+
})

0 commit comments

Comments
 (0)