Run prettier during CI. (#85)

Fixes #83.
pull/86/head
Atul Varma 2021-04-07 19:39:55 -04:00 zatwierdzone przez GitHub
rodzic c448a858da
commit db7d186234
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
5 zmienionych plików z 48 dodań i 28 usunięć

Wyświetl plik

@ -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

1
.prettierignore 100644
Wyświetl plik

@ -0,0 +1 @@
lib/_svg-vocabulary.ts

Wyświetl plik

@ -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:

Wyświetl plik

@ -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<max_luv_samples; i++) {
let L = rng.inRange({ min: 0, max: 100, step: 1 });
let u = rng.inRange({ min: -128, max: 128, step: 1 });
let v = rng.inRange({ min: -128, max: 128, step: 1 });
let rand_color = colorspaces.make_color('CIELUV', [L, u, v]);
if(rand_color.is_displayable()) {
rand_color_hex = rand_color.as('hex');
luv_sample_failed = false;
break;
}
//See if we can pull out a sample inside the LUV solid
for (let i = 0; i < max_luv_samples; i++) {
let L = rng.inRange({ min: 0, max: 100, step: 1 });
let u = rng.inRange({ min: -128, max: 128, step: 1 });
let v = rng.inRange({ min: -128, max: 128, step: 1 });
let rand_color = colorspaces.make_color("CIELUV", [L, u, v]);
if (rand_color.is_displayable()) {
rand_color_hex = rand_color.as("hex");
luv_sample_failed = false;
break;
}
}
//just sample sRGB if I couldn't sample a random LUV color
if(luv_sample_failed) {
console.log("Sampling sRGB")
let rgb = (new Array<number>(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');
//just sample sRGB if I couldn't sample a random LUV color
if (luv_sample_failed) {
console.log("Sampling sRGB");
let rgb = new Array<number>(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;
}
/**

Wyświetl plik

@ -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",