@ canonical/ 无效
Pragma设计系统的实用功能. 这个包包含了经过战斗测试的帮助者,这些帮助者在多个包中证明是有用的.
设计系统助手——导航树, debounce, (中文(简体) ), throttle, (中文(简体) ), humanizeNumber, (中文(简体) ), pluralize 编辑 AllOrNone 类型 —— 居住 @canonical/ds-utils。 。 。 .
安装
bun add @canonical/utils
可用函数
弹壳
在个案惯例之间转换字符串。 每个转换器是一个平面命名导出: capitalize, (中文(简体) ), isPascalCase, (中文(简体) ), toCamelCase, (中文(简体) ), toConstantCase, (中文(简体) ), toKebabCase, (中文(简体) ), toPascalCase, (中文(简体) ), toSnakeCase 财务报告和审定财务报表 toTitleCase。 。 。 .
import { toCamelCase, toKebabCase } from "@canonical/utils";
toCamelCase("hello-world"); // "helloWorld"
toKebabCase("helloWorld"); // "hello-world"
无变化
如果一个条件是假的,则丢出一个错误。 用于在代码中坚持假设 .
import { invariant } from "@canonical/utils";
invariant(user != null, "User must be defined");
// Throws `Invariant violation: User must be defined` when user is null;
// TypeScript now knows user is not null past this line.
缩进
将字符串的每行缩入给定数空格,用于生成可读源输出.
import { indent } from "@canonical/utils";
indent("a\nb", 2); // " a\n b"
加入时
将数组合并为字符串,首先将每个元素转换为字符串.
import { join } from "@canonical/utils";
join(["a", "b", "c"]); // "a, b, c"
join([1, 2, 3], " | "); // "1 | 2 | 3"
设计哲学
函数仅在对多个软件包证明有用后才输入此软件包 。 预先抽象被积极避免. 如果一个工具仅在一个地方需要,它就属于该套件,直到出现第二个使用情况.
每个函数都附有综合的TSDoc评论。 该软件包没有运行时间依赖性,将捆绑的撞击保持在最小.