Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Commit

Permalink
perf: remove unused validate func
Browse files Browse the repository at this point in the history
  • Loading branch information
Haoran committed Apr 14, 2021
1 parent c94cc84 commit 79b08e8
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 45 deletions.
32 changes: 1 addition & 31 deletions utils/index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,3 @@
import isEmail from 'validator/es/lib/isEmail'
import DOMPurify from 'dompurify'

/**
* Validate user input
* @param {String} input the user input string
* @param {Object} [config] the validate configuration
* @param {Boolean} config.email check if the input is email
* @param {Number|Boolean} config.length check if the input exceed certain length
* @returns {{error: Boolean, message: String, data: String}} error ? message : data
*/
function validateInput(input, { email = false, length = false }) {
// @returns {{error: Boolean, message: String, data: String}}
input = input.trim()

if (input == '') {
return { error: true, message: "input can't be empty or only spaces" }
} else if (length && length < input.length) {
return { error: true, message: `input length exceeded, max: ${length}` }
}

if (email) {
return isEmail(input)
? { error: false, data: input }
: { error: true, message: "the email address isn't correct" }
} else {
return { error: false, data: DOMPurify.sanitize(input) }
}
}

/**
* Get current date in yyyy-mm-dd format
*
Expand All @@ -39,4 +9,4 @@ function getCurrentYmd() {
return new Date().toISOString().slice(0, 10)
}

export { validateInput, getCurrentYmd }
export { getCurrentYmd }
5 changes: 1 addition & 4 deletions utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@
"author": "Haoran Sun",
"license": "MIT",
"private": true,
"dependencies": {
"dompurify": "^2.2.7",
"validator": "^13.5.2"
}
"dependencies": {}
}
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1562,11 +1562,6 @@ domhandler@^2.3.0:
dependencies:
domelementtype "1"

dompurify@^2.2.7:
version "2.2.7"
resolved "https://registry.npmjs.org/dompurify/-/dompurify-2.2.7.tgz#a5f055a2a471638680e779bd08fc334962d11fd8"
integrity sha512-jdtDffdGNY+C76jvodNTu9jt5yYj59vuTUyx+wXdzcSwAGTYZDAQkQ7Iwx9zcGrA4ixC1syU4H3RZROqRxokxg==

domutils@^1.5.1:
version "1.7.0"
resolved "https://registry.npmjs.org/domutils/-/domutils-1.7.0.tgz#56ea341e834e06e6748af7a1cb25da67ea9f8c2a"
Expand Down Expand Up @@ -4533,11 +4528,6 @@ validate-npm-package-license@^3.0.1:
spdx-correct "^3.0.0"
spdx-expression-parse "^3.0.0"

validator@^13.5.2:
version "13.5.2"
resolved "https://registry.npmjs.org/validator/-/validator-13.5.2.tgz#c97ae63ed4224999fb6f42c91eaca9567fe69a46"
integrity sha512-mD45p0rvHVBlY2Zuy3F3ESIe1h5X58GPfAtslBjY7EtTqGquZTj+VX/J4RnHWN8FKq0C9WRVt1oWAcytWRuYLQ==

vary@^1, vary@~1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
Expand Down

0 comments on commit 79b08e8

Please sign in to comment.