From cbefd3e41e896b6bc06a3559f8d7f2a37b678e3c Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Thu, 24 Nov 2022 00:06:59 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Better=20configuration=20of=20pr?= =?UTF-8?q?ettier=20(#474)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/dependabot.yml | 8 ++--- .github/workflows/build-status.yml | 4 +-- .prettierignore | 3 +- .prettierrc | 12 ++++---- .yarnrc.yml | 10 +++---- README.md | 16 ++++++---- package.esm-template.json | 4 +-- package.json | 4 +-- perf/benchmark.cjs | 2 +- tsconfig.declaration.json | 16 +++++----- tsconfig.json | 48 +++++++++++++----------------- 11 files changed, 61 insertions(+), 66 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f783338..42cf658 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,9 +5,9 @@ version: 2 updates: - - package-ecosystem: "npm" - directory: "/" + - package-ecosystem: 'npm' + directory: '/' schedule: - interval: "daily" + interval: 'daily' commit-message: - prefix: "⬆️" + prefix: '⬆️' diff --git a/.github/workflows/build-status.yml b/.github/workflows/build-status.yml index 4e2a924..9790640 100644 --- a/.github/workflows/build-status.yml +++ b/.github/workflows/build-status.yml @@ -2,7 +2,7 @@ name: Build Status on: push: - branches: + branches: - main - next-* - fix-v* @@ -131,7 +131,7 @@ jobs: run: node test/legacy/main.js publish_package: name: 'Publish package' - needs: + needs: - production_package - format - test diff --git a/.prettierignore b/.prettierignore index d965450..48aa3be 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ lib/ lib-*/ -coverage/ \ No newline at end of file +coverage/ +.yarn/ diff --git a/.prettierrc b/.prettierrc index 79f07ba..5d40fd8 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,7 +1,5 @@ -{ - "parser": "typescript", - - "printWidth": 120, - "tabWidth": 2, - "singleQuote": true -} \ No newline at end of file +{ + "printWidth": 120, + "tabWidth": 2, + "singleQuote": true +} diff --git a/.yarnrc.yml b/.yarnrc.yml index 169cdd6..a7bba50 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -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 diff --git a/README.md b/README.md index 1708bb7..ab02cb0 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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. @@ -26,8 +27,8 @@ In order to use `pure-rand` from a web-page, you have to reference the web-aware ```html ``` @@ -35,15 +36,15 @@ You can also reference a precise version by setting the version you want in the ```html ``` ## Usage ```javascript -import prand from 'pure-rand' +import prand from 'pure-rand'; const seed = 42; @@ -102,6 +103,7 @@ 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 @@ -109,6 +111,7 @@ The following generators are available: - `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` @@ -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 = (rng: RandomGenerator) => [T, RandomGenerator];`. For the moment, available `Distribution` are: + - `prand.uniformIntDistribution(from: number, to: number): Distribution` - `prand.uniformBigIntDistribution(from: bigint, to: bigint): Distribution`\* - `prand.uniformArrayIntDistribution(from: ArrayInt, to: ArrayInt): Distribution`\*\* diff --git a/package.esm-template.json b/package.esm-template.json index 5ff59f4..3dbc1ca 100644 --- a/package.esm-template.json +++ b/package.esm-template.json @@ -1,3 +1,3 @@ { - "type": "module" -} \ No newline at end of file + "type": "module" +} diff --git a/package.json b/package.json index 3191b48..3fdfeb6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/perf/benchmark.cjs b/perf/benchmark.cjs index d5302fd..db3bf09 100644 --- a/perf/benchmark.cjs +++ b/perf/benchmark.cjs @@ -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) { diff --git a/tsconfig.declaration.json b/tsconfig.declaration.json index 97000ba..72bdedb 100644 --- a/tsconfig.declaration.json +++ b/tsconfig.declaration.json @@ -1,8 +1,8 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "declaration": true, - "emitDeclarationOnly": true, - "outDir": "lib/types" - } -} \ No newline at end of file +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "declaration": true, + "emitDeclarationOnly": true, + "outDir": "lib/types" + } +} diff --git a/tsconfig.json b/tsconfig.json index d95e8f6..5edbc51 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"] +} -- 2.51.2