@visulima/fs 2.3.6 → 2.3.7

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 CHANGED
@@ -1,3 +1,11 @@
1
+ ## @visulima/fs [2.3.7](https://github.com/visulima/visulima/compare/@visulima/fs@2.3.6...@visulima/fs@2.3.7) (2025-01-13)
2
+
3
+
4
+ ### Dependencies
5
+
6
+ * **@visulima/path:** upgraded to 1.3.3
7
+ * **@visulima/error:** upgraded to 4.4.13
8
+
1
9
  ## @visulima/fs [2.3.6](https://github.com/visulima/visulima/compare/@visulima/fs@2.3.5...@visulima/fs@2.3.6) (2025-01-12)
2
10
 
3
11
  ### Bug Fixes
package/dist/index.cjs CHANGED
@@ -23,8 +23,8 @@ 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');
package/dist/index.mjs CHANGED
@@ -19,8 +19,8 @@ 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';
@@ -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;
package/dist/utils.cjs CHANGED
@@ -5,7 +5,7 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
5
5
  const JSONError = require('./packem_shared/JSONError-gkXvBSar.cjs');
6
6
  const assertValidFileContents = require('./packem_shared/assertValidFileContents-CRVvyM6b.cjs');
7
7
  const assertValidFileOrDirectoryPath = require('./packem_shared/assertValidFileOrDirectoryPath-BMbgA-eI.cjs');
8
- const parseJson = require('./packem_shared/parseJson-P3C7DMaS.cjs');
8
+ const parseJson = require('./packem_shared/parseJson-DcUo4Rpt.cjs');
9
9
  const stripJsonComments = require('./packem_shared/stripJsonComments-eDrcJvBT.cjs');
10
10
  const utils = require('@visulima/path/utils');
11
11
 
package/dist/utils.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  export { default as JSONError } from './packem_shared/JSONError-BCIIHvzq.mjs';
2
2
  export { default as assertValidFileContents } from './packem_shared/assertValidFileContents-Ox-ScfeK.mjs';
3
3
  export { default as assertValidFileOrDirectoryPath } from './packem_shared/assertValidFileOrDirectoryPath-BWWgA1wj.mjs';
4
- export { default as parseJson } from './packem_shared/parseJson-B_q4905N.mjs';
4
+ export { default as parseJson } from './packem_shared/parseJson-n9THWOFI.mjs';
5
5
  export { default as stripJsonComments } from './packem_shared/stripJsonComments-B66nRaTZ.mjs';
6
6
  export { toPath } from '@visulima/path/utils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/fs",
3
- "version": "2.3.6",
3
+ "version": "2.3.7",
4
4
  "description": "Human friendly file system utilities for Node.js",
5
5
  "keywords": [
6
6
  "anolilab",
@@ -132,7 +132,7 @@
132
132
  "LICENSE.md"
133
133
  ],
134
134
  "dependencies": {
135
- "@visulima/path": "1.3.2",
135
+ "@visulima/path": "1.3.3",
136
136
  "yaml": "^2.7.0"
137
137
  },
138
138
  "devDependencies": {
@@ -144,7 +144,7 @@
144
144
  "@babel/core": "^7.26.0",
145
145
  "@rushstack/eslint-plugin-security": "^0.8.3",
146
146
  "@types/node": "18.19.15",
147
- "@visulima/error": "4.4.12",
147
+ "@visulima/error": "4.4.13",
148
148
  "@visulima/packem": "1.10.7",
149
149
  "@vitest/coverage-v8": "^2.1.8",
150
150
  "@vitest/ui": "^2.1.8",
@@ -1,160 +0,0 @@
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 P = Object.defineProperty;
6
- var v = /* @__PURE__ */ __name$2((t, e) => P(t, "name", { value: e, configurable: true }), "v");
7
- var E = Object.defineProperty;
8
- var F = v((t, e) => E(t, "name", { value: e, configurable: true }), "r$1");
9
- const N = F((t) => t.replaceAll(/\r\n|\r(?!\n)|\n/gu, `
10
- `), "normalizeLF");
11
- const S = globalThis.process || /* @__PURE__ */ Object.create(null);
12
- const j = { versions: {} };
13
- const k = new Proxy(S, { get(t, e) {
14
- if (e in t) return t[e];
15
- if (e in j) return j[e];
16
- } });
17
- var W = Object.defineProperty;
18
- var C = v((t, e) => W(t, "name", { value: e, configurable: true }), "b");
19
- const T = C((t, e, h, n) => {
20
- const f = { column: 0, line: -1, ...t.start }, i = { ...f, ...t.end }, o = f.line, l = f.column, m = i.line, u = i.column;
21
- let g = Math.max(o - (h + 1), 0), p = Math.min(e.length, m + n);
22
- o === -1 && (g = 0), m === -1 && (p = e.length);
23
- const b = m - o, a = {};
24
- if (b) for (let r = 0; r <= b; r++) {
25
- const s = r + o;
26
- if (!l) a[s] = true;
27
- else if (r === 0) {
28
- const c = e[s - 1]?.length;
29
- a[s] = [l, (c ?? 0) - l + 1];
30
- } else if (r === b) a[s] = [0, u];
31
- else {
32
- const c = e[s - r]?.length;
33
- a[s] = [0, c];
34
- }
35
- }
36
- else l === u ? a[o] = l ? [l, 0] : true : a[o] = [l, (u ?? 0) - (l ?? 0)];
37
- return { end: p, markerLines: a, start: g };
38
- }, "getMarkerLines");
39
- var _ = Object.defineProperty;
40
- var x = v((t, e) => _(t, "name", { value: e, configurable: true }), "o");
41
- const B = k.platform === "win32" && !k.env?.WT_SESSION ? ">" : "❯";
42
- const I = x((t, e, h) => {
43
- const n = { linesAbove: 2, linesBelow: 3, prefix: "", showGutter: true, showLineNumbers: true, tabWidth: 4, ...h, color: { gutter: x((r) => r, "gutter"), marker: x((r) => r, "marker"), message: x((r) => r, "message"), ...h?.color } }, f = e.start && typeof e.start.column == "number";
44
- let i = N(t).split(`
45
- `);
46
- typeof n?.tabWidth == "number" && (i = i.map((r) => r.replaceAll(" ", " ".repeat(n.tabWidth))));
47
- const { end: o, markerLines: l, start: m } = T(e, i, n.linesAbove, n.linesBelow), u = String(o).length, { gutter: g, marker: p, message: b } = n.color;
48
- let a = i.slice(m, o).map((r, s) => {
49
- const c = m + 1 + s, d = l[c], w = (" " + c).slice(-u), L = !l[c + 1], A = " " + w + (n.showGutter ? " |" : "");
50
- if (d) {
51
- let y = "";
52
- if (Array.isArray(d)) {
53
- const O = r.replaceAll(/[^\t]/g, " ").slice(0, Math.max(d[0] - 1, 0)), M = d[1] || 1;
54
- y = [`
55
- `, n.prefix + g(A.replaceAll(/\d/g, " ")), " ", O, p("^").repeat(M)].join(""), L && n.message && (y += ` ${b(n.message)}`);
56
- }
57
- return [n.prefix + p(B), g(A), r.length > 0 ? " " + r : "", y].join("");
58
- }
59
- return n.prefix + " " + g(A) + (r.length > 0 ? " " + r : "");
60
- }).join(`
61
- `);
62
- return n.message && !f && (a = n.prefix + " ".repeat(u + 1) + n.message + `
63
- ` + a), a;
64
- }, "codeFrame");
65
-
66
- var __defProp$1 = Object.defineProperty;
67
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
68
- var c = Object.defineProperty;
69
- var a = /* @__PURE__ */ __name$1((n, t) => c(n, "name", { value: t, configurable: true }), "a");
70
- var f = Object.defineProperty;
71
- var s = a((n, t) => f(n, "name", { value: t, configurable: true }), "l");
72
- const u = s((n, t) => {
73
- let e = 0, i = t.length - 2;
74
- for (; e < i; ) {
75
- const r = e + (i - e >> 1);
76
- if (n < t[r]) i = r - 1;
77
- else if (n >= t[r + 1]) e = r + 1;
78
- else {
79
- e = r;
80
- break;
81
- }
82
- }
83
- return e;
84
- }, "binarySearch");
85
- const y = s((n) => n.split(/\n|\r(?!\n)/).reduce((t, e) => (t.push(t.at(-1) + e.length + 1), t), [0]), "getLineStartIndexes");
86
- const p = s((n, t, e) => {
87
- const i = e?.skipChecks ?? false;
88
- if (!i && (!Array.isArray(n) && typeof n != "string" || (typeof n == "string" || Array.isArray(n)) && n.length === 0)) return { column: 0, line: 0 };
89
- if (!i && (typeof t != "number" || typeof n == "string" && t >= n.length || Array.isArray(n) && t + 1 >= n.at(-1))) return { column: 0, line: 0 };
90
- if (typeof n == "string") {
91
- const l = y(n), o = u(t, l);
92
- return { column: t - l[o] + 1, line: o + 1 };
93
- }
94
- const r = u(t, n);
95
- return { column: t - n[r] + 1, line: r + 1 };
96
- }, "indexToLineColumn");
97
-
98
- var __defProp = Object.defineProperty;
99
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
100
- const getCodePoint = /* @__PURE__ */ __name((character) => `\\u{${character.codePointAt(0).toString(16)}}`, "getCodePoint");
101
- const generateCodeFrame = /* @__PURE__ */ __name((source, location, options) => I(
102
- source,
103
- { start: location },
104
- {
105
- tabWidth: false,
106
- ...options
107
- }
108
- ), "generateCodeFrame");
109
- const getErrorLocation = /* @__PURE__ */ __name((source, message) => {
110
- const match = /in JSON at position (?<index>\d+)(?: \(line (?<line>\d+) column (?<column>\d+)\))?$/.exec(message);
111
- if (!match) {
112
- return undefined;
113
- }
114
- let { column, index, line } = match.groups;
115
- if (line && column) {
116
- return { column: Number(column), line: Number(line) };
117
- }
118
- index = Number(index);
119
- if (index === source.length) {
120
- index = source.length - 1;
121
- }
122
- return p(source, index);
123
- }, "getErrorLocation");
124
- const addCodePointToUnexpectedToken = /* @__PURE__ */ __name((message) => message.replace(
125
- // TODO[engine:node@>=20]: The token always quoted after Node.js 20
126
- // eslint-disable-next-line regexp/no-potentially-useless-backreference
127
- /(?<=^Unexpected token )(?<quote>')?(.)\k<quote>/,
128
- (_, _quote, token) => `"${token}"(${getCodePoint(token)})`
129
- ), "addCodePointToUnexpectedToken");
130
- function parseJson(string, reviver, fileName, options) {
131
- if (typeof reviver === "string") {
132
- if (typeof fileName === "object") {
133
- options = fileName;
134
- }
135
- fileName = reviver;
136
- reviver = undefined;
137
- }
138
- let message;
139
- try {
140
- return JSON.parse(string, reviver);
141
- } catch (error) {
142
- message = error.message;
143
- }
144
- let location;
145
- if (string) {
146
- location = getErrorLocation(string, message);
147
- message = addCodePointToUnexpectedToken(message);
148
- } else {
149
- message += " while parsing empty string";
150
- }
151
- const jsonError = new JSONError(message);
152
- jsonError.fileName = fileName;
153
- if (location) {
154
- jsonError.codeFrame = generateCodeFrame(string, location, options);
155
- }
156
- throw jsonError;
157
- }
158
- __name(parseJson, "parseJson");
159
-
160
- export { parseJson as default };
@@ -1,162 +0,0 @@
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 P = Object.defineProperty;
8
- var v = /* @__PURE__ */ __name$2((t, e) => P(t, "name", { value: e, configurable: true }), "v");
9
- var E = Object.defineProperty;
10
- var F = v((t, e) => E(t, "name", { value: e, configurable: true }), "r$1");
11
- const N = F((t) => t.replaceAll(/\r\n|\r(?!\n)|\n/gu, `
12
- `), "normalizeLF");
13
- const S = globalThis.process || /* @__PURE__ */ Object.create(null);
14
- const j = { versions: {} };
15
- const k = new Proxy(S, { get(t, e) {
16
- if (e in t) return t[e];
17
- if (e in j) return j[e];
18
- } });
19
- var W = Object.defineProperty;
20
- var C = v((t, e) => W(t, "name", { value: e, configurable: true }), "b");
21
- const T = C((t, e, h, n) => {
22
- const f = { column: 0, line: -1, ...t.start }, i = { ...f, ...t.end }, o = f.line, l = f.column, m = i.line, u = i.column;
23
- let g = Math.max(o - (h + 1), 0), p = Math.min(e.length, m + n);
24
- o === -1 && (g = 0), m === -1 && (p = e.length);
25
- const b = m - o, a = {};
26
- if (b) for (let r = 0; r <= b; r++) {
27
- const s = r + o;
28
- if (!l) a[s] = true;
29
- else if (r === 0) {
30
- const c = e[s - 1]?.length;
31
- a[s] = [l, (c ?? 0) - l + 1];
32
- } else if (r === b) a[s] = [0, u];
33
- else {
34
- const c = e[s - r]?.length;
35
- a[s] = [0, c];
36
- }
37
- }
38
- else l === u ? a[o] = l ? [l, 0] : true : a[o] = [l, (u ?? 0) - (l ?? 0)];
39
- return { end: p, markerLines: a, start: g };
40
- }, "getMarkerLines");
41
- var _ = Object.defineProperty;
42
- var x = v((t, e) => _(t, "name", { value: e, configurable: true }), "o");
43
- const B = k.platform === "win32" && !k.env?.WT_SESSION ? ">" : "❯";
44
- const I = x((t, e, h) => {
45
- const n = { linesAbove: 2, linesBelow: 3, prefix: "", showGutter: true, showLineNumbers: true, tabWidth: 4, ...h, color: { gutter: x((r) => r, "gutter"), marker: x((r) => r, "marker"), message: x((r) => r, "message"), ...h?.color } }, f = e.start && typeof e.start.column == "number";
46
- let i = N(t).split(`
47
- `);
48
- typeof n?.tabWidth == "number" && (i = i.map((r) => r.replaceAll(" ", " ".repeat(n.tabWidth))));
49
- const { end: o, markerLines: l, start: m } = T(e, i, n.linesAbove, n.linesBelow), u = String(o).length, { gutter: g, marker: p, message: b } = n.color;
50
- let a = i.slice(m, o).map((r, s) => {
51
- const c = m + 1 + s, d = l[c], w = (" " + c).slice(-u), L = !l[c + 1], A = " " + w + (n.showGutter ? " |" : "");
52
- if (d) {
53
- let y = "";
54
- if (Array.isArray(d)) {
55
- const O = r.replaceAll(/[^\t]/g, " ").slice(0, Math.max(d[0] - 1, 0)), M = d[1] || 1;
56
- y = [`
57
- `, n.prefix + g(A.replaceAll(/\d/g, " ")), " ", O, p("^").repeat(M)].join(""), L && n.message && (y += ` ${b(n.message)}`);
58
- }
59
- return [n.prefix + p(B), g(A), r.length > 0 ? " " + r : "", y].join("");
60
- }
61
- return n.prefix + " " + g(A) + (r.length > 0 ? " " + r : "");
62
- }).join(`
63
- `);
64
- return n.message && !f && (a = n.prefix + " ".repeat(u + 1) + n.message + `
65
- ` + a), a;
66
- }, "codeFrame");
67
-
68
- var __defProp$1 = Object.defineProperty;
69
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
70
- var c = Object.defineProperty;
71
- var a = /* @__PURE__ */ __name$1((n, t) => c(n, "name", { value: t, configurable: true }), "a");
72
- var f = Object.defineProperty;
73
- var s = a((n, t) => f(n, "name", { value: t, configurable: true }), "l");
74
- const u = s((n, t) => {
75
- let e = 0, i = t.length - 2;
76
- for (; e < i; ) {
77
- const r = e + (i - e >> 1);
78
- if (n < t[r]) i = r - 1;
79
- else if (n >= t[r + 1]) e = r + 1;
80
- else {
81
- e = r;
82
- break;
83
- }
84
- }
85
- return e;
86
- }, "binarySearch");
87
- const y = s((n) => n.split(/\n|\r(?!\n)/).reduce((t, e) => (t.push(t.at(-1) + e.length + 1), t), [0]), "getLineStartIndexes");
88
- const p = s((n, t, e) => {
89
- const i = e?.skipChecks ?? false;
90
- if (!i && (!Array.isArray(n) && typeof n != "string" || (typeof n == "string" || Array.isArray(n)) && n.length === 0)) return { column: 0, line: 0 };
91
- if (!i && (typeof t != "number" || typeof n == "string" && t >= n.length || Array.isArray(n) && t + 1 >= n.at(-1))) return { column: 0, line: 0 };
92
- if (typeof n == "string") {
93
- const l = y(n), o = u(t, l);
94
- return { column: t - l[o] + 1, line: o + 1 };
95
- }
96
- const r = u(t, n);
97
- return { column: t - n[r] + 1, line: r + 1 };
98
- }, "indexToLineColumn");
99
-
100
- var __defProp = Object.defineProperty;
101
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
102
- const getCodePoint = /* @__PURE__ */ __name((character) => `\\u{${character.codePointAt(0).toString(16)}}`, "getCodePoint");
103
- const generateCodeFrame = /* @__PURE__ */ __name((source, location, options) => I(
104
- source,
105
- { start: location },
106
- {
107
- tabWidth: false,
108
- ...options
109
- }
110
- ), "generateCodeFrame");
111
- const getErrorLocation = /* @__PURE__ */ __name((source, message) => {
112
- const match = /in JSON at position (?<index>\d+)(?: \(line (?<line>\d+) column (?<column>\d+)\))?$/.exec(message);
113
- if (!match) {
114
- return undefined;
115
- }
116
- let { column, index, line } = match.groups;
117
- if (line && column) {
118
- return { column: Number(column), line: Number(line) };
119
- }
120
- index = Number(index);
121
- if (index === source.length) {
122
- index = source.length - 1;
123
- }
124
- return p(source, index);
125
- }, "getErrorLocation");
126
- const addCodePointToUnexpectedToken = /* @__PURE__ */ __name((message) => message.replace(
127
- // TODO[engine:node@>=20]: The token always quoted after Node.js 20
128
- // eslint-disable-next-line regexp/no-potentially-useless-backreference
129
- /(?<=^Unexpected token )(?<quote>')?(.)\k<quote>/,
130
- (_, _quote, token) => `"${token}"(${getCodePoint(token)})`
131
- ), "addCodePointToUnexpectedToken");
132
- function parseJson(string, reviver, fileName, options) {
133
- if (typeof reviver === "string") {
134
- if (typeof fileName === "object") {
135
- options = fileName;
136
- }
137
- fileName = reviver;
138
- reviver = undefined;
139
- }
140
- let message;
141
- try {
142
- return JSON.parse(string, reviver);
143
- } catch (error) {
144
- message = error.message;
145
- }
146
- let location;
147
- if (string) {
148
- location = getErrorLocation(string, message);
149
- message = addCodePointToUnexpectedToken(message);
150
- } else {
151
- message += " while parsing empty string";
152
- }
153
- const jsonError = new JSONError(message);
154
- jsonError.fileName = fileName;
155
- if (location) {
156
- jsonError.codeFrame = generateCodeFrame(string, location, options);
157
- }
158
- throw jsonError;
159
- }
160
- __name(parseJson, "parseJson");
161
-
162
- module.exports = parseJson;