Skip to content

Commit 5c47c5f

Browse files
authored
chore(deps): remove validator lib (#1372)
| 🚥 Resolves https://github.com/readmeio/rdme/security/dependabot/46 | | :------------------- | ## 🧰 Changes the dependabot alert above is technically for a function we don't use, but in digging into this i realized we really don't need this `validator` library at all. decided to swap out the `isEmail` function for a li'l regex and call it a day 💨
1 parent 44bd9cc commit 5c47c5f

File tree

3 files changed

+12
-25
lines changed

3 files changed

+12
-25
lines changed

package-lock.json

Lines changed: 1 addition & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@
7676
"tmp-promise": "^3.0.3",
7777
"toposort": "^2.0.2",
7878
"undici": "^5.28.4",
79-
"unzipper": "^0.12.3",
80-
"validator": "^13.7.0"
79+
"unzipper": "^0.12.3"
8180
},
8281
"devDependencies": {
8382
"@biomejs/biome": "^2.1.4",
@@ -98,7 +97,6 @@
9897
"@types/semver": "^7.3.12",
9998
"@types/toposort": "^2.0.7",
10099
"@types/unzipper": "^0.10.11",
101-
"@types/validator": "^13.7.6",
102100
"@vitest/coverage-v8": "^3.0.0",
103101
"@vitest/expect": "^3.0.0",
104102
"alex": "^11.0.0",

src/lib/loginFlow.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Hook } from '@oclif/core';
22

33
import chalk from 'chalk';
4-
import isEmail from 'validator/lib/isEmail.js';
54

65
import configStore from './configstore.js';
76
import getCurrentConfig from './getCurrentConfig.js';
@@ -24,6 +23,14 @@ function loginFetch(body: LoginBody) {
2423
});
2524
}
2625

26+
function isEmail(value: string) {
27+
// Simple email regex sourced from https://emailregex.com/
28+
const emailRegex =
29+
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
30+
31+
return emailRegex.test(value);
32+
}
33+
2734
/**
2835
* The prompt flow for logging a user in and writing the credentials to
2936
* `configstore`. This is a separate lib function because we reuse it both
@@ -47,7 +54,7 @@ export default async function loginFlow(
4754
message: 'What is your email address?',
4855
initial: storedConfig.email,
4956
validate(val) {
50-
return isEmail.default(val) ? true : 'Please provide a valid email address.';
57+
return isEmail(val) ? true : 'Please provide a valid email address.';
5158
},
5259
},
5360
{
@@ -68,7 +75,7 @@ export default async function loginFlow(
6875
return Promise.reject(new Error('No project subdomain provided. Please use `--project`.'));
6976
}
7077

71-
if (!isEmail.default(email)) {
78+
if (!isEmail(email)) {
7279
return Promise.reject(new Error('You must provide a valid email address.'));
7380
}
7481

0 commit comments

Comments
 (0)