Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

colord

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

colord - npm Package Compare versions

Comparing version
2.8.0
to
2.9.0
+20
plugins/minify.d.ts
import { Plugin } from "../extend";
interface MinificationOptions {
hex?: boolean;
alphaHex?: boolean;
rgb?: boolean;
hsl?: boolean;
name?: boolean;
transparent?: boolean;
}
declare module "../colord" {
interface Colord {
/** Returns the shortest string representation of the color */
minify(options?: MinificationOptions): string;
}
}
/**
* A plugin adding a color minification utilities.
*/
declare const minifyPlugin: Plugin;
export default minifyPlugin;
module.exports=function(t){var r=function(t){return t>0&&t<1?t.toString().replace("0.","."):t};t.prototype.minify=function(t){void 0===t&&(t={});var n=this.toRgb(),e=r(n.r),h=r(n.g),s=r(n.b),i=this.toHsl(),a=r(i.h),o=r(i.s),u=r(i.l),l=r(this.alpha()),p=Object.assign({hex:!0,rgb:!0,hsl:!0},t),f=[];if(p.hex&&(1===l||p.alphaHex)&&f.push(function(t){var r=t.toHex(),n=r.split(""),e=n[1],h=n[3],s=n[5],i=n[7],a=n[8];if(e===n[2]&&h===n[4]&&s===n[6]){if(1===t.alpha())return"#"+e+h+s;if(i===a)return"#"+e+h+s+i}return r}(this)),p.rgb&&f.push(1===l?"rgb("+e+","+h+","+s+")":"rgba("+e+","+h+","+s+","+l+")"),p.hsl&&f.push(1===l?"hsl("+a+","+o+"%,"+u+"%)":"hsla("+a+","+o+"%,"+u+"%,"+l+")"),p.transparent&&0===e&&0===h&&0===s&&0===l)f.push("transparent");else if(p.name&&"function"==typeof this.toName){var g=this.toName();g&&f.push(g)}return function(t){for(var r=t[0],n=1;n<t.length;n++)t[n].length<r.length&&(r=t[n]);return r}(f)}};
export default function(t){var r=function(t){return t>0&&t<1?t.toString().replace("0.","."):t};t.prototype.minify=function(t){void 0===t&&(t={});var n=this.toRgb(),e=r(n.r),h=r(n.g),a=r(n.b),i=this.toHsl(),s=r(i.h),o=r(i.s),u=r(i.l),l=r(this.alpha()),p=Object.assign({hex:!0,rgb:!0,hsl:!0},t),f=[];if(p.hex&&(1===l||p.alphaHex)&&f.push(function(t){var r=t.toHex(),n=r.split(""),e=n[1],h=n[3],a=n[5],i=n[7],s=n[8];if(e===n[2]&&h===n[4]&&a===n[6]){if(1===t.alpha())return"#"+e+h+a;if(i===s)return"#"+e+h+a+i}return r}(this)),p.rgb&&f.push(1===l?"rgb("+e+","+h+","+a+")":"rgba("+e+","+h+","+a+","+l+")"),p.hsl&&f.push(1===l?"hsl("+s+","+o+"%,"+u+"%)":"hsla("+s+","+o+"%,"+u+"%,"+l+")"),p.transparent&&0===e&&0===h&&0===a&&0===l)f.push("transparent");else if(p.name&&"function"==typeof this.toName){var g=this.toName();g&&f.push(g)}return function(t){for(var r=t[0],n=1;n<t.length;n++)t[n].length<r.length&&(r=t[n]);return r}(f)}}
+4
-0

@@ -0,1 +1,5 @@

### 2.9.0
- New plugin: Color string minification 🗜
### 2.8.0

@@ -2,0 +6,0 @@

{
"name": "colord",
"version": "2.8.0",
"version": "2.9.0",
"description": "👑 A tiny yet powerful tool for high-performance color manipulations and conversions",

@@ -23,2 +23,3 @@ "keywords": [

"mix",
"minify",
"harmonies"

@@ -68,2 +69,7 @@ ],

},
"./plugins/minify": {
"import": "./plugins/minify.mjs",
"require": "./plugins/minify.js",
"default": "./plugins/minify.mjs"
},
"./plugins/mix": {

@@ -178,2 +184,6 @@ "import": "./plugins/mix.mjs",

{
"path": "dist/plugins/minify.mjs",
"limit": "0.5 KB"
},
{
"path": "dist/plugins/mix.mjs",

@@ -180,0 +190,0 @@ "limit": "1 KB"

@@ -746,2 +746,31 @@ <div align="center">

<details>
<summary><b><code>.minify(options?)</code></b></summary>
Converts a color to its shortest string representation.
```js
import { colord, extend } from "colord";
import minifyPlugin from "colord/plugins/minify";
extend([minifyPlugin]);
colord("black").minify(); // "#000"
colord("#112233").minify(); // "#123"
colord("darkgray").minify(); // "#a9a9a9"
colord("rgba(170,170,170,0.4)").minify(); // "hsla(0,0%,67%,.4)"
colord("rgba(170,170,170,0.4)").minify({ alphaHex: true }); // "#aaa6"
```
| Option | Default | Description |
| ------------- | ------- | ------------------------------------------------------------ |
| `hex` | `true` | Enable `#rrggbb` and `#rgb` notations |
| `alphaHex` | `false` | Enable `#rrggbbaa` and `#rgba` notations |
| `rgb` | `true` | Enable `rgb()` and `rgba()` functional notations |
| `hsl` | `true` | Enable `hsl()` and `hsla()` functional notations |
| `name` | `false` | Enable CSS color keywords. Requires `names` plugin installed |
| `transparent` | `false` | Enable `"transparent"` color keyword |
</details>
<div><img src="assets/divider.png" width="838" alt="---" /></div>

@@ -887,5 +916,25 @@

<details>
<summary><b><code>minify</code> (Color string minification)</b> <i>0.5 KB</i></summary>
A plugin adding color string minification utilities.
```js
import { colord, extend } from "colord";
import minifyPlugin from "colord/plugins/minify";
extend([minifyPlugin]);
colord("black").minify(); // "#000"
colord("#112233").minify(); // "#123"
colord("darkgray").minify(); // "#a9a9a9"
colord("rgba(170,170,170,0.4)").minify(); // "hsla(0,0%,67%,.4)"
colord("rgba(170,170,170,0.4)").minify({ alphaHex: true }); // "#aaa6"
```
</details>
<details>
<summary><b><code>mix</code> (Color mixing)</b> <i>0.96 KB</i></summary>
A plugin adding a color mixing utilities.
A plugin adding color mixing utilities.

@@ -892,0 +941,0 @@ In contrast to other libraries that perform RGB values mixing, Colord mixes colors through [LAB color space](https://en.wikipedia.org/wiki/CIELAB_color_space). This approach produces better results and doesn't have the drawbacks the legacy way has.