From ab213dd0a1e51699aae492f8b546e4a311fcb97d Mon Sep 17 00:00:00 2001 From: Vijay Raghavan Aravamudhan Date: Sun, 15 Aug 2021 08:35:57 +0000 Subject: Initial plumbing and conversion of a simple javascript to typescript (#1790) * initial conversion of a simple script * Moved some of the 'gulp' and related npm modules from being runtime dependencies to development dependencies. --- src/helpers/url-helpers.js | 36 ------------------------------------ src/helpers/url-helpers.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 36 deletions(-) delete mode 100644 src/helpers/url-helpers.js create mode 100644 src/helpers/url-helpers.ts (limited to 'src/helpers') diff --git a/src/helpers/url-helpers.js b/src/helpers/url-helpers.js deleted file mode 100644 index b0dc9afbb..000000000 --- a/src/helpers/url-helpers.js +++ /dev/null @@ -1,36 +0,0 @@ -// This is taken from: https://benjamin-altpeter.de/shell-openexternal-dangers/ - -import { URL } from 'url'; -import { ensureDirSync } from 'fs-extra'; -import { shell } from 'electron'; - -import { ALLOWED_PROTOCOLS } from '../config'; - -const debug = require('debug')('Ferdi:Helpers:url'); - -export function isValidExternalURL(url) { - let parsedUrl; - try { - parsedUrl = new URL(url); - } catch (_) { - return false; - } - - const isAllowed = ALLOWED_PROTOCOLS.includes(parsedUrl.protocol); - - debug('protocol check is', isAllowed, 'for:', url); - - return isAllowed; -} - -export async function openPath(folderName) { - ensureDirSync(folderName); - shell.openPath(folderName); -} - -// TODO: Need to verify and fix/remove the skipping logic. Ideally, we should never skip this check -export function openExternalUrl(url, skipValidityCheck = false) { - if (skipValidityCheck || isValidExternalURL(url)) { - shell.openExternal(url); - } -} diff --git a/src/helpers/url-helpers.ts b/src/helpers/url-helpers.ts new file mode 100644 index 000000000..23e8fab29 --- /dev/null +++ b/src/helpers/url-helpers.ts @@ -0,0 +1,36 @@ +// This is taken from: https://benjamin-altpeter.de/shell-openexternal-dangers/ + +import { URL } from 'url'; +import { ensureDirSync } from 'fs-extra'; +import { shell } from 'electron'; + +import { ALLOWED_PROTOCOLS } from '../config'; + +const debug = require('debug')('Ferdi:Helpers:url'); + +export function isValidExternalURL(url: string) { + let parsedUrl: URL; + try { + parsedUrl = new URL(url); + } catch (_) { + return false; + } + + const isAllowed = ALLOWED_PROTOCOLS.includes(parsedUrl.protocol); + + debug('protocol check is', isAllowed, 'for:', url); + + return isAllowed; +} + +export async function openPath(folderName: string) { + ensureDirSync(folderName); + shell.openPath(folderName); +} + +// TODO: Need to verify and fix/remove the skipping logic. Ideally, we should never skip this check +export function openExternalUrl(url: string, skipValidityCheck: boolean = false) { + if (skipValidityCheck || isValidExternalURL(url)) { + shell.openExternal(url); + } +} -- cgit v1.2.3-54-g00ecf