1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【TypeScript】Deno標準の「@std/uuid」でuuid v7を生成してみる

1
Posted at

概要

Cloudflare Workers環境でuuid v7を使いたい場合、npm:uuidを使うという方法が挙げられると思います。ただ、公式としてCloudflare Workers環境での動作を保証しているわけではなさそうです。
他に良さそうな選択肢ないかなと少し探してみたところ、Deno標準の@std/uuidがCloudflare Workers環境で動作確認できているようでした。ので、今回これを試してみました。
なお、DenoでのユニークID(UUIDを含む) サンプル集の記事ではuuid v7は「unstable」のようですが、2026年4月現在ではunstableは外れています。

前提

  • 使用した@std/uuidのバージョンは1.1.0です。
  • Cloudflare Workersのローカルテスト環境(wrangler)で動作確認しています。

前準備

npx jsr add @std/uuidで、パッケージにライブラリを追加します。

実装サンプル

以下でuuid v7の文字列を生成できます。

import { generate as generateV7 } from "@std/uuid/v7";

// uuid v7の文字列を生成
console.log(generateV7());

uuidの文字列から、生成時のエポックタイムを取得することも可能です。

import { extractTimestamp } from "@std/uuid/v7";

// uuid v7の文字列から生成時のエポックタイムを取得
console.log(extractTimestamp(uuidStr));
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?