/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
client/lib/url/decode-utils.ts
39 строк
1 KB
Jarda Snajdr
Fix more jsdoc/tag-lines ESLint errors (#84148)
13 ноя 2023, 17:56
Не верифицирован
13 ноя 2023, 17:56
89432e7
Код
Авторство
О чём код?
import { Falsy } from 'utility-types'; interface Stringable { toString: () => string; } function decodeIfValid( encodedItem: Stringable | Falsy, decodingFunction: ( item: string ) => string ) { const encodedURIString: string = encodedItem && encodedItem.toString ? encodedItem.toString() : ''; try { return decodingFunction( encodedURIString ); } catch ( e ) { return encodedURIString; } } /** * Wrap decodeURI in a try / catch block to prevent `URIError` on invalid input * Passing a non-string value will return an empty string. * @param encodedURI URI to attempt to decode * @returns Decoded URI (or passed in value on error) */ export function decodeURIIfValid( encodedURI: Stringable | Falsy ): string { return decodeIfValid( encodedURI, decodeURI ); } /** * Wrap decodeURIComponent in a try / catch block to prevent `URIError` on invalid input * Passing a non-string value will return an empty string. * @param encodedURIComponent URI component to attempt to decode * @returns Decoded URI component (or passed in value on error) */ export function decodeURIComponentIfValid( encodedURIComponent: Stringable | Falsy ): string { return decodeIfValid( encodedURIComponent, decodeURIComponent ); }