@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
@@ -20,6 +20,7 @@ const writeFile = /* @__PURE__ */ __name(async (path, content, options) => {
20
20
  assertValidFileOrDirectoryPath(path);
21
21
  assertValidFileContents(content);
22
22
  path = toPath(path);
23
+ const temporaryPath = `${path}.tmp`;
23
24
  try {
24
25
  const pathExists = await isAccessible(path, F_OK);
25
26
  if (!pathExists && options.recursive) {
@@ -29,7 +30,7 @@ const writeFile = /* @__PURE__ */ __name(async (path, content, options) => {
29
30
  }
30
31
  }
31
32
  let stat$1;
32
- await writeFile$1(`${path}.tmp`, toUint8Array(content), { encoding: options.encoding, flag: options.flag });
33
+ await writeFile$1(temporaryPath, toUint8Array(content), { encoding: options.encoding, flag: options.flag });
33
34
  if (pathExists && !options.overwrite) {
34
35
  stat$1 = await stat(path);
35
36
  if (options.chown === undefined) {
@@ -37,7 +38,6 @@ const writeFile = /* @__PURE__ */ __name(async (path, content, options) => {
37
38
  }
38
39
  await rename(path, `${path}.bak`);
39
40
  }
40
- const temporaryPath = `${path}.tmp`;
41
41
  if (options.chown) {
42
42
  try {
43
43
  await chown(temporaryPath, options.chown.uid, options.chown.gid);
@@ -49,7 +49,7 @@ const writeFile = /* @__PURE__ */ __name(async (path, content, options) => {
49
49
  } catch (error) {
50
50
  throw new Error(`Failed to write file at: ${path} - ${error.message}`, { cause: error });
51
51
  } finally {
52
- if (await isAccessible(`${path}.tmp`)) {
52
+ if (await isAccessible(temporaryPath)) {
53
53
  await unlink(`${path}.tmp`);
54
54
  }
55
55
  }
@@ -20,6 +20,7 @@ const writeFileSync = /* @__PURE__ */ __name((path, content, options) => {
20
20
  assertValidFileOrDirectoryPath(path);
21
21
  assertValidFileContents(content);
22
22
  path = toPath(path);
23
+ const temporaryPath = `${path}.tmp`;
23
24
  try {
24
25
  const pathExists = isAccessibleSync(path, F_OK);
25
26
  if (!pathExists && options.recursive) {
@@ -29,7 +30,7 @@ const writeFileSync = /* @__PURE__ */ __name((path, content, options) => {
29
30
  }
30
31
  }
31
32
  let stat;
32
- writeFileSync$1(`${path}.tmp`, toUint8Array(content), { encoding: options.encoding, flag: options.flag });
33
+ writeFileSync$1(temporaryPath, toUint8Array(content), { encoding: options.encoding, flag: options.flag });
33
34
  if (pathExists && !options.overwrite) {
34
35
  stat = statSync(path);
35
36
  if (options.chown === undefined) {
@@ -37,7 +38,6 @@ const writeFileSync = /* @__PURE__ */ __name((path, content, options) => {
37
38
  }
38
39
  renameSync(path, `${path}.bak`);
39
40
  }
40
- const temporaryPath = `${path}.tmp`;
41
41
  if (options.chown) {
42
42
  try {
43
43
  chownSync(temporaryPath, options.chown.uid, options.chown.gid);
@@ -49,7 +49,7 @@ const writeFileSync = /* @__PURE__ */ __name((path, content, options) => {
49
49
  } catch (error) {
50
50
  throw new Error(`Failed to write file at: ${path} - ${error.message}`, { cause: error });
51
51
  } finally {
52
- if (isAccessibleSync(`${path}.tmp`)) {
52
+ if (isAccessibleSync(temporaryPath)) {
53
53
  unlinkSync(`${path}.tmp`);
54
54
  }
55
55
  }
@@ -22,6 +22,7 @@ const writeFileSync = /* @__PURE__ */ __name((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 = isAccessibleSync(path$1, F_OK.F_OK);
27
28
  if (!pathExists && options.recursive) {
@@ -31,7 +32,7 @@ const writeFileSync = /* @__PURE__ */ __name((path$1, content, options) => {
31
32
  }
32
33
  }
33
34
  let stat;
34
- node_fs.writeFileSync(`${path$1}.tmp`, toUint8Array.toUint8Array(content), { encoding: options.encoding, flag: options.flag });
35
+ node_fs.writeFileSync(temporaryPath, toUint8Array.toUint8Array(content), { encoding: options.encoding, flag: options.flag });
35
36
  if (pathExists && !options.overwrite) {
36
37
  stat = node_fs.statSync(path$1);
37
38
  if (options.chown === undefined) {
@@ -39,7 +40,6 @@ const writeFileSync = /* @__PURE__ */ __name((path$1, content, options) => {
39
40
  }
40
41
  node_fs.renameSync(path$1, `${path$1}.bak`);
41
42
  }
42
- const temporaryPath = `${path$1}.tmp`;
43
43
  if (options.chown) {
44
44
  try {
45
45
  node_fs.chownSync(temporaryPath, options.chown.uid, options.chown.gid);
@@ -51,7 +51,7 @@ const writeFileSync = /* @__PURE__ */ __name((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 (isAccessibleSync(`${path$1}.tmp`)) {
54
+ if (isAccessibleSync(temporaryPath)) {
55
55
  node_fs.unlinkSync(`${path$1}.tmp`);
56
56
  }
57
57
  }
@@ -4,7 +4,7 @@ const promises = require('node:fs/promises');
4
4
  const index = require('./index-ngvEMjBI.cjs');
5
5
  const F_OK = require('./F_OK-CWSqQIdF.cjs');
6
6
  const isAccessible = require('./isAccessible-ZNVGsSb7.cjs');
7
- const writeFile = require('./writeFile-DKu5-M8x.cjs');
7
+ const writeFile = require('./writeFile-CnWc2ZOW.cjs');
8
8
 
9
9
  var __defProp = Object.defineProperty;
10
10
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -2,7 +2,7 @@ import { readFile } from 'node:fs/promises';
2
2
  import { d as detectIndent } from './index-ajT9ecry.mjs';
3
3
  import { R_OK } from './F_OK-JER1LjUr.mjs';
4
4
  import isAccessible from './isAccessible-Bonsm1Ez.mjs';
5
- import writeFile from './writeFile-B7dhfseN.mjs';
5
+ import writeFile from './writeFile-CzpkxDqy.mjs';
6
6
 
7
7
  var __defProp = Object.defineProperty;
8
8
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -4,7 +4,7 @@ const node_fs = require('node:fs');
4
4
  const index = require('./index-ngvEMjBI.cjs');
5
5
  const F_OK = require('./F_OK-CWSqQIdF.cjs');
6
6
  const isAccessibleSync = require('./isAccessibleSync-VWjQa-US.cjs');
7
- const writeFileSync = require('./writeFileSync-Db6pmY0q.cjs');
7
+ const writeFileSync = require('./writeFileSync-da4qD9Nz.cjs');
8
8
 
9
9
  var __defProp = Object.defineProperty;
10
10
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs';
2
2
  import { d as detectIndent } from './index-ajT9ecry.mjs';
3
3
  import { R_OK } from './F_OK-JER1LjUr.mjs';
4
4
  import isAccessibleSync from './isAccessibleSync-3gnUWUwX.mjs';
5
- import writeFileSync from './writeFileSync-mMGYqOc8.mjs';
5
+ import writeFileSync from './writeFileSync-DYRpumrj.mjs';
6
6
 
7
7
  var __defProp = Object.defineProperty;
8
8
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const yaml = require('yaml');
4
- const writeFile = require('./writeFile-DKu5-M8x.cjs');
4
+ const writeFile = require('./writeFile-CnWc2ZOW.cjs');
5
5
 
6
6
  var __defProp = Object.defineProperty;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -1,5 +1,5 @@
1
1
  import { stringify } from 'yaml';
2
- import writeFile from './writeFile-B7dhfseN.mjs';
2
+ import writeFile from './writeFile-CzpkxDqy.mjs';
3
3
 
4
4
  var __defProp = Object.defineProperty;
5
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -1,5 +1,5 @@
1
1
  import { stringify } from 'yaml';
2
- import writeFileSync from './writeFileSync-mMGYqOc8.mjs';
2
+ import writeFileSync from './writeFileSync-DYRpumrj.mjs';
3
3
 
4
4
  var __defProp = Object.defineProperty;
5
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const yaml = require('yaml');
4
- const writeFileSync = require('./writeFileSync-Db6pmY0q.cjs');
4
+ const writeFileSync = require('./writeFileSync-da4qD9Nz.cjs');
5
5
 
6
6
  var __defProp = Object.defineProperty;
7
7
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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.8",
4
4
  "description": "Human friendly file system utilities for Node.js",
5
5
  "keywords": [
6
6
  "anolilab",
@@ -132,47 +132,9 @@
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
- "devDependencies": {
139
- "@anolilab/eslint-config": "^15.0.3",
140
- "@anolilab/prettier-config": "^5.0.14",
141
- "@anolilab/semantic-release-pnpm": "^1.1.6",
142
- "@anolilab/semantic-release-preset": "^9.0.3",
143
- "@arethetypeswrong/cli": "^0.17.2",
144
- "@babel/core": "^7.26.0",
145
- "@rushstack/eslint-plugin-security": "^0.8.3",
146
- "@types/node": "18.19.15",
147
- "@visulima/error": "4.4.12",
148
- "@visulima/packem": "1.10.7",
149
- "@vitest/coverage-v8": "^2.1.8",
150
- "@vitest/ui": "^2.1.8",
151
- "conventional-changelog-conventionalcommits": "8.0.0",
152
- "cross-env": "^7.0.3",
153
- "detect-indent": "^7.0.1",
154
- "esbuild": "0.24.2",
155
- "eslint": "8.57.0",
156
- "eslint-plugin-deprecation": "^3.0.0",
157
- "eslint-plugin-etc": "^2.0.3",
158
- "eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
159
- "eslint-plugin-mdx": "^3.1.5",
160
- "eslint-plugin-vitest": "^0.5.4",
161
- "eslint-plugin-vitest-globals": "^1.5.0",
162
- "fast-safe-stringify": "2.1.1",
163
- "prettier": "^3.4.2",
164
- "redos-detector": "^6.1.2",
165
- "rimraf": "6.0.1",
166
- "safe-regex2": "^4.0.1",
167
- "semantic-release": "24.2.1",
168
- "tempy": "^3.1.0",
169
- "type-fest": "^4.32.0",
170
- "typedoc": "0.27.6",
171
- "typedoc-plugin-markdown": "4.4.1",
172
- "typedoc-plugin-rename-defaults": "0.7.2",
173
- "typescript": "5.7.3",
174
- "vitest": "^2.1.8"
175
- },
176
138
  "engines": {
177
139
  "node": ">=18.* <=23.*"
178
140
  },
@@ -184,39 +146,5 @@
184
146
  "publishConfig": {
185
147
  "access": "public",
186
148
  "provenance": true
187
- },
188
- "anolilab": {
189
- "eslint-config": {
190
- "plugin": {
191
- "tsdoc": false
192
- },
193
- "warn_on_unsupported_typescript_version": false,
194
- "info_on_disabling_jsx_react_rule": false,
195
- "info_on_disabling_prettier_conflict_rule": false,
196
- "info_on_disabling_jsonc_sort_keys_rule": false,
197
- "info_on_disabling_etc_no_deprecated": false
198
- }
199
- },
200
- "sources": [
201
- "src/index.ts",
202
- "src/error.ts",
203
- "src/utils.ts"
204
- ],
205
- "scripts": {
206
- "build": "cross-env NODE_ENV=development packem build",
207
- "build:prod": "cross-env NODE_ENV=production packem build",
208
- "clean": "rimraf node_modules dist .eslintcache",
209
- "dev": "pnpm run build --watch",
210
- "lint:attw": "attw --pack",
211
- "lint:eslint": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.cjs",
212
- "lint:eslint:fix": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.cjs --fix",
213
- "lint:package-json": "publint --strict",
214
- "lint:prettier": "prettier --config=.prettierrc.cjs --check .",
215
- "lint:prettier:fix": "prettier --config=.prettierrc.cjs --write .",
216
- "lint:types": "tsc --noEmit",
217
- "test": "vitest run",
218
- "test:coverage": "vitest run --coverage",
219
- "test:ui": "vitest --ui --coverage.enabled=true",
220
- "test:watch": "vitest"
221
149
  }
222
150
  }
@@ -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;