@visulima/fs 2.3.6 → 2.3.8

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.
Files changed (30) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +1377 -1029
  3. package/dist/index.cjs +8 -8
  4. package/dist/index.d.cts +1 -1
  5. package/dist/index.d.mts +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.mjs +8 -8
  8. package/dist/packem_shared/parseJson-DcUo4Rpt.cjs +251 -0
  9. package/dist/packem_shared/parseJson-n9THWOFI.mjs +249 -0
  10. package/dist/packem_shared/{readJson-Bqr9Oi3I.mjs → readJson-DIHRleEE.mjs} +1 -1
  11. package/dist/packem_shared/{readJson-D7rMdkkq.cjs → readJson-JrCHMN3m.cjs} +1 -1
  12. package/dist/packem_shared/{readJsonSync-Don8Jw5D.mjs → readJsonSync-BPfxTuQL.mjs} +1 -1
  13. package/dist/packem_shared/{readJsonSync-D3s2y651.cjs → readJsonSync-o_MAOlUv.cjs} +1 -1
  14. package/dist/packem_shared/{writeFile-DKu5-M8x.cjs → writeFile-CnWc2ZOW.cjs} +3 -3
  15. package/dist/packem_shared/{writeFile-B7dhfseN.mjs → writeFile-CzpkxDqy.mjs} +3 -3
  16. package/dist/packem_shared/{writeFileSync-mMGYqOc8.mjs → writeFileSync-DYRpumrj.mjs} +3 -3
  17. package/dist/packem_shared/{writeFileSync-Db6pmY0q.cjs → writeFileSync-da4qD9Nz.cjs} +3 -3
  18. package/dist/packem_shared/{writeJson-DtnnjTix.cjs → writeJson-9_C3v2B3.cjs} +1 -1
  19. package/dist/packem_shared/{writeJson-BSQE2uFN.mjs → writeJson-V9KBXfw2.mjs} +1 -1
  20. package/dist/packem_shared/{writeJsonSync-Dz5-B2PD.cjs → writeJsonSync-C5kkxqE7.cjs} +1 -1
  21. package/dist/packem_shared/{writeJsonSync-C_i6LsGT.mjs → writeJsonSync-CyaXNy3X.mjs} +1 -1
  22. package/dist/packem_shared/{writeYaml-B-KoZN0E.cjs → writeYaml-DDLK7NDr.cjs} +1 -1
  23. package/dist/packem_shared/{writeYaml-DSTzKc0_.mjs → writeYaml-DJ17fqNj.mjs} +1 -1
  24. package/dist/packem_shared/{writeYamlSync-agxYIea0.mjs → writeYamlSync-C6nrcP2e.mjs} +1 -1
  25. package/dist/packem_shared/{writeYamlSync-D6borSP1.cjs → writeYamlSync-DST-W6N7.cjs} +1 -1
  26. package/dist/utils.cjs +1 -1
  27. package/dist/utils.mjs +1 -1
  28. package/package.json +2 -74
  29. package/dist/packem_shared/parseJson-B_q4905N.mjs +0 -160
  30. package/dist/packem_shared/parseJson-P3C7DMaS.cjs +0 -162
package/dist/index.cjs CHANGED
@@ -23,20 +23,20 @@ const isAccessibleSync = require('./packem_shared/isAccessibleSync-VWjQa-US.cjs'
23
23
  const move = require('./packem_shared/move-Dh925GL9.cjs');
24
24
  const readFile = require('./packem_shared/readFile-iFUhZHnh.cjs');
25
25
  const readFileSync = require('./packem_shared/readFileSync-B3NTOR-W.cjs');
26
- const readJson = require('./packem_shared/readJson-D7rMdkkq.cjs');
27
- const readJsonSync = require('./packem_shared/readJsonSync-D3s2y651.cjs');
26
+ const readJson = require('./packem_shared/readJson-JrCHMN3m.cjs');
27
+ const readJsonSync = require('./packem_shared/readJsonSync-o_MAOlUv.cjs');
28
28
  const readYaml = require('./packem_shared/readYaml-sR4bqUel.cjs');
29
29
  const readYamlSync = require('./packem_shared/readYamlSync-C3oOzxiN.cjs');
30
30
  const emptyDir = require('./packem_shared/emptyDir-DcCfiNcf.cjs');
31
31
  const emptyDirSync = require('./packem_shared/emptyDirSync-BoknkGUe.cjs');
32
32
  const remove = require('./packem_shared/remove-BpDiVPns.cjs');
33
33
  const removeSync = require('./packem_shared/removeSync-BosXW624.cjs');
34
- const writeFile = require('./packem_shared/writeFile-DKu5-M8x.cjs');
35
- const writeFileSync = require('./packem_shared/writeFileSync-Db6pmY0q.cjs');
36
- const writeJson = require('./packem_shared/writeJson-DtnnjTix.cjs');
37
- const writeJsonSync = require('./packem_shared/writeJsonSync-Dz5-B2PD.cjs');
38
- const writeYaml = require('./packem_shared/writeYaml-B-KoZN0E.cjs');
39
- const writeYamlSync = require('./packem_shared/writeYamlSync-D6borSP1.cjs');
34
+ const writeFile = require('./packem_shared/writeFile-CnWc2ZOW.cjs');
35
+ const writeFileSync = require('./packem_shared/writeFileSync-da4qD9Nz.cjs');
36
+ const writeJson = require('./packem_shared/writeJson-9_C3v2B3.cjs');
37
+ const writeJsonSync = require('./packem_shared/writeJsonSync-C5kkxqE7.cjs');
38
+ const writeYaml = require('./packem_shared/writeYaml-DDLK7NDr.cjs');
39
+ const writeYamlSync = require('./packem_shared/writeYamlSync-DST-W6N7.cjs');
40
40
 
41
41
 
42
42
 
package/dist/index.d.cts CHANGED
@@ -64,7 +64,7 @@ declare const readFile: <O extends ReadFileOptions<keyof typeof decompressionMet
64
64
  declare const decompressionMethods: {
65
65
  readonly brotli: typeof brotliDecompressSync;
66
66
  readonly gzip: typeof unzipSync;
67
- readonly none: (buffer: Buffer) => Buffer;
67
+ readonly none: (buffer: Buffer) => Buffer<ArrayBufferLike>;
68
68
  };
69
69
  declare const readFileSync: <O extends ReadFileOptions<keyof typeof decompressionMethods> | undefined = undefined>(path: URL | string, options?: O) => ContentType<O>;
70
70
 
package/dist/index.d.mts CHANGED
@@ -64,7 +64,7 @@ declare const readFile: <O extends ReadFileOptions<keyof typeof decompressionMet
64
64
  declare const decompressionMethods: {
65
65
  readonly brotli: typeof brotliDecompressSync;
66
66
  readonly gzip: typeof unzipSync;
67
- readonly none: (buffer: Buffer) => Buffer;
67
+ readonly none: (buffer: Buffer) => Buffer<ArrayBufferLike>;
68
68
  };
69
69
  declare const readFileSync: <O extends ReadFileOptions<keyof typeof decompressionMethods> | undefined = undefined>(path: URL | string, options?: O) => ContentType<O>;
70
70
 
package/dist/index.d.ts CHANGED
@@ -64,7 +64,7 @@ declare const readFile: <O extends ReadFileOptions<keyof typeof decompressionMet
64
64
  declare const decompressionMethods: {
65
65
  readonly brotli: typeof brotliDecompressSync;
66
66
  readonly gzip: typeof unzipSync;
67
- readonly none: (buffer: Buffer) => Buffer;
67
+ readonly none: (buffer: Buffer) => Buffer<ArrayBufferLike>;
68
68
  };
69
69
  declare const readFileSync: <O extends ReadFileOptions<keyof typeof decompressionMethods> | undefined = undefined>(path: URL | string, options?: O) => ContentType<O>;
70
70
 
package/dist/index.mjs CHANGED
@@ -19,17 +19,17 @@ export { default as isAccessibleSync } from './packem_shared/isAccessibleSync-3g
19
19
  export { move, moveSync, rename, renameSync } from './packem_shared/move-DgF7Ul9L.mjs';
20
20
  export { default as readFile } from './packem_shared/readFile-DUM-xNoB.mjs';
21
21
  export { default as readFileSync } from './packem_shared/readFileSync-Cck96_o0.mjs';
22
- export { default as readJson } from './packem_shared/readJson-Bqr9Oi3I.mjs';
23
- export { default as readJsonSync } from './packem_shared/readJsonSync-Don8Jw5D.mjs';
22
+ export { default as readJson } from './packem_shared/readJson-DIHRleEE.mjs';
23
+ export { default as readJsonSync } from './packem_shared/readJsonSync-BPfxTuQL.mjs';
24
24
  export { default as readYaml } from './packem_shared/readYaml-vVKK8ZzY.mjs';
25
25
  export { default as readYamlSync } from './packem_shared/readYamlSync-MOLH4gXB.mjs';
26
26
  export { default as emptyDir } from './packem_shared/emptyDir-Dw5xSBox.mjs';
27
27
  export { default as emptyDirSync } from './packem_shared/emptyDirSync-DTGPXQ3v.mjs';
28
28
  export { default as remove } from './packem_shared/remove-B2nxUObP.mjs';
29
29
  export { default as removeSync } from './packem_shared/removeSync-C87yepDI.mjs';
30
- export { default as writeFile } from './packem_shared/writeFile-B7dhfseN.mjs';
31
- export { default as writeFileSync } from './packem_shared/writeFileSync-mMGYqOc8.mjs';
32
- export { default as writeJson } from './packem_shared/writeJson-BSQE2uFN.mjs';
33
- export { default as writeJsonSync } from './packem_shared/writeJsonSync-C_i6LsGT.mjs';
34
- export { default as writeYaml } from './packem_shared/writeYaml-DSTzKc0_.mjs';
35
- export { default as writeYamlSync } from './packem_shared/writeYamlSync-agxYIea0.mjs';
30
+ export { default as writeFile } from './packem_shared/writeFile-CzpkxDqy.mjs';
31
+ export { default as writeFileSync } from './packem_shared/writeFileSync-DYRpumrj.mjs';
32
+ export { default as writeJson } from './packem_shared/writeJson-V9KBXfw2.mjs';
33
+ export { default as writeJsonSync } from './packem_shared/writeJsonSync-CyaXNy3X.mjs';
34
+ export { default as writeYaml } from './packem_shared/writeYaml-DJ17fqNj.mjs';
35
+ export { default as writeYamlSync } from './packem_shared/writeYamlSync-C6nrcP2e.mjs';
@@ -0,0 +1,251 @@
1
+ 'use strict';
2
+
3
+ const JSONError = require('./JSONError-gkXvBSar.cjs');
4
+
5
+ var __defProp$2 = Object.defineProperty;
6
+ var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
7
+ var __defProp$2$1 = Object.defineProperty;
8
+ var __name$2$1 = /* @__PURE__ */ __name$2((target, value) => __defProp$2$1(target, "name", { value, configurable: true }), "__name$2");
9
+ const normalizeLF = /* @__PURE__ */ __name$2$1((code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n"), "normalizeLF");
10
+ const _process = globalThis.process || /* @__PURE__ */ Object.create(null);
11
+ const processShims = {
12
+ versions: {}
13
+ };
14
+ const process = new Proxy(_process, {
15
+ get(target, property) {
16
+ if (property in target) {
17
+ return target[property];
18
+ }
19
+ if (property in processShims) {
20
+ return processShims[property];
21
+ }
22
+ return undefined;
23
+ }
24
+ });
25
+ var __defProp$1$1 = Object.defineProperty;
26
+ var __name$1$1 = /* @__PURE__ */ __name$2((target, value) => __defProp$1$1(target, "name", { value, configurable: true }), "__name$1");
27
+ const getMarkerLines = /* @__PURE__ */ __name$1$1((loc, source, linesAbove, linesBelow) => {
28
+ const startLoc = {
29
+ column: 0,
30
+ // @ts-expect-error Can be overwritten
31
+ line: -1,
32
+ ...loc.start
33
+ };
34
+ const endLoc = {
35
+ ...startLoc,
36
+ ...loc.end
37
+ };
38
+ const startLine = startLoc.line;
39
+ const startColumn = startLoc.column;
40
+ const endLine = endLoc.line;
41
+ const endColumn = endLoc.column;
42
+ let start = Math.max(startLine - (linesAbove + 1), 0);
43
+ let end = Math.min(source.length, endLine + linesBelow);
44
+ if (startLine === -1) {
45
+ start = 0;
46
+ }
47
+ if (endLine === -1) {
48
+ end = source.length;
49
+ }
50
+ const lineDiff = endLine - startLine;
51
+ const markerLines = {};
52
+ if (lineDiff) {
53
+ for (let index = 0; index <= lineDiff; index++) {
54
+ const lineNumber = index + startLine;
55
+ if (!startColumn) {
56
+ markerLines[lineNumber] = true;
57
+ } else if (index === 0) {
58
+ const sourceLength = source[lineNumber - 1]?.length;
59
+ markerLines[lineNumber] = [startColumn, (sourceLength ?? 0) - startColumn + 1];
60
+ } else if (index === lineDiff) {
61
+ markerLines[lineNumber] = [0, endColumn];
62
+ } else {
63
+ const sourceLength = source[lineNumber - index]?.length;
64
+ markerLines[lineNumber] = [0, sourceLength];
65
+ }
66
+ }
67
+ } else if (startColumn === endColumn) {
68
+ markerLines[startLine] = startColumn ? [startColumn, 0] : true;
69
+ } else {
70
+ markerLines[startLine] = [startColumn, (endColumn ?? 0) - (startColumn ?? 0)];
71
+ }
72
+ return { end, markerLines, start };
73
+ }, "getMarkerLines");
74
+ var __defProp2$1 = Object.defineProperty;
75
+ var __name2$1 = /* @__PURE__ */ __name$2((target, value) => __defProp2$1(target, "name", { value, configurable: true }), "__name");
76
+ const CODE_FRAME_POINTER = process.platform === "win32" && !process.env?.WT_SESSION ? ">" : "❯";
77
+ const codeFrame = /* @__PURE__ */ __name2$1((source, loc, options) => {
78
+ const config = {
79
+ // grab 2 lines before, and 3 lines after focused line
80
+ linesAbove: 2,
81
+ linesBelow: 3,
82
+ prefix: "",
83
+ showGutter: true,
84
+ showLineNumbers: true,
85
+ tabWidth: 4,
86
+ ...options,
87
+ color: {
88
+ gutter: /* @__PURE__ */ __name2$1((value) => value, "gutter"),
89
+ marker: /* @__PURE__ */ __name2$1((value) => value, "marker"),
90
+ message: /* @__PURE__ */ __name2$1((value) => value, "message"),
91
+ ...options?.color
92
+ }
93
+ };
94
+ const hasColumns = loc.start && typeof loc.start.column === "number";
95
+ let lines = normalizeLF(source).split("\n");
96
+ if (typeof config?.tabWidth === "number") {
97
+ lines = lines.map((ln) => ln.replaceAll(" ", " ".repeat(config.tabWidth)));
98
+ }
99
+ const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);
100
+ const numberMaxWidth = String(end).length;
101
+ const { gutter: colorizeGutter, marker: colorizeMarker, message: colorizeMessage } = config.color;
102
+ let frame = lines.slice(start, end).map((line, index) => {
103
+ const number = start + 1 + index;
104
+ const hasMarker = markerLines[number];
105
+ const paddedNumber = (" " + number).slice(-numberMaxWidth);
106
+ const lastMarkerLine = !markerLines[number + 1];
107
+ const gutter = " " + paddedNumber + (config.showGutter ? " |" : "");
108
+ if (hasMarker) {
109
+ let markerLine = "";
110
+ if (Array.isArray(hasMarker)) {
111
+ const markerSpacing = line.replaceAll(/[^\t]/g, " ").slice(0, Math.max(hasMarker[0] - 1, 0));
112
+ const numberOfMarkers = hasMarker[1] || 1;
113
+ markerLine = [
114
+ "\n ",
115
+ config.prefix + colorizeGutter(gutter.replaceAll(/\d/g, " ")),
116
+ " ",
117
+ markerSpacing,
118
+ colorizeMarker("^").repeat(numberOfMarkers)
119
+ ].join("");
120
+ if (lastMarkerLine && config.message) {
121
+ markerLine += ` ${colorizeMessage(config.message)}`;
122
+ }
123
+ }
124
+ return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? " " + line : "", markerLine].join("");
125
+ }
126
+ return config.prefix + " " + colorizeGutter(gutter) + (line.length > 0 ? " " + line : "");
127
+ }).join("\n");
128
+ if (config.message && !hasColumns) {
129
+ frame = config.prefix + " ".repeat(numberMaxWidth + 1) + config.message + "\n" + frame;
130
+ }
131
+ return frame;
132
+ }, "codeFrame");
133
+
134
+ var __defProp$1 = Object.defineProperty;
135
+ var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
136
+ var __defProp2 = Object.defineProperty;
137
+ var __name2 = /* @__PURE__ */ __name$1((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
138
+ const binarySearch = /* @__PURE__ */ __name2((element, array) => {
139
+ let m = 0;
140
+ let n = array.length - 2;
141
+ while (m < n) {
142
+ const key = m + (n - m >> 1);
143
+ if (element < array[key]) {
144
+ n = key - 1;
145
+ } else if (element >= array[key + 1]) {
146
+ m = key + 1;
147
+ } else {
148
+ m = key;
149
+ break;
150
+ }
151
+ }
152
+ return m;
153
+ }, "binarySearch");
154
+ const getLineStartIndexes = /* @__PURE__ */ __name2((string_) => (
155
+ // eslint-disable-next-line unicorn/no-array-reduce
156
+ string_.split(/\n|\r(?!\n)/).reduce(
157
+ (accumulator, current) => {
158
+ accumulator.push(accumulator.at(-1) + current.length + 1);
159
+ return accumulator;
160
+ },
161
+ [0]
162
+ )
163
+ ), "getLineStartIndexes");
164
+ const indexToLineColumn = /* @__PURE__ */ __name2((input, index, options) => {
165
+ const skipChecks = options?.skipChecks ?? false;
166
+ if (!skipChecks && (!Array.isArray(input) && typeof input !== "string" || (typeof input === "string" || Array.isArray(input)) && input.length === 0)) {
167
+ return { column: 0, line: 0 };
168
+ }
169
+ if (!skipChecks && (typeof index !== "number" || typeof input === "string" && index >= input.length || Array.isArray(input) && index + 1 >= input.at(-1))) {
170
+ return { column: 0, line: 0 };
171
+ }
172
+ if (typeof input === "string") {
173
+ const startIndexesOfEachLine = getLineStartIndexes(input);
174
+ const line2 = binarySearch(index, startIndexesOfEachLine);
175
+ return {
176
+ // eslint-disable-next-line security/detect-object-injection
177
+ column: index - startIndexesOfEachLine[line2] + 1,
178
+ line: line2 + 1
179
+ };
180
+ }
181
+ const line = binarySearch(index, input);
182
+ return {
183
+ // eslint-disable-next-line security/detect-object-injection
184
+ column: index - input[line] + 1,
185
+ line: line + 1
186
+ };
187
+ }, "indexToLineColumn");
188
+
189
+ var __defProp = Object.defineProperty;
190
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
191
+ const getCodePoint = /* @__PURE__ */ __name((character) => `\\u{${character.codePointAt(0).toString(16)}}`, "getCodePoint");
192
+ const generateCodeFrame = /* @__PURE__ */ __name((source, location, options) => codeFrame(
193
+ source,
194
+ { start: location },
195
+ {
196
+ tabWidth: false,
197
+ ...options
198
+ }
199
+ ), "generateCodeFrame");
200
+ const getErrorLocation = /* @__PURE__ */ __name((source, message) => {
201
+ const match = /in JSON at position (?<index>\d+)(?: \(line (?<line>\d+) column (?<column>\d+)\))?$/.exec(message);
202
+ if (!match) {
203
+ return undefined;
204
+ }
205
+ let { column, index, line } = match.groups;
206
+ if (line && column) {
207
+ return { column: Number(column), line: Number(line) };
208
+ }
209
+ index = Number(index);
210
+ if (index === source.length) {
211
+ index = source.length - 1;
212
+ }
213
+ return indexToLineColumn(source, index);
214
+ }, "getErrorLocation");
215
+ const addCodePointToUnexpectedToken = /* @__PURE__ */ __name((message) => message.replace(
216
+ // TODO[engine:node@>=20]: The token always quoted after Node.js 20
217
+ // eslint-disable-next-line regexp/no-potentially-useless-backreference
218
+ /(?<=^Unexpected token )(?<quote>')?(.)\k<quote>/,
219
+ (_, _quote, token) => `"${token}"(${getCodePoint(token)})`
220
+ ), "addCodePointToUnexpectedToken");
221
+ function parseJson(string, reviver, fileName, options) {
222
+ if (typeof reviver === "string") {
223
+ if (typeof fileName === "object") {
224
+ options = fileName;
225
+ }
226
+ fileName = reviver;
227
+ reviver = undefined;
228
+ }
229
+ let message;
230
+ try {
231
+ return JSON.parse(string, reviver);
232
+ } catch (error) {
233
+ message = error.message;
234
+ }
235
+ let location;
236
+ if (string) {
237
+ location = getErrorLocation(string, message);
238
+ message = addCodePointToUnexpectedToken(message);
239
+ } else {
240
+ message += " while parsing empty string";
241
+ }
242
+ const jsonError = new JSONError(message);
243
+ jsonError.fileName = fileName;
244
+ if (location) {
245
+ jsonError.codeFrame = generateCodeFrame(string, location, options);
246
+ }
247
+ throw jsonError;
248
+ }
249
+ __name(parseJson, "parseJson");
250
+
251
+ module.exports = parseJson;
@@ -0,0 +1,249 @@
1
+ import JSONError from './JSONError-BCIIHvzq.mjs';
2
+
3
+ var __defProp$2 = Object.defineProperty;
4
+ var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
5
+ var __defProp$2$1 = Object.defineProperty;
6
+ var __name$2$1 = /* @__PURE__ */ __name$2((target, value) => __defProp$2$1(target, "name", { value, configurable: true }), "__name$2");
7
+ const normalizeLF = /* @__PURE__ */ __name$2$1((code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n"), "normalizeLF");
8
+ const _process = globalThis.process || /* @__PURE__ */ Object.create(null);
9
+ const processShims = {
10
+ versions: {}
11
+ };
12
+ const process = new Proxy(_process, {
13
+ get(target, property) {
14
+ if (property in target) {
15
+ return target[property];
16
+ }
17
+ if (property in processShims) {
18
+ return processShims[property];
19
+ }
20
+ return undefined;
21
+ }
22
+ });
23
+ var __defProp$1$1 = Object.defineProperty;
24
+ var __name$1$1 = /* @__PURE__ */ __name$2((target, value) => __defProp$1$1(target, "name", { value, configurable: true }), "__name$1");
25
+ const getMarkerLines = /* @__PURE__ */ __name$1$1((loc, source, linesAbove, linesBelow) => {
26
+ const startLoc = {
27
+ column: 0,
28
+ // @ts-expect-error Can be overwritten
29
+ line: -1,
30
+ ...loc.start
31
+ };
32
+ const endLoc = {
33
+ ...startLoc,
34
+ ...loc.end
35
+ };
36
+ const startLine = startLoc.line;
37
+ const startColumn = startLoc.column;
38
+ const endLine = endLoc.line;
39
+ const endColumn = endLoc.column;
40
+ let start = Math.max(startLine - (linesAbove + 1), 0);
41
+ let end = Math.min(source.length, endLine + linesBelow);
42
+ if (startLine === -1) {
43
+ start = 0;
44
+ }
45
+ if (endLine === -1) {
46
+ end = source.length;
47
+ }
48
+ const lineDiff = endLine - startLine;
49
+ const markerLines = {};
50
+ if (lineDiff) {
51
+ for (let index = 0; index <= lineDiff; index++) {
52
+ const lineNumber = index + startLine;
53
+ if (!startColumn) {
54
+ markerLines[lineNumber] = true;
55
+ } else if (index === 0) {
56
+ const sourceLength = source[lineNumber - 1]?.length;
57
+ markerLines[lineNumber] = [startColumn, (sourceLength ?? 0) - startColumn + 1];
58
+ } else if (index === lineDiff) {
59
+ markerLines[lineNumber] = [0, endColumn];
60
+ } else {
61
+ const sourceLength = source[lineNumber - index]?.length;
62
+ markerLines[lineNumber] = [0, sourceLength];
63
+ }
64
+ }
65
+ } else if (startColumn === endColumn) {
66
+ markerLines[startLine] = startColumn ? [startColumn, 0] : true;
67
+ } else {
68
+ markerLines[startLine] = [startColumn, (endColumn ?? 0) - (startColumn ?? 0)];
69
+ }
70
+ return { end, markerLines, start };
71
+ }, "getMarkerLines");
72
+ var __defProp2$1 = Object.defineProperty;
73
+ var __name2$1 = /* @__PURE__ */ __name$2((target, value) => __defProp2$1(target, "name", { value, configurable: true }), "__name");
74
+ const CODE_FRAME_POINTER = process.platform === "win32" && !process.env?.WT_SESSION ? ">" : "❯";
75
+ const codeFrame = /* @__PURE__ */ __name2$1((source, loc, options) => {
76
+ const config = {
77
+ // grab 2 lines before, and 3 lines after focused line
78
+ linesAbove: 2,
79
+ linesBelow: 3,
80
+ prefix: "",
81
+ showGutter: true,
82
+ showLineNumbers: true,
83
+ tabWidth: 4,
84
+ ...options,
85
+ color: {
86
+ gutter: /* @__PURE__ */ __name2$1((value) => value, "gutter"),
87
+ marker: /* @__PURE__ */ __name2$1((value) => value, "marker"),
88
+ message: /* @__PURE__ */ __name2$1((value) => value, "message"),
89
+ ...options?.color
90
+ }
91
+ };
92
+ const hasColumns = loc.start && typeof loc.start.column === "number";
93
+ let lines = normalizeLF(source).split("\n");
94
+ if (typeof config?.tabWidth === "number") {
95
+ lines = lines.map((ln) => ln.replaceAll(" ", " ".repeat(config.tabWidth)));
96
+ }
97
+ const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);
98
+ const numberMaxWidth = String(end).length;
99
+ const { gutter: colorizeGutter, marker: colorizeMarker, message: colorizeMessage } = config.color;
100
+ let frame = lines.slice(start, end).map((line, index) => {
101
+ const number = start + 1 + index;
102
+ const hasMarker = markerLines[number];
103
+ const paddedNumber = (" " + number).slice(-numberMaxWidth);
104
+ const lastMarkerLine = !markerLines[number + 1];
105
+ const gutter = " " + paddedNumber + (config.showGutter ? " |" : "");
106
+ if (hasMarker) {
107
+ let markerLine = "";
108
+ if (Array.isArray(hasMarker)) {
109
+ const markerSpacing = line.replaceAll(/[^\t]/g, " ").slice(0, Math.max(hasMarker[0] - 1, 0));
110
+ const numberOfMarkers = hasMarker[1] || 1;
111
+ markerLine = [
112
+ "\n ",
113
+ config.prefix + colorizeGutter(gutter.replaceAll(/\d/g, " ")),
114
+ " ",
115
+ markerSpacing,
116
+ colorizeMarker("^").repeat(numberOfMarkers)
117
+ ].join("");
118
+ if (lastMarkerLine && config.message) {
119
+ markerLine += ` ${colorizeMessage(config.message)}`;
120
+ }
121
+ }
122
+ return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? " " + line : "", markerLine].join("");
123
+ }
124
+ return config.prefix + " " + colorizeGutter(gutter) + (line.length > 0 ? " " + line : "");
125
+ }).join("\n");
126
+ if (config.message && !hasColumns) {
127
+ frame = config.prefix + " ".repeat(numberMaxWidth + 1) + config.message + "\n" + frame;
128
+ }
129
+ return frame;
130
+ }, "codeFrame");
131
+
132
+ var __defProp$1 = Object.defineProperty;
133
+ var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
134
+ var __defProp2 = Object.defineProperty;
135
+ var __name2 = /* @__PURE__ */ __name$1((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
136
+ const binarySearch = /* @__PURE__ */ __name2((element, array) => {
137
+ let m = 0;
138
+ let n = array.length - 2;
139
+ while (m < n) {
140
+ const key = m + (n - m >> 1);
141
+ if (element < array[key]) {
142
+ n = key - 1;
143
+ } else if (element >= array[key + 1]) {
144
+ m = key + 1;
145
+ } else {
146
+ m = key;
147
+ break;
148
+ }
149
+ }
150
+ return m;
151
+ }, "binarySearch");
152
+ const getLineStartIndexes = /* @__PURE__ */ __name2((string_) => (
153
+ // eslint-disable-next-line unicorn/no-array-reduce
154
+ string_.split(/\n|\r(?!\n)/).reduce(
155
+ (accumulator, current) => {
156
+ accumulator.push(accumulator.at(-1) + current.length + 1);
157
+ return accumulator;
158
+ },
159
+ [0]
160
+ )
161
+ ), "getLineStartIndexes");
162
+ const indexToLineColumn = /* @__PURE__ */ __name2((input, index, options) => {
163
+ const skipChecks = options?.skipChecks ?? false;
164
+ if (!skipChecks && (!Array.isArray(input) && typeof input !== "string" || (typeof input === "string" || Array.isArray(input)) && input.length === 0)) {
165
+ return { column: 0, line: 0 };
166
+ }
167
+ if (!skipChecks && (typeof index !== "number" || typeof input === "string" && index >= input.length || Array.isArray(input) && index + 1 >= input.at(-1))) {
168
+ return { column: 0, line: 0 };
169
+ }
170
+ if (typeof input === "string") {
171
+ const startIndexesOfEachLine = getLineStartIndexes(input);
172
+ const line2 = binarySearch(index, startIndexesOfEachLine);
173
+ return {
174
+ // eslint-disable-next-line security/detect-object-injection
175
+ column: index - startIndexesOfEachLine[line2] + 1,
176
+ line: line2 + 1
177
+ };
178
+ }
179
+ const line = binarySearch(index, input);
180
+ return {
181
+ // eslint-disable-next-line security/detect-object-injection
182
+ column: index - input[line] + 1,
183
+ line: line + 1
184
+ };
185
+ }, "indexToLineColumn");
186
+
187
+ var __defProp = Object.defineProperty;
188
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
189
+ const getCodePoint = /* @__PURE__ */ __name((character) => `\\u{${character.codePointAt(0).toString(16)}}`, "getCodePoint");
190
+ const generateCodeFrame = /* @__PURE__ */ __name((source, location, options) => codeFrame(
191
+ source,
192
+ { start: location },
193
+ {
194
+ tabWidth: false,
195
+ ...options
196
+ }
197
+ ), "generateCodeFrame");
198
+ const getErrorLocation = /* @__PURE__ */ __name((source, message) => {
199
+ const match = /in JSON at position (?<index>\d+)(?: \(line (?<line>\d+) column (?<column>\d+)\))?$/.exec(message);
200
+ if (!match) {
201
+ return undefined;
202
+ }
203
+ let { column, index, line } = match.groups;
204
+ if (line && column) {
205
+ return { column: Number(column), line: Number(line) };
206
+ }
207
+ index = Number(index);
208
+ if (index === source.length) {
209
+ index = source.length - 1;
210
+ }
211
+ return indexToLineColumn(source, index);
212
+ }, "getErrorLocation");
213
+ const addCodePointToUnexpectedToken = /* @__PURE__ */ __name((message) => message.replace(
214
+ // TODO[engine:node@>=20]: The token always quoted after Node.js 20
215
+ // eslint-disable-next-line regexp/no-potentially-useless-backreference
216
+ /(?<=^Unexpected token )(?<quote>')?(.)\k<quote>/,
217
+ (_, _quote, token) => `"${token}"(${getCodePoint(token)})`
218
+ ), "addCodePointToUnexpectedToken");
219
+ function parseJson(string, reviver, fileName, options) {
220
+ if (typeof reviver === "string") {
221
+ if (typeof fileName === "object") {
222
+ options = fileName;
223
+ }
224
+ fileName = reviver;
225
+ reviver = undefined;
226
+ }
227
+ let message;
228
+ try {
229
+ return JSON.parse(string, reviver);
230
+ } catch (error) {
231
+ message = error.message;
232
+ }
233
+ let location;
234
+ if (string) {
235
+ location = getErrorLocation(string, message);
236
+ message = addCodePointToUnexpectedToken(message);
237
+ } else {
238
+ message += " while parsing empty string";
239
+ }
240
+ const jsonError = new JSONError(message);
241
+ jsonError.fileName = fileName;
242
+ if (location) {
243
+ jsonError.codeFrame = generateCodeFrame(string, location, options);
244
+ }
245
+ throw jsonError;
246
+ }
247
+ __name(parseJson, "parseJson");
248
+
249
+ export { parseJson as default };
@@ -1,5 +1,5 @@
1
1
  import { toPath } from '@visulima/path/utils';
2
- import parseJson from './parseJson-B_q4905N.mjs';
2
+ import parseJson from './parseJson-n9THWOFI.mjs';
3
3
  import readFile from './readFile-DUM-xNoB.mjs';
4
4
 
5
5
  var __defProp = Object.defineProperty;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const utils = require('@visulima/path/utils');
4
- const parseJson = require('./parseJson-P3C7DMaS.cjs');
4
+ const parseJson = require('./parseJson-DcUo4Rpt.cjs');
5
5
  const readFile = require('./readFile-iFUhZHnh.cjs');
6
6
 
7
7
  var __defProp = Object.defineProperty;
@@ -1,5 +1,5 @@
1
1
  import { toPath } from '@visulima/path/utils';
2
- import parseJson from './parseJson-B_q4905N.mjs';
2
+ import parseJson from './parseJson-n9THWOFI.mjs';
3
3
  import readFileSync from './readFileSync-Cck96_o0.mjs';
4
4
 
5
5
  var __defProp = Object.defineProperty;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const utils = require('@visulima/path/utils');
4
- const parseJson = require('./parseJson-P3C7DMaS.cjs');
4
+ const parseJson = require('./parseJson-DcUo4Rpt.cjs');
5
5
  const readFileSync = require('./readFileSync-B3NTOR-W.cjs');
6
6
 
7
7
  var __defProp = Object.defineProperty;
@@ -22,6 +22,7 @@ const writeFile = /* @__PURE__ */ __name(async (path$1, content, options) => {
22
22
  assertValidFileOrDirectoryPath(path$1);
23
23
  assertValidFileContents(content);
24
24
  path$1 = utils.toPath(path$1);
25
+ const temporaryPath = `${path$1}.tmp`;
25
26
  try {
26
27
  const pathExists = await isAccessible(path$1, F_OK.F_OK);
27
28
  if (!pathExists && options.recursive) {
@@ -31,7 +32,7 @@ const writeFile = /* @__PURE__ */ __name(async (path$1, content, options) => {
31
32
  }
32
33
  }
33
34
  let stat;
34
- await promises.writeFile(`${path$1}.tmp`, toUint8Array.toUint8Array(content), { encoding: options.encoding, flag: options.flag });
35
+ await promises.writeFile(temporaryPath, toUint8Array.toUint8Array(content), { encoding: options.encoding, flag: options.flag });
35
36
  if (pathExists && !options.overwrite) {
36
37
  stat = await promises.stat(path$1);
37
38
  if (options.chown === undefined) {
@@ -39,7 +40,6 @@ const writeFile = /* @__PURE__ */ __name(async (path$1, content, options) => {
39
40
  }
40
41
  await promises.rename(path$1, `${path$1}.bak`);
41
42
  }
42
- const temporaryPath = `${path$1}.tmp`;
43
43
  if (options.chown) {
44
44
  try {
45
45
  await promises.chown(temporaryPath, options.chown.uid, options.chown.gid);
@@ -51,7 +51,7 @@ const writeFile = /* @__PURE__ */ __name(async (path$1, content, options) => {
51
51
  } catch (error) {
52
52
  throw new Error(`Failed to write file at: ${path$1} - ${error.message}`, { cause: error });
53
53
  } finally {
54
- if (await isAccessible(`${path$1}.tmp`)) {
54
+ if (await isAccessible(temporaryPath)) {
55
55
  await promises.unlink(`${path$1}.tmp`);
56
56
  }
57
57
  }