From dea4e5137157697cee0452df0f3ad9b899d8d6e7 Mon Sep 17 00:00:00 2001 From: Sky020 <2397860h@student.gla.ac.uk> Date: Thu, 10 Sep 2020 12:47:27 +0100 Subject: [PATCH] fix(client): remove unused formHelper functions --- client/src/components/formHelpers/index.js | 56 ---------------------- 1 file changed, 56 deletions(-) diff --git a/client/src/components/formHelpers/index.js b/client/src/components/formHelpers/index.js index 13c1d7ae72..79dfd0540a 100644 --- a/client/src/components/formHelpers/index.js +++ b/client/src/components/formHelpers/index.js @@ -1,5 +1,4 @@ import normalizeUrl from 'normalize-url'; -import isURL from 'validator/lib/isURL'; export { default as BlockSaveButton } from './BlockSaveButton.js'; export { default as BlockSaveWrapper } from './BlockSaveWrapper.js'; @@ -9,10 +8,6 @@ export { default as FormFields } from './FormFields.js'; const normalizeOptions = { stripWWW: false }; -// callIfDefined(fn: (Any) => Any) => (value: Any) => Any -export function callIfDefined(fn) { - return value => (value ? fn(value) : value); -} export function formatUrlValues(values, options) { return Object.keys(values).reduce((result, key) => { @@ -23,54 +18,3 @@ export function formatUrlValues(values, options) { return { ...result, [key]: value }; }, {}); } -// formatUrl(url: String) => String -export function formatUrl(url) { - if (typeof url === 'string' && url.length > 4 && url.indexOf('.') !== -1) { - // prevent trailing / from being stripped during typing - let lastChar = ''; - if (url.substring(url.length - 1) === '/') { - lastChar = '/'; - } - // prevent normalize-url from stripping last dot during typing - if (url.substring(url.length - 1) === '.') { - lastChar = '.'; - } - return normalizeUrl(url, normalizeOptions) + lastChar; - } - return url; -} -export function isValidURL(data) { - /* eslint-disable camelcase */ - return isURL(data, { require_protocol: true }); - /* eslint-enable camelcase */ -} -export function makeOptional(validator) { - return val => (val ? validator(val) : true); -} -export function makeRequired(validator) { - return val => (val ? validator(val) : false); -} -export function createFormValidator(fieldValidators) { - const fieldKeys = Object.keys(fieldValidators); - return values => - fieldKeys - .map(field => { - if (fieldValidators[field](values[field])) { - return null; - } - return { [field]: !fieldValidators[field](values[field]) }; - }) - .filter(Boolean) - .reduce((errors, error) => ({ ...errors, ...error }), {}); -} -export function getValidationState(field) { - if (field.pristine) { - return null; - } - - if (/https?:\/\/glitch\.com\/edit\/#!\/.*/g.test(field.value)) { - return 'glitch-warning'; - } - - return field.error ? 'error' : 'success'; -}