Skip to content

Commit

Permalink
docs: version 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kabeep committed Jan 17, 2025
1 parent 9f3f017 commit 4c95910
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 49 deletions.
6 changes: 3 additions & 3 deletions docs/Exception.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h4 class="name" id="Exception"><span class="type-signature"></span>new Exceptio

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line326">line 326</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line385">line 385</a>
</li></ul></dd>


Expand Down Expand Up @@ -289,7 +289,7 @@ <h4 class="name" id="toString"><span class="type-signature"></span>toString<span

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line333">line 333</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line392">line 392</a>
</li></ul></dd>


Expand Down Expand Up @@ -396,7 +396,7 @@ <h5 class="h5-returns">Returns:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Jan 09 2025 06:46:26 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Jan 17 2025 19:14:51 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
10 changes: 5 additions & 5 deletions docs/PaletteError.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h4 class="name" id="PaletteError"><span class="type-signature"></span>new Palet

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line69">line 69</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line89">line 89</a>
</li></ul></dd>


Expand Down Expand Up @@ -243,7 +243,7 @@ <h4 class="name" id="info"><span class="type-signature"></span>info<span class="

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line107">line 107</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line127">line 127</a>
</li></ul></dd>


Expand Down Expand Up @@ -403,7 +403,7 @@ <h4 class="name" id="padding"><span class="type-signature"></span>padding<span c

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line99">line 99</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line119">line 119</a>
</li></ul></dd>


Expand Down Expand Up @@ -563,7 +563,7 @@ <h4 class="name" id="palette"><span class="type-signature"></span>palette<span c

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line79">line 79</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line99">line 99</a>
</li></ul></dd>


Expand Down Expand Up @@ -744,7 +744,7 @@ <h5 class="h5-returns">Returns:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Jan 09 2025 06:46:26 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Jan 17 2025 19:14:51 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
4 changes: 2 additions & 2 deletions docs/PrintError.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h4 class="name" id="PrintError"><span class="type-signature"></span>new PrintEr

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line216">line 216</a>
<a href="index.js.html">index.js</a>, <a href="index.js.html#line236">line 236</a>
</li></ul></dd>


Expand Down Expand Up @@ -260,7 +260,7 @@ <h5 class="h5-parameters">Parameters:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Jan 09 2025 06:46:26 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Jan 17 2025 19:14:51 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
7 changes: 3 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ <h3>@kabeep/exception 1.3.0</h3>

<section class="readme usertext">
<article><div align="center">
<img width="814" src="assets/logo-dark.png" alt="logo-dark">
<p>Exception is a custom error library for Node.js that provides a more flexible and customizable way of handling errors.</p>
<hr>
<img width="512" src="assets/logo-dark.png" alt="logo-dark">
<p>🖨️ A Node.js Custom Error Library that print error stack without clutter.</p>
<p><a href="https://nodejs.org/docs/latest/api/"><img src="https://img.shields.io/node/v/%40kabeep%2Fexception?color=lightseagreen" alt="NodeJS"></a>
<a href="LICENSE"><img src="https://img.shields.io/github/license/kabeep/exception?color=slateblue" alt="License"></a>
<a href="https://www.npmjs.com/package/@kabeep/exception"><img src="https://img.shields.io/npm/d18m/%40kabeep%2Fexception?color=cornflowerblue" alt="NPM"></a>
Expand Down Expand Up @@ -237,7 +236,7 @@ <h2>📄 License</h2>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Jan 09 2025 06:46:26 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Jan 17 2025 19:14:51 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
129 changes: 94 additions & 35 deletions docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,54 @@ <h1 class="page-title">index.js</h1>
<article>
<pre class="prettyprint source linenums"><code>import { basename, dirname } from 'path';
import { cwd, stdout } from 'process';
import chalk from 'chalk';
import chalkPipe from 'chalk-pipe';
import { eastAsianWidth } from 'get-east-asian-width';
import chalkPipe, { chalk } from 'chalk-pipe';

// src/core/PrintError.ts

// src/helpers/is-bg-rgb.ts
function isBgRgb(value) {
if (!value.startsWith("bg"))
return false;
const rgbRegular = /^bg\((?:\d{1,3},){2}\d{1,3}\)$/;
const numberRegular = /\d{1,3}/g;
const numberMatch = value.match(numberRegular);
const validNumber = Boolean(numberMatch?.every((item) => Number(item) &lt;= 255));
const validRgb = rgbRegular.test(value.replace(/\s/g, ""));
return validNumber &amp;&amp; validRgb;
// src/helpers/get-address.ts
function getAddress(text) {
let index = 0;
let start = -1;
let end = -1;
while (index >= 0) {
const nextIndex = text.slice(Math.max(0, index)).indexOf("(");
index = nextIndex > 0 ? nextIndex + index + 1 : -1;
if (nextIndex > 0) {
start = index;
}
}
if (start === -1)
return "";
index = text.slice(Math.max(0, start)).indexOf(")");
if (index === -1)
return "";
end = index + start;
return text.slice(start, end);
}
var is_bg_rgb_default = isBgRgb;
var get_address_default = getAddress;

// src/helpers/is-rgb.ts
function isRgb(value) {
const rgbRegular = /^\((?:\d{1,3},){2}\d{1,3}\)$/;
const rgbRegular = /^\(\d{1,3},\d{1,3},\d{1,3}\)$/;
const validRgb = rgbRegular.test(value.replace(/\s/g, ""));
if (!validRgb)
return false;
const numberRegular = /\d{1,3}/g;
const numberMatch = value.match(numberRegular);
const validNumber = Boolean(numberMatch?.every((item) => Number(item) &lt;= 255));
const validRgb = rgbRegular.test(value.replace(/\s/g, ""));
return validNumber &amp;&amp; validRgb;
return Boolean(numberMatch?.every((item) => Number(item) &lt;= 255));
}
var is_rgb_default = isRgb;

// src/helpers/is-bg-rgb.ts
function isBgRgb(value) {
if (!value.startsWith("bg"))
return false;
const rgbValue = value.slice(2).replace(/\s/g, "");
return is_rgb_default(rgbValue);
}
var is_bg_rgb_default = isBgRgb;

// src/helpers/is-string.ts
function isString(value) {
return typeof value === "string";
Expand All @@ -96,7 +115,8 @@ <h1 class="page-title">index.js</h1>

// src/helpers/normalize-rgb.ts
function normalizeRgb(color, prefix = "") {
const rgb = color.replace(/[\s()]/g, "").replace(new RegExp(`^${prefix}`), "");
const length = color.startsWith(prefix) ? prefix.length : 0;
const rgb = color.replace(/[\s()]/g, "").slice(Math.max(0, length));
const [r, g, b] = rgb.split(",").map(Number);
return [r, g, b];
}
Expand Down Expand Up @@ -214,9 +234,9 @@ <h1 class="page-title">index.js</h1>
let line;
let col;
let packageName = "[current]";
const addressMatch = /\(([^)&lt;>]+)\)(?:,\s&lt;anonymous>:\d+:\d+\))?$/.exec(text);
const addressMatch = get_address_default(text);
if (addressMatch) {
address = addressMatch[1].trim();
address = addressMatch.trim();
name = isEval ? "eval" : text.slice(0, Math.max(0, text.length - address.length - 2)).trim();
} else {
address = text;
Expand Down Expand Up @@ -274,16 +294,28 @@ <h1 class="page-title">index.js</h1>
* @returns {string} The opening part of the error stack trace.
*/
opening(defaultLength) {
const title = ` ${this.message} `;
const { length } = title;
const width = this.calc((defaultLength ?? length) + 2) / 2;
const prefixLength = Math.floor(width);
const prefixString = this.divide(prefixLength);
let title = this.padding(this.message);
const length = this.length(title);
const width = this.calc((defaultLength ?? length) + 2);
let halfWidth = Math.floor(width / 2);
const isAlternate = halfWidth &lt;= 0;
if (isAlternate) {
title = this.padding("Error Message");
halfWidth = Math.floor((width + length - 15) / 2);
}
const prefixString = this.divide(halfWidth);
const prefix = this.highlight("red", prefixString);
const suffixLength = Math.ceil(width);
const suffixString = this.divide(suffixLength);
const suffixString = this.divide(halfWidth);
const suffix = this.highlight("red", suffixString);
return `${prefix}${this.highlight("cyanBright", title)}${suffix}]`;
let output = `${prefix}${this.highlight("cyanBright", title)}${suffix}]`;
if (isAlternate) {
output += `
${this.message}`;
const divider = this.divide((this.column() ?? 32) - 2);
output += `
${this.highlight("grey", `[${divider}]`)}`;
}
return output;
}
/**
* Formats the trace information for printing.
Expand Down Expand Up @@ -318,14 +350,34 @@ <h1 class="page-title">index.js</h1>
* @returns {string} The closing part of the error stack trace.
*/
closing(styles, defaultLength) {
const title = this.padding(this.name);
const { length } = title;
const width = this.calc((defaultLength ?? length) + 3);
let title = this.padding(this.name);
const length = this.length(title);
let width = this.calc((defaultLength ?? length) + 3);
if (width &lt;= 0) {
title = this.padding("Exception");
width += length - 9;
}
const prefix = this.highlight("red", this.divide(width));
const suffix = this.highlight("red", this.divide(1));
const stylish = this.palette(styles);
return `[${prefix}${stylish(title)}${suffix}`;
}
/**
* Calculates the display length of a string, considering East Asian Width rules.
* @private
* @param {string} content - The string content whose display length is to be calculated.
* @returns {number} The total display length of the string, accounting for wide and narrow characters.
*/
length(content) {
let result = 0;
for (const char of content) {
const codePoint = char.codePointAt(0);
if (typeof codePoint !== "number")
continue;
result += eastAsianWidth(codePoint);
}
return result;
}
/**
* Calculates the width of the terminal.
* @private
Expand All @@ -334,9 +386,16 @@ <h1 class="page-title">index.js</h1>
* @returns {number} The calculated width.
*/
calc(length, defaultLength = 32) {
const columns = stdout?.columns;
const clientWidth = (columns ?? defaultLength) - length;
return clientWidth &lt;= 0 ? defaultLength : clientWidth;
const columns = this.column();
return (columns ?? defaultLength) - length;
}
/**
* Retrieves the current width of the terminal in columns.
* @private
* @returns {number | undefined} The number of columns in the terminal, or `undefined` if the terminal width cannot be determined.
*/
column() {
return stdout?.columns;
}
/**
* Applies a highlight color to the content.
Expand Down Expand Up @@ -398,7 +457,7 @@ <h1 class="page-title">index.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Thu Jan 09 2025 06:46:26 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Fri Jan 17 2025 19:14:51 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down

0 comments on commit 4c95910

Please sign in to comment.