Skip to content

Commit

Permalink
馃敡 Better configuration of prettier (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Nov 23, 2022
1 parent 58c4573 commit cbefd3e
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 66 deletions.
8 changes: 4 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: "daily"
interval: 'daily'
commit-message:
prefix: "猬嗭笍"
prefix: '猬嗭笍'
4 changes: 2 additions & 2 deletions .github/workflows/build-status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build Status

on:
push:
branches:
branches:
- main
- next-*
- fix-v*
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
run: node test/legacy/main.js
publish_package:
name: 'Publish package'
needs:
needs:
- production_package
- format
- test
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
lib/
lib-*/
coverage/
coverage/
.yarn/
12 changes: 5 additions & 7 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"parser": "typescript",

"printWidth": 120,
"tabWidth": 2,
"singleQuote": true
}
{
"printWidth": 120,
"tabWidth": 2,
"singleQuote": true
}
10 changes: 5 additions & 5 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
enableGlobalCache: true
enableScripts: false
nodeLinker: node-modules
enableTransparentWorkspaces: false
yarnPath: .yarn/releases/yarn-3.3.0.cjs
enableGlobalCache: true
enableScripts: false
nodeLinker: node-modules
enableTransparentWorkspaces: false
yarnPath: .yarn/releases/yarn-3.3.0.cjs
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# pure-rand

#### Pure random number generator written in TypeScript

[![Build Status](https://github.com/dubzzz/pure-rand/workflows/Build%20Status/badge.svg?branch=main)](https://github.com/dubzzz/pure-rand/actions)
Expand All @@ -15,7 +16,7 @@

Install the module with: `npm install pure-rand`

Unlike classical random number generators, `pure-rand` comes with a set of *pure* and *seeded* generators (implementing the interface [RandomGenerator](https://github.com/dubzzz/pure-rand/blob/main/src/generator/RandomGenerator.ts)).
Unlike classical random number generators, `pure-rand` comes with a set of _pure_ and _seeded_ generators (implementing the interface [RandomGenerator](https://github.com/dubzzz/pure-rand/blob/main/src/generator/RandomGenerator.ts)).
Each time a call to `.next()` method is done, the generator provides both the generated value and the next generator.

As a consequence, a given generator will always produce the same value. It can be called as many times as required without impacting its state. This ability makes it easier to replay code section relying on random without having to re-seed a new generator and replay the whole path to be in the same state.
Expand All @@ -26,24 +27,24 @@ In order to use `pure-rand` from a web-page, you have to reference the web-aware

```html
<script type="module">
import * as prand from "https://unpkg.com/pure-rand/lib/esm/pure-rand.js";
// prand is now available
import * as prand from 'https://unpkg.com/pure-rand/lib/esm/pure-rand.js';
// prand is now available
</script>
```

You can also reference a precise version by setting the version you want in the url:

```html
<script type="module">
import * as prand from "https://unpkg.com/pure-rand@1.2.0/lib/esm/pure-rand.js";
// prand is now available
import * as prand from 'https://unpkg.com/pure-rand@1.2.0/lib/esm/pure-rand.js';
// prand is now available
</script>
```

## Usage

```javascript
import prand from 'pure-rand'
import prand from 'pure-rand';

const seed = 42;

Expand Down Expand Up @@ -102,13 +103,15 @@ const { mersenne } = require('pure-rand');
All the [RandomGenerator](https://github.com/dubzzz/pure-rand/blob/main/src/generator/) provided by `pure-rand` derive from the interface [RandomGenerator](https://github.com/dubzzz/pure-rand/blob/main/src/generator/RandomGenerator.ts) and are pure and seeded as described above.

The following generators are available:

- `prand.xorshift128plus(seed: number)`: xorshift128+ generator whose values are within the range -0x80000000 to 0x7fffffff
- `prand.xoroshiro128plus(seed: number)`: xoroshiro128+ generator whose values are within the range -0x80000000 to 0x7fffffff
- `prand.mersenne(seed: number)`: Mersenne Twister generator whose values are within the range 0 to 0xffffffff
- `prand.congruential(seed: number)`: Linear Congruential generator whose values are within the range 0 to 0x7fff
- `prand.congruential32(seed: number)`: Linear Congruential generator whose values are within the range 0 to 0xffffffff

Some helpers are also provided in order to ease the use of `RandomGenerator` instances:

- `prand.generateN(rng: RandomGenerator, num: number): [number[], RandomGenerator]`: generates `num` random values using `rng` and return the next `RandomGenerator`
- `prand.skipN(rng: RandomGenerator, num: number): RandomGenerator`: skips `num` random values and return the next `RandomGenerator`

Expand All @@ -117,6 +120,7 @@ Some helpers are also provided in order to ease the use of `RandomGenerator` ins
All the [Distribution](https://github.com/dubzzz/pure-rand/tree/main/src/distribution) take a `RandomGenerator` as input and produce a couple `(n: number, nextGenerator: RandomGenerator)`. A `Distribution` is defined as `type Distribution<T> = (rng: RandomGenerator) => [T, RandomGenerator];`.

For the moment, available `Distribution` are:

- `prand.uniformIntDistribution(from: number, to: number): Distribution<number>`
- `prand.uniformBigIntDistribution(from: bigint, to: bigint): Distribution<bigint>`\*
- `prand.uniformArrayIntDistribution(from: ArrayInt, to: ArrayInt): Distribution<ArrayInt>`\*\*
Expand Down
4 changes: 2 additions & 2 deletions package.esm-template.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"type": "module"
}
"type": "module"
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"sideEffects": false,
"packageManager": "yarn@3.3.0",
"scripts": {
"format:check": "prettier --list-different \"**/*.{js,ts}\"",
"format": "prettier --write \"**/*.{js,ts}\"",
"format:check": "prettier --list-different .",
"format": "prettier --write .",
"build": "tsc && tsc -p ./tsconfig.declaration.json",
"build:esm": "tsc --module es2015 --outDir lib/esm --moduleResolution node && cp package.esm-template.json lib/esm/package.json",
"build:prod": "yarn build && yarn build:esm && node postbuild/main.cjs",
Expand Down
2 changes: 1 addition & 1 deletion perf/benchmark.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const numIterations = 1_000;

function noDistribution(from, to, g) {
const out = g.unsafeNext();
return from + (out % (to - from + 1))
return from + (out % (to - from + 1));
}

function fillBench(bench) {
Expand Down
16 changes: 8 additions & 8 deletions tsconfig.declaration.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "lib/types"
}
}
{
"extends": "./tsconfig.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "lib/types"
}
}
48 changes: 20 additions & 28 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
{
"compilerOptions": {
"declaration": false,
"sourceMap": false,
"alwaysStrict": true,
"noImplicitAny": true,
"noImplicitThis": true,
"removeComments": true,
"preserveConstEnums": true,
"strictNullChecks": true,
"downlevelIteration": true,
"moduleResolution": "node",
"module": "commonjs",
"target": "es3",
"lib": [
"es6",
"esnext.bigint"
],
"outDir": "lib/"
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
{
"compilerOptions": {
"declaration": false,
"sourceMap": false,
"alwaysStrict": true,
"noImplicitAny": true,
"noImplicitThis": true,
"removeComments": true,
"preserveConstEnums": true,
"strictNullChecks": true,
"downlevelIteration": true,
"moduleResolution": "node",
"module": "commonjs",
"target": "es3",
"lib": ["es6", "esnext.bigint"],
"outDir": "lib/"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}

0 comments on commit cbefd3e

Please sign in to comment.