@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?
Optional. See QuestionmarkOptions.
Returns
string
The string with the punctuation added at the end.
Example
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?
readonlyoptionalcollapse?:boolean
Defined in: string/questionmark/questionmark.types.ts:12
Treat a run of replacement characters as one: "What.!" -> "What?"
replacementCharacters?
readonlyoptionalreplacementCharacters?: readonlystring[]
Defined in: string/questionmark/questionmark.types.ts:8
The characters that should be replaced when found at the end. Defaults to ., ! and ?.
skipEmpty?
readonlyoptionalskipEmpty?:boolean
Defined in: string/questionmark/questionmark.types.ts:14
Leave a string with no content alone instead of returning bare punctuation.
trim?
readonlyoptionaltrim?:boolean
Defined in: string/questionmark/questionmark.types.ts:10
Strip trailing whitespace before deciding, and drop it from the result.