diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 50a2d53..3a44311 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,5 +23,6 @@ jobs: node-version: ${{ matrix.node-version }} - run: npm ci - run: npm run build -- --no-minify + - run: npm run prettier:check - run: npm run typecheck - run: npm test diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..7db7487 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +lib/_svg-vocabulary.ts diff --git a/README.md b/README.md index 6f72fd3..269cfa7 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,20 @@ To run tests interactively, run: npm run test:watch ``` +## Code style + +All code styling is managed by [Prettier][]. + +To format the code automatically, run: + +``` +npm run prettier:fix +``` + +You can alternatively install a Prettier extension for your editor; see its website for more details. + +[Prettier]: https://prettier.io/ + ## Deployment To deploy the project to GitHub Pages, run: diff --git a/lib/random-colors.ts b/lib/random-colors.ts index 9a7ecb2..1830551 100644 --- a/lib/random-colors.ts +++ b/lib/random-colors.ts @@ -1,6 +1,6 @@ import { Random } from "./random"; import { range } from "./util"; -import * as colorspaces from 'colorspaces'; +import * as colorspaces from "colorspaces"; /** * Clamp the given number to be between 0 and 255, then @@ -20,38 +20,40 @@ export function clampedByteToHex(value: number): string { } function createRandomColor(rng: Random): string { - const max_luv_samples = 100; - let luv_sample_failed = true; - let rand_color_hex:string = "#000000"; + const max_luv_samples = 100; + let luv_sample_failed = true; + let rand_color_hex: string = "#000000"; - //See if we can pull out a sample inside the LUV solid - for (let i=0; i(3)).map(() => rng.inRange({ min: 0, max: 255, step: 1 })); - console.log(rgb) - for(let i=0; i(3).map(() => + rng.inRange({ min: 0, max: 255, step: 1 }) + ); + console.log(rgb); + for (let i = 0; i < rgb.length; i++) { + rgb[i] = rgb[i] / 255.0; } + console.log(rgb); + let rand_color = colorspaces.make_color("sRGB", rgb); + rand_color_hex = rand_color.as("hex"); + } - return rand_color_hex; + return rand_color_hex; } /** diff --git a/package.json b/package.json index 606e170..f7cc39e 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ "main": "index.js", "scripts": { "deploy": "npm run build && gh-pages -d dist", + "prettier:check": "prettier --check lib/**/*.ts lib/**/*.ts", + "prettier:fix": "prettier --write lib/**/*.ts lib/**/*.ts", "typecheck": "tsc --noemit", "test:watch": "jest --watch", "test": "jest",