JSPM

  • Created
  • Published
  • Downloads 21669
  • Score
    100M100P100Q169574F
  • License MIT

Convert shorthand hex color codes into full

Package Exports

  • color-shorthand-hex-to-six-digit

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (color-shorthand-hex-to-six-digit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

color-shorthand-hex-to-six-digit

Convert shorthand hex color codes into full

Install

npm i color-shorthand-hex-to-six-digit

Quick Take

import { strict as assert } from "assert";
import { conv } from "color-shorthand-hex-to-six-digit";

// converts shorthand hex color codes within strings (imagine that could be
// email template source code):
assert.equal(
  conv("aaaa #f0c zzzz\n\t\t\t#fc0"),
  "aaaa #ff00cc zzzz\n\t\t\t#ffcc00"
);

// converts shorthand hex colour codes within plain objects:
assert.deepEqual(
  conv({
    a: "#ffcc00",
    b: "#f0c",
    c: "text",
  }),
  {
    a: "#ffcc00",
    b: "#ff00cc",
    c: "text",
  }
);

// converts shorthand hex colour codes within arrays:
assert.deepEqual(conv(["#fc0", "#f0c", "text", ""]), [
  "#ffcc00",
  "#ff00cc",
  "text",
  "",
]);

// converts shorthand hex colour codes within nested spaghetti's:
assert.deepEqual(
  conv([[[[[[{ x: ["#fc0"] }]]]]], { z: "#f0c" }, ["text"], { y: "" }]),
  [[[[[[{ x: ["#ffcc00"] }]]]]], { z: "#ff00cc" }, ["text"], { y: "" }]
);

// in all other cases it silently returns the input:
assert.equal(conv(null), null);

Documentation

Please visit codsen.com for a full description of the API and examples.

Contributing

To report bugs or request features or assistance, raise an issue on GitHub.

Licence

MIT License

Copyright (c) 2010-2021 Roy Revelt and other contributors

ok codsen star