-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Prettifier, Convert class to namespace, Improve showcase website,…
… Improve JSDocs
- Loading branch information
1 parent
fe06009
commit 604d170
Showing
12 changed files
with
240 additions
and
216 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": true, | ||
"printWidth": 160 | ||
} |
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,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); | ||
} | ||
} |
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,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> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,5 +1,5 @@ | ||
{ | ||
"name": "@rabbit-company/password-entropy", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"exports": "./src/password-entropy.ts" | ||
} |
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,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 {}; |
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,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 | ||
}; |
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,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" | ||
} | ||
} |
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,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> |
Oops, something went wrong.