Skip to content

Commit

Permalink
Converted from class to namespace, Add JSDocs to namespace, Add prett…
Browse files Browse the repository at this point in the history
…ifier, Improve showcase website
  • Loading branch information
zigazajc007 committed Aug 11, 2024
1 parent 2a97645 commit 506567f
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 166 deletions.
5 changes: 5 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 2,
"useTabs": true,
"printWidth": 160
}
58 changes: 28 additions & 30 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
import dts from 'bun-plugin-dts';
import Logger from '@rabbit-company/logger';
import fs from 'fs/promises';
import dts from "bun-plugin-dts";
import Logger from "@rabbit-company/logger";
import fs from "fs/promises";

await fs.rm('./module', {recursive: true, force: true});
await fs.rm('./dist', {recursive: true, force: true});
await fs.rm("./module", { recursive: true, force: true });
await fs.rm("./dist", { recursive: true, force: true });

Logger.info('Start bulding module...');
Logger.info("Start bulding module...");
let moduleBuild = await Bun.build({
entrypoints: ['./src/password-generator.ts'],
outdir: './module',
target: 'browser',
format: 'esm',
plugins: [
dts({output: {noBanner: true}})
],
entrypoints: ["./src/password-generator.ts"],
outdir: "./module",
target: "browser",
format: "esm",
plugins: [dts({ output: { noBanner: true } })],
});

if(moduleBuild.success){
Logger.info('Bulding module complete');
}else{
Logger.error('Bulding module failed');
if (moduleBuild.success) {
Logger.info("Bulding module complete");
} else {
Logger.error("Bulding module failed");
}

fs.cp('./src/index.html', './dist/index.html', {recursive: true, force: true});
fs.cp("./src/index.html", "./dist/index.html", { recursive: true, force: true });

Logger.info('Start bundling dist...');
Logger.info("Start bundling dist...");
let distBuild = await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist',
target: 'browser',
format: 'esm',
entrypoints: ["./src/index.ts"],
outdir: "./dist",
target: "browser",
format: "esm",
minify: true,
sourcemap: 'none', // Bun still generates incorrect sourcemaps
plugins: [],
sourcemap: "none",
plugins: [],
});

if(distBuild.success){
Logger.info('Bundling dist complete');
}else{
Logger.error('Bundling dist failed');
if (distBuild.success) {
Logger.info("Bundling dist complete");
} else {
Logger.error("Bundling dist failed");
Logger.error(distBuild.logs);
}
}
Binary file modified bun.lockb
Binary file not shown.
50 changes: 25 additions & 25 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<title>PasswordGenerator-JS</title>
</head>
<body>
<h1><a href="https://github.com/Rabbit-Company/PasswordGenerator-JS" target="_blank">PasswordGenerator-JS</a></h1>
<head>
<title>PasswordGenerator-JS</title>
</head>
<body>
<h1><a href="https://github.com/Rabbit-Company/PasswordGenerator-JS" target="_blank">PasswordGenerator-JS</a></h1>

<input type="checkbox" id="upperCase" checked />
<label>Uppercase</label></br>
<input type="checkbox" id="upperCase" checked />
<label for="upperCase">Uppercase</label><br />

<input type="checkbox" id="numbers" checked />
<label>Numbers</label></br>
<input type="checkbox" id="numbers" checked />
<label for="numbers">Numbers</label><br />

<input type="checkbox" id="symbols" checked />
<label>Symbols</label></br></br>
<input type="checkbox" id="symbols" checked />
<label for="symbols">Symbols</label><br /><br />

<label>Length: </label>
<input id="length" type="range" min="8" max="50" value="20" placeholder="Length" /><label id="label-length">20</label></br></br>
<label for="length">Length: </label>
<input id="length" type="range" min="8" max="50" value="20" placeholder="Length" /><label id="label-length">20</label><br /><br />

<button id="generate">Generate</button>
<button id="generate">Generate</button>

<p>Password: <b id="result"></b></p>
<p>Password: <b id="result"></b></p>

<h1>Performance Test</h1>
<div>
<label>Number of executions:</label>
<input id="amount" type="number" min="1" max="100000" placeholder="Amount" value="1000" />
<button id="btn-start">Start</button>
</div>
<p id="perf"></p>
<h1>Performance Test</h1>
<div>
<label for="amount">Number of executions:</label>
<input id="amount" type="number" min="1" max="100000" placeholder="Amount" value="1000" />
<button id="btn-start">Start</button>
</div>
<p id="perf"></p>

<script type="module" src="index.js"></script>
</body>
</html>
<script type="module" src="index.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@rabbit-company/password-generator",
"version": "2.0.1",
"version": "2.1.0",
"exports": "./src/password-generator.ts"
}
38 changes: 24 additions & 14 deletions module/password-generator.d.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,56 @@
export default class PasswordGenerator {
/**
* The `PasswordGenerator` namespace provides utilities for generating random, secure passwords.
*
* Developers can customize the characters used for generating passwords by modifying
* the properties `lcase`, `ucase`, `numb`, and `symbols`.
*/
declare namespace PasswordGenerator {
/**
* Lowercase letters used for password generation. Developers can customize this string.
* Default: "abcdefghijklmnopqrstuvwxyz".
* @type {string}
*/
static lcase: string;
*/
let lcase: string;
/**
* Uppercase letters used for password generation. Developers can customize this string.
* Default: "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
* @type {string}
*/
static ucase: string;
*/
let ucase: string;
/**
* Numbers used for password generation. Developers can customize this string.
* Default: "1234567890".
* @type {string}
*/
static numb: string;
*/
let numb: string;
/**
* Symbols used for password generation. Developers can customize this string.
* Default: "!@#$%?&*".
* @type {string}
*/
static symbols: string;
*/
let symbols: string;
/**
* Generates a cryptographically secure random number within a specified range.
*
* @param {number} [min=0] - The minimum value of the range (inclusive).
* @param {number} [max=100] - The maximum value of the range (exclusive).
* @returns {number} A random number within the specified range.
*/
static randRange(min?: number, max?: number): number;
*/
function randRange(min?: number, max?: number): number;
/**
* Generates a random password based on specified criteria.
*
* @param {number} [length=10] - The length of the password.
* @param {number} [length=20] - The length of the password.
* @param {boolean} [upperCase=true] - Include uppercase letters in the password.
* @param {boolean} [numbers=true] - Include numbers in the password.
* @param {boolean} [specials=true] - Include special characters in the password.
* @returns {string} The generated password.
*/
static generate(length?: number, upperCase?: boolean, numbers?: boolean, specials?: boolean): string;
*/
function generate(length?: number, upperCase?: boolean, numbers?: boolean, specials?: boolean): string;
}

export {
PasswordGenerator as default,
};

export {};
36 changes: 20 additions & 16 deletions module/password-generator.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// src/password-generator.ts
class PasswordGenerator {
static lcase = "abcdefghijklmnopqrstuvwxyz";
static ucase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static numb = "1234567890";
static symbols = "!@#$%?&*";
static randRange(min = 0, max = 100) {
var PasswordGenerator;
((PasswordGenerator) => {
PasswordGenerator.lcase = "abcdefghijklmnopqrstuvwxyz";
PasswordGenerator.ucase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
PasswordGenerator.numb = "1234567890";
PasswordGenerator.symbols = "!@#$%?&*";
function randRange(min = 0, max = 100) {
var range = max - min;
var requestBytes = Math.ceil(Math.log2(range) / 8);
if (!requestBytes)
Expand All @@ -20,31 +21,34 @@ class PasswordGenerator {
return min + val % range;
}
}
static generate(length = 20, upperCase = true, numbers = true, specials = true) {
PasswordGenerator.randRange = randRange;
function generate(length = 20, upperCase = true, numbers = true, specials = true) {
let password = [];
for (let i = 0;i < length; i++)
password.push(this.lcase.charAt(this.randRange(0, this.lcase.length)));
password.push(PasswordGenerator.lcase.charAt(randRange(0, PasswordGenerator.lcase.length)));
if (upperCase) {
let ucase_amount = this.randRange(1, Math.floor(length / 2) + 1);
let ucase_amount = randRange(1, Math.floor(length / 2) + 1);
for (let i = 0;i < ucase_amount; i++) {
password[this.randRange(0, password.length)] = this.ucase.charAt(this.randRange(0, this.ucase.length));
password[randRange(0, password.length)] = PasswordGenerator.ucase.charAt(randRange(0, PasswordGenerator.ucase.length));
}
}
if (numbers) {
let numbers_amount = this.randRange(1, Math.floor(length / 2) + 1);
let numbers_amount = randRange(1, Math.floor(length / 2) + 1);
for (let i = 0;i < numbers_amount; i++) {
password[this.randRange(0, password.length)] = this.numb.charAt(this.randRange(0, this.numb.length));
password[randRange(0, password.length)] = PasswordGenerator.numb.charAt(randRange(0, PasswordGenerator.numb.length));
}
}
if (specials) {
let specials_amount = this.randRange(1, 3);
let specials_amount = randRange(1, 3);
for (let i = 0;i < specials_amount; i++) {
password[this.randRange(0, password.length)] = this.symbols.charAt(this.randRange(0, this.symbols.length));
password[randRange(0, password.length)] = PasswordGenerator.symbols.charAt(randRange(0, PasswordGenerator.symbols.length));
}
}
return password.join("");
}
}
PasswordGenerator.generate = generate;
})(PasswordGenerator ||= {});
var password_generator_default = PasswordGenerator;
export {
PasswordGenerator as default
password_generator_default as default
};
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rabbit-company/password-generator",
"version": "2.0.1",
"version": "2.1.0",
"description": "Password generator",
"main": "./module/password-generator.js",
"browser": "./module/password-generator.js",
Expand Down Expand Up @@ -34,12 +34,12 @@
"security",
"strength"
],
"devDependencies": {
"@types/bun": "latest",
"bun-plugin-dts": "^0.2.1",
"@rabbit-company/logger": "^2.1.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}
"devDependencies": {
"@types/bun": "latest",
"bun-plugin-dts": "^0.2.3",
"@rabbit-company/logger": "^3.1.0"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}
50 changes: 25 additions & 25 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<!DOCTYPE html>
<html>
<head>
<title>PasswordGenerator-JS</title>
</head>
<body>
<h1><a href="https://github.com/Rabbit-Company/PasswordGenerator-JS" target="_blank">PasswordGenerator-JS</a></h1>
<head>
<title>PasswordGenerator-JS</title>
</head>
<body>
<h1><a href="https://github.com/Rabbit-Company/PasswordGenerator-JS" target="_blank">PasswordGenerator-JS</a></h1>

<input type="checkbox" id="upperCase" checked />
<label>Uppercase</label></br>
<input type="checkbox" id="upperCase" checked />
<label for="upperCase">Uppercase</label><br />

<input type="checkbox" id="numbers" checked />
<label>Numbers</label></br>
<input type="checkbox" id="numbers" checked />
<label for="numbers">Numbers</label><br />

<input type="checkbox" id="symbols" checked />
<label>Symbols</label></br></br>
<input type="checkbox" id="symbols" checked />
<label for="symbols">Symbols</label><br /><br />

<label>Length: </label>
<input id="length" type="range" min="8" max="50" value="20" placeholder="Length" /><label id="label-length">20</label></br></br>
<label for="length">Length: </label>
<input id="length" type="range" min="8" max="50" value="20" placeholder="Length" /><label id="label-length">20</label><br /><br />

<button id="generate">Generate</button>
<button id="generate">Generate</button>

<p>Password: <b id="result"></b></p>
<p>Password: <b id="result"></b></p>

<h1>Performance Test</h1>
<div>
<label>Number of executions:</label>
<input id="amount" type="number" min="1" max="100000" placeholder="Amount" value="1000" />
<button id="btn-start">Start</button>
</div>
<p id="perf"></p>
<h1>Performance Test</h1>
<div>
<label for="amount">Number of executions:</label>
<input id="amount" type="number" min="1" max="100000" placeholder="Amount" value="1000" />
<button id="btn-start">Start</button>
</div>
<p id="perf"></p>

<script type="module" src="index.js"></script>
</body>
</html>
<script type="module" src="index.js"></script>
</body>
</html>
Loading

0 comments on commit 506567f

Please sign in to comment.