-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from zoontek/0.5.0
0.5.0
- Loading branch information
Showing
8 changed files
with
1,089 additions
and
1,069 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,24 +7,23 @@ const nodeEnv: Validator<"development" | "test" | "production"> = (value) => { | |
} | ||
}; | ||
|
||
const email: Validator<string> = (value) => { | ||
const email: Validator<string> = (value = "") => { | ||
if (/.+@.+\..+/.test(value)) { | ||
return value; | ||
} | ||
}; | ||
|
||
const url: Validator<string> = (value) => { | ||
const url: Validator<URL> = (value = "") => { | ||
try { | ||
new URL(value); | ||
return value; | ||
} catch (_error) {} // eslint-disable-line no-empty | ||
return new URL(value); | ||
} catch {} // eslint-disable-line no-empty | ||
}; | ||
|
||
const port: Validator<number> = (value) => { | ||
const parsed = parseInt(value); | ||
const port: Validator<number> = (value = "") => { | ||
const number = Number.parseInt(value); | ||
|
||
if (parsed > 0 && parsed < 65536) { | ||
return parsed; | ||
if (number > 0 && number < 65536) { | ||
return number; | ||
} | ||
}; | ||
|
||
|
@@ -46,17 +45,19 @@ test("with valid input", () => { | |
}, | ||
}); | ||
|
||
expect(output).toEqual({ | ||
expect(output).toStrictEqual({ | ||
NODE_ENV: "test", | ||
USER_EMAIL: "[email protected]", | ||
SERVER_URL: "https://github.com", | ||
SERVER_URL: new URL("https://github.com"), | ||
SERVER_PORT: 3000, | ||
}); | ||
}); | ||
|
||
test("with invalid input", () => { | ||
const input = { | ||
NODE_ENV: "staging", | ||
USER_EMAIL: "mathieu", | ||
SERVER_URL: "youtube", | ||
SERVER_PORT: "three thousand", | ||
}; | ||
|
||
|
@@ -74,21 +75,14 @@ test("with invalid input", () => { | |
expect(error).toBeInstanceOf(EnvValidationError); | ||
|
||
expect((error as EnvValidationError).message).toBe( | ||
[ | ||
"Some environment variables cannot be validated", | ||
"Invalid variables: NODE_ENV, SERVER_PORT", | ||
"Missing variables: USER_EMAIL, SERVER_URL", | ||
].join("\n"), | ||
"Some environment variables cannot be validated: NODE_ENV, USER_EMAIL, SERVER_URL, SERVER_PORT", | ||
); | ||
|
||
expect((error as EnvValidationError).invalidVariables).toEqual([ | ||
expect((error as EnvValidationError).variables).toStrictEqual([ | ||
"NODE_ENV", | ||
"SERVER_PORT", | ||
]); | ||
|
||
expect((error as EnvValidationError).missingVariables).toEqual([ | ||
"USER_EMAIL", | ||
"SERVER_URL", | ||
"SERVER_PORT", | ||
]); | ||
} | ||
}); | ||
|
@@ -107,13 +101,13 @@ test("with invalid overrides", () => { | |
SERVER_PORT: port, | ||
}, | ||
overrides: { | ||
SERVER_URL: "", | ||
SERVER_URL: new URL("https://github.com"), | ||
SERVER_PORT: 0, | ||
}, | ||
}); | ||
|
||
expect(output).toEqual({ | ||
SERVER_URL: "", | ||
expect(output).toStrictEqual({ | ||
SERVER_URL: new URL("https://github.com"), | ||
SERVER_PORT: 0, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"name": "valienv", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"license": "MIT", | ||
"description": "A simple environment variables validator for Node.js and web browsers.", | ||
"description": "A simple environment variables validator for Node.js, web browsers and React Native", | ||
"author": "Mathieu Acthernoene <[email protected]>", | ||
"homepage": "https://github.com/zoontek/valienv#readme", | ||
"repository": { | ||
|
@@ -44,14 +44,14 @@ | |
"trailingComma": "all" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.15.10", | ||
"@typescript-eslint/eslint-plugin": "^5.56.0", | ||
"@typescript-eslint/parser": "^5.56.0", | ||
"eslint": "^8.36.0", | ||
"@types/node": "^20.2.5", | ||
"@typescript-eslint/eslint-plugin": "^5.59.9", | ||
"@typescript-eslint/parser": "^5.59.9", | ||
"eslint": "^8.42.0", | ||
"microbundle": "^0.15.1", | ||
"prettier": "^2.8.7", | ||
"prettier": "^2.8.8", | ||
"prettier-plugin-organize-imports": "^3.2.2", | ||
"typescript": "^5.0.2", | ||
"vitest": "^0.29.7" | ||
"typescript": "^5.1.3", | ||
"vitest": "^0.32.0" | ||
} | ||
} |
Oops, something went wrong.