Skip to content

Commit 506567f

Browse files
committed
Converted from class to namespace, Add JSDocs to namespace, Add prettifier, Improve showcase website
1 parent 2a97645 commit 506567f

12 files changed

Lines changed: 190 additions & 166 deletions

.prettierrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"tabWidth": 2,
3+
"useTabs": true,
4+
"printWidth": 160
5+
}

build.ts

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
1-
import dts from 'bun-plugin-dts';
2-
import Logger from '@rabbit-company/logger';
3-
import fs from 'fs/promises';
1+
import dts from "bun-plugin-dts";
2+
import Logger from "@rabbit-company/logger";
3+
import fs from "fs/promises";
44

5-
await fs.rm('./module', {recursive: true, force: true});
6-
await fs.rm('./dist', {recursive: true, force: true});
5+
await fs.rm("./module", { recursive: true, force: true });
6+
await fs.rm("./dist", { recursive: true, force: true });
77

8-
Logger.info('Start bulding module...');
8+
Logger.info("Start bulding module...");
99
let moduleBuild = await Bun.build({
10-
entrypoints: ['./src/password-generator.ts'],
11-
outdir: './module',
12-
target: 'browser',
13-
format: 'esm',
14-
plugins: [
15-
dts({output: {noBanner: true}})
16-
],
10+
entrypoints: ["./src/password-generator.ts"],
11+
outdir: "./module",
12+
target: "browser",
13+
format: "esm",
14+
plugins: [dts({ output: { noBanner: true } })],
1715
});
1816

19-
if(moduleBuild.success){
20-
Logger.info('Bulding module complete');
21-
}else{
22-
Logger.error('Bulding module failed');
17+
if (moduleBuild.success) {
18+
Logger.info("Bulding module complete");
19+
} else {
20+
Logger.error("Bulding module failed");
2321
}
2422

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

27-
Logger.info('Start bundling dist...');
25+
Logger.info("Start bundling dist...");
2826
let distBuild = await Bun.build({
29-
entrypoints: ['./src/index.ts'],
30-
outdir: './dist',
31-
target: 'browser',
32-
format: 'esm',
27+
entrypoints: ["./src/index.ts"],
28+
outdir: "./dist",
29+
target: "browser",
30+
format: "esm",
3331
minify: true,
34-
sourcemap: 'none', // Bun still generates incorrect sourcemaps
35-
plugins: [],
32+
sourcemap: "none",
33+
plugins: [],
3634
});
3735

38-
if(distBuild.success){
39-
Logger.info('Bundling dist complete');
40-
}else{
41-
Logger.error('Bundling dist failed');
36+
if (distBuild.success) {
37+
Logger.info("Bundling dist complete");
38+
} else {
39+
Logger.error("Bundling dist failed");
4240
Logger.error(distBuild.logs);
43-
}
41+
}

bun.lockb

-298 Bytes
Binary file not shown.

dist/index.html

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
4-
<title>PasswordGenerator-JS</title>
5-
</head>
6-
<body>
7-
<h1><a href="https://github.com/Rabbit-Company/PasswordGenerator-JS" target="_blank">PasswordGenerator-JS</a></h1>
3+
<head>
4+
<title>PasswordGenerator-JS</title>
5+
</head>
6+
<body>
7+
<h1><a href="https://github.com/Rabbit-Company/PasswordGenerator-JS" target="_blank">PasswordGenerator-JS</a></h1>
88

9-
<input type="checkbox" id="upperCase" checked />
10-
<label>Uppercase</label></br>
9+
<input type="checkbox" id="upperCase" checked />
10+
<label for="upperCase">Uppercase</label><br />
1111

12-
<input type="checkbox" id="numbers" checked />
13-
<label>Numbers</label></br>
12+
<input type="checkbox" id="numbers" checked />
13+
<label for="numbers">Numbers</label><br />
1414

15-
<input type="checkbox" id="symbols" checked />
16-
<label>Symbols</label></br></br>
15+
<input type="checkbox" id="symbols" checked />
16+
<label for="symbols">Symbols</label><br /><br />
1717

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

21-
<button id="generate">Generate</button>
21+
<button id="generate">Generate</button>
2222

23-
<p>Password: <b id="result"></b></p>
23+
<p>Password: <b id="result"></b></p>
2424

25-
<h1>Performance Test</h1>
26-
<div>
27-
<label>Number of executions:</label>
28-
<input id="amount" type="number" min="1" max="100000" placeholder="Amount" value="1000" />
29-
<button id="btn-start">Start</button>
30-
</div>
31-
<p id="perf"></p>
25+
<h1>Performance Test</h1>
26+
<div>
27+
<label for="amount">Number of executions:</label>
28+
<input id="amount" type="number" min="1" max="100000" placeholder="Amount" value="1000" />
29+
<button id="btn-start">Start</button>
30+
</div>
31+
<p id="perf"></p>
3232

33-
<script type="module" src="index.js"></script>
34-
</body>
35-
</html>
33+
<script type="module" src="index.js"></script>
34+
</body>
35+
</html>

dist/index.js

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

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name": "@rabbit-company/password-generator",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"exports": "./src/password-generator.ts"
55
}

module/password-generator.d.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,56 @@
1-
export default class PasswordGenerator {
1+
/**
2+
* The `PasswordGenerator` namespace provides utilities for generating random, secure passwords.
3+
*
4+
* Developers can customize the characters used for generating passwords by modifying
5+
* the properties `lcase`, `ucase`, `numb`, and `symbols`.
6+
*/
7+
declare namespace PasswordGenerator {
28
/**
39
* Lowercase letters used for password generation. Developers can customize this string.
410
* Default: "abcdefghijklmnopqrstuvwxyz".
511
* @type {string}
6-
*/
7-
static lcase: string;
12+
*/
13+
let lcase: string;
814
/**
915
* Uppercase letters used for password generation. Developers can customize this string.
1016
* Default: "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
1117
* @type {string}
12-
*/
13-
static ucase: string;
18+
*/
19+
let ucase: string;
1420
/**
1521
* Numbers used for password generation. Developers can customize this string.
1622
* Default: "1234567890".
1723
* @type {string}
18-
*/
19-
static numb: string;
24+
*/
25+
let numb: string;
2026
/**
2127
* Symbols used for password generation. Developers can customize this string.
2228
* Default: "!@#$%?&*".
2329
* @type {string}
24-
*/
25-
static symbols: string;
30+
*/
31+
let symbols: string;
2632
/**
2733
* Generates a cryptographically secure random number within a specified range.
2834
*
2935
* @param {number} [min=0] - The minimum value of the range (inclusive).
3036
* @param {number} [max=100] - The maximum value of the range (exclusive).
3137
* @returns {number} A random number within the specified range.
32-
*/
33-
static randRange(min?: number, max?: number): number;
38+
*/
39+
function randRange(min?: number, max?: number): number;
3440
/**
3541
* Generates a random password based on specified criteria.
3642
*
37-
* @param {number} [length=10] - The length of the password.
43+
* @param {number} [length=20] - The length of the password.
3844
* @param {boolean} [upperCase=true] - Include uppercase letters in the password.
3945
* @param {boolean} [numbers=true] - Include numbers in the password.
4046
* @param {boolean} [specials=true] - Include special characters in the password.
4147
* @returns {string} The generated password.
42-
*/
43-
static generate(length?: number, upperCase?: boolean, numbers?: boolean, specials?: boolean): string;
48+
*/
49+
function generate(length?: number, upperCase?: boolean, numbers?: boolean, specials?: boolean): string;
4450
}
4551

52+
export {
53+
PasswordGenerator as default,
54+
};
55+
4656
export {};

module/password-generator.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// src/password-generator.ts
2-
class PasswordGenerator {
3-
static lcase = "abcdefghijklmnopqrstuvwxyz";
4-
static ucase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
5-
static numb = "1234567890";
6-
static symbols = "!@#$%?&*";
7-
static randRange(min = 0, max = 100) {
2+
var PasswordGenerator;
3+
((PasswordGenerator) => {
4+
PasswordGenerator.lcase = "abcdefghijklmnopqrstuvwxyz";
5+
PasswordGenerator.ucase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
6+
PasswordGenerator.numb = "1234567890";
7+
PasswordGenerator.symbols = "!@#$%?&*";
8+
function randRange(min = 0, max = 100) {
89
var range = max - min;
910
var requestBytes = Math.ceil(Math.log2(range) / 8);
1011
if (!requestBytes)
@@ -20,31 +21,34 @@ class PasswordGenerator {
2021
return min + val % range;
2122
}
2223
}
23-
static generate(length = 20, upperCase = true, numbers = true, specials = true) {
24+
PasswordGenerator.randRange = randRange;
25+
function generate(length = 20, upperCase = true, numbers = true, specials = true) {
2426
let password = [];
2527
for (let i = 0;i < length; i++)
26-
password.push(this.lcase.charAt(this.randRange(0, this.lcase.length)));
28+
password.push(PasswordGenerator.lcase.charAt(randRange(0, PasswordGenerator.lcase.length)));
2729
if (upperCase) {
28-
let ucase_amount = this.randRange(1, Math.floor(length / 2) + 1);
30+
let ucase_amount = randRange(1, Math.floor(length / 2) + 1);
2931
for (let i = 0;i < ucase_amount; i++) {
30-
password[this.randRange(0, password.length)] = this.ucase.charAt(this.randRange(0, this.ucase.length));
32+
password[randRange(0, password.length)] = PasswordGenerator.ucase.charAt(randRange(0, PasswordGenerator.ucase.length));
3133
}
3234
}
3335
if (numbers) {
34-
let numbers_amount = this.randRange(1, Math.floor(length / 2) + 1);
36+
let numbers_amount = randRange(1, Math.floor(length / 2) + 1);
3537
for (let i = 0;i < numbers_amount; i++) {
36-
password[this.randRange(0, password.length)] = this.numb.charAt(this.randRange(0, this.numb.length));
38+
password[randRange(0, password.length)] = PasswordGenerator.numb.charAt(randRange(0, PasswordGenerator.numb.length));
3739
}
3840
}
3941
if (specials) {
40-
let specials_amount = this.randRange(1, 3);
42+
let specials_amount = randRange(1, 3);
4143
for (let i = 0;i < specials_amount; i++) {
42-
password[this.randRange(0, password.length)] = this.symbols.charAt(this.randRange(0, this.symbols.length));
44+
password[randRange(0, password.length)] = PasswordGenerator.symbols.charAt(randRange(0, PasswordGenerator.symbols.length));
4345
}
4446
}
4547
return password.join("");
4648
}
47-
}
49+
PasswordGenerator.generate = generate;
50+
})(PasswordGenerator ||= {});
51+
var password_generator_default = PasswordGenerator;
4852
export {
49-
PasswordGenerator as default
53+
password_generator_default as default
5054
};

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rabbit-company/password-generator",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "Password generator",
55
"main": "./module/password-generator.js",
66
"browser": "./module/password-generator.js",
@@ -34,12 +34,12 @@
3434
"security",
3535
"strength"
3636
],
37-
"devDependencies": {
38-
"@types/bun": "latest",
39-
"bun-plugin-dts": "^0.2.1",
40-
"@rabbit-company/logger": "^2.1.1"
41-
},
42-
"peerDependencies": {
43-
"typescript": "^5.0.0"
44-
}
45-
}
37+
"devDependencies": {
38+
"@types/bun": "latest",
39+
"bun-plugin-dts": "^0.2.3",
40+
"@rabbit-company/logger": "^3.1.0"
41+
},
42+
"peerDependencies": {
43+
"typescript": "^5.0.0"
44+
}
45+
}

src/index.html

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
4-
<title>PasswordGenerator-JS</title>
5-
</head>
6-
<body>
7-
<h1><a href="https://github.com/Rabbit-Company/PasswordGenerator-JS" target="_blank">PasswordGenerator-JS</a></h1>
3+
<head>
4+
<title>PasswordGenerator-JS</title>
5+
</head>
6+
<body>
7+
<h1><a href="https://github.com/Rabbit-Company/PasswordGenerator-JS" target="_blank">PasswordGenerator-JS</a></h1>
88

9-
<input type="checkbox" id="upperCase" checked />
10-
<label>Uppercase</label></br>
9+
<input type="checkbox" id="upperCase" checked />
10+
<label for="upperCase">Uppercase</label><br />
1111

12-
<input type="checkbox" id="numbers" checked />
13-
<label>Numbers</label></br>
12+
<input type="checkbox" id="numbers" checked />
13+
<label for="numbers">Numbers</label><br />
1414

15-
<input type="checkbox" id="symbols" checked />
16-
<label>Symbols</label></br></br>
15+
<input type="checkbox" id="symbols" checked />
16+
<label for="symbols">Symbols</label><br /><br />
1717

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

21-
<button id="generate">Generate</button>
21+
<button id="generate">Generate</button>
2222

23-
<p>Password: <b id="result"></b></p>
23+
<p>Password: <b id="result"></b></p>
2424

25-
<h1>Performance Test</h1>
26-
<div>
27-
<label>Number of executions:</label>
28-
<input id="amount" type="number" min="1" max="100000" placeholder="Amount" value="1000" />
29-
<button id="btn-start">Start</button>
30-
</div>
31-
<p id="perf"></p>
25+
<h1>Performance Test</h1>
26+
<div>
27+
<label for="amount">Number of executions:</label>
28+
<input id="amount" type="number" min="1" max="100000" placeholder="Amount" value="1000" />
29+
<button id="btn-start">Start</button>
30+
</div>
31+
<p id="perf"></p>
3232

33-
<script type="module" src="index.js"></script>
34-
</body>
35-
</html>
33+
<script type="module" src="index.js"></script>
34+
</body>
35+
</html>

0 commit comments

Comments
 (0)