@consolelabs/mochi-ui

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

用于配置、数字、文本的 Mochi UI

中文使用文档
文档目录5 节
  1. 使用量
  2. • API
  3. resolve(on: Platform.Web | Platform.Discord | Platform.Tele…
  4. 公用事业
  5. (即将到来)

mochi pose 13

莫奇内 npm latest version

本套件包括您需要制作任何Mochi数据的基本组件,一般有3个主要目标:

  • 伦德·莫奇身份
  • 使用余额列表,活动,交易列表等组件.
  • 使用文本/ 数字格式化器等帮助...

使用量

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);

在一个你正在渲染的平台上 一对需要解决的特征, profile_id_B 默认为 profile_id_A 如果不是通过。 返回值是一个具有以下属性的对象

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;
};

公用事业

  • formatUsdDigit(input: string | number | object): string: 返回带有 $ 前缀的 usd 值的字符串表达式
  • formatPercentDigit(input: string | number | object): string: 返回带有%后缀的百分比值的字符串表示符
  • formatTokenDigit(input: string | number | object): string: 返回符号值的字符串表示符
  • formatDigit(options: object): string: 基物,选项形状为:
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;
};

注意: 所有格式函数除外 formatDigit 遵循相同的小数点格式化规则,即:

  • 对于百分比值,如果值为%\ 10,则自动隐藏小数点

  • 对于美元值,如果值为 QQ 100,则自动隐藏小数点

  • 对于符号值,如果值为 QQ 1000,则自动隐藏小数点

  • 如果必须显示小数点,我们只取最大2位数而不是从点起的0,如果两者均为0,那么取第一个不是0的数字,一些例子:

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

(即将到来)

版本与发布记录

@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

如何安装 @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 和提交记录判断。