Skip to content

@kaelyx/ts-kit / string / questionmark

Function: questionmark() ​

questionmark(input, options?): string

Defined in: string/questionmark/questionmark.ts:27

Ensures that the input string ends with a question mark.

Parameters ​

input ​

string

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

options? ​

QuestionmarkOptions

Optional. See QuestionmarkOptions.

Returns ​

string

The string with the punctuation added at the end.

Example ​

ts
questionmark('are you sure') // 'are you sure?'
questionmark('are you sure.') // 'are you sure?'
questionmark('really!.') // 'really?'
questionmark('really!.', { collapse: false }) // 'really!?'
questionmark('are you sure   ', { trim: false }) // 'are you sure   ?'
questionmark('', { skipEmpty: false }) // '?'
questionmark('really:', { replacementCharacters: [':'] }) // 'really?'

Types ​

QuestionmarkOptions interface ​

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

Options for questionmark.

Properties ​

collapse? ​

readonly optional collapse?: boolean

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

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


replacementCharacters? ​

readonly optional replacementCharacters?: readonly string[]

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

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


trim? ​

readonly optional trim?: boolean

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

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