@visulima/error 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/LICENSE.md +21 -0
- package/README.md +110 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/package.json +121 -0
package/CHANGELOG.md
ADDED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 visulima
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h3>Visulima error</h3>
|
|
3
|
+
<p>
|
|
4
|
+
Error with more than just a message.
|
|
5
|
+
</p>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<br />
|
|
9
|
+
|
|
10
|
+
<div align="center">
|
|
11
|
+
|
|
12
|
+
[![typescript-image]][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url]
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
<div align="center">
|
|
19
|
+
<p>
|
|
20
|
+
<sup>
|
|
21
|
+
Daniel Bannert's open source work is supported by the community on <a href="https://github.com/sponsors/prisis">GitHub Sponsors</a>
|
|
22
|
+
</sup>
|
|
23
|
+
</p>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npm install @visulima/error
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
yarn add @visulima/error
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
pnpm add @visulima/error
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
### Extend the VisulimaError
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { VisulimaError } from "@visulima/error";
|
|
48
|
+
|
|
49
|
+
class MyError extends VisulimaError {
|
|
50
|
+
constructor(message: string) {
|
|
51
|
+
super({
|
|
52
|
+
name: "MyError",
|
|
53
|
+
message,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
throw new MyError("My error message");
|
|
59
|
+
|
|
60
|
+
// or
|
|
61
|
+
|
|
62
|
+
const error = new MyError("My error message");
|
|
63
|
+
|
|
64
|
+
error.hint = "My error hint";
|
|
65
|
+
|
|
66
|
+
throw error;
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Pretty code frame
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { codeFrame } from "@visulima/error";
|
|
73
|
+
|
|
74
|
+
const source = "const x = 10;\nconst error = x.y;\n";
|
|
75
|
+
const loc = { column: 16, line: 2 };
|
|
76
|
+
|
|
77
|
+
const frame = codeFrame(source, loc);
|
|
78
|
+
|
|
79
|
+
console.log(frame);
|
|
80
|
+
// 1 | const x = 10;
|
|
81
|
+
// > 2 | const error = x.y;
|
|
82
|
+
// | ^
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Supported Node.js Versions
|
|
86
|
+
|
|
87
|
+
Libraries in this ecosystem make the best effort to track [Node.js’ release schedule](https://github.com/nodejs/release#release-schedule).
|
|
88
|
+
Here’s [a post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).
|
|
89
|
+
|
|
90
|
+
## Contributing
|
|
91
|
+
|
|
92
|
+
If you would like to help take a look at the [list of issues](https://github.com/visulima/visulima/issues) and check our [Contributing](.github/CONTRIBUTING.md) guild.
|
|
93
|
+
|
|
94
|
+
> **Note:** please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
|
|
95
|
+
|
|
96
|
+
## Credits
|
|
97
|
+
|
|
98
|
+
- [Daniel Bannert](https://github.com/prisis)
|
|
99
|
+
- [All Contributors](https://github.com/visulima/visulima/graphs/contributors)
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
The visulima error is open-sourced software licensed under the [MIT][license-url]
|
|
104
|
+
|
|
105
|
+
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
|
|
106
|
+
[typescript-url]: "typescript"
|
|
107
|
+
[license-image]: https://img.shields.io/npm/l/@visulima/error?color=blueviolet&style=for-the-badge
|
|
108
|
+
[license-url]: LICENSE.md "license"
|
|
109
|
+
[npm-image]: https://img.shields.io/npm/v/@visulima/error/latest.svg?style=for-the-badge&logo=npm
|
|
110
|
+
[npm-url]: https://www.npmjs.com/package/@visulima/error/v/latest "npm"
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
interface ErrorProperties {
|
|
2
|
+
hint?: string;
|
|
3
|
+
location?: ErrorLocation;
|
|
4
|
+
message?: string;
|
|
5
|
+
name: string;
|
|
6
|
+
stack?: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
}
|
|
9
|
+
interface ErrorLocation {
|
|
10
|
+
column?: number;
|
|
11
|
+
file?: string;
|
|
12
|
+
line?: number;
|
|
13
|
+
}
|
|
14
|
+
interface ErrorWithMetadata<Type = NonNullable<unknown> & string> {
|
|
15
|
+
[name: string]: any;
|
|
16
|
+
cause?: any;
|
|
17
|
+
frame?: string;
|
|
18
|
+
fullCode?: string;
|
|
19
|
+
hint?: string;
|
|
20
|
+
id?: string;
|
|
21
|
+
loc?: {
|
|
22
|
+
column?: number;
|
|
23
|
+
file?: string;
|
|
24
|
+
line?: number;
|
|
25
|
+
};
|
|
26
|
+
message: string;
|
|
27
|
+
name: string;
|
|
28
|
+
stack: string;
|
|
29
|
+
title?: string;
|
|
30
|
+
type?: Type | "VisulimaError";
|
|
31
|
+
}
|
|
32
|
+
type CodeFrameOptions = {
|
|
33
|
+
focusLineColor?: (value: string) => string;
|
|
34
|
+
linesAbove?: number;
|
|
35
|
+
linesBelow?: number;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
declare const codeFrame: (source: string, loc: ErrorLocation, options?: CodeFrameOptions) => string;
|
|
39
|
+
|
|
40
|
+
declare const isVisulimaError: (error: unknown) => error is VisulimaError;
|
|
41
|
+
declare class VisulimaError extends Error {
|
|
42
|
+
loc: ErrorLocation | undefined;
|
|
43
|
+
title: string | undefined;
|
|
44
|
+
hint: string[] | string | undefined;
|
|
45
|
+
type: string;
|
|
46
|
+
constructor(properties: ErrorProperties, ...parameters: any);
|
|
47
|
+
setLocation(location: ErrorLocation): void;
|
|
48
|
+
setName(name: string): void;
|
|
49
|
+
setMessage(message: string): void;
|
|
50
|
+
setHint(hint: string[] | string): void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare const positionAt: (offset: number, text: string) => {
|
|
54
|
+
column: number;
|
|
55
|
+
line: number;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export { CodeFrameOptions, ErrorLocation, ErrorProperties, ErrorWithMetadata, VisulimaError, codeFrame, isVisulimaError, positionAt };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { platform, env } from 'process';
|
|
2
|
+
|
|
3
|
+
var E=Object.defineProperty;var b=(r,n,t)=>n in r?E(r,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[n]=t;var u=(r,n,t)=>(b(r,typeof n!="symbol"?n+"":n,t),t);var L=r=>{let n=[],t=!0;for(let i=0;i<r.length;i++){t&&(n.push(i),t=!1);let o=r.charAt(i);t=o==="\r"||o===`
|
|
4
|
+
`,o==="\r"&&i+1<r.length&&r.charAt(i+1)===`
|
|
5
|
+
`&&i++;}return t&&r.length>0&&n.push(r.length),n},g=r=>r.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
|
|
6
|
+
`),y=(r,n)=>{let t=L(n);r=Math.max(0,Math.min(n.length,r));let i=0,o=t.length;if(o===0)return {column:r,line:0};for(;i<=o;){let s=Math.floor((i+o)/2),c=t[s];if(c===r)return {column:0,line:s};r>c?i=s+1:o=s-1;}let a=i-1;return {column:r-t[a],line:a}};var d=platform==="win32"&&!env.WT_SESSION?">":"\u276F",O=(r,n,t)=>{if(n.line===void 0||n.column===void 0)return "";let i={focusLineColor:e=>e,linesAbove:2,linesBelow:3,...t},o=g(r).split(`
|
|
7
|
+
`).map(e=>e.replaceAll(" "," ")),a=[];for(let e=-(i.linesAbove+1);e<=i.linesBelow;e++)o[n.line+e]&&a.push(n.line+e);let s=0;a.forEach(e=>{let l=`${d} ${e}${e<9?" ":""}`;l.length>s&&(s=l.length);});let c="";return a.forEach(e=>{let l="",m=e===n.line-1;l+=m?`${d} `:" ",l+=`${e<9?" ":""}${e+1} | ${o[e]}
|
|
8
|
+
`,m&&(l+=`${Array.from({length:s}).join(" ")} | ${Array.from({length:n.column}).join(" ")}^`),c+=m?`${i.focusLineColor(l)}
|
|
9
|
+
`:l;}),c},v=O;var F=r=>r instanceof Error&&r.type==="VisulimaError",f=class extends Error{constructor(t,...i){super(...i);u(this,"loc");u(this,"title");u(this,"hint");u(this,"type","VisulimaError");let{hint:o,location:a,message:s,name:c,stack:e,title:l}=t;this.title=l,this.name=c,s&&(this.message=s),this.stack=e??this.stack,this.loc=a,this.hint=o,Error.captureStackTrace(this,this.constructor);}setLocation(t){this.loc=t;}setName(t){this.name=t;}setMessage(t){this.message=t;}setHint(t){this.hint=t;}};
|
|
10
|
+
|
|
11
|
+
export { f as VisulimaError, v as codeFrame, F as isVisulimaError, y as positionAt };
|
|
12
|
+
//# sourceMappingURL=out.js.map
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/code-frame.ts","../src/utils.ts","../src/error.ts"],"names":["env","platform","getLineOffsets","text","lineOffsets","isLineStart","index","ch","normalizeLF","code","positionAt","offset","low","high","mid","lineOffset","line","POINTER","codeFrame","source","loc","options","config","value","lines","ln","visibleLines","n","gutterWidth","lineNo","w","output","isFocusedLine","code_frame_default","isVisulimaError","error","VisulimaError","properties","parameters","__publicField","hint","location","message","name","stack","title"],"mappings":"wKAAA,OAAS,OAAAA,EAAK,YAAAC,MAAgB,UCA9B,IAAMC,EAAkBC,GAA2B,CAC/C,IAAMC,EAAc,CAAC,EACjBC,EAAc,GAGlB,QAASC,EAAQ,EAAGA,EAAQH,EAAK,OAAQG,IAAS,CAC1CD,IACAD,EAAY,KAAKE,CAAK,EACtBD,EAAc,IAGlB,IAAME,EAAKJ,EAAK,OAAOG,CAAK,EAE5BD,EAAcE,IAAO,MAAQA,IAAO;AAAA,EAEh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AM,kBAAkB,KAAM,KAAK,WAAW,CAClD,CAEO,YAAYC,EAA+B,CAC9C,KAAK,IAAMA,CACf,CAEO,QAAQE,EAAoB,CAC/B,KAAK,KAAOA,CAChB,CAEO,WAAWD,EAAuB,CACrC,KAAK,QAAUA,CACnB,CAEO,QAAQF,EAA+B,CAC1C,KAAK,KAAOA,CAChB,CACJ","sourcesContent":["import { env, platform } from \"node:process\";\n\nimport type { CodeFrameOptions, ErrorLocation } from \"./types\";\nimport { normalizeLF } from \"./utils\";\n\nconst POINTER = platform === \"win32\" && !env[\"WT_SESSION\"] ? \">\" : \"❯\";\n\n/** Generate a code frame from string and an error location */\nconst codeFrame = (\n source: string,\n loc: ErrorLocation,\n options?: CodeFrameOptions,\n // eslint-disable-next-line sonarjs/cognitive-complexity\n): string => {\n if (loc.line === undefined || loc.column === undefined) {\n return \"\";\n }\n\n // grab 2 lines before, and 3 lines after focused line\n const config = {\n focusLineColor: (value: string) => value,\n linesAbove: 2,\n linesBelow: 3,\n ...options,\n };\n\n const lines = normalizeLF(source)\n .split(\"\\n\")\n .map((ln) => ln.replaceAll(\"\\t\", \" \"));\n\n const visibleLines = [];\n\n // eslint-disable-next-line no-loops/no-loops,no-plusplus\n for (let n = -(config.linesAbove + 1); n <= config.linesBelow; n++) {\n if (lines[loc.line + n]) {\n visibleLines.push(loc.line + n);\n }\n }\n\n // figure out gutter width\n let gutterWidth = 0;\n\n visibleLines.forEach((lineNo) => {\n const w = `${POINTER} ${lineNo}${lineNo < 9 ? \" \" : \"\"}`;\n\n if (w.length > gutterWidth) {\n gutterWidth = w.length;\n }\n });\n\n // print lines\n let output = \"\";\n\n visibleLines.forEach((lineNo) => {\n let code = \"\";\n const isFocusedLine = lineNo === (loc.line as number) - 1;\n\n code += isFocusedLine ? `${POINTER} ` : \" \";\n // eslint-disable-next-line security/detect-object-injection\n code += `${lineNo < 9 ? \" \" : \"\"}${lineNo + 1} | ${lines[lineNo]}\\n`;\n\n if (isFocusedLine) {\n code += `${Array.from({ length: gutterWidth }).join(\" \")} | ${Array.from({\n length: loc.column as number,\n }).join(\" \")}^`;\n }\n\n output += isFocusedLine ? `${config.focusLineColor(code)}\\n` : code;\n });\n\n return output;\n};\n\nexport default codeFrame;\n","const getLineOffsets = (text: string): number[] => {\n const lineOffsets = [];\n let isLineStart = true;\n\n // eslint-disable-next-line no-plusplus,no-loops/no-loops\n for (let index = 0; index < text.length; index++) {\n if (isLineStart) {\n lineOffsets.push(index);\n isLineStart = false;\n }\n\n const ch = text.charAt(index);\n\n isLineStart = ch === \"\\r\" || ch === \"\\n\";\n\n if (ch === \"\\r\" && index + 1 < text.length && text.charAt(index + 1) === \"\\n\") {\n // eslint-disable-next-line no-plusplus\n index++;\n }\n }\n\n if (isLineStart && text.length > 0) {\n lineOffsets.push(text.length);\n }\n\n return lineOffsets;\n};\n\nexport const normalizeLF = (code: string): string => code.replaceAll(/\\r\\n|\\r(?!\\n)|\\n/gu, \"\\n\");\n\n/**\n * Get the line and character based on the offset\n * @param offset The index of the position\n * @param text The text for which the position should be retrieved\n */\nexport const positionAt = (\n offset: number,\n text: string,\n): {\n column: number;\n line: number;\n} => {\n const lineOffsets = getLineOffsets(text);\n\n // eslint-disable-next-line no-param-reassign\n offset = Math.max(0, Math.min(text.length, offset));\n\n let low = 0;\n let high = lineOffsets.length;\n\n if (high === 0) {\n return {\n column: offset,\n line: 0,\n };\n }\n\n // eslint-disable-next-line no-loops/no-loops\n while (low <= high) {\n const mid = Math.floor((low + high) / 2);\n // eslint-disable-next-line security/detect-object-injection\n const lineOffset = lineOffsets[mid] as number;\n\n if (lineOffset === offset) {\n return {\n column: 0,\n line: mid,\n };\n }\n\n if (offset > lineOffset) {\n low = mid + 1;\n } else {\n high = mid - 1;\n }\n }\n\n // low is the least x for which the line offset is larger than the current offset\n // or array.length if no line offset is larger than the current offset\n const line = low - 1;\n\n // eslint-disable-next-line security/detect-object-injection\n return { column: offset - (lineOffsets[line] as number), line };\n};\n","import type { ErrorLocation, ErrorProperties } from \"./types\";\n\nexport const isVisulimaError = (error: unknown): error is VisulimaError => error instanceof Error && (error as VisulimaError).type === \"VisulimaError\";\n\nexport class VisulimaError extends Error {\n public loc: ErrorLocation | undefined;\n\n public title: string | undefined;\n\n /**\n * A message that explains to the user how they can fix the error.\n */\n public hint: string[] | string | undefined;\n\n public type = \"VisulimaError\";\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types,@typescript-eslint/no-explicit-any\n public constructor(properties: ErrorProperties, ...parameters: any) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n super(...parameters);\n\n const { hint, location, message, name, stack, title } = properties;\n this.title = title;\n this.name = name;\n\n if (message) {\n this.message = message;\n }\n\n // Only set this if we actually have a stack passed, otherwise uses Error's\n this.stack = stack ?? (this.stack as string);\n this.loc = location;\n this.hint = hint;\n\n Error.captureStackTrace(this, this.constructor);\n }\n\n public setLocation(location: ErrorLocation): void {\n this.loc = location;\n }\n\n public setName(name: string): void {\n this.name = name;\n }\n\n public setMessage(message: string): void {\n this.message = message;\n }\n\n public setHint(hint: string[] | string): void {\n this.hint = hint;\n }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@visulima/error",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Error with more than just a message.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"visulima",
|
|
7
|
+
"anolilab",
|
|
8
|
+
"error",
|
|
9
|
+
"exception",
|
|
10
|
+
"code-frame",
|
|
11
|
+
"codeframe"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://visulima.com/packages/cerebro-ui",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/visulima/visulima.git",
|
|
17
|
+
"directory": "packages/cerebro-tui"
|
|
18
|
+
},
|
|
19
|
+
"funding": [
|
|
20
|
+
{
|
|
21
|
+
"type": "github",
|
|
22
|
+
"url": "https://github.com/sponsors/prisis"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"type": "consulting",
|
|
26
|
+
"url": "https://anolilab.com/support"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"author": {
|
|
31
|
+
"name": "Daniel Bannert",
|
|
32
|
+
"email": "d.bannert@anolilab.de"
|
|
33
|
+
},
|
|
34
|
+
"sideEffects": false,
|
|
35
|
+
"type": "module",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"default": "./dist/index.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"source": "src/index.ts",
|
|
46
|
+
"types": "dist/index.d.ts",
|
|
47
|
+
"files": [
|
|
48
|
+
"dist",
|
|
49
|
+
"README.md",
|
|
50
|
+
"CHANGELOG.md",
|
|
51
|
+
"LICENSE.md"
|
|
52
|
+
],
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "rimraf dist && cross-env NODE_ENV=development tsup",
|
|
55
|
+
"build:prod": "rimraf dist && cross-env NODE_ENV=production tsup",
|
|
56
|
+
"clean": "rimraf node_modules dist .eslintcache",
|
|
57
|
+
"coverage": "vitest run --coverage",
|
|
58
|
+
"dev": "pnpm run build --watch",
|
|
59
|
+
"lint:eslint": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.cjs",
|
|
60
|
+
"lint:eslint:fix": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.cjs --fix",
|
|
61
|
+
"lint:packagejson": "publint --strict",
|
|
62
|
+
"lint:prettier": "prettier --config=.prettierrc.cjs --check .",
|
|
63
|
+
"lint:prettier:fix": "prettier --config=.prettierrc.cjs --write .",
|
|
64
|
+
"lint:types": "tsc --noEmit --project tsconfig.json",
|
|
65
|
+
"test": "vitest run",
|
|
66
|
+
"test:watch": "vitest"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@anolilab/eslint-config": "^15.0.1",
|
|
70
|
+
"@anolilab/prettier-config": "^5.0.12",
|
|
71
|
+
"@anolilab/semantic-release-preset": "^8.0.1",
|
|
72
|
+
"@babel/core": "^7.23.2",
|
|
73
|
+
"@eslint-types/deprecation": "^2.0.0",
|
|
74
|
+
"@eslint-types/import": "^2.29.0",
|
|
75
|
+
"@eslint-types/jsdoc": "^46.8.2",
|
|
76
|
+
"@eslint-types/typescript-eslint": "^6.9.0",
|
|
77
|
+
"@eslint-types/unicorn": "^48.0.1",
|
|
78
|
+
"@rushstack/eslint-plugin-security": "^0.7.1",
|
|
79
|
+
"@total-typescript/ts-reset": "^0.5.1",
|
|
80
|
+
"@types/command-line-args": "^5.2.2",
|
|
81
|
+
"@types/node": "18.18.5",
|
|
82
|
+
"@visulima/nextra-theme-docs": "4.0.7",
|
|
83
|
+
"@vitest/coverage-v8": "^0.34.6",
|
|
84
|
+
"chalk": "^5.3.0",
|
|
85
|
+
"cross-env": "^7.0.3",
|
|
86
|
+
"eslint": "^8.52.0",
|
|
87
|
+
"eslint-plugin-deprecation": "^2.0.0",
|
|
88
|
+
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.0",
|
|
89
|
+
"eslint-plugin-mdx": "^2.2.0",
|
|
90
|
+
"eslint-plugin-vitest": "^0.3.8",
|
|
91
|
+
"eslint-plugin-vitest-globals": "^1.4.0",
|
|
92
|
+
"prettier": "^3.0.3",
|
|
93
|
+
"rimraf": "^5.0.5",
|
|
94
|
+
"semantic-release": "^22.0.6",
|
|
95
|
+
"sort-package-json": "^2.6.0",
|
|
96
|
+
"tsup": "^7.2.0",
|
|
97
|
+
"typescript": "^5.2.2",
|
|
98
|
+
"vitest": "^0.34.6",
|
|
99
|
+
"vitest-console": "0.1.1"
|
|
100
|
+
},
|
|
101
|
+
"engines": {
|
|
102
|
+
"node": ">=18.* <=21.*"
|
|
103
|
+
},
|
|
104
|
+
"publishConfig": {
|
|
105
|
+
"access": "public",
|
|
106
|
+
"provenance": true
|
|
107
|
+
},
|
|
108
|
+
"anolilab": {
|
|
109
|
+
"eslint-config": {
|
|
110
|
+
"plugin": {
|
|
111
|
+
"tsdoc": false,
|
|
112
|
+
"etc": false
|
|
113
|
+
},
|
|
114
|
+
"warn_on_unsupported_typescript_version": false,
|
|
115
|
+
"info_on_disabling_jsx_react_rule": false,
|
|
116
|
+
"info_on_disabling_prettier_conflict_rule": false,
|
|
117
|
+
"info_on_disabling_jsonc_sort_keys_rule": false,
|
|
118
|
+
"info_on_disabling_etc_no_deprecated": false
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|