莫奇内 
本套件包括您需要制作任何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