Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final code #6

Merged
merged 18 commits into from
Feb 19, 2024
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dist/
node_modules/
node_modules/
8 changes: 2 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{
"env": {
"browser": true,
"es2021": true
"es2015": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
Expand Down
78 changes: 78 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Deploy to Github Pages

on:
pull_request:
branches:
- main
push:
branches:
- develop

permissions:
contents: read
pages: write
id-token: write

jobs:
lint_and_test:
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v4

- name: Install Node versions
uses: actions/setup-node@v4
with:
node-version: 18
cache: "npm"

- name: Install
run: npm i

- name: Linter
run: npm run linter

- name: Test
run: npm run test

build_and_deploy:
runs-on: ubuntu-latest
needs: lint_and_test

environment:
name: github-pages
url: ${{steps.deployment.outputs.page_url}}

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 18
cache: "npm"

- run: npm i

- name: Configure GH pages
uses: actions/configure-pages@v3

- name: Tailwind
run: npm run design

- name: Compile TS to JS
run: npm run compile

- name: Copy index.html in dist folder
run: cp index.html ./dist/

- name: Copy font to dist
run: cp -r ./public/font ./dist/public/font

- name: Uploading Artifacts
uses: actions/upload-pages-artifact@v2
with:
path: ./dist/

- name: Deploy to GH pages
uses: actions/deploy-pages@v1
id: deployment
6 changes: 4 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Password Generator</title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="dist/output.css" />
<!--<link rel="stylesheet" href="dist/output.css" /> Dev -->
<link rel="stylesheet" href="public/output.css" />
</head>
<body class="flex h-full w-full items-center bg-darkBalticSea">
<main class="flex h-5/6 w-full flex-col items-center justify-center">
Expand Down Expand Up @@ -141,6 +142,7 @@
</div>
</form>
</main>
<script type="module" src="/dist/index.js"></script>
<!--<script type="module" src="/dist/index.js"></script> Dev-->
<script type="module" src="index.js"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"scripts": {
"dev:compile": "tsc --watch",
"dev:design": "npx tailwindcss -i ./public/style/tailwind.css -o ./dist/output.css --watch",
"dev:design": "npx tailwindcss -i ./public/style/tailwind.css -o ./dist/public/output.css --watch",
"dev:formater": "prettier --write .",
"compile": "tsc",
"design": "npx tailwindcss -i ./public/style/tailwind.css -o ./dist/output.css",
"linter": "eslint --ignore-path .eslintignore --ext .js .",
"design": "npx tailwindcss -i ./public/style/tailwind.css -o ./dist/public/output.css",
"linter": "eslint --ignore-path .eslintignore --ext .ts .",
"test": "vitest"
},
"devDependencies": {
Expand Down
14 changes: 12 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Password generator
# "Password Generator"

Lien du figma en description de la carte trello.
## About the project

This application allows users to generate random passwords. These are generated based on the criteria selected by the users: lowercase, uppercase, numbers, and symbols. The password can be copied/pasted via an icon. The generator also indicates the strength of the password according to levels: 'too weak', 'weak', 'medium', and 'strong'.

## Objectives

Creation of a password generator working with JavaScript, modules, and unit tests. The design is implemented using the Tailwind framework.

## Coding Technologies Used

<img src="https://skillicons.dev/icons?i=git,html,css,tailwind,js"/>
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { clipboardText } from "./utils/clipboardText.js";
import { countCheckedInputs } from "./utils/countCheckedInputs.js";
import { calculatePasswordStrength } from "./utils/calculatePasswordStrength.js";
import { currentLength } from "./utils/currentLength.js";
import { generatePassword } from "./utils/generatePassword.js";
import { strengthLevel } from "./utils/strengthLevel.js";
Expand All @@ -24,7 +24,6 @@ const handleSubmit = () => {
const passwordLength = document.querySelector(
"#password-length",
) as HTMLInputElement;
const allCheckbox = document.querySelectorAll(".input_checkbox");

if (form) {
form.addEventListener("submit", (e) => {
Expand All @@ -45,7 +44,7 @@ const handleSubmit = () => {
);
displayPassword.innerHTML = password;
clipboardText(password);
const count = countCheckedInputs(password);
const count = calculatePasswordStrength(password);
strengthLevel(count);
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/type/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export type InputType = {
length: Number;
length: number;
hasLowerCase: boolean;
hasUpperCase: boolean;
hasNumbers: boolean;
Expand Down
24 changes: 24 additions & 0 deletions src/utils/calculatePasswordStrength.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, it, expect } from "vitest";
import { calculatePasswordStrength } from "./calculatePasswordStrength";

describe("strengthLevel Unit Test Suite", () => {
it("should return something", () => {
expect(calculatePasswordStrength("gqgcgfznlx")).toBeDefined();
});
it("should return 1", () => {
expect(calculatePasswordStrength("gqgcgfznlx")).toBe(1);
expect(calculatePasswordStrength("HTQYSTCKNF")).toBe(1);
expect(calculatePasswordStrength("8628445976")).toBe(1);
expect(calculatePasswordStrength("^)^&^!^&*)")).toBe(1);
});

it("should return 2", () => {
expect(calculatePasswordStrength("MdampZhLLe")).toBe(2);
});
it("should return 3", () => {
expect(calculatePasswordStrength("wg6BPPYq0t")).toBe(3);
});
it("should return 4", () => {
expect(calculatePasswordStrength("&E!@Zr8iyv")).toBe(4);
});
});
10 changes: 10 additions & 0 deletions src/utils/calculatePasswordStrength.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const calculatePasswordStrength = (password: string): number => {
let count = 0;

if (password.match(/[a-z]+/)) count += 1;
if (password.match(/[A-Z]+/)) count += 1;
if (password.match(/[0-9]+/)) count += 1;
if (password.match(/[!@#$%^&*()]+/)) count += 1;

return count;
};
29 changes: 0 additions & 29 deletions src/utils/countCheckedInputs.spec.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/utils/countCheckedInputs.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"strict": true,
"noImplicitAny": true,
},
"include": ["src", "dist/index.js"],
"include": ["src"],
"exclude": ["node_modules/", "src/**/*.spec.ts"],
}
Loading