@kastov/uuid-color 0.0.1 → 0.0.2
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/package.json +1 -1
- package/README.md +0 -71
package/package.json
CHANGED
package/README.md
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
**uuid-color package on npm: https://www.npmjs.com/package/uuid-color**
|
|
2
|
-
|
|
3
|
-
A lightweight package to deterministically generate unique and uniformly sampled colors from UUIDs.
|
|
4
|
-
|
|
5
|
-
### How it works
|
|
6
|
-
|
|
7
|
-
The RGB color space is represented by hexadecimal numbers in the 0x000000 to 0xffffff range. We use a simple modulo hash function (`% (0xffffff + 0x000001)` i.e. `% 0x100000`) to produce numbers in that range from the decimal representation of the UUID (a base 10 39-digit integer). We then extract the red, green, and blue components from the resulting hash (which represents a specific color in hexadecimal notation) using bit masks.
|
|
8
|
-
|
|
9
|
-
### Limitations
|
|
10
|
-
|
|
11
|
-
Since the color space is only 256^3 whereas the UUID space is much larger ([approximtely 5.3 x 10^36 possible UUIDs](https://www.uuidtools.com/what-is-uuid#overview)), it is impossible to create a complete bijection between the spaces, and so collisions in the generated color space can occur. This package does however guarantee that the color space is maximally utilized, assuming a uniform distribution of the input UUIDs within the UUID space.
|
|
12
|
-
|
|
13
|
-
# Installation:
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
npm i uuid-color
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
# Usage
|
|
20
|
-
|
|
21
|
-
```js
|
|
22
|
-
import { v4 as uuidv4 } from "uuid";
|
|
23
|
-
import { colorFromUuid } from "uuid-color";
|
|
24
|
-
|
|
25
|
-
const myUuid = uuidv4();
|
|
26
|
-
|
|
27
|
-
// returns a hex color code as a string "#rrggbb"
|
|
28
|
-
const hexColor = colorFromUuid(myUuid);
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
[Live demo](https://codesandbox.io/s/uuid-color-usage-o0e4o)
|
|
32
|
-
|
|
33
|
-
# Reference - v0.1.0
|
|
34
|
-
|
|
35
|
-
## Table of contents
|
|
36
|
-
|
|
37
|
-
### Interfaces
|
|
38
|
-
|
|
39
|
-
- [Options](docs/dist/interfaces/Options.md)
|
|
40
|
-
|
|
41
|
-
### Functions
|
|
42
|
-
|
|
43
|
-
- [colorFromUuid](docs/dist/README.md#colorfromuuid)
|
|
44
|
-
|
|
45
|
-
## Functions
|
|
46
|
-
|
|
47
|
-
### colorFromUuid
|
|
48
|
-
|
|
49
|
-
▸ **colorFromUuid**(`uuid`, `options?`): `string`
|
|
50
|
-
|
|
51
|
-
Returns the generated color associated with the given uuid.
|
|
52
|
-
|
|
53
|
-
**`throws`** [Error](https://developer.mozilla.org/en-US/docs/web/javascript/reference/global_objects/error)
|
|
54
|
-
This exception is thrown if the input uuid string is not a valid UUID.
|
|
55
|
-
|
|
56
|
-
#### Parameters
|
|
57
|
-
|
|
58
|
-
| Name | Type | Description |
|
|
59
|
-
| :------ | :------ | :------ |
|
|
60
|
-
| `uuid` | `string` | The uuid for which to generate a color |
|
|
61
|
-
| `options` | [`Options`](docs/dist/interfaces/Options.md) | An optional object to configure the color generation, and attach callbacks that directly receive the generated color code or components in various formats |
|
|
62
|
-
|
|
63
|
-
#### Returns
|
|
64
|
-
|
|
65
|
-
`string`
|
|
66
|
-
|
|
67
|
-
The generated color as a CSS `<color>` notation string
|
|
68
|
-
|
|
69
|
-
#### Defined in
|
|
70
|
-
|
|
71
|
-
[index.ts:81](https://github.com/loucadufault/uuid-color/blob/1d2a5c0/src/index.ts#L81)
|