From f086823e6d5ea4d3b70bbaa27a44c89bd577b16c Mon Sep 17 00:00:00 2001
From: Anca Ursachi <anca.ursachi@thinslices.com>
Date: Mon, 3 Dec 2018 12:39:05 +0200
Subject: [PATCH] refactor(Utils.js(component-faraday-ui)): Move password
 validators functions to Utils.js from compon

---
 .../src/PasswordConfirmation.js               |  2 +-
 packages/component-faraday-ui/src/Utils.js    | 76 +++++++++++++++++++
 .../src/components/utils.js                   | 76 -------------------
 3 files changed, 77 insertions(+), 77 deletions(-)
 create mode 100644 packages/component-faraday-ui/src/Utils.js

diff --git a/packages/component-faraday-ui/src/PasswordConfirmation.js b/packages/component-faraday-ui/src/PasswordConfirmation.js
index 44eef64e6..9bd7fcbd7 100644
--- a/packages/component-faraday-ui/src/PasswordConfirmation.js
+++ b/packages/component-faraday-ui/src/PasswordConfirmation.js
@@ -14,7 +14,7 @@ import {
   atLeastOneUppercase,
   atLeastOneLowerrcase,
   atLeastOnePunctuation,
-} from '../../components-faraday/src/components/utils'
+} from './Utils.js'
 
 const PasswordField = input => <TextField {...input} type="password" />
 
diff --git a/packages/component-faraday-ui/src/Utils.js b/packages/component-faraday-ui/src/Utils.js
new file mode 100644
index 000000000..704a4daf3
--- /dev/null
+++ b/packages/component-faraday-ui/src/Utils.js
@@ -0,0 +1,76 @@
+export const minLength = (value, min) => !!(value && value.length >= min)
+
+export const atLeastOneUppercase = value => {
+  const uppercaseRegex = new RegExp(/([A-Z])+/)
+  return uppercaseRegex.test(value)
+}
+export const atLeastOneLowerrcase = value => {
+  const lowercaseRegex = new RegExp(/([a-z])+/)
+  return lowercaseRegex.test(value)
+}
+export const atLeastOneDigit = value => {
+  const digitRegex = new RegExp(/([0-9])+/)
+  return digitRegex.test(value)
+}
+export const atLeastOnePunctuation = value => {
+  const punctuationRegex = new RegExp(/([,'!@#$%^&*=(){}[\]<>?/\\|.:;_-])+/)
+  return punctuationRegex.test(value)
+}
+
+export const passwordValidator = values => {
+  const errors = {}
+  const { password, confirmPassword } = values
+
+  if (
+    !(
+      minLength(password, 6) &&
+      atLeastOneUppercase(password) &&
+      atLeastOneLowerrcase(password) &&
+      atLeastOnePunctuation(password) &&
+      atLeastOneDigit(password)
+    )
+  ) {
+    errors.password = 'Password criteria not met'
+  }
+  if (!password) {
+    errors.password = 'Required'
+  }
+  if (!confirmPassword) {
+    errors.confirmPassword = 'Required'
+  } else if (confirmPassword !== password) {
+    errors.confirmPassword = "Passwords don't match."
+  }
+
+  return errors
+}
+
+export const changePasswordValidator = values => {
+  const {
+    currentPassword = '',
+    confirmNewPassword = '',
+    password = '',
+  } = values
+  const errors = {}
+  if (
+    !(
+      minLength(password, 6) &&
+      atLeastOneUppercase(password) &&
+      atLeastOneLowerrcase(password) &&
+      atLeastOnePunctuation(password) &&
+      atLeastOneDigit(password)
+    )
+  ) {
+    errors.password = 'Password criteria not met'
+  }
+  if (!currentPassword) {
+    errors.currentPassword = 'Required'
+  }
+
+  if (!password) {
+    errors.password = 'Required'
+  } else if (password !== confirmNewPassword) {
+    errors.confirmNewPassword = "Passwords don't match."
+  }
+
+  return errors
+}
diff --git a/packages/components-faraday/src/components/utils.js b/packages/components-faraday/src/components/utils.js
index 5ec731314..6ca28eae7 100644
--- a/packages/components-faraday/src/components/utils.js
+++ b/packages/components-faraday/src/components/utils.js
@@ -101,82 +101,6 @@ export const redirectToError = redirectFn => err => {
     errorText || 'Something went wrong. Please try again.',
   )
 }
-export const minLength = (value, min) => !!(value && value.length >= min)
-export const atLeastOneUppercase = value => {
-  const uppercaseRegex = new RegExp(/([A-Z])+/)
-  return uppercaseRegex.test(value)
-}
-export const atLeastOneLowerrcase = value => {
-  const lowercaseRegex = new RegExp(/([a-z])+/)
-  return lowercaseRegex.test(value)
-}
-export const atLeastOneDigit = value => {
-  const digitRegex = new RegExp(/([0-9])+/)
-  return digitRegex.test(value)
-}
-export const atLeastOnePunctuation = value => {
-  const punctuationRegex = new RegExp(/([,'!@#$%^&*=(){}[\]<>?/\\|.:;_-])+/)
-  return punctuationRegex.test(value)
-}
-
-export const passwordValidator = values => {
-  const errors = {}
-  const { password, confirmPassword } = values
-
-  if (
-    !(
-      minLength(password, 6) &&
-      atLeastOneUppercase(password) &&
-      atLeastOneLowerrcase(password) &&
-      atLeastOnePunctuation(password) &&
-      atLeastOneDigit(password)
-    )
-  ) {
-    errors.password = 'Password criteria not met'
-  }
-  if (!password) {
-    errors.password = 'Required'
-  }
-  if (!confirmPassword) {
-    errors.confirmPassword = 'Required'
-  } else if (confirmPassword !== password) {
-    errors.confirmPassword = "Passwords don't match."
-  }
-
-  return errors
-}
-
-export const changePasswordValidator = values => {
-  const {
-    currentPassword = '',
-    confirmNewPassword = '',
-    password = '',
-  } = values
-  const errors = {}
-  if (
-    !(
-      minLength(password, 6) &&
-      atLeastOneUppercase(password) &&
-      atLeastOneLowerrcase(password) &&
-      atLeastOnePunctuation(password) &&
-      atLeastOneDigit(password)
-    )
-  ) {
-    errors.password = 'Password criteria not met'
-  }
-  if (!currentPassword) {
-    errors.currentPassword = 'Required'
-  }
-
-  if (!password) {
-    errors.password = 'Required'
-  } else if (password !== confirmNewPassword) {
-    errors.confirmNewPassword = "Passwords don't match."
-  }
-
-  return errors
-}
-
 export const parseSearchParams = url => {
   const params = new URLSearchParams(url)
   const parsedObject = {}
-- 
GitLab