@camwiegert/typical

中文文档
0.1.1发布于 2019/10/20MITCommonJS零依赖近 30 天下载 6109

Animated typing in ~400 bytes

原始使用文档
文档目录8 节
  1. Install
  2. API
  3. Usage
  4. Pausing
  5. Looping
  6. Waiting
  7. Functions
  8. Support

typical

Animated typing in ~400 bytes :blowfish: of JavaScript.

  • Zero dependencies
  • MIT licensed →
  • Emoji support
  • Smart delete: only delete what needs deleting
  • Pausing: pause between steps
  • Looping: easily loop from any point
  • Waiting: wait on arbitrary Promises
  • Humanity: slightly varied typing speed

Demo →


Install

npm install @camwiegert/typical
More install options

Instead of using a package manager, you can download typical.js from GitHub and import it locally or import it directly from a CDN like unpkg.

API

type(target: HTMLElement, ...steps: any[]) => Promise<void>;

The module exports a single function, type, which takes a target element as its first argument, and any number of additional arguments as the steps to perform. Additional arguments perform actions based on their type:

  • string arguments will be typed
  • number arguments will pause, in milliseconds
  • function arguments will be called with the target element as an argument
  • Promise arguments will wait for resolution

Usage

The most basic usage of type is providing a target element and a string to type.

import { type } from '@camwiegert/typical';

type(element, 'text');

Pausing

In order to pause typing at any point, pass a number of milliseconds to pause.

type(element, 'Hello', 1000, 'Hello world!');

Looping

In order to loop, pass type as a parameter to itself at the point at which you'd like to start looping. It can be helpful to alias type as loop to be explicit.

import {
    type,
    type as loop
};

const steps = [1000, 'Ready', 1000, 'Set', 1000, 'Go'];

type(element, ...steps, loop);

To loop a finite amount, pass your steps multiple times.

type(element, ...steps, ...steps, ...steps);

Waiting

When passed a Promise, type will wait for it to resolve before continuing. Because type itself returns a Promise, that means you can wait on a set of steps to complete before starting another.

const init = type(target, 'In a moment...', 500);

type(target, init, 'start', 500, 'looping', loop);

Functions

Function arguments are passed the target element, and can be useful for operating on the target element between steps. If you return a Promise, type will wait for it to resolve.

const toggle = (element) =>
    element.classList.toggle('is-typing');

type(target, toggle, 'Type me', toggle);

Support

  • Chrome
  • Edge
  • Firefox
  • Safari
  • Internet Explorer

版本与发布记录

@camwiegert/typical 共发布 2 个版本,首次发布于 2019/10/15;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.1latest2019/10/207 年前
0.1.02019/10/157 年前

关于 @camwiegert/typical 的常见问题

@camwiegert/typical 是什么?

Animated typing in ~400 bytes

如何安装 @camwiegert/typical?

在项目目录运行 npm install @camwiegert/typical,或使用 pnpm add / yarn add / bun add。

@camwiegert/typical 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/camwiegert__typical 是否存在。

@camwiegert/typical 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@camwiegert/typical 可以商用吗?

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

@camwiegert/typical 的下载量有多少?

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

@camwiegert/typical 还在维护吗?

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