@smockle/contrast 8.0.1 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2021 Clay Miller
3
+ Copyright (c) 2017-2025 Clay Miller
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # contrast
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@smockle/contrast.svg)](https://www.npmjs.com/package/@smockle/contrast)
4
- [![Publish Workflow](https://github.com/smockle/contrast/workflows/Publish/badge.svg)](https://github.com/smockle/contrast/actions)
5
4
  [![codecov](https://codecov.io/gh/smockle/contrast/branch/main/graph/badge.svg)](https://codecov.io/gh/smockle/contrast)
6
5
 
7
6
  Analyse luminosity contrast ratio
package/dist/bin/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { Contrast } from "../lib/index.js";
3
- import { existsSync, readFileSync } from "fs";
4
- import { inspect } from "util";
5
- import url from "url";
3
+ import { existsSync, readFileSync } from "node:fs";
4
+ import { inspect } from "node:util";
5
+ import url from "node:url";
6
6
  const { URL } = url;
7
7
  const foreground = process.argv.slice(2)[0];
8
8
  const background = process.argv.slice(2)[1];
@@ -1,5 +1,4 @@
1
1
  import { HexColor } from "./hexcolor.js";
2
- declare const inspect: unique symbol;
3
2
  export declare class Contrast {
4
3
  /** The foreground color, e.g. "#FFFFFF". */
5
4
  foreground: HexColor;
@@ -10,7 +9,4 @@ export declare class Contrast {
10
9
  constructor(foreground: string, background: string);
11
10
  /** Returns the luminosity contrast ratio. */
12
11
  valueOf(): number;
13
- /** Returns a formatted representation of the luminosity contrast ratio, e.g. "4.5:1". */
14
- [inspect](): string;
15
12
  }
16
- export {};
@@ -1,5 +1,4 @@
1
1
  import { HexColor } from "./hexcolor.js";
2
- const inspect = Symbol.for("nodejs.util.inspect.custom");
3
2
  export class Contrast {
4
3
  /** The foreground color, e.g. "#FFFFFF". */
5
4
  foreground;
@@ -24,7 +23,7 @@ export class Contrast {
24
23
  return this.value;
25
24
  }
26
25
  /** Returns a formatted representation of the luminosity contrast ratio, e.g. "4.5:1". */
27
- [inspect]() {
26
+ [Symbol.for("nodejs.util.inspect.custom")]() {
28
27
  return `${this.value}:1`;
29
28
  }
30
29
  }
@@ -1,16 +1,12 @@
1
1
  import { Hex } from "./hex.js";
2
- declare const inspect: unique symbol;
3
2
  export declare class EightBit implements EightBit {
4
3
  /** A number between 0 and 255. */
5
4
  value: number;
6
5
  constructor(value: EightBit | number | null);
7
6
  /** Returns the current value, e.g. 255. */
8
7
  valueOf(): number;
9
- /** Returns a formatted representation of the current value, e.g. "EightBit(255)". */
10
- [inspect](): string;
11
8
  /** Convert from sRGB to linear RGB. */
12
9
  linearize(): number;
13
10
  /** Returns a Hex with the current value, e.g. Hex("#FF"). */
14
11
  toHex(): Hex;
15
12
  }
16
- export {};
@@ -1,5 +1,4 @@
1
1
  import { Hex } from "./hex.js";
2
- const inspect = Symbol.for("nodejs.util.inspect.custom");
3
2
  export class EightBit {
4
3
  /** A number between 0 and 255. */
5
4
  value;
@@ -11,7 +10,7 @@ export class EightBit {
11
10
  return this.value;
12
11
  }
13
12
  /** Returns a formatted representation of the current value, e.g. "EightBit(255)". */
14
- [inspect]() {
13
+ [Symbol.for("nodejs.util.inspect.custom")]() {
15
14
  return `EightBit(${this.value})`;
16
15
  }
17
16
  /** Convert from sRGB to linear RGB. */
@@ -1,6 +1,5 @@
1
1
  import { EightBit } from "./eightbit.js";
2
2
  import { HexColor } from "./hexcolor.js";
3
- declare const inspect: unique symbol;
4
3
  export declare class EightBitColor {
5
4
  /** The current red value, e.g. EightBit(255). */
6
5
  R: EightBit;
@@ -15,11 +14,8 @@ export declare class EightBitColor {
15
14
  G: number;
16
15
  B: number;
17
16
  };
18
- /** Returns a formatted representation of the current rgb value, e.g. "rgb(255, 255, 255)". */
19
- [inspect](): string;
20
17
  /** Returns the luminosity. */
21
18
  luminosity(): number;
22
19
  /** Returns a HexColor with the current value, e.g. Hex("#FFFFFF"). */
23
20
  toHexColor(): HexColor;
24
21
  }
25
- export {};
@@ -1,6 +1,5 @@
1
1
  import { EightBit } from "./eightbit.js";
2
2
  import { HexColor } from "./hexcolor.js";
3
- const inspect = Symbol.for("nodejs.util.inspect.custom");
4
3
  export class EightBitColor {
5
4
  /** The current red value, e.g. EightBit(255). */
6
5
  R;
@@ -21,7 +20,7 @@ export class EightBitColor {
21
20
  return { R, G, B };
22
21
  }
23
22
  /** Returns a formatted representation of the current rgb value, e.g. "rgb(255, 255, 255)". */
24
- [inspect]() {
23
+ [Symbol.for("nodejs.util.inspect.custom")]() {
25
24
  const R = this.R.valueOf();
26
25
  const G = this.G.valueOf();
27
26
  const B = this.B.valueOf();
package/dist/lib/hex.d.ts CHANGED
@@ -1,14 +1,10 @@
1
1
  import { EightBit } from "./eightbit.js";
2
- declare const inspect: unique symbol;
3
2
  export declare class Hex {
4
3
  /** The string representation of a hexadecimal value between 0 ("00") and 255 ("FF"). */
5
4
  value: string | null;
6
5
  constructor(value?: string | null);
7
6
  /** Returns the current value, e.g. "FF". */
8
7
  valueOf(): string | null;
9
- /** Returns a formatted representation of the current value, e.g. "#FF". */
10
- [inspect](): string;
11
8
  /** Returns an EightBit with the current value, e.g. EightBit(255). */
12
9
  toEightBit(): EightBit;
13
10
  }
14
- export {};
package/dist/lib/hex.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { EightBit } from "./eightbit.js";
2
- const inspect = Symbol.for("nodejs.util.inspect.custom");
3
2
  /**
4
3
  * Pads the provided string with another string (repeated, if needed) so that the resulting string reaches the given length. The padding is applied from the start (left) of the provided string.
5
4
  * @param string The provided string.
@@ -25,7 +24,7 @@ export class Hex {
25
24
  return this.value;
26
25
  }
27
26
  /** Returns a formatted representation of the current value, e.g. "#FF". */
28
- [inspect]() {
27
+ [Symbol.for("nodejs.util.inspect.custom")]() {
29
28
  return `#${this.value}`;
30
29
  }
31
30
  /** Returns an EightBit with the current value, e.g. EightBit(255). */
@@ -1,6 +1,5 @@
1
1
  import { Hex } from "./hex.js";
2
2
  import { EightBitColor } from "./eightbitcolor.js";
3
- declare const inspect: unique symbol;
4
3
  export declare class HexColor {
5
4
  /** The string representation of a hexadecimal value between 0 ("00") and 255 ("FF"). */
6
5
  value: string | null;
@@ -13,9 +12,6 @@ export declare class HexColor {
13
12
  constructor(value?: string | null);
14
13
  /** Returns the current value, e.g. "FF". */
15
14
  valueOf(): string | null;
16
- /** Returns a formatted representation of the current value, e.g. "#FF". */
17
- [inspect](): string;
18
15
  /** Returns an EightBit with the current value, e.g. { R: 255, G: 255, B: 255 }. */
19
16
  toEightBitColor(): EightBitColor;
20
17
  }
21
- export {};
@@ -1,6 +1,5 @@
1
1
  import { Hex } from "./hex.js";
2
2
  import { EightBitColor } from "./eightbitcolor.js";
3
- const inspect = Symbol.for("nodejs.util.inspect.custom");
4
3
  export class HexColor {
5
4
  /** The string representation of a hexadecimal value between 0 ("00") and 255 ("FF"). */
6
5
  value;
@@ -47,7 +46,7 @@ export class HexColor {
47
46
  return this.value;
48
47
  }
49
48
  /** Returns a formatted representation of the current value, e.g. "#FF". */
50
- [inspect]() {
49
+ [Symbol.for("nodejs.util.inspect.custom")]() {
51
50
  return `#${this.value}`;
52
51
  }
53
52
  /** Returns an EightBit with the current value, e.g. { R: 255, G: 255, B: 255 }. */
package/package.json CHANGED
@@ -1,20 +1,16 @@
1
1
  {
2
2
  "name": "@smockle/contrast",
3
- "version": "8.0.1",
3
+ "version": "9.0.0",
4
4
  "description": "Analyse luminosity contrast ratio",
5
- "files": [
6
- "dist"
7
- ],
8
5
  "type": "module",
9
6
  "main": "dist/lib/index.js",
10
- "types": "dist/lib/index.d.ts",
11
7
  "bin": {
12
8
  "contrast": "dist/bin/index.js"
13
9
  },
14
10
  "scripts": {
15
11
  "build": "tsc",
16
- "test": "node node_modules/jest/bin/jest.js",
17
- "start": "node dist/bin/index.js"
12
+ "test": "NODE_OPTIONS='--no-warnings=ExperimentalWarning --experimental-vm-modules' npx jest",
13
+ "start": "node --no-warnings=ExperimentalWarning --experimental-vm-modules dist/bin/index.js"
18
14
  },
19
15
  "repository": {
20
16
  "type": "git",
@@ -27,33 +23,23 @@
27
23
  },
28
24
  "homepage": "https://github.com/smockle/contrast#readme",
29
25
  "devDependencies": {
30
- "@types/jest": "^27.0.0",
31
- "@types/node": "^20.1.0",
32
- "jest": "^27.0.1",
33
- "ts-jest": "^27.0.0",
34
- "typescript": "^4.1.3"
35
- },
36
- "engines": {
37
- "node": ">= 20.0.0"
26
+ "jest": "^29.7.0",
27
+ "ts-jest": "^29.1.1",
28
+ "typescript": "^5.2.2"
38
29
  },
39
30
  "jest": {
40
31
  "preset": "ts-jest/presets/default-esm",
41
32
  "collectCoverage": true,
42
- "testRegex": "(\\.|/)(test|spec)\\.[jt]sx?$",
43
- "testPathIgnorePatterns": [
44
- "/node_modules/",
45
- "<rootDir>/dist/"
46
- ],
47
33
  "extensionsToTreatAsEsm": [
48
34
  ".ts"
49
35
  ],
50
- "globals": {
51
- "ts-jest": {
52
- "useESM": true
53
- }
54
- },
36
+ "roots": [
37
+ "<rootDir>/src"
38
+ ],
39
+ "testRegex": "\\.test\\.ts$",
55
40
  "moduleNameMapper": {
56
- "^(\\.\\.?\\/.+)\\.jsx?$": "$1"
41
+ "^(\\.{1,2}/.*)\\.js$": "$1",
42
+ "^@/(.*)\\.js$": "<rootDir>/src/$1"
57
43
  }
58
44
  }
59
45
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- import { Contrast } from "../lib/index.js";
2
- import { THRESHOLD } from "./util.js";
3
- import { inspect } from "util";
4
- describe("Contrast", () => {
5
- test("constructor", () => {
6
- expect(new Contrast("#0080FF", "#FFFFFF").foreground.valueOf()).toEqual("0080FF");
7
- });
8
- test("constructor, value", () => {
9
- expect(Math.abs(new Contrast("#0080FF", "#FFFFFF").value - 3.796322871580839)).toBeLessThan(THRESHOLD);
10
- });
11
- test("valueOf", () => {
12
- expect(Math.abs(new Contrast("#0080FF", "#FFFFFF").valueOf() - 3.796322871580839)).toBeLessThan(THRESHOLD);
13
- });
14
- test("inspect", () => {
15
- expect(inspect(new Contrast("#0080FF", "#FFFFFF"))).toEqual("3.796322871580839:1");
16
- });
17
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,20 +0,0 @@
1
- import { EightBit } from "../lib/index.js";
2
- import { THRESHOLD } from "./util.js";
3
- import { inspect } from "util";
4
- describe("EightBit", () => {
5
- test("constructor", () => {
6
- expect(new EightBit(128).value).toEqual(128);
7
- });
8
- test("valueOf", () => {
9
- expect(new EightBit(128).valueOf()).toEqual(128);
10
- });
11
- test("inspect", () => {
12
- expect(inspect(new EightBit(128))).toEqual("EightBit(128)");
13
- });
14
- test("linearize", () => {
15
- expect(Math.abs(new EightBit(128).linearize() - 0.21586050011389926)).toBeLessThan(THRESHOLD);
16
- });
17
- test("toHex", () => {
18
- expect(inspect(new EightBit(128).toHex())).toEqual("#80");
19
- });
20
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,27 +0,0 @@
1
- import { EightBit, EightBitColor } from "../lib/index.js";
2
- import { THRESHOLD } from "./util.js";
3
- import { inspect } from "util";
4
- describe("EightBitColor", () => {
5
- test("constructor, with Number", () => {
6
- expect(new EightBitColor(0, 128, 255).G.valueOf()).toEqual(128);
7
- });
8
- test("constructor, with EightBit", () => {
9
- expect(new EightBitColor(new EightBit(0), new EightBit(128), new EightBit(255)).G.valueOf()).toEqual(128);
10
- });
11
- test("valueOf", () => {
12
- expect(new EightBitColor(0, 128, 255).valueOf()).toEqual({
13
- R: 0,
14
- G: 128,
15
- B: 255,
16
- });
17
- });
18
- test("inspect", () => {
19
- expect(inspect(new EightBitColor(0, 128, 255))).toEqual("rgb(0, 128, 255)");
20
- });
21
- test("luminosity", () => {
22
- expect(Math.abs(new EightBitColor(0, 128, 255).luminosity() - 0.22658342968146072)).toBeLessThan(THRESHOLD);
23
- });
24
- test("toHexColor", () => {
25
- expect(inspect(new EightBitColor(0, 128, 255).toHexColor())).toEqual("#0080FF");
26
- });
27
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,28 +0,0 @@
1
- import { Hex } from "../lib/index.js";
2
- import { inspect } from "util";
3
- describe("Hex", () => {
4
- test("constructor, with #", () => {
5
- expect(new Hex("#FF").value).toEqual("FF");
6
- });
7
- test("constructor, without #", () => {
8
- expect(new Hex("FF").value).toEqual("FF");
9
- });
10
- test("constructor, lowercase", () => {
11
- expect(new Hex("ff").value).toEqual("FF");
12
- });
13
- test("constructor, no args", () => {
14
- expect(new Hex().value).toEqual(null);
15
- });
16
- test("valueOf", () => {
17
- expect(new Hex("#80").valueOf()).toEqual("80");
18
- });
19
- test("inspect", () => {
20
- expect(inspect(new Hex("#80"))).toEqual("#80");
21
- });
22
- test("toEightBit", () => {
23
- expect(new Hex("#80").toEightBit().valueOf()).toEqual(128);
24
- });
25
- test("toEightBit", () => {
26
- expect(new Hex(null).toEightBit().valueOf()).toEqual(0);
27
- });
28
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,48 +0,0 @@
1
- import { HexColor } from "../lib/index.js";
2
- import { inspect } from "util";
3
- describe("HexColor", () => {
4
- test("constructor", () => {
5
- expect((new HexColor("#0080FF").G || {}).valueOf()).toEqual("80");
6
- });
7
- test("constructor, two-length", () => {
8
- expect(new HexColor("#80").value).toEqual("808080");
9
- });
10
- test("constructor, three-length", () => {
11
- expect(new HexColor("#FC0").value).toEqual("FFCC00");
12
- });
13
- test("constructor, six-length", () => {
14
- expect(new HexColor("#0080FF").value).toEqual("0080FF");
15
- });
16
- test("constructor, black", () => {
17
- expect(new HexColor("black").value).toEqual("000000");
18
- });
19
- test("constructor, white", () => {
20
- expect(new HexColor("white").value).toEqual("FFFFFF");
21
- });
22
- test("constructor, no args", () => {
23
- expect(new HexColor().value).toEqual(null);
24
- });
25
- test("valueOf, inherited", () => {
26
- expect(new HexColor("#0080FF").valueOf()).toEqual("0080FF");
27
- });
28
- test("inspect, inherited", () => {
29
- expect(inspect(new HexColor("#0080FF"))).toEqual("#0080FF");
30
- });
31
- test("toEightBit, removed", () => {
32
- expect(Object.getPrototypeOf(new HexColor("#0080FF"))).not.toHaveProperty("toEightBit");
33
- });
34
- test("toEightBitColor", () => {
35
- expect(new HexColor("#0080FF").toEightBitColor().valueOf()).toEqual({
36
- R: 0,
37
- G: 128,
38
- B: 255,
39
- });
40
- });
41
- test("toEightBitColor", () => {
42
- expect(new HexColor(null).toEightBitColor().valueOf()).toEqual({
43
- R: 0,
44
- G: 0,
45
- B: 0,
46
- });
47
- });
48
- });
@@ -1,2 +0,0 @@
1
- /** Tolerance for comparing floating point numbers. */
2
- export declare const THRESHOLD: number;
@@ -1,2 +0,0 @@
1
- /** Tolerance for comparing floating point numbers. */
2
- export const THRESHOLD = 0.000001;