Skip to content

Commit

Permalink
Move getFormat to "Color parsing" section
Browse files Browse the repository at this point in the history
  • Loading branch information
omgovich authored and Vlad Shilov committed May 11, 2021
1 parent ab0900c commit e68cfa2
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@ colord("hsl(0deg, 50%, 50%)").darken(0.25).toHex(); // "#602020"

<div><img src="assets/divider.png" width="838" alt="---" /></div>

## API

### Color parsing

#### Accepted input formats
## Supported Color Models

- Hexadecimal strings (including 3, 4 and 8 digit notations)
- RGB strings and objects
Expand All @@ -86,7 +82,20 @@ colord("hsl(0deg, 50%, 50%)").darken(0.25).toHex(); // "#602020"
- LAB objects ([via plugin](#plugins))
- XYZ objects ([via plugin](#plugins))

<div><img src="assets/divider.png" width="838" alt="---" /></div>

## API

### Color parsing

<details>
<summary><b><code>colord(input)</code></b></summary>

Parses the given input and creates a new Colord instance.

```js
import { colord } from "colord";

// String input examples
colord("FFF");
colord("#ffffff");
Expand All @@ -106,6 +115,8 @@ colord({ h: 360, s: 100, v: 100 });
colord({ h: 360, s: 100, v: 100, a: 1 });
```

Check out the ["Plugins"](#plugins) section for more input format examples.

#### Permissive parser

The parser of the library is user-friendly: it trims unnecessary whitespaces, clamps numbers, disregards character case, punctuation, brackets, etc. Here are some examples:
Expand All @@ -117,6 +128,24 @@ colord(" hsL( -10, 200% 30 .5!!!").toHslString(); // "hsla(350, 100%, 30%, 0.5)
colord({ r: NaN, g: -Infinity, b: +Infinity, a: 100500 }).toRgb(); // { r: 0, g: 0, b: 255, a: 1 }
```

</details>

<details>
<summary><b><code>getFormat(input)</code></b></summary>

Returns a color model name for the input passed to the function. Uses the same parsing system as `colord` function.

```js
import { getFormat } from "colord";

getFormat("#aabbcc"); // "hex"
getFormat({ r: 13, g: 237, b: 162, a: 0.5 }); // "rgb"
getFormat("hsl(180deg, 50%, 50%)"); // "hsl"
getFormat("WUT?"); // undefined
```

</details>

### Color conversion

<details>
Expand Down Expand Up @@ -547,22 +576,6 @@ random().alpha(0.5).toRgb(); // { r: 13, g: 237, b: 162, a: 0.5 }

</details>

<details>
<summary><b><code>getFormat(input)</code></b></summary>

Returns a color model name for the input passed to the function.

```js
import { getFormat } from "colord";

getFormat("#aabbcc"); // "hex"
getFormat({ r: 13, g: 237, b: 162, a: 0.5 }); // "rgb"
getFormat("hsl(180deg, 50%, 50%)"); // "hsl"
getFormat("WUT?"); // undefined
```

</details>

<div><img src="assets/divider.png" width="838" alt="---" /></div>

## Plugins
Expand Down

0 comments on commit e68cfa2

Please sign in to comment.