mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-11-17 05:18:33 +05:30
utils: moving unquote function to utlis (string)
This commit is contained in:
parent
863f7d05fa
commit
3d243665f3
1 changed files with 13 additions and 0 deletions
|
|
@ -46,3 +46,16 @@ export function reverseString(input: string): string {
|
|||
export function containsOnlyDigits(input: string): boolean {
|
||||
return /^\d+(\.\d+)?$/.test(input.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* unquote a string if properly quoted.
|
||||
* @param value - The string to unquote.
|
||||
* @param quoteCharacter - The character used for quoting (e.g., '"', "'").
|
||||
* @returns The unquoted string if it was quoted, otherwise the original string.
|
||||
*/
|
||||
export function unquoteIfQuoted(value: string, quoteCharacter: string): string {
|
||||
if (value.startsWith(quoteCharacter) && value.endsWith(quoteCharacter)) {
|
||||
return value.slice(1, -1); // Remove first and last character
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue