@allmaps/id

中文文档
1.0.0-beta.39发布于 2026/09/22ISCES Module零依赖近 30 天下载 9110

IDs for Allmaps

原始使用文档
文档目录13 节
  1. Usage
  2. Async (default)
  3. Sync
  4. Browser (via CDN)
  5. CLI
  6. License
  7. API
  8. generateChecksum(obj, length)
  9. generateId(str, length)
  10. generateRandomId(length)
  11. generateChecksum(obj, length)
  12. generateId(str, length)
  13. generateRandomId(length)

@allmaps/id

Uses the SHA-1 algorithm to generate IDs from strings, random IDs from UUIDs and checksums from JSON objects.

Allmaps uses this module to create IDs from IIIF URIs. For example:

To see @allmaps/id in action, view this Observable notebook.

Usage

This is an ESM-only module that works in browsers, Node.js, and Cloudflare Workers.

There are two variants:

  • Async (default) — uses SubtleCrypto.digest() and Crypto.randomUUID(). Works everywhere.
  • Sync (@allmaps/id/sync) — pure-JS SHA-1 implementation with no external dependencies. Returns values synchronously. Useful when an async context is not available (e.g. inside Svelte $derived).

Both variants produce identical output.

Async (default)

import { generateId } from '@allmaps/id'

const url = 'https://digital.zlb.de/viewer/api/v1/records/34231682/manifest/'
const id = await generateId(url)
// id = '6f5a7b547c8f6fbe'

Sync

import { generateId, generateChecksum } from '@allmaps/id/sync'

const url = 'https://digital.zlb.de/viewer/api/v1/records/34231682/manifest/'
const id = generateId(url)
// id = '6f5a7b547c8f6fbe'

Browser (via CDN)

<script type="module">
  import { generateId } from 'https://esm.run/@allmaps/id'

  const url =
    'https://orka.bibliothek.uni-kassel.de/viewer/rest/iiif/manifests/1535113582549/manifest/'
  const id = await generateId(url)
  console.log(id)
</script>

CLI

Generating Allmaps IDs is also possible using the Allmaps CLI.

For example:

echo https://digital.zlb.de/viewer/api/v1/records/34231682/manifest/ | allmaps id

License

MIT

API

generateChecksum(obj, length)

Generates a checksum of a JSON object.

Parameters
  • obj (unknown)
    • JSON object.
  • length (number | undefined)
    • Length of returned hash. The maximum length of the hash is 40 characters.
Returns

First length characters of the SHA-1 hash of sorted and serialized version of obj (Promise<string>).

generateId(str, length)

Generates an ID from a string using the SHA-1 algorithm. Given the same input, the ID will always be the same.

Parameters
  • str (string)
    • Input string
  • length (number | undefined)
    • Length of returned hash. The maximum length of the hash is 40 characters. The default length is 16.
Returns

First length characters of the SHA-1 hash of str (Promise<string>).

generateRandomId(length)

Generates a random ID.

Parameters
  • length (number | undefined)
    • Length of returned hash. The maximum length of the hash is 40 characters.
Returns

First length characters of the SHA-1 hash of a random UUID (Promise<string>).

generateChecksum(obj, length)

Generates a checksum of a JSON object.

Parameters
  • obj (unknown)
    • JSON object.
  • length (number | undefined)
    • Length of returned hash. The maximum length of the hash is 40 characters.
Returns

First length characters of the SHA-1 hash of sorted and serialized version of obj (string).

generateId(str, length)

Generates an ID from a string using the SHA-1 algorithm. Given the same input, the ID will always be the same.

Parameters
  • str (string)
    • Input string
  • length (number | undefined)
    • Length of returned hash. The maximum length of the hash is 40 characters. The default length is 16.
Returns

First length characters of the SHA-1 hash of str (string).

generateRandomId(length)

Generates a random ID.

Parameters
  • length (number | undefined)
    • Length of returned hash. The maximum length of the hash is 40 characters.
Returns

First length characters of the SHA-1 hash of a random UUID (string).

版本与发布记录

@allmaps/id 共发布 48 个版本,首次发布于 2021/04/06;过去 12 个月发布了 4 个版本。

版本发布日期距今
1.0.0-beta.39latest2026/09/221 个月前
1.0.0-beta.382026/05/295 个月前
1.0.0-beta.372025/11/2711 个月前
1.0.0-beta.362025/11/1111 个月前
1.0.0-beta.352025/07/101.3 年前
1.0.0-beta.342025/07/071.3 年前

其他发布通道:beta → 1.0.0-beta.33。

关于 @allmaps/id 的常见问题

@allmaps/id 是什么?

IDs for Allmaps

如何安装 @allmaps/id?

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

@allmaps/id 支持 TypeScript 吗?

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

@allmaps/id 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@allmaps/id 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=v19.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@allmaps/id 可以商用吗?

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

@allmaps/id 的下载量有多少?

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

@allmaps/id 还在维护吗?

最新版本 1.0.0-beta.39 发布于 2026/09/22(1 个月前);至今共发布 48 个版本,其中过去 12 个月发布了 4 个;首次发布于 2021/04/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。