@consolelabs/mochi-ui

中文文档
17.0.3发布于 2023/12/26ISCTypeScriptESM + CJS近 30 天下载 2092

Mochi UI for profiles, numbers, texts

原始使用文档
文档目录5 节
  1. 🚀 Usage
  2. 🤖 API
  3. resolve(on: Platform.Web | Platform.Discord | Platform.Tele…
  4. Utilities
  5. components (coming soon)

mochi pose 13

Mochi UI npm latest version

This package includes the basic components that you need to render any Mochi data, generally speaking there are 3 main goal:

  • Render Mochi identity
  • Use components such as balance list, activities, transactions list, etc...
  • Utilize helpers such as text/number formatters, etc...

🚀 Usage

import API from "@consolelabs/mochi-rest";
import UI, { utils } from "@consolelabs/mochi-formatter";
import Redis from "ioredis";

// optionally use redis for better perf
UI.redis = new Redis();

const api = new API({});
api.init().then(() => {
  UI.api = api;
});

const [account, otherAccount] = await UI.resolve(
  Platform.Web,
  profile_id,
  other_profile_id
);

const markdownText = await UI.components.balance({
  /* props */
});

const formattedUsd = utils.formatUsdDigit(23.12563);
console.log(formattedUsd); // "$23.12"

🤖 API

resolve(on: Platform.Web | Platform.Discord | Platform.Telegram, profile_id_A: string, profile_id_B?: string)

const [account, otherAccount] = await UI.resolve(
  Platform.Web, // if you're using UI library on web
  profile_id,
  other_profile_id
);

// or using it on self
const [account] = await UI.resolve(Platform.Web, profile_id);

Takes in a platform that you're rendering on, a pair of profile ids to resolve, profile_id_B defaults to profile_id_A if not passed in. The return value is an object with the following properties

type UsernameFmt = {
  // this value is markdown
  value: string;
  // the id of that platform
  id: string;
  // url of this account
  url: string;
  // same as `value` but in plain text format
  plain: string;
  // in case of invalid account, this will be null
  platform?:
    | Platform.App
    | Platform.Mochi
    | Platform.Discord
    | Platform.Telegram
    | Platform.Twitter
    | Platform.Vault
    | null;
};

Utilities

  • formatUsdDigit(input: string | number | object): string: returns a string representation of the usd value with $ prefix
  • formatPercentDigit(input: string | number | object): string: returns a string representation of the percentage value with % suffix
  • formatTokenDigit(input: string | number | object): string: returns a string representation of the token value
  • formatDigit(options: object): string: the base formatter, the shape of options is:
type Options = {
  value: string | number;
  // how many numbers to keep after decimal point
  fractionDigits?: number;
  // decides whether the result should have commas
  withoutCommas?: boolean;
  // use shorten form e.g. 200,000 -> 200K, $1,234,567,890 -> $1B
  // note that by using this option some precision of number will be lost
  shorten?: boolean;
  // use for very small numbers e.g. 1e-8
  scientificFormat?: boolean;
};

Note: All the format functions except formatDigit follows the same decimal point formatting rule, that is:

  • For percentage value, automatically hide decimal point if value >= 10

  • For USD value, automatically hide decimal point if value >= 100

  • For token value, automatically hide decimal point if value >= 1000

  • In case of having to show decimal point, we only take maximum 2 digits that are not 0 starting from the dot, if both are 0 then take the first digit that is not zero, some examples:

0.02345 -> 0.02
0.2103 -> 0.2
0.00003981 -> 0.0003

components (coming soon)

版本与发布记录

@consolelabs/mochi-ui 共发布 114 个版本,首次发布于 2023/08/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
17.0.3latest2023/12/262 年前
17.0.22023/12/262 年前
17.0.12023/12/112 年前
17.0.02023/12/112 年前
16.0.62023/12/072 年前
16.0.52023/12/072 年前

其他发布通道:next → 0.0.2-rc.4。

关于 @consolelabs/mochi-ui 的常见问题

@consolelabs/mochi-ui 是什么?

Mochi UI for profiles, numbers, texts

如何安装 @consolelabs/mochi-ui?

在项目目录运行 npm install @consolelabs/mochi-ui,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:ioredis(^5.x.x)、@consolelabs/mochi-rest(^5.1.9)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@consolelabs/mochi-ui 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@consolelabs/mochi-ui 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@consolelabs/mochi-ui 可以商用吗?

@consolelabs/mochi-ui 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@consolelabs/mochi-ui 的下载量有多少?

根据 npm 官方下载统计,@consolelabs/mochi-ui 在 2026/10/11 – 2026/11/09 这 30 天内被下载 2,092 次,日均约 70 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@consolelabs/mochi-ui 还在维护吗?

最新版本 17.0.3 发布于 2023/12/26(2 年前);至今共发布 114 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/08/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。