Skip to content

Commit

Permalink
Add Prettifier, Convert class to namespace, Improve showcase website,…
Browse files Browse the repository at this point in the history
… Improve JSDocs
  • Loading branch information
zigazajc007 committed Aug 11, 2024
1 parent fe06009 commit 604d170
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 216 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-entropy.ts'],
outdir: './module',
target: 'browser',
format: 'esm',
plugins: [
dts({output: {noBanner: true}})
],
entrypoints: ["./src/password-entropy.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", // Bun still generates incorrect sourcemaps
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.
34 changes: 17 additions & 17 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>PasswordEntropy-JS</title>
</head>
<body>
<h1><a href="https://github.com/Rabbit-Company/PasswordEntropy-JS" target="_blank">PasswordEntropy-JS</a></h1>
<head>
<title>PasswordEntropy-JS</title>
</head>
<body>
<h1><a href="https://github.com/Rabbit-Company/PasswordEntropy-JS" target="_blank">PasswordEntropy-JS</a></h1>

<input id="password" type="password" placeholder="Password" />
<p>Your password entropy is <b id="result">0</b>.</p>
<input id="password" type="password" placeholder="Password" />
<p>Your password entropy is <b id="result">0</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-entropy",
"version": "2.0.1",
"version": "2.1.0",
"exports": "./src/password-entropy.ts"
}
74 changes: 40 additions & 34 deletions module/password-entropy.d.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,49 @@
/**
* PasswordEntropy class provides methods for calculating password entropy.
*/
export default class PasswordEntropy {
* The `PasswordEntropy` namespace provides methods for calculating the entropy of a password.
*
* Developers can customize the character sets used for entropy calculation by modifying
* the properties `lcase`, `ucase`, `numb`, and `symbol`.
*/
declare namespace PasswordEntropy {
/**
* Lowercase letters: "abcdefghijklmnopqrstuvwxyz".
* @type {string}
*/
static lcase: string;
* Lowercase letters used in password entropy calculation. Developers can customize this string.
* Default: "abcdefghijklmnopqrstuvwxyz".
* @type {string}
*/
let lcase: string;
/**
* Uppercase letters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
* @type {string}
*/
static ucase: string;
* Uppercase letters used in password entropy calculation. Developers can customize this string.
* Default: "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
* @type {string}
*/
let ucase: string;
/**
* Numbers: "1234567890".
* @type {string}
*/
static numb: string;
* Numbers used in password entropy calculation. Developers can customize this string.
* Default: "1234567890".
* @type {string}
*/
let numb: string;
/**
* Symbols: "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ".
* @type {string}
*/
static symbol: string;
* Symbols used in password entropy calculation. Developers can customize this string.
* Default: "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ".
* @type {string}
*/
let symbol: string;
/**
* Checks if the given text includes any character from the provided character list.
*
* @private
* @param {string} text - The text to check.
* @param {string} charlist - The character list to check against.
* @returns {boolean} True if the text includes any character from the character list, false otherwise.
*/
private static _includesChar;
/**
* Calculates the entropy of a given password.
*
* @param {string} password - The password for which to calculate entropy.
* @returns {number} The calculated password entropy.
*/
static calculate(password: string): number;
* Calculates the entropy of a given password.
*
* @param {string} password - The password for which to calculate entropy.
* @returns {number} The calculated password entropy.
*
* @example
* const entropy = PasswordEntropy.calculate("P@ssw0rd");
* console.log(entropy); // Outputs the entropy value for the given password
*/
function calculate(password: string): number;
}

export {
PasswordEntropy as default,
};

export {};
39 changes: 21 additions & 18 deletions module/password-entropy.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
// src/password-entropy.ts
class PasswordEntropy {
static lcase = "abcdefghijklmnopqrstuvwxyz";
static ucase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static numb = "1234567890";
static symbol = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ";
static _includesChar(text, charlist) {
var PasswordEntropy;
((PasswordEntropy) => {
PasswordEntropy.lcase = "abcdefghijklmnopqrstuvwxyz";
PasswordEntropy.ucase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
PasswordEntropy.numb = "1234567890";
PasswordEntropy.symbol = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ";
function _includesChar(text, charlist) {
for (let i = 0;i < text.length; i++) {
if (charlist.includes(text[i]))
return true;
}
return false;
}
static calculate(password) {
function calculate(password) {
if (typeof password !== "string")
return 0;
let pool = 0;
if (this._includesChar(password, this.lcase))
pool += 26;
if (this._includesChar(password, this.ucase))
pool += 26;
if (this._includesChar(password, this.numb))
pool += 10;
if (this._includesChar(password, this.symbol))
pool += 33;
if (!this._includesChar(password, this.lcase + this.ucase + this.numb + this.symbol))
if (_includesChar(password, PasswordEntropy.lcase))
pool += PasswordEntropy.lcase.length;
if (_includesChar(password, PasswordEntropy.ucase))
pool += PasswordEntropy.ucase.length;
if (_includesChar(password, PasswordEntropy.numb))
pool += PasswordEntropy.numb.length;
if (_includesChar(password, PasswordEntropy.symbol))
pool += PasswordEntropy.symbol.length;
if (!_includesChar(password, PasswordEntropy.lcase + PasswordEntropy.ucase + PasswordEntropy.numb + PasswordEntropy.symbol))
pool += 100;
if (pool == 0)
return 0;
return Math.round(password.length * Math.log(pool) / Math.LN2);
}
}
PasswordEntropy.calculate = calculate;
})(PasswordEntropy ||= {});
var password_entropy_default = PasswordEntropy;
export {
PasswordEntropy as default
password_entropy_default as default
};
82 changes: 41 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
{
"name": "@rabbit-company/password-entropy",
"version": "2.0.1",
"description": "Password entropy calculator",
"main": "./module/password-entropy.js",
"name": "@rabbit-company/password-entropy",
"version": "2.1.0",
"description": "Password entropy calculator",
"main": "./module/password-entropy.js",
"browser": "./module/password-entropy.js",
"type": "module",
"homepage": "https://github.com/Rabbit-Company/PasswordEntropy-JS",
"funding": "https://rabbit-company.com/donation",
"author": "Rabbit Company <info@rabbit-company.com>",
"license": "MIT",
"private": false,
"scripts": {
"build": "bun run build.ts"
},
"files": [
"type": "module",
"homepage": "https://github.com/Rabbit-Company/PasswordEntropy-JS",
"funding": "https://rabbit-company.com/donation",
"author": "Rabbit Company <info@rabbit-company.com>",
"license": "MIT",
"private": false,
"scripts": {
"build": "bun run build.ts"
},
"files": [
"module/password-entropy.js",
"module/password-entropy.d.ts"
],
"repository": {
"type": "git",
"url": "git+https://github.com/Rabbit-Company/PasswordEntropy-JS.git"
},
"contributors": [
"Rabbit Company <info@rabbit-company.com> (https://github.com/Rabbit-Company)"
],
"bugs": {
"url": "https://github.com/Rabbit-Company/PasswordEntropy-JS/issues",
"email": "info@rabbit-company.com"
},
"keywords": [
"password",
"entropy",
"security",
"strength"
],
"devDependencies": {
"@types/bun": "latest",
"bun-plugin-dts": "^0.2.1",
"@rabbit-company/logger": "^2.1.1"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}
],
"repository": {
"type": "git",
"url": "git+https://github.com/Rabbit-Company/PasswordEntropy-JS.git"
},
"contributors": [
"Rabbit Company <info@rabbit-company.com> (https://github.com/Rabbit-Company)"
],
"bugs": {
"url": "https://github.com/Rabbit-Company/PasswordEntropy-JS/issues",
"email": "info@rabbit-company.com"
},
"keywords": [
"password",
"entropy",
"security",
"strength"
],
"devDependencies": {
"@types/bun": "latest",
"bun-plugin-dts": "^0.2.3",
"@rabbit-company/logger": "^3.1.0"
},
"peerDependencies": {
"typescript": "^5.0.0"
}
}
34 changes: 17 additions & 17 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>PasswordEntropy-JS</title>
</head>
<body>
<h1><a href="https://github.com/Rabbit-Company/PasswordEntropy-JS" target="_blank">PasswordEntropy-JS</a></h1>
<head>
<title>PasswordEntropy-JS</title>
</head>
<body>
<h1><a href="https://github.com/Rabbit-Company/PasswordEntropy-JS" target="_blank">PasswordEntropy-JS</a></h1>

<input id="password" type="password" placeholder="Password" />
<p>Your password entropy is <b id="result">0</b>.</p>
<input id="password" type="password" placeholder="Password" />
<p>Your password entropy is <b id="result">0</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 604d170

Please sign in to comment.