All files / text / unstable_to_sentence_case.ts

100.00% Branches 0/0
100.00% Lines 6/6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
 
x2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
x2
x2
x2
 
x14
x14




































// Copyright 2018-2025 the Deno authors. MIT license.
// This module is browser compatible.
import { resolveOptions, titleCaseSegment } from "./_title_case_util.ts";
import type { BaseTitleCaseOptions } from "./_title_case_util.ts";
export type { BaseTitleCaseOptions };

/** Options for {@linkcode toSentenceCase} */
export interface SentenceCaseOptions extends BaseTitleCaseOptions {}

/**
 * Converts a string into Sentence Case.
 *
 * > [!NOTE]
 * > This function preserves punctuation and does not insert spaces or other
 * > characters where none exist in the input (e.g. it doesn't split up
 * > `camelCase` words). This is in contrast to some other `to{X}Case`
 * > functions, such as `toSnakeCase`.
 *
 * @experimental **UNSTABLE**: New API, yet to be vetted.
 *
 * @param input The string that is going to be converted into Sentence Case
 * @param options Optional settings to customize the conversion
 * @returns The string as Sentence Case
 *
 * @example Usage
 * ```ts
 * import { toSentenceCase } from "@std/text/unstable-to-sentence-case";
 * import { assertEquals } from "@std/assert/equals";
 *
 * assertEquals(toSentenceCase("deno is awesome"), "Deno is awesome");
 * ```
 */
export function toSentenceCase(
  input: string,
  options?: SentenceCaseOptions,
): string {
  return titleCaseSegment(input, resolveOptions(options));
}