npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

colord-rand-loop

v1.0.6

Published

基於 Colord 的隨機顏色循環生成器,提供去重功能的顏色生成工具 (Random color loop generator based on Colord with deduplication functionality)

Readme

colord-rand-loop

基於 Colord 的隨機顏色循環生成器,提供去重功能的顏色生成工具 (Random color loop generator based on Colord with deduplication functionality)

安裝 (Installation)

# 使用 yarn / Using yarn
yarn add colord-rand-loop

# 使用 yarn-tool / Using yarn-tool
yarn-tool add colord-rand-loop
# yt 是 yarn-tool 的別名 / yt is an alias for yarn-tool
yt add colord-rand-loop

# 使用 pnpm / Using pnpm
pnpm add colord-rand-loop

# 使用 npm / Using npm
npm install colord-rand-loop

使用方式 (Usage)

import { colordRandLoop, createColordRandLoop, IOptionsColordRandLoop } from 'colord-rand-loop';

// 基本使用 - 從預設顏色開始生成隨機顏色
const generator = colordRandLoop();
const color1 = generator.next().value; // 第一個隨機顏色
const color2 = generator.next().value; // 第二個隨機顏色(不重複)

// 指定起始索引
const generatorFromIndex = colordRandLoop(2); // 從索引 2 開始

// 自定義顏色來源
const myColors = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00'];
const customGenerator = colordRandLoop(0, { colors: myColors });

// 自定義隨機函式
const seededGenerator = colordRandLoop(0, {
  randFn: () => 0.5 // 固定隨機種子
});

// 進階配置
const options: IOptionsColordRandLoop = {
  colors: ['#FF0000', '#00FF00'],
  randFn: Math.random,
  // cache 會自動管理
};
const advancedGenerator = createColordRandLoop(options);

// 使用方式
for (let i = 0; i < 5; i++) {
  const color = advancedGenerator.next().value;
  console.log(color.toHex()); // 輸出十六進位顏色
}

API 參考

colordRandLoop(startIndex?, options?)

創建一個配置完成的 Colord 隨機循環生成器。

參數:

  • startIndex (number, 可選): 起始索引,預設為 0
  • options (IOptionsColordRandLoop, 可選): 配置選項

返回值: 可迭代的 Generator,每次調用 .next().value 返回一個 Colord 實例

createColordRandLoop(options?)

創建一個可配置的 Colord 隨機循環生成器工廠。

參數:

  • options (IOptionsColordRandLoop, 可選): 配置選項

返回值: 配置完成的 Generator 函式

IOptionsColordRandLoop 介面

  • cache (Set, 可選): 用於去重的顏色快取集合
  • colors (ITSArrayListMaybeReadonly, 可選): 顏色來源陣列
  • 繼承自 IOptions<IColorInput, Colord>IOptionsRandColorUtil

範例

基本隨機顏色生成

import { colordRandLoop } from 'colord-rand-loop';

const rgbValues = [];
const gen = colordRandLoop();

for (let i = 0; i < 10; i++) {
  const color = gen.next().value;
  rgbValues.push(color.toRgb());
}
// rgbValues 包含 10 個不重複的隨機 RGB 顏色

自定義顏色盤

import { colordRandLoop } from 'colord-rand-loop';

const brandColors = ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFBE0B'];
const brandGen = colordRandLoop(0, { colors: brandColors });

// 只會從品牌顏色中選擇
const color = brandGen.next().value;