@oscarpalmer/atoms 0.79.0 → 0.80.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.
@@ -36,11 +36,7 @@ function sort(array, first, second) {
36
36
  const sorted = array.sort((first2, second2) => {
37
37
  for (let index = 0; index < length; index += 1) {
38
38
  const { callback, direction: direction2 } = keys[index];
39
- const descending = direction2 === "desc";
40
- const compared = value_compare.compare(
41
- callback(descending ? second2 : first2),
42
- callback(descending ? first2 : second2)
43
- );
39
+ const compared = value_compare.compare(callback(first2), callback(second2)) * (direction2 === "asc" ? 1 : -1);
44
40
  if (compared !== 0) {
45
41
  return compared;
46
42
  }
@@ -34,11 +34,7 @@ function sort(array, first, second) {
34
34
  const sorted = array.sort((first2, second2) => {
35
35
  for (let index = 0; index < length; index += 1) {
36
36
  const { callback, direction: direction2 } = keys[index];
37
- const descending = direction2 === "desc";
38
- const compared = compare(
39
- callback(descending ? second2 : first2),
40
- callback(descending ? first2 : second2)
41
- );
37
+ const compared = compare(callback(first2), callback(second2)) * (direction2 === "asc" ? 1 : -1);
42
38
  if (compared !== 0) {
43
39
  return compared;
44
40
  }
@@ -1,6 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const colour_is = require("./is.cjs");
4
+ const defaults = {
5
+ hsl: {
6
+ hue: 0,
7
+ lightness: 0,
8
+ saturation: 0
9
+ },
10
+ rgb: {
11
+ blue: 0,
12
+ green: 0,
13
+ red: 0
14
+ }
15
+ };
16
+ const properties = {
17
+ hsl: ["hue", "lightness", "saturation"],
18
+ rgb: ["blue", "green", "red"]
19
+ };
20
+ function getValue(value, type) {
21
+ return colour_is.isColourValue(value, properties[type]) ? { ...value } : { ...defaults[type] };
22
+ }
4
23
  class Colour {
5
24
  /**
6
25
  * Get the current value of the colour
@@ -8,10 +27,16 @@ class Colour {
8
27
  get value() {
9
28
  return { ...this.state.value };
10
29
  }
11
- constructor(type, value, defaults, properties) {
30
+ /**
31
+ * Set the current value of the colour
32
+ */
33
+ set value(value) {
34
+ this.state.value = getValue(value, this.$colour);
35
+ }
36
+ constructor(type, value) {
12
37
  this.$colour = type;
13
38
  this.state = {
14
- value: colour_is.isColourValue(value, properties) ? { ...value } : { ...defaults }
39
+ value: getValue(value, type)
15
40
  };
16
41
  }
17
42
  }
@@ -1,4 +1,23 @@
1
1
  import { isColourValue } from "./is.js";
2
+ const defaults = {
3
+ hsl: {
4
+ hue: 0,
5
+ lightness: 0,
6
+ saturation: 0
7
+ },
8
+ rgb: {
9
+ blue: 0,
10
+ green: 0,
11
+ red: 0
12
+ }
13
+ };
14
+ const properties = {
15
+ hsl: ["hue", "lightness", "saturation"],
16
+ rgb: ["blue", "green", "red"]
17
+ };
18
+ function getValue(value, type) {
19
+ return isColourValue(value, properties[type]) ? { ...value } : { ...defaults[type] };
20
+ }
2
21
  class Colour {
3
22
  /**
4
23
  * Get the current value of the colour
@@ -6,10 +25,16 @@ class Colour {
6
25
  get value() {
7
26
  return { ...this.state.value };
8
27
  }
9
- constructor(type, value, defaults, properties) {
28
+ /**
29
+ * Set the current value of the colour
30
+ */
31
+ set value(value) {
32
+ this.state.value = getValue(value, this.$colour);
33
+ }
34
+ constructor(type, value) {
10
35
  this.$colour = type;
11
36
  this.state = {
12
- value: isColourValue(value, properties) ? { ...value } : { ...defaults }
37
+ value: getValue(value, type)
13
38
  };
14
39
  }
15
40
  }
@@ -41,7 +41,7 @@ class HSLColour extends colour_base.Colour {
41
41
  this.state.value.saturation = number.clamp(value, 0, 100);
42
42
  }
43
43
  constructor(value) {
44
- super("hsl", value, defaults, properties);
44
+ super("hsl", value);
45
45
  }
46
46
  /**
47
47
  * @inheritdoc
@@ -68,16 +68,6 @@ class HSLColour extends colour_base.Colour {
68
68
  return colour_functions.hslToRgb(value);
69
69
  }
70
70
  }
71
- const defaults = {
72
- hue: 0,
73
- lightness: 0,
74
- saturation: 0
75
- };
76
- const properties = [
77
- "hue",
78
- "lightness",
79
- "saturation"
80
- ];
81
71
  function getHSLColour(value) {
82
72
  return new HSLColour(value);
83
73
  }
@@ -39,7 +39,7 @@ class HSLColour extends Colour {
39
39
  this.state.value.saturation = clamp(value, 0, 100);
40
40
  }
41
41
  constructor(value) {
42
- super("hsl", value, defaults, properties);
42
+ super("hsl", value);
43
43
  }
44
44
  /**
45
45
  * @inheritdoc
@@ -66,16 +66,6 @@ class HSLColour extends Colour {
66
66
  return hslToRgb(value);
67
67
  }
68
68
  }
69
- const defaults = {
70
- hue: 0,
71
- lightness: 0,
72
- saturation: 0
73
- };
74
- const properties = [
75
- "hue",
76
- "lightness",
77
- "saturation"
78
- ];
79
69
  function getHSLColour(value) {
80
70
  return new HSLColour(value);
81
71
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const colour_functions = require("./functions.cjs");
3
4
  const colour_hex = require("./hex.cjs");
4
5
  const colour_hsl = require("./hsl.cjs");
5
6
  const colour_is = require("./is.cjs");
@@ -16,6 +17,10 @@ function getForegroundColour(value) {
16
17
  const luminance = 0.2126 * values[2] + 0.7152 * values[1] + 0.0722 * values[0];
17
18
  return luminance > 0.625 ? "black" : "white";
18
19
  }
20
+ exports.hexToRgb = colour_functions.hexToRgb;
21
+ exports.hslToRgb = colour_functions.hslToRgb;
22
+ exports.rgbToHex = colour_functions.rgbToHex;
23
+ exports.rgbToHsl = colour_functions.rgbToHsl;
19
24
  exports.HexColour = colour_hex.HexColour;
20
25
  exports.getHexColour = colour_hex.getHexColour;
21
26
  exports.HSLColour = colour_hsl.HSLColour;
@@ -1,3 +1,4 @@
1
+ import { hexToRgb, hslToRgb, rgbToHex, rgbToHsl } from "./functions.js";
1
2
  import { HexColour, getHexColour } from "./hex.js";
2
3
  import { HSLColour, getHSLColour } from "./hsl.js";
3
4
  import { isColour, isHSLColour, isHexColour, isRGBColour } from "./is.js";
@@ -22,8 +23,12 @@ export {
22
23
  getHSLColour,
23
24
  getHexColour,
24
25
  getRGBColour,
26
+ hexToRgb,
27
+ hslToRgb,
25
28
  isColour,
26
29
  isHSLColour,
27
30
  isHexColour,
28
- isRGBColour
31
+ isRGBColour,
32
+ rgbToHex,
33
+ rgbToHsl
29
34
  };
@@ -41,7 +41,7 @@ class RGBColour extends colour_base.Colour {
41
41
  this.state.value.red = number.clamp(value, 0, 255);
42
42
  }
43
43
  constructor(value) {
44
- super("rgb", value, defaults, properties);
44
+ super("rgb", value);
45
45
  }
46
46
  /**
47
47
  * @inheritdoc
@@ -74,12 +74,6 @@ class RGBColour extends colour_base.Colour {
74
74
  return colour_functions.rgbToHsl(rgb);
75
75
  }
76
76
  }
77
- const defaults = {
78
- blue: 0,
79
- green: 0,
80
- red: 0
81
- };
82
- const properties = ["blue", "green", "red"];
83
77
  function getRGBColour(value) {
84
78
  return new RGBColour(value);
85
79
  }
@@ -39,7 +39,7 @@ class RGBColour extends Colour {
39
39
  this.state.value.red = clamp(value, 0, 255);
40
40
  }
41
41
  constructor(value) {
42
- super("rgb", value, defaults, properties);
42
+ super("rgb", value);
43
43
  }
44
44
  /**
45
45
  * @inheritdoc
@@ -72,12 +72,6 @@ class RGBColour extends Colour {
72
72
  return rgbToHsl(rgb);
73
73
  }
74
74
  }
75
- const defaults = {
76
- blue: 0,
77
- green: 0,
78
- red: 0
79
- };
80
- const properties = ["blue", "green", "red"];
81
75
  function getRGBColour(value) {
82
76
  return new RGBColour(value);
83
77
  }
package/dist/index.cjs CHANGED
@@ -30,6 +30,7 @@ const array_splice = require("./array/splice.cjs");
30
30
  const array_toMap = require("./array/to-map.cjs");
31
31
  const array_toRecord = require("./array/to-record.cjs");
32
32
  const array_unique = require("./array/unique.cjs");
33
+ const colour_functions = require("./colour/functions.cjs");
33
34
  const colour_hex = require("./colour/hex.cjs");
34
35
  const colour_hsl = require("./colour/hsl.cjs");
35
36
  const colour_is = require("./colour/is.cjs");
@@ -108,6 +109,10 @@ exports.splice = array_splice.splice;
108
109
  exports.toMap = array_toMap.toMap;
109
110
  exports.toRecord = array_toRecord.toRecord;
110
111
  exports.unique = array_unique.unique;
112
+ exports.hexToRgb = colour_functions.hexToRgb;
113
+ exports.hslToRgb = colour_functions.hslToRgb;
114
+ exports.rgbToHex = colour_functions.rgbToHex;
115
+ exports.rgbToHsl = colour_functions.rgbToHsl;
111
116
  exports.HexColour = colour_hex.HexColour;
112
117
  exports.getHexColour = colour_hex.getHexColour;
113
118
  exports.HSLColour = colour_hsl.HSLColour;
package/dist/index.js CHANGED
@@ -28,6 +28,7 @@ import { splice } from "./array/splice.js";
28
28
  import { toMap } from "./array/to-map.js";
29
29
  import { toRecord } from "./array/to-record.js";
30
30
  import { unique } from "./array/unique.js";
31
+ import { hexToRgb, hslToRgb, rgbToHex, rgbToHsl } from "./colour/functions.js";
31
32
  import { HexColour, getHexColour } from "./colour/hex.js";
32
33
  import { HSLColour, getHSLColour } from "./colour/hsl.js";
33
34
  import { isColour, isHSLColour, isHexColour, isRGBColour } from "./colour/is.js";
@@ -85,6 +86,8 @@ export {
85
86
  getString,
86
87
  getValue,
87
88
  groupBy,
89
+ hexToRgb,
90
+ hslToRgb,
88
91
  indexOf,
89
92
  insert,
90
93
  isArrayOrPlainObject,
@@ -115,6 +118,8 @@ export {
115
118
  pascalCase,
116
119
  push,
117
120
  queue,
121
+ rgbToHex,
122
+ rgbToHsl,
118
123
  round,
119
124
  setValue,
120
125
  shuffle,
@@ -6,7 +6,7 @@ function findValue(type, array, parameters) {
6
6
  const { bool, key, value } = getParameters(parameters);
7
7
  const callbacks = internal_array_callbacks.getCallbacks(bool, key);
8
8
  if ((callbacks == null ? void 0 : callbacks.bool) == null && (callbacks == null ? void 0 : callbacks.key) == null) {
9
- return type === "index" ? array.findIndex((item) => item === value) : array.find((item) => item === value);
9
+ return type === "index" ? array.indexOf(value) : array.find((item) => item === value);
10
10
  }
11
11
  if (callbacks.bool != null) {
12
12
  const index = array.findIndex(callbacks.bool);
@@ -35,18 +35,17 @@ function findValues(type, array, parameters) {
35
35
  if (type === "all" && key == null) {
36
36
  return array.filter((item) => item === value);
37
37
  }
38
+ const keys = /* @__PURE__ */ new Set();
38
39
  const result = [];
39
- const values = (callbacks == null ? void 0 : callbacks.key) != null ? [] : result;
40
40
  for (let index = 0; index < length; index += 1) {
41
41
  const item = array[index];
42
- const keyed = ((_a = callbacks == null ? void 0 : callbacks.key) == null ? void 0 : _a.call(callbacks, item, index, array)) ?? item;
43
- if (type === "all" && keyed === value || type === "unique" && values.indexOf(keyed) === -1) {
44
- if (values !== result) {
45
- values.push(keyed);
46
- }
42
+ const key2 = ((_a = callbacks == null ? void 0 : callbacks.key) == null ? void 0 : _a.call(callbacks, item, index, array)) ?? item;
43
+ if (type === "all" && key2 === value || type === "unique" && !keys.has(key2)) {
44
+ keys.add(key2);
47
45
  result.push(item);
48
46
  }
49
47
  }
48
+ keys.clear();
50
49
  return result;
51
50
  }
52
51
  function getParameters(original) {
@@ -4,7 +4,7 @@ function findValue(type, array, parameters) {
4
4
  const { bool, key, value } = getParameters(parameters);
5
5
  const callbacks = getCallbacks(bool, key);
6
6
  if ((callbacks == null ? void 0 : callbacks.bool) == null && (callbacks == null ? void 0 : callbacks.key) == null) {
7
- return type === "index" ? array.findIndex((item) => item === value) : array.find((item) => item === value);
7
+ return type === "index" ? array.indexOf(value) : array.find((item) => item === value);
8
8
  }
9
9
  if (callbacks.bool != null) {
10
10
  const index = array.findIndex(callbacks.bool);
@@ -33,18 +33,17 @@ function findValues(type, array, parameters) {
33
33
  if (type === "all" && key == null) {
34
34
  return array.filter((item) => item === value);
35
35
  }
36
+ const keys = /* @__PURE__ */ new Set();
36
37
  const result = [];
37
- const values = (callbacks == null ? void 0 : callbacks.key) != null ? [] : result;
38
38
  for (let index = 0; index < length; index += 1) {
39
39
  const item = array[index];
40
- const keyed = ((_a = callbacks == null ? void 0 : callbacks.key) == null ? void 0 : _a.call(callbacks, item, index, array)) ?? item;
41
- if (type === "all" && keyed === value || type === "unique" && values.indexOf(keyed) === -1) {
42
- if (values !== result) {
43
- values.push(keyed);
44
- }
40
+ const key2 = ((_a = callbacks == null ? void 0 : callbacks.key) == null ? void 0 : _a.call(callbacks, item, index, array)) ?? item;
41
+ if (type === "all" && key2 === value || type === "unique" && !keys.has(key2)) {
42
+ keys.add(key2);
45
43
  result.push(item);
46
44
  }
47
45
  }
46
+ keys.clear();
48
47
  return result;
49
48
  }
50
49
  function getParameters(original) {
package/package.json CHANGED
@@ -4,18 +4,18 @@
4
4
  "url": "https://oscarpalmer.se"
5
5
  },
6
6
  "dependencies": {
7
- "type-fest": "^4.26"
7
+ "type-fest": "^4.30"
8
8
  },
9
9
  "description": "Atomic utilities for making your JavaScript better.",
10
10
  "devDependencies": {
11
11
  "@biomejs/biome": "^1.9",
12
- "@types/node": "^22.9",
12
+ "@types/node": "^22.10",
13
13
  "@vitest/coverage-istanbul": "^2.1",
14
14
  "dts-bundle-generator": "^9.5",
15
15
  "glob": "^11",
16
16
  "happy-dom": "^15.11",
17
- "typescript": "^5.6",
18
- "vite": "^5.4",
17
+ "typescript": "^5.7",
18
+ "vite": "^6",
19
19
  "vitest": "^2.1"
20
20
  },
21
21
  "exports": {
@@ -205,5 +205,5 @@
205
205
  },
206
206
  "type": "module",
207
207
  "types": "./types/index.d.cts",
208
- "version": "0.79.0"
208
+ "version": "0.80.0"
209
209
  }
package/src/array/sort.ts CHANGED
@@ -105,12 +105,9 @@ export function sort(
105
105
  for (let index = 0; index < length; index += 1) {
106
106
  const {callback, direction} = keys[index];
107
107
 
108
- const descending = direction === 'desc';
109
-
110
- const compared = compare(
111
- callback(descending ? second : first),
112
- callback(descending ? first : second),
113
- );
108
+ const compared =
109
+ compare(callback(first), callback(second)) *
110
+ (direction === 'asc' ? 1 : -1);
114
111
 
115
112
  if (compared !== 0) {
116
113
  return compared;
@@ -1,8 +1,44 @@
1
1
  import type {HexColour} from './hex';
2
+ import type {HSLColourValue} from './hsl';
2
3
  import {isColourValue} from './is';
4
+ import type {RGBColourValue} from './rgb';
5
+
6
+ type Defaults = {
7
+ hsl: HSLColourValue;
8
+ rgb: RGBColourValue;
9
+ };
10
+
11
+ type Properties = {
12
+ hsl: Array<keyof HSLColourValue>;
13
+ rgb: Array<keyof RGBColourValue>;
14
+ };
15
+
16
+ const defaults: Defaults = {
17
+ hsl: {
18
+ hue: 0,
19
+ lightness: 0,
20
+ saturation: 0,
21
+ },
22
+ rgb: {
23
+ blue: 0,
24
+ green: 0,
25
+ red: 0,
26
+ },
27
+ };
28
+
29
+ const properties: Properties = {
30
+ hsl: ['hue', 'lightness', 'saturation'],
31
+ rgb: ['blue', 'green', 'red'],
32
+ };
33
+
34
+ function getValue<Model>(value: Model, type: keyof Properties): Model {
35
+ return (
36
+ isColourValue(value, properties[type]) ? {...value} : {...defaults[type]}
37
+ ) as Model;
38
+ }
3
39
 
4
40
  export abstract class Colour<Model> {
5
- private declare readonly $colour: string;
41
+ private declare readonly $colour: keyof Properties;
6
42
  protected declare readonly state: ColourState<Model>;
7
43
 
8
44
  /**
@@ -12,18 +48,18 @@ export abstract class Colour<Model> {
12
48
  return {...this.state.value};
13
49
  }
14
50
 
15
- constructor(
16
- type: string,
17
- value: Model,
18
- defaults: Model,
19
- properties: Array<keyof Model>,
20
- ) {
51
+ /**
52
+ * Set the current value of the colour
53
+ */
54
+ set value(value: Model) {
55
+ this.state.value = getValue(value, this.$colour);
56
+ }
57
+
58
+ constructor(type: keyof Properties, value: Model) {
21
59
  this.$colour = type;
22
60
 
23
61
  this.state = {
24
- value: isColourValue<Model>(value, properties)
25
- ? {...value}
26
- : {...defaults},
62
+ value: getValue(value, type),
27
63
  };
28
64
  }
29
65
 
package/src/colour/hsl.ts CHANGED
@@ -54,7 +54,7 @@ export class HSLColour extends Colour<HSLColourValue> {
54
54
  }
55
55
 
56
56
  constructor(value: HSLColourValue) {
57
- super('hsl', value, defaults, properties);
57
+ super('hsl', value);
58
58
  }
59
59
 
60
60
  /**
@@ -86,18 +86,6 @@ export class HSLColour extends Colour<HSLColourValue> {
86
86
  }
87
87
  }
88
88
 
89
- const defaults: HSLColourValue = {
90
- hue: 0,
91
- lightness: 0,
92
- saturation: 0,
93
- };
94
-
95
- const properties: Array<keyof HSLColourValue> = [
96
- 'hue',
97
- 'lightness',
98
- 'saturation',
99
- ];
100
-
101
89
  /**
102
90
  * Get an HSL-colour from a value-object
103
91
  */
@@ -21,6 +21,7 @@ export function getForegroundColour(value: RGBColourValue): string {
21
21
  return luminance > 0.625 ? 'black' : 'white';
22
22
  }
23
23
 
24
+ export {hexToRgb, hslToRgb, rgbToHex, rgbToHsl} from './functions';
24
25
  export {getHexColour, HexColour} from './hex';
25
26
  export {getHSLColour, HSLColour, type HSLColourValue} from './hsl';
26
27
  export {isColour, isHexColour, isHSLColour, isRGBColour} from './is';
package/src/colour/is.ts CHANGED
@@ -11,10 +11,7 @@ export function isColour(
11
11
  return isInstance(/^(hex|hsl|rgb)$/, value);
12
12
  }
13
13
 
14
- export function isColourValue<Expected>(
15
- value: unknown,
16
- properties: Array<keyof Expected>,
17
- ): value is Expected {
14
+ export function isColourValue(value: unknown, properties: string[]): boolean {
18
15
  return (
19
16
  typeof value === 'object' &&
20
17
  value !== null &&
package/src/colour/rgb.ts CHANGED
@@ -54,7 +54,7 @@ export class RGBColour extends Colour<RGBColourValue> {
54
54
  }
55
55
 
56
56
  constructor(value: RGBColourValue) {
57
- super('rgb', value, defaults, properties);
57
+ super('rgb', value);
58
58
  }
59
59
 
60
60
  /**
@@ -93,14 +93,6 @@ export class RGBColour extends Colour<RGBColourValue> {
93
93
  }
94
94
  }
95
95
 
96
- const defaults: RGBColourValue = {
97
- blue: 0,
98
- green: 0,
99
- red: 0,
100
- };
101
-
102
- const properties: Array<keyof RGBColourValue> = ['blue', 'green', 'red'];
103
-
104
96
  /**
105
97
  * Get an RGB-colour from a value-object
106
98
  */
@@ -18,7 +18,7 @@ export function findValue(
18
18
 
19
19
  if (callbacks?.bool == null && callbacks?.key == null) {
20
20
  return type === 'index'
21
- ? array.findIndex(item => item === value)
21
+ ? array.indexOf(value)
22
22
  : array.find(item => item === value);
23
23
  }
24
24
 
@@ -64,25 +64,24 @@ export function findValues(
64
64
  return array.filter(item => item === value);
65
65
  }
66
66
 
67
+ const keys = new Set();
67
68
  const result: unknown[] = [];
68
- const values: unknown[] = callbacks?.key != null ? [] : result;
69
69
 
70
70
  for (let index = 0; index < length; index += 1) {
71
71
  const item = array[index];
72
- const keyed = callbacks?.key?.(item, index, array) ?? item;
72
+ const key = callbacks?.key?.(item, index, array) ?? item;
73
73
 
74
74
  if (
75
- (type === 'all' && keyed === value) ||
76
- (type === 'unique' && values.indexOf(keyed) === -1)
75
+ (type === 'all' && key === value) ||
76
+ (type === 'unique' && !keys.has(key))
77
77
  ) {
78
- if (values !== result) {
79
- values.push(keyed);
80
- }
81
-
78
+ keys.add(key);
82
79
  result.push(item);
83
80
  }
84
81
  }
85
82
 
83
+ keys.clear();
84
+
86
85
  return result;
87
86
  }
88
87
 
@@ -77,6 +77,10 @@ declare class HexColour {
77
77
  */
78
78
  static toRgb(value: string): RGBColour;
79
79
  }
80
+ export type Properties = {
81
+ hsl: Array<keyof HSLColourValue>;
82
+ rgb: Array<keyof RGBColourValue>;
83
+ };
80
84
  export declare abstract class Colour<Model> {
81
85
  private readonly $colour;
82
86
  protected readonly state: ColourState<Model>;
@@ -84,7 +88,11 @@ export declare abstract class Colour<Model> {
84
88
  * Get the current value of the colour
85
89
  */
86
90
  get value(): Model;
87
- constructor(type: string, value: Model, defaults: Model, properties: Array<keyof Model>);
91
+ /**
92
+ * Set the current value of the colour
93
+ */
94
+ set value(value: Model);
95
+ constructor(type: keyof Properties, value: Model);
88
96
  /**
89
97
  * Convert the colour to a hex-colour
90
98
  */
@@ -1,4 +1,10 @@
1
1
  import type { HexColour } from './hex';
2
+ import type { HSLColourValue } from './hsl';
3
+ import type { RGBColourValue } from './rgb';
4
+ type Properties = {
5
+ hsl: Array<keyof HSLColourValue>;
6
+ rgb: Array<keyof RGBColourValue>;
7
+ };
2
8
  export declare abstract class Colour<Model> {
3
9
  private readonly $colour;
4
10
  protected readonly state: ColourState<Model>;
@@ -6,7 +12,11 @@ export declare abstract class Colour<Model> {
6
12
  * Get the current value of the colour
7
13
  */
8
14
  get value(): Model;
9
- constructor(type: string, value: Model, defaults: Model, properties: Array<keyof Model>);
15
+ /**
16
+ * Set the current value of the colour
17
+ */
18
+ set value(value: Model);
19
+ constructor(type: keyof Properties, value: Model);
10
20
  /**
11
21
  * Convert the colour to a hex-colour
12
22
  */
@@ -77,6 +77,10 @@ declare class HexColour {
77
77
  */
78
78
  static toRgb(value: string): RGBColour;
79
79
  }
80
+ export type Properties = {
81
+ hsl: Array<keyof HSLColourValue>;
82
+ rgb: Array<keyof RGBColourValue>;
83
+ };
80
84
  declare abstract class Colour<Model> {
81
85
  private readonly $colour;
82
86
  protected readonly state: ColourState<Model>;
@@ -84,7 +88,11 @@ declare abstract class Colour<Model> {
84
88
  * Get the current value of the colour
85
89
  */
86
90
  get value(): Model;
87
- constructor(type: string, value: Model, defaults: Model, properties: Array<keyof Model>);
91
+ /**
92
+ * Set the current value of the colour
93
+ */
94
+ set value(value: Model);
95
+ constructor(type: keyof Properties, value: Model);
88
96
  /**
89
97
  * Convert the colour to a hex-colour
90
98
  */
@@ -81,6 +81,10 @@ export declare class HexColour {
81
81
  * Get a hex-colour from a string
82
82
  */
83
83
  export declare function getHexColour(value: string): HexColour;
84
+ export type Properties = {
85
+ hsl: Array<keyof HSLColourValue>;
86
+ rgb: Array<keyof RGBColourValue>;
87
+ };
84
88
  declare abstract class Colour<Model> {
85
89
  private readonly $colour;
86
90
  protected readonly state: ColourState<Model>;
@@ -88,7 +92,11 @@ declare abstract class Colour<Model> {
88
92
  * Get the current value of the colour
89
93
  */
90
94
  get value(): Model;
91
- constructor(type: string, value: Model, defaults: Model, properties: Array<keyof Model>);
95
+ /**
96
+ * Set the current value of the colour
97
+ */
98
+ set value(value: Model);
99
+ constructor(type: keyof Properties, value: Model);
92
100
  /**
93
101
  * Convert the colour to a hex-colour
94
102
  */
@@ -81,6 +81,10 @@ declare class HexColour {
81
81
  */
82
82
  static toRgb(value: string): RGBColour;
83
83
  }
84
+ export type Properties = {
85
+ hsl: Array<keyof HSLColourValue>;
86
+ rgb: Array<keyof RGBColourValue>;
87
+ };
84
88
  declare abstract class Colour<Model> {
85
89
  private readonly $colour;
86
90
  protected readonly state: ColourState<Model>;
@@ -88,7 +92,11 @@ declare abstract class Colour<Model> {
88
92
  * Get the current value of the colour
89
93
  */
90
94
  get value(): Model;
91
- constructor(type: string, value: Model, defaults: Model, properties: Array<keyof Model>);
95
+ /**
96
+ * Set the current value of the colour
97
+ */
98
+ set value(value: Model);
99
+ constructor(type: keyof Properties, value: Model);
92
100
  /**
93
101
  * Convert the colour to a hex-colour
94
102
  */
@@ -85,6 +85,10 @@ export declare class HexColour {
85
85
  * Get a hex-colour from a string
86
86
  */
87
87
  export declare function getHexColour(value: string): HexColour;
88
+ export type Properties = {
89
+ hsl: Array<keyof HSLColourValue>;
90
+ rgb: Array<keyof RGBColourValue>;
91
+ };
88
92
  declare abstract class Colour<Model> {
89
93
  private readonly $colour;
90
94
  protected readonly state: ColourState<Model>;
@@ -92,7 +96,11 @@ declare abstract class Colour<Model> {
92
96
  * Get the current value of the colour
93
97
  */
94
98
  get value(): Model;
95
- constructor(type: string, value: Model, defaults: Model, properties: Array<keyof Model>);
99
+ /**
100
+ * Set the current value of the colour
101
+ */
102
+ set value(value: Model);
103
+ constructor(type: keyof Properties, value: Model);
96
104
  /**
97
105
  * Convert the colour to a hex-colour
98
106
  */
@@ -161,6 +169,24 @@ export declare class RGBColour extends Colour<RGBColourValue> {
161
169
  * Get an RGB-colour from a value-object
162
170
  */
163
171
  export declare function getRGBColour(value: RGBColourValue): RGBColour;
172
+ /**
173
+ * Convert a hex-colour to an RGB-colour
174
+ */
175
+ export declare function hexToRgb(value: string): RGBColour;
176
+ /**
177
+ * - Convert an HSL-colour to an RGB-colour
178
+ * - Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61
179
+ */
180
+ export declare function hslToRgb(value: HSLColourValue): RGBColour;
181
+ /**
182
+ * Convert an RGB-colour to a hex-colour
183
+ */
184
+ export declare function rgbToHex(value: RGBColourValue): HexColour;
185
+ /**
186
+ * - Convert an RGB-colour to an HSL-colour
187
+ * - Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26
188
+ */
189
+ export declare function rgbToHsl(rgb: RGBColourValue): HSLColour;
164
190
  /**
165
191
  * Is the value a colour?
166
192
  */
@@ -3,6 +3,7 @@ import type { RGBColourValue } from './rgb';
3
3
  * Get a foreground colour _(usually text)_ based on a background colour's luminance
4
4
  */
5
5
  export declare function getForegroundColour(value: RGBColourValue): string;
6
+ export { hexToRgb, hslToRgb, rgbToHex, rgbToHsl } from './functions';
6
7
  export { getHexColour, HexColour } from './hex';
7
8
  export { getHSLColour, HSLColour, type HSLColourValue } from './hsl';
8
9
  export { isColour, isHexColour, isHSLColour, isRGBColour } from './is';
@@ -77,6 +77,10 @@ declare class HexColour {
77
77
  */
78
78
  static toRgb(value: string): RGBColour;
79
79
  }
80
+ export type Properties = {
81
+ hsl: Array<keyof HSLColourValue>;
82
+ rgb: Array<keyof RGBColourValue>;
83
+ };
80
84
  declare abstract class Colour<Model> {
81
85
  private readonly $colour;
82
86
  protected readonly state: ColourState<Model>;
@@ -84,7 +88,11 @@ declare abstract class Colour<Model> {
84
88
  * Get the current value of the colour
85
89
  */
86
90
  get value(): Model;
87
- constructor(type: string, value: Model, defaults: Model, properties: Array<keyof Model>);
91
+ /**
92
+ * Set the current value of the colour
93
+ */
94
+ set value(value: Model);
95
+ constructor(type: keyof Properties, value: Model);
88
96
  /**
89
97
  * Convert the colour to a hex-colour
90
98
  */
@@ -153,7 +161,7 @@ declare class RGBColour extends Colour<RGBColourValue> {
153
161
  * Is the value a colour?
154
162
  */
155
163
  export declare function isColour(value: unknown): value is HexColour | HSLColour | RGBColour;
156
- export declare function isColourValue<Expected>(value: unknown, properties: Array<keyof Expected>): value is Expected;
164
+ export declare function isColourValue(value: unknown, properties: string[]): boolean;
157
165
  /**
158
166
  * Is the value a hex-colour?
159
167
  */
@@ -5,7 +5,7 @@ import type { RGBColour } from './rgb';
5
5
  * Is the value a colour?
6
6
  */
7
7
  export declare function isColour(value: unknown): value is HexColour | HSLColour | RGBColour;
8
- export declare function isColourValue<Expected>(value: unknown, properties: Array<keyof Expected>): value is Expected;
8
+ export declare function isColourValue(value: unknown, properties: string[]): boolean;
9
9
  /**
10
10
  * Is the value a hex-colour?
11
11
  */
@@ -77,6 +77,10 @@ declare class HexColour {
77
77
  */
78
78
  static toRgb(value: string): RGBColour;
79
79
  }
80
+ export type Properties = {
81
+ hsl: Array<keyof HSLColourValue>;
82
+ rgb: Array<keyof RGBColourValue>;
83
+ };
80
84
  declare abstract class Colour<Model> {
81
85
  private readonly $colour;
82
86
  protected readonly state: ColourState<Model>;
@@ -84,7 +88,11 @@ declare abstract class Colour<Model> {
84
88
  * Get the current value of the colour
85
89
  */
86
90
  get value(): Model;
87
- constructor(type: string, value: Model, defaults: Model, properties: Array<keyof Model>);
91
+ /**
92
+ * Set the current value of the colour
93
+ */
94
+ set value(value: Model);
95
+ constructor(type: keyof Properties, value: Model);
88
96
  /**
89
97
  * Convert the colour to a hex-colour
90
98
  */
package/types/index.d.cts CHANGED
@@ -401,6 +401,7 @@ export type StringDigit =
401
401
  | '7'
402
402
  | '8'
403
403
  | '9';
404
+ type NoInfer$1<T> = T extends infer U ? U : never;
404
405
  /**
405
406
  Returns a boolean for whether the given type is `any`.
406
407
 
@@ -429,7 +430,7 @@ const anyA = get(anyObject, 'a');
429
430
  @category Type Guard
430
431
  @category Utilities
431
432
  */
432
- export type IsAny<T> = 0 extends 1 & T ? true : false;
433
+ export type IsAny<T> = 0 extends 1 & NoInfer$1<T> ? true : false;
433
434
  export type Numeric = number | bigint;
434
435
  export type Zero = 0 | 0n;
435
436
  /**
@@ -2512,6 +2513,10 @@ export declare class HexColour {
2512
2513
  * Get a hex-colour from a string
2513
2514
  */
2514
2515
  export declare function getHexColour(value: string): HexColour;
2516
+ export type Properties = {
2517
+ hsl: Array<keyof HSLColourValue>;
2518
+ rgb: Array<keyof RGBColourValue>;
2519
+ };
2515
2520
  declare abstract class Colour<Model> {
2516
2521
  private readonly $colour;
2517
2522
  protected readonly state: ColourState<Model>;
@@ -2519,12 +2524,11 @@ declare abstract class Colour<Model> {
2519
2524
  * Get the current value of the colour
2520
2525
  */
2521
2526
  get value(): Model;
2522
- constructor(
2523
- type: string,
2524
- value: Model,
2525
- defaults: Model,
2526
- properties: Array<keyof Model>,
2527
- );
2527
+ /**
2528
+ * Set the current value of the colour
2529
+ */
2530
+ set value(value: Model);
2531
+ constructor(type: keyof Properties, value: Model);
2528
2532
  /**
2529
2533
  * Convert the colour to a hex-colour
2530
2534
  */
@@ -2593,6 +2597,24 @@ export declare class RGBColour extends Colour<RGBColourValue> {
2593
2597
  * Get an RGB-colour from a value-object
2594
2598
  */
2595
2599
  export declare function getRGBColour(value: RGBColourValue): RGBColour;
2600
+ /**
2601
+ * Convert a hex-colour to an RGB-colour
2602
+ */
2603
+ export declare function hexToRgb(value: string): RGBColour;
2604
+ /**
2605
+ * - Convert an HSL-colour to an RGB-colour
2606
+ * - Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61
2607
+ */
2608
+ export declare function hslToRgb(value: HSLColourValue): RGBColour;
2609
+ /**
2610
+ * Convert an RGB-colour to a hex-colour
2611
+ */
2612
+ export declare function rgbToHex(value: RGBColourValue): HexColour;
2613
+ /**
2614
+ * - Convert an RGB-colour to an HSL-colour
2615
+ * - Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26
2616
+ */
2617
+ export declare function rgbToHsl(rgb: RGBColourValue): HSLColour;
2596
2618
  /**
2597
2619
  * Is the value a colour?
2598
2620
  */
@@ -176,6 +176,7 @@ export type StringDigit =
176
176
  | '7'
177
177
  | '8'
178
178
  | '9';
179
+ type NoInfer$1<T> = T extends infer U ? U : never;
179
180
  /**
180
181
  Returns a boolean for whether the given type is `any`.
181
182
 
@@ -204,7 +205,7 @@ const anyA = get(anyObject, 'a');
204
205
  @category Type Guard
205
206
  @category Utilities
206
207
  */
207
- export type IsAny<T> = 0 extends 1 & T ? true : false;
208
+ export type IsAny<T> = 0 extends 1 & NoInfer$1<T> ? true : false;
208
209
  export type Numeric = number | bigint;
209
210
  export type Zero = 0 | 0n;
210
211
  /**
@@ -176,6 +176,7 @@ export type StringDigit =
176
176
  | '7'
177
177
  | '8'
178
178
  | '9';
179
+ type NoInfer$1<T> = T extends infer U ? U : never;
179
180
  /**
180
181
  Returns a boolean for whether the given type is `any`.
181
182
 
@@ -204,7 +205,7 @@ const anyA = get(anyObject, 'a');
204
205
  @category Type Guard
205
206
  @category Utilities
206
207
  */
207
- export type IsAny<T> = 0 extends 1 & T ? true : false;
208
+ export type IsAny<T> = 0 extends 1 & NoInfer$1<T> ? true : false;
208
209
  export type Numeric = number | bigint;
209
210
  export type Zero = 0 | 0n;
210
211
  /**
@@ -276,6 +276,7 @@ export type StringDigit =
276
276
  | '7'
277
277
  | '8'
278
278
  | '9';
279
+ type NoInfer$1<T> = T extends infer U ? U : never;
279
280
  /**
280
281
  Returns a boolean for whether the given type is `any`.
281
282
 
@@ -304,7 +305,7 @@ const anyA = get(anyObject, 'a');
304
305
  @category Type Guard
305
306
  @category Utilities
306
307
  */
307
- export type IsAny<T> = 0 extends 1 & T ? true : false;
308
+ export type IsAny<T> = 0 extends 1 & NoInfer$1<T> ? true : false;
308
309
  export type Numeric = number | bigint;
309
310
  export type Zero = 0 | 0n;
310
311
  /**
@@ -165,6 +165,7 @@ export type VariablePartOfArray<T extends UnknownArray> = T extends unknown
165
165
  ? U
166
166
  : []
167
167
  : never; // Should never happen
168
+ type NoInfer$1<T> = T extends infer U ? U : never;
168
169
  /**
169
170
  Returns a boolean for whether the given type is `any`.
170
171
 
@@ -193,7 +194,7 @@ const anyA = get(anyObject, 'a');
193
194
  @category Type Guard
194
195
  @category Utilities
195
196
  */
196
- export type IsAny<T> = 0 extends 1 & T ? true : false;
197
+ export type IsAny<T> = 0 extends 1 & NoInfer$1<T> ? true : false;
197
198
  export type Numeric = number | bigint;
198
199
  export type Zero = 0 | 0n;
199
200
  /**
@@ -236,6 +236,7 @@ export type StringDigit =
236
236
  | '7'
237
237
  | '8'
238
238
  | '9';
239
+ type NoInfer$1<T> = T extends infer U ? U : never;
239
240
  /**
240
241
  Returns a boolean for whether the given type is `any`.
241
242
 
@@ -264,7 +265,7 @@ const anyA = get(anyObject, 'a');
264
265
  @category Type Guard
265
266
  @category Utilities
266
267
  */
267
- export type IsAny<T> = 0 extends 1 & T ? true : false;
268
+ export type IsAny<T> = 0 extends 1 & NoInfer$1<T> ? true : false;
268
269
  export type Numeric = number | bigint;
269
270
  export type Zero = 0 | 0n;
270
271
  /**