@visulima/error 3.1.2 → 3.2.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 +7 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## @visulima/error [3.2.0](https://github.com/visulima/visulima/compare/@visulima/error@3.1.2...@visulima/error@3.2.0) (2024-03-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* added new index-to-line-column function ([c794be0](https://github.com/visulima/visulima/commit/c794be0867eae45ce66096bd15691d7437545a5d))
|
|
7
|
+
|
|
1
8
|
## @visulima/error [3.1.2](https://github.com/visulima/visulima/compare/@visulima/error@3.1.1...@visulima/error@3.1.2) (2024-03-10)
|
|
2
9
|
|
|
3
10
|
|
package/dist/index.d.ts
CHANGED
|
@@ -3,3 +3,12 @@ export { ErrorHint, ErrorLocation, ErrorProperties, VisulimaError, getErrorCause
|
|
|
3
3
|
export { loadSourceMap } from './sourcemap/index.js';
|
|
4
4
|
export { TraceMap, generatedPositionFor, originalPositionFor, sourceContentFor, traceSegment } from '@jridgewell/trace-mapping';
|
|
5
5
|
export { Trace, TraceType, parseStacktrace } from './stacktrace/index.js';
|
|
6
|
+
|
|
7
|
+
declare const indexToLineColumn: (input: number[] | string, index: number, options?: {
|
|
8
|
+
skipChecks: boolean;
|
|
9
|
+
}) => {
|
|
10
|
+
column: number;
|
|
11
|
+
line: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { indexToLineColumn };
|
package/dist/index.js
CHANGED
|
@@ -2,5 +2,9 @@ export { a as CODE_FRAME_POINTER, b as codeFrame } from './chunk-CCMH6IHO.js';
|
|
|
2
2
|
export { c as VisulimaError, a as getErrorCauses, b as isVisulimaError } from './chunk-HAVTTG7L.js';
|
|
3
3
|
export { b as generatedPositionFor, a as loadSourceMap, c as originalPositionFor, d as sourceContentFor, e as traceSegment } from './chunk-7G4U7I4C.js';
|
|
4
4
|
export { a as parseStacktrace } from './chunk-57YC2IM6.js';
|
|
5
|
+
|
|
6
|
+
var m=(r,e)=>{let o=0,t=e.length-2;for(;o<t;){let n=o+(t-o>>1);if(r<e[n])t=n-1;else if(r>=e[n+1])o=n+1;else {o=n;break}}return o},E=r=>r.split(/\n|\r(?!\n)/).reduce((e,o)=>(e.push(e.at(-1)+o.length+1),e),[0]),x=(r,e,o)=>{let t=o?.skipChecks??!1;if(!t&&(!Array.isArray(r)&&typeof r!="string"||(typeof r=="string"||Array.isArray(r))&&r.length===0))return {column:0,line:0};if(!t&&(typeof e!="number"||typeof r=="string"&&e>=r.length||Array.isArray(r)&&e+1>=r.at(-1)))return {column:0,line:0};if(typeof r=="string"){let s=E(r),a=m(e,s);return {column:e-s[a]+1,line:a+1}}let n=m(e,r);return {column:e-r[n]+1,line:n+1}},F=x;
|
|
7
|
+
|
|
8
|
+
export { F as indexToLineColumn };
|
|
5
9
|
//# sourceMappingURL=out.js.map
|
|
6
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"sources":["../src/code-frame/index-to-line-column.ts"],"names":["binarySearch","element","array","m","n","key","getLineStartIndexes","string_","accumulator","current","indexToLineColumn","input","index","options","skipChecks","startIndexesOfEachLine","line","index_to_line_column_default"],"mappings":"iNAAA,IAAMA,EAAe,CAACC,EAAiBC,IAA4B,CAC/D,IAAIC,EAAI,EACJC,EAAIF,EAAM,OAAS,EAGvB,KAAOC,EAAIC,GAAG,CAEV,IAAMC,EAAMF,GAAMC,EAAID,GAAM,GAE5B,GAAIF,EAAWC,EAAMG,CAAG,EACpBD,EAAIC,EAAM,UACHJ,GAAYC,EAAMG,EAAM,CAAC,EAChCF,EAAIE,EAAM,MACP,CACHF,EAAIE,EACJ,KACJ,CACJ,CAEA,OAAOF,CACX,EAIMG,EAAuBC,GACzBA,EAAQ,MAAM,aAAa,EAAE,OACzB,CAACC,EAAuBC,KACpBD,EAAY,KAAMA,EAAY,GAAG,EAAE,EAAeC,EAAQ,OAAS,CAAC,EAE7DD,GAEX,CAAC,CAAC,CACN,EAEEE,EAAoB,CACtBC,EACAC,EACAC,IAMC,CACD,IAAMC,EAAaD,GAAS,YAAc,GAE1C,GAAI,CAACC,IAAgB,CAAC,MAAM,QAAQH,CAAK,GAAK,OAAOA,GAAU,WAAe,OAAOA,GAAU,UAAY,MAAM,QAAQA,CAAK,IAAMA,EAAM,SAAW,GACjJ,MAAO,CAAE,OAAQ,EAAG,KAAM,CAAE,EAGhC,GACI,CAACG,IACA,OAAOF,GAAU,UAAa,OAAOD,GAAU,UAAYC,GAASD,EAAM,QAAY,MAAM,QAAQA,CAAK,GAAKC,EAAQ,GAAMD,EAAM,GAAG,EAAE,GAExI,MAAO,CAAE,OAAQ,EAAG,KAAM,CAAE,EAIhC,GAAI,OAAOA,GAAU,SAAU,CAE3B,IAAMI,EAAyBT,EAAoBK,CAAK,EAClDK,EAAOhB,EAAaY,EAAOG,CAAsB,EAEvD,MAAO,CACH,OAAQH,EAASG,EAAuBC,CAAI,EAAe,EAC3D,KAAMA,EAAO,CACjB,CACJ,CAGA,IAAMA,EAAOhB,EAAaY,EAAOD,CAAK,EAEtC,MAAO,CACH,OAAQC,EAASD,EAAMK,CAAI,EAAe,EAC1C,KAAMA,EAAO,CACjB,CACJ,EAEOC,EAAQP","sourcesContent":["const binarySearch = (element: number, array: number[]): number => {\n let m = 0;\n let n = array.length - 2;\n\n // eslint-disable-next-line no-loops/no-loops\n while (m < n) {\n // eslint-disable-next-line no-bitwise\n const key = m + ((n - m) >> 1);\n // eslint-disable-next-line security/detect-object-injection\n if (element < (array[key] as number)) {\n n = key - 1;\n } else if (element >= (array[key + 1] as number)) {\n m = key + 1;\n } else {\n m = key;\n break;\n }\n }\n\n return m;\n};\n\n// split by line break characters, CR, LF or CRLF\n// compile an array of indexes, where each line starts\nconst getLineStartIndexes = (string_: string): number[] =>\n string_.split(/\\n|\\r(?!\\n)/).reduce(\n (accumulator: number[], current) => {\n accumulator.push((accumulator.at(-1) as number) + current.length + 1);\n\n return accumulator;\n },\n [0],\n );\n\nconst indexToLineColumn = (\n input: number[] | string,\n index: number,\n options?: {\n skipChecks: boolean;\n },\n): {\n column: number;\n line: number;\n} => {\n const skipChecks = options?.skipChecks ?? false;\n\n if (!skipChecks && ((!Array.isArray(input) && typeof input !== \"string\") || ((typeof input === \"string\" || Array.isArray(input)) && input.length === 0))) {\n return { column: 0, line: 0 };\n }\n\n if (\n !skipChecks &&\n (typeof index !== \"number\" || (typeof input === \"string\" && index >= input.length) || (Array.isArray(input) && index + 1 >= (input.at(-1) as number)))\n ) {\n return { column: 0, line: 0 };\n }\n\n // it depends, pre-cached input was given or a string\n if (typeof input === \"string\") {\n // not cached - calculate the line start indexes\n const startIndexesOfEachLine = getLineStartIndexes(input);\n const line = binarySearch(index, startIndexesOfEachLine);\n\n return {\n column: index - (startIndexesOfEachLine[line] as number) + 1,\n line: line + 1,\n };\n }\n\n // ELSE - cached line start indexes - we don't even need the string source!\n const line = binarySearch(index, input);\n\n return {\n column: index - (input[line] as number) + 1,\n line: line + 1,\n };\n};\n\nexport default indexToLineColumn;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/error",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Error with more than just a message, stacktrace parsing and sourcemap loading.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"visulima",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"eslint-plugin-deprecation": "^2.0.0",
|
|
122
122
|
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
|
|
123
123
|
"eslint-plugin-mdx": "^3.1.5",
|
|
124
|
-
"eslint-plugin-vitest": "^0.3.
|
|
124
|
+
"eslint-plugin-vitest": "^0.3.25",
|
|
125
125
|
"eslint-plugin-vitest-globals": "^1.4.0",
|
|
126
126
|
"prettier": "^3.2.5",
|
|
127
127
|
"rimraf": "^5.0.5",
|