From 04771a88c27899204df0dd8c6febcbbd45476c30 Mon Sep 17 00:00:00 2001 From: Tomas Zijdemans Date: Sun, 23 Aug 2026 20:05:09 +0200 Subject: [PATCH] feat(text): stabilize `truncate()` --- text/deno.json | 2 +- text/mod.ts | 1 + text/{unstable_truncate.ts => truncate.ts} | 10 ++++------ text/{unstable_truncate_test.ts => truncate_test.ts} | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) rename text/{unstable_truncate.ts => truncate.ts} (93%) rename text/{unstable_truncate_test.ts => truncate_test.ts} (98%) diff --git a/text/deno.json b/text/deno.json index 917a67dffff8..ee2304abb750 100644 --- a/text/deno.json +++ b/text/deno.json @@ -18,7 +18,7 @@ "./unstable-to-sentence-case": "./unstable_to_sentence_case.ts", "./to-snake-case": "./to_snake_case.ts", "./unstable-to-title-case": "./unstable_to_title_case.ts", - "./unstable-truncate": "./unstable_truncate.ts", + "./truncate": "./truncate.ts", "./word-similarity-sort": "./word_similarity_sort.ts" } } diff --git a/text/mod.ts b/text/mod.ts index f232dc488a8a..df07383d4653 100644 --- a/text/mod.ts +++ b/text/mod.ts @@ -27,3 +27,4 @@ export * from "./to_camel_case.ts"; export * from "./to_kebab_case.ts"; export * from "./to_pascal_case.ts"; export * from "./to_snake_case.ts"; +export * from "./truncate.ts"; diff --git a/text/unstable_truncate.ts b/text/truncate.ts similarity index 93% rename from text/unstable_truncate.ts rename to text/truncate.ts index 052ad95139fb..61017605a9db 100644 --- a/text/unstable_truncate.ts +++ b/text/truncate.ts @@ -31,8 +31,6 @@ export interface TruncateOptions { * Note: this function is not grapheme-cluster-aware. Combining characters, flag * emoji, and ZWJ sequences may still be visually split. * - * @experimental **UNSTABLE**: New API, yet to be vetted. - * * @param str The string to truncate. * @param maxLength The maximum length of the returned string (must be a * non-negative integer). @@ -43,7 +41,7 @@ export interface TruncateOptions { * * @example End truncation (default) * ```ts - * import { truncate } from "@std/text/unstable-truncate"; + * import { truncate } from "@std/text/truncate"; * import { assertEquals } from "@std/assert"; * * assertEquals(truncate("Hello, world!", 8), "Hello, …"); @@ -52,7 +50,7 @@ export interface TruncateOptions { * * @example Middle truncation * ```ts - * import { truncate } from "@std/text/unstable-truncate"; + * import { truncate } from "@std/text/truncate"; * import { assertEquals } from "@std/assert"; * * assertEquals( @@ -63,7 +61,7 @@ export interface TruncateOptions { * * @example Start truncation * ```ts - * import { truncate } from "@std/text/unstable-truncate"; + * import { truncate } from "@std/text/truncate"; * import { assertEquals } from "@std/assert"; * * assertEquals( @@ -74,7 +72,7 @@ export interface TruncateOptions { * * @example Custom suffix * ```ts - * import { truncate } from "@std/text/unstable-truncate"; + * import { truncate } from "@std/text/truncate"; * import { assertEquals } from "@std/assert"; * * assertEquals( diff --git a/text/unstable_truncate_test.ts b/text/truncate_test.ts similarity index 98% rename from text/unstable_truncate_test.ts rename to text/truncate_test.ts index 1d6a3c379def..bab61fe1e1c8 100644 --- a/text/unstable_truncate_test.ts +++ b/text/truncate_test.ts @@ -1,7 +1,7 @@ // Copyright 2018-2026 the Deno authors. MIT license. import { assertEquals } from "@std/assert/equals"; import { assertThrows } from "@std/assert/throws"; -import { truncate } from "./unstable_truncate.ts"; +import { truncate } from "./truncate.ts"; Deno.test("truncate() returns empty string when maxLength is zero", () => { assertEquals(truncate("hello", 0), "");