Skip to content

@kaelyx/ts-kit / string / exclamationmark

Function: exclamationmark() ​

exclamationmark(input, options?): string

Defined in: string/exclamationmark/exclamationmark.ts:26

Ensures that the input string ends with an exclamation mark.

Parameters ​

input ​

string

Takes a string, considered to be a sentence, and ensures it ends in an exclamation mark. Use the options to customize the behaviour.

options? ​

ExclamationmarkOptions

Optional. See ExclamationmarkOptions.

Returns ​

string

The string with the punctuation added at the end.

Example ​

ts
exclamationmark('watch out') // 'watch out!'
exclamationmark('watch out.') // 'watch out!'
exclamationmark('no way?.') // 'no way!'
exclamationmark('no way?.', { collapse: false }) // 'no way?!'
exclamationmark('watch out   ', { trim: false }) // 'watch out   !'
exclamationmark('', { skipEmpty: false }) // '!'

Types ​

ExclamationmarkOptions interface ​

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

Options for exclamationmark.

Properties ​

collapse? ​

readonly optional collapse?: boolean

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

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


replacementCharacters? ​

readonly optional replacementCharacters?: readonly string[]

Defined in: string/exclamationmark/exclamationmark.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/exclamationmark/exclamationmark.types.ts:14

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


trim? ​

readonly optional trim?: boolean

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

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