mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-11-17 18:44:02 +01:00
utils: moving unquote function to utlis (string)
This commit is contained in:
@@ -46,3 +46,16 @@ export function reverseString(input: string): string {
|
|||||||
export function containsOnlyDigits(input: string): boolean {
|
export function containsOnlyDigits(input: string): boolean {
|
||||||
return /^\d+(\.\d+)?$/.test(input.trim());
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user