@reliverse/relifso 1.4.0 → 1.4.2

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 (71) hide show
  1. package/LICENSES +16 -0
  2. package/README.md +48 -17
  3. package/bin/impl/bun.d.ts +5 -28
  4. package/bin/impl/bun.js +2 -126
  5. package/bin/impl/copy.js +8 -7
  6. package/bin/impl/create.d.ts +34 -0
  7. package/bin/impl/create.js +54 -0
  8. package/bin/impl/dive.d.ts +10 -0
  9. package/bin/impl/dive.js +89 -0
  10. package/bin/impl/empty.d.ts +28 -0
  11. package/bin/impl/empty.js +75 -0
  12. package/bin/impl/extras.d.ts +22 -2
  13. package/bin/impl/extras.js +68 -3
  14. package/bin/impl/json-utils.d.ts +30 -0
  15. package/bin/impl/json-utils.js +46 -0
  16. package/bin/impl/output-file.d.ts +3 -2
  17. package/bin/impl/output-json.d.ts +7 -2
  18. package/bin/impl/output-json.js +73 -11
  19. package/bin/impl/read-file.d.ts +15 -4
  20. package/bin/impl/read-file.js +88 -10
  21. package/bin/impl/read-json.d.ts +6 -0
  22. package/bin/impl/read-json.js +133 -21
  23. package/bin/impl/stats.d.ts +31 -0
  24. package/bin/impl/stats.js +141 -0
  25. package/bin/impl/write-file.d.ts +19 -8
  26. package/bin/impl/write-file.js +153 -24
  27. package/bin/impl/write-json.d.ts +13 -2
  28. package/bin/impl/write-json.js +46 -7
  29. package/bin/mod.d.ts +84 -36
  30. package/bin/mod.js +108 -39
  31. package/bin/utils/json/helpers/JSONRepairError.d.ts +4 -0
  32. package/bin/utils/json/helpers/JSONRepairError.js +7 -0
  33. package/bin/utils/json/helpers/JsonSchemaError.d.ts +6 -0
  34. package/bin/utils/json/helpers/JsonSchemaError.js +6 -0
  35. package/bin/utils/json/helpers/stringUtils.d.ts +64 -0
  36. package/bin/utils/json/helpers/stringUtils.js +87 -0
  37. package/bin/utils/json/regular/jsonc.d.ts +45 -0
  38. package/bin/utils/json/regular/jsonc.js +88 -0
  39. package/bin/utils/json/regular/jsonrepair.d.ts +17 -0
  40. package/bin/utils/json/regular/jsonrepair.js +576 -0
  41. package/bin/utils/json/regular/validate.d.ts +22 -0
  42. package/bin/utils/json/regular/validate.js +52 -0
  43. package/bin/utils/json/stream/JsonStreamError.d.ts +6 -0
  44. package/bin/utils/json/stream/JsonStreamError.js +6 -0
  45. package/bin/utils/json/stream/buffer/InputBuffer.d.ts +13 -0
  46. package/bin/utils/json/stream/buffer/InputBuffer.js +68 -0
  47. package/bin/utils/json/stream/buffer/OutputBuffer.d.ts +17 -0
  48. package/bin/utils/json/stream/buffer/OutputBuffer.js +101 -0
  49. package/bin/utils/json/stream/core.d.ts +10 -0
  50. package/bin/utils/json/stream/core.js +695 -0
  51. package/bin/utils/json/stream/jsonl.d.ts +21 -0
  52. package/bin/utils/json/stream/jsonl.js +55 -0
  53. package/bin/utils/json/stream/parser.d.ts +14 -0
  54. package/bin/utils/json/stream/parser.js +81 -0
  55. package/bin/utils/json/stream/stack.d.ts +19 -0
  56. package/bin/utils/json/stream/stack.js +43 -0
  57. package/bin/utils/json/stream/stream.d.ts +6 -0
  58. package/bin/utils/json/stream/stream.js +30 -0
  59. package/bin/utils/json/stream/writer.d.ts +14 -0
  60. package/bin/utils/json/stream/writer.js +44 -0
  61. package/package.json +3 -2
  62. package/bin/impl/create-file.d.ts +0 -2
  63. package/bin/impl/create-file.js +0 -21
  64. package/bin/impl/dive-async.d.ts +0 -11
  65. package/bin/impl/dive-async.js +0 -88
  66. package/bin/impl/empty-dir.d.ts +0 -2
  67. package/bin/impl/empty-dir.js +0 -24
  68. package/bin/impl/file-utils.d.ts +0 -20
  69. package/bin/impl/file-utils.js +0 -63
  70. /package/bin/{impl/logger.d.ts → utils/log.d.ts} +0 -0
  71. /package/bin/{impl/logger.js → utils/log.js} +0 -0
@@ -0,0 +1,68 @@
1
+ export function createInputBuffer() {
2
+ let buffer = "";
3
+ let offset = 0;
4
+ let currentLength = 0;
5
+ let closed = false;
6
+ function ensure(index) {
7
+ if (index < offset) {
8
+ throw new Error(`${indexOutOfRangeMessage} (index: ${index}, offset: ${offset})`);
9
+ }
10
+ if (index >= currentLength) {
11
+ if (!closed) {
12
+ throw new Error(`${indexOutOfRangeMessage} (index: ${index})`);
13
+ }
14
+ }
15
+ }
16
+ function push(chunk) {
17
+ buffer += chunk;
18
+ currentLength += chunk.length;
19
+ }
20
+ function flush(position) {
21
+ if (position > currentLength) {
22
+ return;
23
+ }
24
+ buffer = buffer.substring(position - offset);
25
+ offset = position;
26
+ }
27
+ function charAt(index) {
28
+ ensure(index);
29
+ return buffer.charAt(index - offset);
30
+ }
31
+ function charCodeAt(index) {
32
+ ensure(index);
33
+ return buffer.charCodeAt(index - offset);
34
+ }
35
+ function substring(start, end) {
36
+ ensure(end - 1);
37
+ ensure(start);
38
+ return buffer.slice(start - offset, end - offset);
39
+ }
40
+ function length() {
41
+ if (!closed) {
42
+ throw new Error("Cannot get length: input is not yet closed");
43
+ }
44
+ return currentLength;
45
+ }
46
+ function isEnd(index) {
47
+ if (!closed) {
48
+ ensure(index);
49
+ }
50
+ return index >= currentLength;
51
+ }
52
+ function close() {
53
+ closed = true;
54
+ }
55
+ return {
56
+ push,
57
+ flush,
58
+ charAt,
59
+ charCodeAt,
60
+ substring,
61
+ length,
62
+ currentLength: () => currentLength,
63
+ currentBufferSize: () => buffer.length,
64
+ isEnd,
65
+ close
66
+ };
67
+ }
68
+ const indexOutOfRangeMessage = "Index out of range, please configure a larger buffer size";
@@ -0,0 +1,17 @@
1
+ export interface OutputBuffer {
2
+ push: (text: string) => void;
3
+ unshift: (text: string) => void;
4
+ remove: (start: number, end?: number) => void;
5
+ insertAt: (index: number, text: string) => void;
6
+ length: () => number;
7
+ flush: () => void;
8
+ stripLastOccurrence: (textToStrip: string, stripRemainingText?: boolean) => void;
9
+ insertBeforeLastWhitespace: (textToInsert: string) => void;
10
+ endsWithIgnoringWhitespace: (char: string) => boolean;
11
+ }
12
+ export interface OutputBufferOptions {
13
+ write: (chunk: string) => void;
14
+ chunkSize: number;
15
+ bufferSize: number;
16
+ }
17
+ export declare function createOutputBuffer({ write, chunkSize, bufferSize }: OutputBufferOptions): OutputBuffer;
@@ -0,0 +1,101 @@
1
+ import { isWhitespace } from "../../helpers/stringUtils.js";
2
+ export function createOutputBuffer({ write, chunkSize, bufferSize }) {
3
+ let buffer = "";
4
+ let offset = 0;
5
+ function flushChunks(minSize = bufferSize) {
6
+ while (buffer.length >= minSize + chunkSize) {
7
+ const chunk = buffer.substring(0, chunkSize);
8
+ write(chunk);
9
+ offset += chunkSize;
10
+ buffer = buffer.substring(chunkSize);
11
+ }
12
+ }
13
+ function flush() {
14
+ flushChunks(0);
15
+ if (buffer.length > 0) {
16
+ write(buffer);
17
+ offset += buffer.length;
18
+ buffer = "";
19
+ }
20
+ }
21
+ function push(text) {
22
+ buffer += text;
23
+ flushChunks();
24
+ }
25
+ function unshift(text) {
26
+ if (offset > 0) {
27
+ throw new Error(`Cannot unshift: ${flushedMessage}`);
28
+ }
29
+ buffer = text + buffer;
30
+ flushChunks();
31
+ }
32
+ function remove(start, end) {
33
+ if (start < offset) {
34
+ throw new Error(`Cannot remove: ${flushedMessage}`);
35
+ }
36
+ if (end !== void 0) {
37
+ buffer = buffer.substring(0, start - offset) + buffer.substring(end - offset);
38
+ } else {
39
+ buffer = buffer.substring(0, start - offset);
40
+ }
41
+ }
42
+ function insertAt(index, text) {
43
+ if (index < offset) {
44
+ throw new Error(`Cannot insert: ${flushedMessage}`);
45
+ }
46
+ buffer = buffer.substring(0, index - offset) + text + buffer.substring(index - offset);
47
+ }
48
+ function length() {
49
+ return offset + buffer.length;
50
+ }
51
+ function stripLastOccurrence(textToStrip, stripRemainingText = false) {
52
+ const bufferIndex = buffer.lastIndexOf(textToStrip);
53
+ if (bufferIndex !== -1) {
54
+ if (stripRemainingText) {
55
+ buffer = buffer.substring(0, bufferIndex);
56
+ } else {
57
+ buffer = buffer.substring(0, bufferIndex) + buffer.substring(bufferIndex + textToStrip.length);
58
+ }
59
+ }
60
+ }
61
+ function insertBeforeLastWhitespace(textToInsert) {
62
+ let bufferIndex = buffer.length;
63
+ if (!isWhitespace(buffer, bufferIndex - 1)) {
64
+ push(textToInsert);
65
+ return;
66
+ }
67
+ while (isWhitespace(buffer, bufferIndex - 1)) {
68
+ bufferIndex--;
69
+ }
70
+ if (bufferIndex <= 0) {
71
+ throw new Error(`Cannot insert: ${flushedMessage}`);
72
+ }
73
+ buffer = buffer.substring(0, bufferIndex) + textToInsert + buffer.substring(bufferIndex);
74
+ flushChunks();
75
+ }
76
+ function endsWithIgnoringWhitespace(char) {
77
+ let i = buffer.length - 1;
78
+ while (i > 0) {
79
+ if (char === buffer.charAt(i)) {
80
+ return true;
81
+ }
82
+ if (!isWhitespace(buffer, i)) {
83
+ return false;
84
+ }
85
+ i--;
86
+ }
87
+ return false;
88
+ }
89
+ return {
90
+ push,
91
+ unshift,
92
+ remove,
93
+ insertAt,
94
+ length,
95
+ flush,
96
+ stripLastOccurrence,
97
+ insertBeforeLastWhitespace,
98
+ endsWithIgnoringWhitespace
99
+ };
100
+ }
101
+ const flushedMessage = "start of the output is already flushed from the buffer";
@@ -0,0 +1,10 @@
1
+ export interface JsonRepairCoreOptions {
2
+ onData: (chunk: string) => void;
3
+ chunkSize?: number;
4
+ bufferSize?: number;
5
+ }
6
+ export interface JsonRepairCore {
7
+ transform: (chunk: string) => void;
8
+ flush: () => void;
9
+ }
10
+ export declare function jsonrepairCore({ onData, bufferSize, chunkSize, }: JsonRepairCoreOptions): JsonRepairCore;