Skip to content

Str.Nat

Str / Nat

Import

typescript
import { Str } from '@wollybeard/kit'

// Access via namespace
Str.Nat.someFunction()
typescript
import * as Str from '@wollybeard/kit/str'

// Access via namespace
Str.Nat.someFunction()

Natural Language

[F] list

typescript
(items: string[]): string

Parameters:

  • items - Array of strings to format

Returns: Formatted list string

Format an array as an English list with commas and "or".

Examples:

typescript
Str
.Nat.list([]) // ''
Str
.Nat.list(['a']) // 'a'
Str
.Nat.list(['a', 'b']) // 'a or b'
Str
.Nat.list(['a', 'b', 'c']) // 'a, b, or c'

[F] ordinal

typescript
(n: number): string

Parameters:

  • n - Number to convert

Returns: Ordinal string (e.g., "1st", "2nd", "3rd", "21st")

Convert a number to its ordinal string representation.

Examples:

typescript
Str
.Nat.ordinal(1) // '1st'
Str
.Nat.ordinal(2) // '2nd'
Str
.Nat.ordinal(3) // '3rd'
Str
.Nat.ordinal(11) // '11th'
Str
.Nat.ordinal(21) // '21st'
Str
.Nat.ordinal(42) // '42nd'

[F] article

typescript
(word: string): "a" | "an"

Parameters:

  • word - Word to get article for

Returns: "a" or "an"

Determine the correct indefinite article ("a" or "an") for a word.

Examples:

typescript
Str
.Nat.article('apple') // 'an'
Str
.Nat.article('banana') // 'a'
Str
.Nat.article('hour') // 'an' (irregular)
Str
.Nat.article('unicorn') // 'a' (irregular)
Str
.Nat.article('university') // 'a' (irregular)

Other

[C] pluralize

typescript
{ (word: string, count?: number | undefined, inclusive?: boolean | undefined): string; plural(word: string): string; singular(word: string): string; addPluralRule(rule: Rule, replacement: string): void; addSingularRule(rule: Rule, replacement: string): void; addIrregularRule(single: string, plural: string): void; addUncountableRule(rule: Rule): void; isPlural(word: string): boolean; isSingular(word: string): boolean; }

[C] plural

typescript
;((word: string) => string)

[C] singular

typescript
;((word: string) => string)

[C] isPlural

typescript
;((word: string) => boolean)

[C] isSingular

typescript
;((word: string) => boolean)