web-csv-toolbox 0.13.0-next-cec6905200814e21efa17adbb4a6652519dd1e74 → 0.13.0-next-3946273aa1c59a7b4a9fae6c2dbfae0d80999761

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/README.md CHANGED
@@ -59,6 +59,8 @@ A CSV Toolbox utilizing Web Standard APIs.
59
59
  - 🚨 Throws `RangeError` when buffer exceeds the limit.
60
60
  - 📊 Configurable maximum field count (default: 100,000 fields/record) to prevent excessive column attacks.
61
61
  - ⚠️ Throws `RangeError` when field count exceeds the limit.
62
+ - 💾 Configurable maximum binary size (default: 100MB bytes) for ArrayBuffer/Uint8Array inputs.
63
+ - 🛑 Throws `RangeError` when binary size exceeds the limit.
62
64
  - 🎨 **Flexible Source Support**
63
65
  - 🧩 Parse CSVs directly from `string`s, `ReadableStream`s, or `Response` objects.
64
66
  - ⚙️ **Advanced Parsing Options**: Customize your experience with various delimiters and quotation marks.
@@ -386,6 +388,7 @@ console.log(result);
386
388
  | Option | Description | Default | Notes |
387
389
  | --------------------------------- | ------------------------------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
388
390
  | `charset` | Character encoding for binary CSV inputs | `utf-8` | See [Encoding API Compatibility](https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API/Encodings) for the encoding formats that can be specified. |
391
+ | `maxBinarySize` | Maximum binary size for ArrayBuffer/Uint8Array inputs (bytes) | `100 * 1024 * 1024` (100MB) | Set to `Number.POSITIVE_INFINITY` to disable (not recommended for untrusted input) |
389
392
  | `decompression` | Decompression algorithm for compressed CSV inputs | | See [DecompressionStream Compatibility](https://developer.mozilla.org/en-US/docs/Web/API/DecompressionStream#browser_compatibilit). Supports: gzip, deflate, deflate-raw |
390
393
  | `ignoreBOM` | Whether to ignore Byte Order Mark (BOM) | `false` | See [TextDecoderOptions.ignoreBOM](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoderStream/ignoreBOM) for more information about the BOM. |
391
394
  | `fatal` | Throw an error on invalid characters | `false` | See [TextDecoderOptions.fatal](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoderStream/fatal) for more information. |
@@ -512,7 +515,10 @@ const records = parseStringToArraySyncWASM(csvString);
512
515
 
513
516
  For production use with untrusted input, consider:
514
517
  - Setting timeouts using `AbortSignal.timeout()` to prevent resource exhaustion
515
- - Implementing file size limits at the application level
518
+ - Using `maxBinarySize` option to limit ArrayBuffer/Uint8Array inputs (default: 100MB bytes)
519
+ - Using `maxBufferSize` option to limit internal buffer size (default: 10M characters)
520
+ - Using `maxFieldCount` option to limit fields per record (default: 100,000)
521
+ - Implementing additional file size limits at the application level
516
522
  - Validating parsed data before use
517
523
 
518
524
  #### Implementing Size Limits for Untrusted Sources
@@ -197,6 +197,19 @@ export interface BinaryOptions {
197
197
  * @default 'utf-8'
198
198
  */
199
199
  charset?: string;
200
+ /**
201
+ * Maximum binary size in bytes for ArrayBuffer/Uint8Array inputs.
202
+ *
203
+ * @remarks
204
+ * This option limits the size of ArrayBuffer or Uint8Array inputs
205
+ * to prevent memory exhaustion attacks. When the binary size exceeds
206
+ * this limit, a `RangeError` will be thrown.
207
+ *
208
+ * Set to `Number.POSITIVE_INFINITY` to disable the limit (not recommended for untrusted input).
209
+ *
210
+ * @default 100 * 1024 * 1024 (100MB)
211
+ */
212
+ maxBinarySize?: number;
200
213
  /**
201
214
  * If the binary has a BOM, you can specify whether to ignore it.
202
215
  *
@@ -1,2 +1,26 @@
1
1
  import { CSVRecord, ParseBinaryOptions } from './common/types.ts';
2
+ /**
3
+ * Synchronously parses binary CSV data into an array of records.
4
+ *
5
+ * @param binary - The binary CSV data to parse (Uint8Array or ArrayBuffer).
6
+ * @param options - Parsing options including charset, maxBinarySize, etc.
7
+ * @returns An array of CSV records.
8
+ * @throws {RangeError} If the binary size exceeds maxBinarySize limit.
9
+ * @throws {ParseError} If the CSV data is malformed.
10
+ *
11
+ * @remarks
12
+ * **WARNING**: This function loads the entire binary data into memory synchronously.
13
+ * For large files (>100MB), consider using streaming alternatives like `parseStream()` or `parseUint8ArrayStream()`
14
+ * to avoid memory exhaustion and blocking the event loop.
15
+ *
16
+ * The default maxBinarySize is 100MB. You can increase it via options, but this may lead to
17
+ * memory issues with very large files.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const binary = new TextEncoder().encode("name,age\nAlice,30");
22
+ * const records = parseBinaryToArraySync(binary);
23
+ * // [{ name: "Alice", age: "30" }]
24
+ * ```
25
+ */
2
26
  export declare function parseBinaryToArraySync<Header extends ReadonlyArray<string>>(binary: Uint8Array | ArrayBuffer, options?: ParseBinaryOptions<Header>): CSVRecord<Header>[];
@@ -1 +1 @@
1
- {"version":3,"file":"parseBinaryToArraySync.js","sources":["../src/parseBinaryToArraySync.ts"],"sourcesContent":["import type { CSVRecord, ParseBinaryOptions } from \"./common/types.ts\";\nimport { commonParseErrorHandling } from \"./commonParseErrorHandling.ts\";\nimport { parseStringToArraySync } from \"./parseStringToArraySync.ts\";\nimport { convertBinaryToString } from \"./utils/convertBinaryToString.ts\";\n\nexport function parseBinaryToArraySync<Header extends ReadonlyArray<string>>(\n binary: Uint8Array | ArrayBuffer,\n options: ParseBinaryOptions<Header> = {},\n): CSVRecord<Header>[] {\n try {\n const csv = convertBinaryToString(binary, options);\n return parseStringToArraySync(csv, options);\n } catch (error) {\n commonParseErrorHandling(error);\n }\n}\n"],"names":[],"mappings":";;;;AAKO,SAAS,sBACd,CAAA,MAAA,EACA,OAAsC,GAAA,EACjB,EAAA;AACrB,EAAI,IAAA;AACF,IAAM,MAAA,GAAA,GAAM,qBAAsB,CAAA,MAAA,EAAQ,OAAO,CAAA;AACjD,IAAO,OAAA,sBAAA,CAAuB,KAAK,OAAO,CAAA;AAAA,WACnC,KAAO,EAAA;AACd,IAAA,wBAAA,CAAyB,KAAK,CAAA;AAAA;AAElC;;;;"}
1
+ {"version":3,"file":"parseBinaryToArraySync.js","sources":["../src/parseBinaryToArraySync.ts"],"sourcesContent":["import type { CSVRecord, ParseBinaryOptions } from \"./common/types.ts\";\nimport { commonParseErrorHandling } from \"./commonParseErrorHandling.ts\";\nimport { parseStringToArraySync } from \"./parseStringToArraySync.ts\";\nimport { convertBinaryToString } from \"./utils/convertBinaryToString.ts\";\n\n/**\n * Synchronously parses binary CSV data into an array of records.\n *\n * @param binary - The binary CSV data to parse (Uint8Array or ArrayBuffer).\n * @param options - Parsing options including charset, maxBinarySize, etc.\n * @returns An array of CSV records.\n * @throws {RangeError} If the binary size exceeds maxBinarySize limit.\n * @throws {ParseError} If the CSV data is malformed.\n *\n * @remarks\n * **WARNING**: This function loads the entire binary data into memory synchronously.\n * For large files (>100MB), consider using streaming alternatives like `parseStream()` or `parseUint8ArrayStream()`\n * to avoid memory exhaustion and blocking the event loop.\n *\n * The default maxBinarySize is 100MB. You can increase it via options, but this may lead to\n * memory issues with very large files.\n *\n * @example\n * ```ts\n * const binary = new TextEncoder().encode(\"name,age\\nAlice,30\");\n * const records = parseBinaryToArraySync(binary);\n * // [{ name: \"Alice\", age: \"30\" }]\n * ```\n */\nexport function parseBinaryToArraySync<Header extends ReadonlyArray<string>>(\n binary: Uint8Array | ArrayBuffer,\n options: ParseBinaryOptions<Header> = {},\n): CSVRecord<Header>[] {\n try {\n const csv = convertBinaryToString(binary, options);\n return parseStringToArraySync(csv, options);\n } catch (error) {\n commonParseErrorHandling(error);\n }\n}\n"],"names":[],"mappings":";;;;AA6BO,SAAS,sBACd,CAAA,MAAA,EACA,OAAsC,GAAA,EACjB,EAAA;AACrB,EAAI,IAAA;AACF,IAAM,MAAA,GAAA,GAAM,qBAAsB,CAAA,MAAA,EAAQ,OAAO,CAAA;AACjD,IAAO,OAAA,sBAAA,CAAuB,KAAK,OAAO,CAAA;AAAA,WACnC,KAAO,EAAA;AACd,IAAA,wBAAA,CAAyB,KAAK,CAAA;AAAA;AAElC;;;;"}
@@ -5,6 +5,15 @@ import { CSVRecord, ParseBinaryOptions } from './common/types.ts';
5
5
  * @param binary - The binary data to parse.
6
6
  * @param options - The parse options.
7
7
  * @returns An iterable iterator of CSV records.
8
+ * @throws {RangeError} If the binary size exceeds maxBinarySize limit.
8
9
  * @throws {ParseError} When an error occurs while parsing the CSV data.
10
+ *
11
+ * @remarks
12
+ * **WARNING**: This function loads the entire binary data into memory before iteration.
13
+ * For large files (>100MB), consider using streaming alternatives like `parseStream()` or `parseUint8ArrayStream()`
14
+ * to avoid memory exhaustion.
15
+ *
16
+ * The default maxBinarySize is 100MB. While this function returns an iterator, the entire
17
+ * binary is converted to a string in memory before iteration begins.
9
18
  */
10
19
  export declare function parseBinaryToIterableIterator<Header extends ReadonlyArray<string>>(binary: Uint8Array | ArrayBuffer, options?: ParseBinaryOptions<Header>): IterableIterator<CSVRecord<Header>>;
@@ -1 +1 @@
1
- {"version":3,"file":"parseBinaryToIterableIterator.js","sources":["../src/parseBinaryToIterableIterator.ts"],"sourcesContent":["import type { CSVRecord, ParseBinaryOptions } from \"./common/types.ts\";\nimport { commonParseErrorHandling } from \"./commonParseErrorHandling.ts\";\nimport { parseStringToIterableIterator } from \"./parseStringToIterableIterator.ts\";\nimport { convertBinaryToString } from \"./utils/convertBinaryToString.ts\";\n\n/**\n * Parses the given binary data into an iterable iterator of CSV records.\n *\n * @param binary - The binary data to parse.\n * @param options - The parse options.\n * @returns An iterable iterator of CSV records.\n * @throws {ParseError} When an error occurs while parsing the CSV data.\n */\nexport function parseBinaryToIterableIterator<\n Header extends ReadonlyArray<string>,\n>(\n binary: Uint8Array | ArrayBuffer,\n options: ParseBinaryOptions<Header> = {},\n): IterableIterator<CSVRecord<Header>> {\n try {\n const csv = convertBinaryToString(binary, options);\n return parseStringToIterableIterator(csv, options);\n } catch (error) {\n commonParseErrorHandling(error);\n }\n}\n"],"names":[],"mappings":";;;;AAaO,SAAS,6BAGd,CAAA,MAAA,EACA,OAAsC,GAAA,EACD,EAAA;AACrC,EAAI,IAAA;AACF,IAAM,MAAA,GAAA,GAAM,qBAAsB,CAAA,MAAA,EAAQ,OAAO,CAAA;AACjD,IAAO,OAAA,6BAAA,CAA8B,KAAK,OAAO,CAAA;AAAA,WAC1C,KAAO,EAAA;AACd,IAAA,wBAAA,CAAyB,KAAK,CAAA;AAAA;AAElC;;;;"}
1
+ {"version":3,"file":"parseBinaryToIterableIterator.js","sources":["../src/parseBinaryToIterableIterator.ts"],"sourcesContent":["import type { CSVRecord, ParseBinaryOptions } from \"./common/types.ts\";\nimport { commonParseErrorHandling } from \"./commonParseErrorHandling.ts\";\nimport { parseStringToIterableIterator } from \"./parseStringToIterableIterator.ts\";\nimport { convertBinaryToString } from \"./utils/convertBinaryToString.ts\";\n\n/**\n * Parses the given binary data into an iterable iterator of CSV records.\n *\n * @param binary - The binary data to parse.\n * @param options - The parse options.\n * @returns An iterable iterator of CSV records.\n * @throws {RangeError} If the binary size exceeds maxBinarySize limit.\n * @throws {ParseError} When an error occurs while parsing the CSV data.\n *\n * @remarks\n * **WARNING**: This function loads the entire binary data into memory before iteration.\n * For large files (>100MB), consider using streaming alternatives like `parseStream()` or `parseUint8ArrayStream()`\n * to avoid memory exhaustion.\n *\n * The default maxBinarySize is 100MB. While this function returns an iterator, the entire\n * binary is converted to a string in memory before iteration begins.\n */\nexport function parseBinaryToIterableIterator<\n Header extends ReadonlyArray<string>,\n>(\n binary: Uint8Array | ArrayBuffer,\n options: ParseBinaryOptions<Header> = {},\n): IterableIterator<CSVRecord<Header>> {\n try {\n const csv = convertBinaryToString(binary, options);\n return parseStringToIterableIterator(csv, options);\n } catch (error) {\n commonParseErrorHandling(error);\n }\n}\n"],"names":[],"mappings":";;;;AAsBO,SAAS,6BAGd,CAAA,MAAA,EACA,OAAsC,GAAA,EACD,EAAA;AACrC,EAAI,IAAA;AACF,IAAM,MAAA,GAAA,GAAM,qBAAsB,CAAA,MAAA,EAAQ,OAAO,CAAA;AACjD,IAAO,OAAA,6BAAA,CAA8B,KAAK,OAAO,CAAA;AAAA,WAC1C,KAAO,EAAA;AACd,IAAA,wBAAA,CAAyB,KAAK,CAAA;AAAA;AAElC;;;;"}
@@ -1,6 +1,26 @@
1
1
  import { CSVRecord, ParseOptions } from './common/types.ts';
2
2
  import { DEFAULT_DELIMITER, DEFAULT_QUOTATION } from './constants.ts';
3
3
  import { PickCSVHeader } from './utils/types.ts';
4
+ /**
5
+ * Synchronously parses a CSV string into an array of records.
6
+ *
7
+ * @param csv - The CSV string to parse.
8
+ * @param options - Parsing options including delimiter, quotation, header, etc.
9
+ * @returns An array of CSV records.
10
+ * @throws {ParseError} If the CSV data is malformed.
11
+ *
12
+ * @remarks
13
+ * **WARNING**: This function loads all parsed records into memory as an array.
14
+ * For CSV data with a large number of records, consider using `parseStringToIterableIterator()`
15
+ * to iterate over records without loading them all into memory at once.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * const csv = "name,age\nAlice,30\nBob,25";
20
+ * const records = parseStringToArraySync(csv);
21
+ * // [{ name: "Alice", age: "30" }, { name: "Bob", age: "25" }]
22
+ * ```
23
+ */
4
24
  export declare function parseStringToArraySync<const CSVSource extends string, const Delimiter extends string = DEFAULT_DELIMITER, const Quotation extends string = DEFAULT_QUOTATION, const Header extends ReadonlyArray<string> = PickCSVHeader<CSVSource, Delimiter, Quotation>>(csv: CSVSource, options: ParseOptions<Header, Delimiter, Quotation>): CSVRecord<Header>[];
5
25
  export declare function parseStringToArraySync<const CSVSource extends string, const Header extends ReadonlyArray<string> = PickCSVHeader<CSVSource>>(csv: CSVSource, options?: ParseOptions<Header>): CSVRecord<Header>[];
6
26
  export declare function parseStringToArraySync<const Header extends ReadonlyArray<string>>(csv: string, options?: ParseOptions<Header>): CSVRecord<Header>[];
@@ -1 +1 @@
1
- {"version":3,"file":"parseStringToArraySync.js","sources":["../src/parseStringToArraySync.ts"],"sourcesContent":["import { Lexer } from \"./Lexer.ts\";\nimport { RecordAssembler } from \"./RecordAssembler.ts\";\nimport type { CSVRecord, ParseOptions } from \"./common/types.ts\";\nimport { commonParseErrorHandling } from \"./commonParseErrorHandling.ts\";\nimport type { DEFAULT_DELIMITER, DEFAULT_QUOTATION } from \"./constants.ts\";\nimport type { PickCSVHeader } from \"./utils/types.ts\";\n\nexport function parseStringToArraySync<\n const CSVSource extends string,\n const Delimiter extends string = DEFAULT_DELIMITER,\n const Quotation extends string = DEFAULT_QUOTATION,\n const Header extends ReadonlyArray<string> = PickCSVHeader<\n CSVSource,\n Delimiter,\n Quotation\n >,\n>(\n csv: CSVSource,\n options: ParseOptions<Header, Delimiter, Quotation>,\n): CSVRecord<Header>[];\nexport function parseStringToArraySync<\n const CSVSource extends string,\n const Header extends ReadonlyArray<string> = PickCSVHeader<CSVSource>,\n>(csv: CSVSource, options?: ParseOptions<Header>): CSVRecord<Header>[];\nexport function parseStringToArraySync<\n const Header extends ReadonlyArray<string>,\n>(csv: string, options?: ParseOptions<Header>): CSVRecord<Header>[];\nexport function parseStringToArraySync<\n const Header extends ReadonlyArray<string>,\n>(csv: string, options?: ParseOptions<Header>): CSVRecord<Header>[] {\n try {\n const lexer = new Lexer(options);\n const assembler = new RecordAssembler(options);\n const tokens = lexer.lex(csv);\n return [...assembler.assemble(tokens)];\n } catch (error) {\n commonParseErrorHandling(error);\n }\n}\n"],"names":[],"mappings":";;;;AA2BgB,SAAA,sBAAA,CAEd,KAAa,OAAqD,EAAA;AAClE,EAAI,IAAA;AACF,IAAM,MAAA,KAAA,GAAQ,IAAI,KAAA,CAAM,OAAO,CAAA;AAC/B,IAAM,MAAA,SAAA,GAAY,IAAI,eAAA,CAAgB,OAAO,CAAA;AAC7C,IAAM,MAAA,MAAA,GAAS,KAAM,CAAA,GAAA,CAAI,GAAG,CAAA;AAC5B,IAAA,OAAO,CAAC,GAAG,SAAU,CAAA,QAAA,CAAS,MAAM,CAAC,CAAA;AAAA,WAC9B,KAAO,EAAA;AACd,IAAA,wBAAA,CAAyB,KAAK,CAAA;AAAA;AAElC;;;;"}
1
+ {"version":3,"file":"parseStringToArraySync.js","sources":["../src/parseStringToArraySync.ts"],"sourcesContent":["import { Lexer } from \"./Lexer.ts\";\nimport { RecordAssembler } from \"./RecordAssembler.ts\";\nimport type { CSVRecord, ParseOptions } from \"./common/types.ts\";\nimport { commonParseErrorHandling } from \"./commonParseErrorHandling.ts\";\nimport type { DEFAULT_DELIMITER, DEFAULT_QUOTATION } from \"./constants.ts\";\nimport type { PickCSVHeader } from \"./utils/types.ts\";\n\n/**\n * Synchronously parses a CSV string into an array of records.\n *\n * @param csv - The CSV string to parse.\n * @param options - Parsing options including delimiter, quotation, header, etc.\n * @returns An array of CSV records.\n * @throws {ParseError} If the CSV data is malformed.\n *\n * @remarks\n * **WARNING**: This function loads all parsed records into memory as an array.\n * For CSV data with a large number of records, consider using `parseStringToIterableIterator()`\n * to iterate over records without loading them all into memory at once.\n *\n * @example\n * ```ts\n * const csv = \"name,age\\nAlice,30\\nBob,25\";\n * const records = parseStringToArraySync(csv);\n * // [{ name: \"Alice\", age: \"30\" }, { name: \"Bob\", age: \"25\" }]\n * ```\n */\nexport function parseStringToArraySync<\n const CSVSource extends string,\n const Delimiter extends string = DEFAULT_DELIMITER,\n const Quotation extends string = DEFAULT_QUOTATION,\n const Header extends ReadonlyArray<string> = PickCSVHeader<\n CSVSource,\n Delimiter,\n Quotation\n >,\n>(\n csv: CSVSource,\n options: ParseOptions<Header, Delimiter, Quotation>,\n): CSVRecord<Header>[];\nexport function parseStringToArraySync<\n const CSVSource extends string,\n const Header extends ReadonlyArray<string> = PickCSVHeader<CSVSource>,\n>(csv: CSVSource, options?: ParseOptions<Header>): CSVRecord<Header>[];\nexport function parseStringToArraySync<\n const Header extends ReadonlyArray<string>,\n>(csv: string, options?: ParseOptions<Header>): CSVRecord<Header>[];\nexport function parseStringToArraySync<\n const Header extends ReadonlyArray<string>,\n>(csv: string, options?: ParseOptions<Header>): CSVRecord<Header>[] {\n try {\n const lexer = new Lexer(options);\n const assembler = new RecordAssembler(options);\n const tokens = lexer.lex(csv);\n return [...assembler.assemble(tokens)];\n } catch (error) {\n commonParseErrorHandling(error);\n }\n}\n"],"names":[],"mappings":";;;;AA+CgB,SAAA,sBAAA,CAEd,KAAa,OAAqD,EAAA;AAClE,EAAI,IAAA;AACF,IAAM,MAAA,KAAA,GAAQ,IAAI,KAAA,CAAM,OAAO,CAAA;AAC/B,IAAM,MAAA,SAAA,GAAY,IAAI,eAAA,CAAgB,OAAO,CAAA;AAC7C,IAAM,MAAA,MAAA,GAAS,KAAM,CAAA,GAAA,CAAI,GAAG,CAAA;AAC5B,IAAA,OAAO,CAAC,GAAG,SAAU,CAAA,QAAA,CAAS,MAAM,CAAC,CAAA;AAAA,WAC9B,KAAO,EAAA;AACd,IAAA,wBAAA,CAAyB,KAAK,CAAA;AAAA;AAElC;;;;"}
@@ -5,7 +5,7 @@ import { BinaryOptions } from '../common/types.ts';
5
5
  * @param binary - The binary string to convert.
6
6
  * @param options - The options for parsing the binary string.
7
7
  * @returns The converted string.
8
- * @throws {RangeError} The given charset is not supported.
8
+ * @throws {RangeError} The given charset is not supported or binary size exceeds the limit.
9
9
  * @throws {TypeError} The encoded data was not valid.
10
10
  */
11
11
  export declare function convertBinaryToString(binary: Uint8Array | ArrayBuffer, options: BinaryOptions): string;
@@ -1,4 +1,16 @@
1
+ const DEFAULT_MAX_BINARY_SIZE = 100 * 1024 * 1024;
1
2
  function convertBinaryToString(binary, options) {
3
+ const maxBinarySize = options?.maxBinarySize ?? DEFAULT_MAX_BINARY_SIZE;
4
+ if (!(Number.isFinite(maxBinarySize) || maxBinarySize === Number.POSITIVE_INFINITY) || Number.isFinite(maxBinarySize) && maxBinarySize < 0) {
5
+ throw new RangeError(
6
+ "maxBinarySize must be a non-negative number or Number.POSITIVE_INFINITY"
7
+ );
8
+ }
9
+ if (Number.isFinite(maxBinarySize) && binary.byteLength > maxBinarySize) {
10
+ throw new RangeError(
11
+ `Binary size (${binary.byteLength} bytes) exceeded maximum allowed size of ${maxBinarySize} bytes`
12
+ );
13
+ }
2
14
  return new TextDecoder(options?.charset, {
3
15
  ignoreBOM: options?.ignoreBOM,
4
16
  fatal: options?.fatal
@@ -1 +1 @@
1
- {"version":3,"file":"convertBinaryToString.js","sources":["../../src/utils/convertBinaryToString.ts"],"sourcesContent":["import type { BinaryOptions } from \"../common/types.ts\";\n\n/**\n * Converts a binary string to a string.\n *\n * @param binary - The binary string to convert.\n * @param options - The options for parsing the binary string.\n * @returns The converted string.\n * @throws {RangeError} The given charset is not supported.\n * @throws {TypeError} The encoded data was not valid.\n */\nexport function convertBinaryToString(\n binary: Uint8Array | ArrayBuffer,\n options: BinaryOptions,\n): string {\n return new TextDecoder(options?.charset, {\n ignoreBOM: options?.ignoreBOM,\n fatal: options?.fatal,\n }).decode(binary instanceof ArrayBuffer ? new Uint8Array(binary) : binary);\n}\n"],"names":[],"mappings":"AAWgB,SAAA,qBAAA,CACd,QACA,OACQ,EAAA;AACR,EAAO,OAAA,IAAI,WAAY,CAAA,OAAA,EAAS,OAAS,EAAA;AAAA,IACvC,WAAW,OAAS,EAAA,SAAA;AAAA,IACpB,OAAO,OAAS,EAAA;AAAA,GACjB,EAAE,MAAO,CAAA,MAAA,YAAkB,cAAc,IAAI,UAAA,CAAW,MAAM,CAAA,GAAI,MAAM,CAAA;AAC3E;;;;"}
1
+ {"version":3,"file":"convertBinaryToString.js","sources":["../../src/utils/convertBinaryToString.ts"],"sourcesContent":["import type { BinaryOptions } from \"../common/types.ts\";\n\n/**\n * Default maximum binary size in bytes (100MB).\n */\nconst DEFAULT_MAX_BINARY_SIZE = 100 * 1024 * 1024;\n\n/**\n * Converts a binary string to a string.\n *\n * @param binary - The binary string to convert.\n * @param options - The options for parsing the binary string.\n * @returns The converted string.\n * @throws {RangeError} The given charset is not supported or binary size exceeds the limit.\n * @throws {TypeError} The encoded data was not valid.\n */\nexport function convertBinaryToString(\n binary: Uint8Array | ArrayBuffer,\n options: BinaryOptions,\n): string {\n const maxBinarySize = options?.maxBinarySize ?? DEFAULT_MAX_BINARY_SIZE;\n\n // Validate maxBinarySize\n if (\n !(\n Number.isFinite(maxBinarySize) ||\n maxBinarySize === Number.POSITIVE_INFINITY\n ) ||\n (Number.isFinite(maxBinarySize) && maxBinarySize < 0)\n ) {\n throw new RangeError(\n \"maxBinarySize must be a non-negative number or Number.POSITIVE_INFINITY\",\n );\n }\n\n // Check binary size\n if (Number.isFinite(maxBinarySize) && binary.byteLength > maxBinarySize) {\n throw new RangeError(\n `Binary size (${binary.byteLength} bytes) exceeded maximum allowed size of ${maxBinarySize} bytes`,\n );\n }\n\n return new TextDecoder(options?.charset, {\n ignoreBOM: options?.ignoreBOM,\n fatal: options?.fatal,\n }).decode(binary instanceof ArrayBuffer ? new Uint8Array(binary) : binary);\n}\n"],"names":[],"mappings":"AAKA,MAAM,uBAAA,GAA0B,MAAM,IAAO,GAAA,IAAA;AAW7B,SAAA,qBAAA,CACd,QACA,OACQ,EAAA;AACR,EAAM,MAAA,aAAA,GAAgB,SAAS,aAAiB,IAAA,uBAAA;AAGhD,EAAA,IACE,EACE,MAAA,CAAO,QAAS,CAAA,aAAa,CAC7B,IAAA,aAAA,KAAkB,MAAO,CAAA,iBAAA,CAAA,IAE1B,MAAO,CAAA,QAAA,CAAS,aAAa,CAAA,IAAK,gBAAgB,CACnD,EAAA;AACA,IAAA,MAAM,IAAI,UAAA;AAAA,MACR;AAAA,KACF;AAAA;AAIF,EAAA,IAAI,OAAO,QAAS,CAAA,aAAa,CAAK,IAAA,MAAA,CAAO,aAAa,aAAe,EAAA;AACvE,IAAA,MAAM,IAAI,UAAA;AAAA,MACR,CAAgB,aAAA,EAAA,MAAA,CAAO,UAAU,CAAA,yCAAA,EAA4C,aAAa,CAAA,MAAA;AAAA,KAC5F;AAAA;AAGF,EAAO,OAAA,IAAI,WAAY,CAAA,OAAA,EAAS,OAAS,EAAA;AAAA,IACvC,WAAW,OAAS,EAAA,SAAA;AAAA,IACpB,OAAO,OAAS,EAAA;AAAA,GACjB,EAAE,MAAO,CAAA,MAAA,YAAkB,cAAc,IAAI,UAAA,CAAW,MAAM,CAAA,GAAI,MAAM,CAAA;AAC3E;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-csv-toolbox",
3
- "version": "0.13.0-next-cec6905200814e21efa17adbb4a6652519dd1e74",
3
+ "version": "0.13.0-next-3946273aa1c59a7b4a9fae6c2dbfae0d80999761",
4
4
  "description": "A CSV Toolbox utilizing Web Standard APIs.",
5
5
  "type": "module",
6
6
  "module": "dist/web-csv-toolbox.js",