Skip to content

@kaelyx/ts-kit / string / fullstop

Function: fullstop() ​

fullstop(input, options?): string

Defined in: string/fullstop/fullstop.ts:29

Ensures that the input string ends with a full stop (period).

Parameters ​

input ​

string

Takes a string, considered to be a sentence, and ensure it ends in a fullstop (period). Use the options to customize the behaviour.

options? ​

FullstopOptions

Optional. See FullstopOptions.

Returns ​

string

The string with the punctuation added at the end.

Example ​

ts
fullstop('hello') // 'hello.'
fullstop('hello!') // 'hello.'
fullstop('What?!') // 'What.'
fullstop('What?!', { collapse: false }) // 'What?.'
fullstop('hello   ') // 'hello.'
fullstop('hello   ', { trim: false }) // 'hello   .'
fullstop('') // ''
fullstop('', { skipEmpty: false }) // '.'
fullstop('a list;', { replacementCharacters: [';'] }) // 'a list.'

Types ​

FullstopOptions interface ​

Defined in: string/fullstop/fullstop.types.ts:5

Options for fullstop.

Properties ​

collapse? ​

readonly optional collapse?: boolean

Defined in: string/fullstop/fullstop.types.ts:12

Treat a run of replacement characters as one: "What?!" -> "What."


replacementCharacters? ​

readonly optional replacementCharacters?: readonly string[]

Defined in: string/fullstop/fullstop.types.ts:8

The characters that should be replaced when found at the end. Defaults to ., ! and ?.


skipEmpty? ​

readonly optional skipEmpty?: boolean

Defined in: string/fullstop/fullstop.types.ts:14

Leave a string with no content alone instead of returning bare punctuation.


trim? ​

readonly optional trim?: boolean

Defined in: string/fullstop/fullstop.types.ts:10

Strip trailing whitespace before deciding, and drop it from the result.