Skip to content

Commit

Permalink
feat: esm only! node v18+ 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb committed Jun 5, 2024
1 parent 60d7654 commit 1fdb6c7
Show file tree
Hide file tree
Showing 15 changed files with 5,969 additions and 8,684 deletions.
12 changes: 12 additions & 0 deletions .github/SPONSORS.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# These are supported funding model platforms

github: mesqueeb
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test
on:
push:
branches: main
paths:
- src/**
- test/**
- '*.js'
- '*.ts'
- '*.json'
- .github/workflows/test.yml
pull_request:
branches: main
paths:
- src/**
- test/**
- '*.js'
- '*.ts'
- '*.json'
- .github/workflows/test.yml
concurrency:
group: test-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
strategy:
matrix:
node-version: ['18', '20']
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
- run: npm ci
- run: npm test
9 changes: 0 additions & 9 deletions .prettierrc

This file was deleted.

3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import prettier from "@cycraft/eslint/prettier"

export default prettier
31 changes: 0 additions & 31 deletions dist/cjs/index.cjs

This file was deleted.

27 changes: 0 additions & 27 deletions dist/cjs/index.d.cts

This file was deleted.

8 changes: 3 additions & 5 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* @param {number} [max] When passing 2 arguments, they are considered "min" and "max"; it returns a number between min - max; including min and max
* @returns {number}
*/
declare function roll(minOrMax?: number, max?: number): number;
export declare function roll(minOrMax?: number, max?: number): number;
/**
* Returns 'heads' or 'tails' at random
* @returns {'heads' | 'tails'}
*/
declare function flip(): 'heads' | 'tails';
export declare function flip(): 'heads' | 'tails';
/**
* Create a dice with any number of sides, dice(6).roll() to roll it!
* You can also try rolling a specific side to return a boolean like so: dice(6).rollAssert(6).
Expand All @@ -18,10 +18,8 @@ declare function flip(): 'heads' | 'tails';
* @param {?number} [sides=6] The number of sides
* @returns {{ sides: number, roll: () => number, rollAssert: (target: number) => boolean }}
*/
declare function Dice(sides?: number): {
export declare function Dice(sides?: number): {
sides: number;
roll: () => number;
rollAssert: (target: number) => boolean;
};

export { Dice, flip, roll };
69 changes: 45 additions & 24 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
function roll(minOrMax, max) {
let _min = 0, _max = 100;
if (minOrMax === void 0) ; else if (max === void 0) {
_min = 0;
_max = minOrMax;
} else {
_min = minOrMax;
_max = max;
}
return Math.floor(Math.random() * (_max - _min + 1)) + _min;
/**
* Roll any number. When passing no arguments it returns a number between 0 - 100; including 0 and 100
* @param {number} [minOrMax] When passing only 1 argument it returns a number between 0 and the argument; including 0 and the argument
* @param {number} [max] When passing 2 arguments, they are considered "min" and "max"; it returns a number between min - max; including min and max
* @returns {number}
*/
export function roll(minOrMax, max) {
let _min = 0;
let _max = 100;
if (minOrMax === void 0) {
// keep 0 - 100
}
else if (max === void 0) {
_min = 0;
_max = minOrMax;
}
else {
_min = minOrMax;
_max = max;
}
return Math.floor(Math.random() * (_max - _min + 1)) + _min;
}
function flip() {
return roll(1) === 0 ? "heads" : "tails";
/**
* Returns 'heads' or 'tails' at random
* @returns {'heads' | 'tails'}
*/
export function flip() {
return roll(1) === 0 ? 'heads' : 'tails';
}
function Dice(sides = 6) {
return {
sides,
roll() {
return roll(1, this.sides);
},
rollAssert(targetNumber) {
return roll(1, this.sides) === targetNumber;
}
};
/**
* Create a dice with any number of sides, dice(6).roll() to roll it!
* You can also try rolling a specific side to return a boolean like so: dice(6).rollAssert(6).
*
* @export
* @param {?number} [sides=6] The number of sides
* @returns {{ sides: number, roll: () => number, rollAssert: (target: number) => boolean }}
*/
export function Dice(sides = 6) {
return {
sides,
roll() {
return roll(1, this.sides);
},
rollAssert(targetNumber) {
return roll(1, this.sides) === targetNumber;
},
};
}

export { Dice, flip, roll };
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from '@cycraft/eslint/config'

export default config
Loading

0 comments on commit 1fdb6c7

Please sign in to comment.