包详细信息

color-shorthand-hex-to-six-digit

codsen100.3kMIT5.0.20

Convert shorthand hex color codes into full

characters, code, codes, color

自述文件

color-shorthand-hex-to-six-digit

Convert shorthand hex color codes into full

page on codsen.com page on npm page on github Downloads per month changelog MIT Licence

Install

This package is pure ESM. If you're not ready yet, install an older version of this program, 3.1.0 (npm i color-shorthand-hex-to-six-digit@3.1.0).

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.

Contributing

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

Licence

MIT License.

Copyright © 2010-2025 Roy Revelt and other contributors.

ok codsen star

更新日志

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

5.0.0 (2022-12-01)

BREAKING CHANGES

  • Minimum supported Node version is v14.18; we're dropping v12 support

4.1.0 (2022-08-12)

Features

4.0.0 (2021-09-09)

Features

BREAKING CHANGES

  • programs now are in ES Modules and won't work with Common JS require()

3.1.0 (2021-05-24)

Features

  • config file based major bump blacklisting (e15f9bb)

3.0.15 (2021-04-11)

Reverts

  • Revert "chore: setup refresh" (23cf206)

3.0.1 (2021-01-28)

Fixed

  • add testStats to npmignore (f3c84e9)

3.0.0 (2021-01-23)

Features

  • rewrite in TS, start using named exports (df180c5)

BREAKING CHANGES

  • previously: import conv from ... - now import { conv } from ...

2.11.0 (2020-11-28)

Accidental version bump during migration to SourceHut. Sorry about that.

2.10.0 (2019-01-20)

  • Various documentation and setup tweaks after we migrated to monorepo
  • Setup refresh: updated dependencies and all config files using automated tools

2.4.0 (2018-10-15)

  • Updated all dependencies and restored coverage tracking both via terminal when testing and through coveralls.io

2.3.0 (2018-06-27)

  • Set up Rollup to remove any comments from build files
  • Attempt to fix reported issues with UMD builds undefined$3 variable not found

2.2.0 (2018-06-08)

Features

  • Fixed false positive cases of HTML entities, for example |. Thanks James Kupczak!
  • Rebased a little
  • Migrated to BitBucket...
  • ...which means we dropped Travis. But we kept Coveralls.
  • RIP BitHound

2.1.0 (2018-05-03)

Features

  • Set up Prettier
  • Removed package.lock and .editorconfig
  • Wired Rollup to remove comments from non-dev builds. This means we can now leave the console.logs in the source code — Rollup will remove from production code.

2.0.0 (2017-12-06)

Changes

  • Rebased in ES Modules
  • Set up Rollup (nice rhyming), now generating transpiled CommonJS, UMD and native ES Module builds.

Bumping major just in case it breaks somebody's API. It shouldn't though.

1.5.0 (2017-05-25)

Fixed

  • Dependencies to request the latest _.clonedeep
  • Readme, added more examples

1.4.0 (2017-03-06)

Features

  • More unit tests to cover XHTML code.

1.3.0 (2017-03-02)

Fixed

  • Now any input args are not mutated. Ever.

1.2.0 (2017-02-17)

Features

  • Table of Contents in README

Fixed

  • Set up blanket deps ranges because it's tedious to update them and these deps never breaking-change
  • Updated company name in README and LICENSE

1.1.0 (2017-01-09)

Features

  • All hex codes, three and six digits long, are converted to lowercase. This is to prevent case mismatches.
  • Test 05.01 to prove this works as intended.

1.0.0 (2017-01-06)

Initial release. 100% test coverage.