marc-ts 0.1.0 → 0.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.
- package/README.md +118 -523
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +399 -358
- package/dist/index.js.map +1 -1
- package/dist/marcjson.cjs +1 -1
- package/dist/marcjson.cjs.map +1 -1
- package/dist/marcjson.d.ts +11 -6
- package/dist/marcjson.js +53 -44
- package/dist/marcjson.js.map +1 -1
- package/dist/marctxt.cjs +4 -4
- package/dist/marctxt.cjs.map +1 -1
- package/dist/marctxt.d.ts +0 -10
- package/dist/marctxt.js +44 -51
- package/dist/marctxt.js.map +1 -1
- package/dist/marcxml.cjs +6 -6
- package/dist/marcxml.cjs.map +1 -1
- package/dist/marcxml.d.ts +7 -11
- package/dist/marcxml.js +183 -129
- package/dist/marcxml.js.map +1 -1
- package/dist/parser.d.ts +15 -35
- package/dist/serializer.d.ts +16 -37
- package/dist/{types-c4Mo9m9u.js → types-BMKDHD1l.js} +1 -1
- package/dist/types-BMKDHD1l.js.map +1 -0
- package/dist/{types-CJcxHJff.cjs → types-CsOhH4OF.cjs} +1 -1
- package/dist/types-CsOhH4OF.cjs.map +1 -0
- package/dist/types.d.ts +23 -1
- package/dist/warnings-6yoB06xI.cjs +3 -0
- package/dist/warnings-6yoB06xI.cjs.map +1 -0
- package/dist/warnings-Bt6wvWFe.js +13 -0
- package/dist/warnings-Bt6wvWFe.js.map +1 -0
- package/dist/warnings.d.ts +1 -2
- package/package.json +2 -2
- package/dist/types-CJcxHJff.cjs.map +0 -1
- package/dist/types-c4Mo9m9u.js.map +0 -1
package/dist/serializer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MarcRecord,
|
|
1
|
+
import { MarcRecord, SerializeBatchResult } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Options for serializing MARC records.
|
|
4
4
|
*/
|
|
@@ -11,47 +11,26 @@ export interface SerializeOptions {
|
|
|
11
11
|
* to ASCII plus ANSEL Latin/combining characters.
|
|
12
12
|
*/
|
|
13
13
|
readonly encoding?: 'utf8' | 'marc8';
|
|
14
|
+
/**
|
|
15
|
+
* Maximum number of warnings to collect per record before stopping.
|
|
16
|
+
* Default: 100
|
|
17
|
+
*/
|
|
18
|
+
readonly maxWarnings?: number;
|
|
14
19
|
}
|
|
15
20
|
/**
|
|
16
|
-
* Serialize
|
|
17
|
-
*
|
|
18
|
-
* @param record - The MARC record to serialize
|
|
19
|
-
* @returns Binary representation of the record (Uint8Array for browser compatibility)
|
|
21
|
+
* Serialize an array of MARC records to a concatenated ISO2709 binary stream.
|
|
20
22
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* const record: MarcRecord = {
|
|
24
|
-
* leader: '00000nam 2200000 4500',
|
|
25
|
-
* fields: [
|
|
26
|
-
* { tag: '001', data: 'ocm12345678' },
|
|
27
|
-
* {
|
|
28
|
-
* tag: '245',
|
|
29
|
-
* indicator1: '1',
|
|
30
|
-
* indicator2: '0',
|
|
31
|
-
* subfields: [{ code: 'a', value: 'Title' }],
|
|
32
|
-
* },
|
|
33
|
-
* ],
|
|
34
|
-
* };
|
|
23
|
+
* Each record is individually serialized (with its own 0x1D terminator) and
|
|
24
|
+
* the results are concatenated into a single Uint8Array.
|
|
35
25
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
26
|
+
* @param records - MARC records to serialize
|
|
27
|
+
* @param options - Encoding options forwarded to the per-record serializer
|
|
28
|
+
* @returns Concatenated binary representation of all records
|
|
39
29
|
*/
|
|
40
|
-
export declare function
|
|
41
|
-
/**
|
|
42
|
-
* Result of {@link serializeMarcRecordWithWarnings}: the serialized bytes
|
|
43
|
-
* along with any warnings generated by the encoder (e.g. lossy MARC-8
|
|
44
|
-
* substitutions).
|
|
45
|
-
*/
|
|
46
|
-
export interface SerializeResult {
|
|
47
|
-
readonly bytes: Uint8Array;
|
|
48
|
-
readonly warnings: readonly MarcWarning[];
|
|
49
|
-
}
|
|
30
|
+
export declare function serializeMarcBinary(records: MarcRecord[], options?: SerializeOptions): Uint8Array;
|
|
50
31
|
/**
|
|
51
|
-
* Serialize
|
|
52
|
-
*
|
|
53
|
-
* example, MARC-8 output of records containing characters with no MARC-8
|
|
54
|
-
* equivalent.
|
|
32
|
+
* Serialize an array of MARC records to a concatenated ISO2709 binary
|
|
33
|
+
* stream, returning per-record serialization warnings.
|
|
55
34
|
*/
|
|
56
|
-
export declare function
|
|
35
|
+
export declare function serializeMarcBinaryWithWarnings(records: MarcRecord[], options?: SerializeOptions): SerializeBatchResult;
|
|
57
36
|
//# sourceMappingURL=serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-BMKDHD1l.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Core type definitions for MARC21 records.\n * All types use readonly modifiers to enforce immutability.\n */\n\n/**\n * A subfield within a MARC data field.\n * Contains a single-character code and its associated value.\n *\n * @example\n * ```typescript\n * const subfield: Subfield = { code: 'a', value: 'The Catcher in the Rye' };\n * ```\n */\nexport interface Subfield {\n readonly code: string;\n readonly value: string;\n}\n\n/**\n * A MARC control field (tag 00X).\n * Control fields have no indicators or subfields, only a tag and data.\n *\n * @example\n * ```typescript\n * const controlField: ControlField = { tag: '001', data: 'ocm12345678' };\n * ```\n */\nexport interface ControlField {\n readonly tag: string;\n readonly data: string;\n}\n\n/**\n * A MARC data field (tag 01X-9XX).\n * Data fields have a tag, two indicators, and one or more subfields.\n *\n * @example\n * ```typescript\n * const dataField: DataField = {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [\n * { code: 'a', value: 'The Catcher in the Rye /' },\n * { code: 'c', value: 'J.D. Salinger.' },\n * ],\n * };\n * ```\n */\nexport interface DataField {\n readonly tag: string;\n readonly indicator1: string; // Use ' ' for blank indicator\n readonly indicator2: string; // Use ' ' for blank indicator\n readonly subfields: readonly Subfield[];\n}\n\n/**\n * A complete MARC21 record.\n * Contains a 24-character leader and an array of fields (control or data fields).\n *\n * @example\n * ```typescript\n * const record: MarcRecord = {\n * leader: '00000nam 2200000 4500',\n * fields: [\n * { tag: '001', data: 'ocm12345678' },\n * {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [{ code: 'a', value: 'Title' }],\n * },\n * ],\n * };\n * ```\n */\nexport interface MarcRecord {\n readonly leader: string; // Always 24 characters\n readonly fields: readonly (ControlField | DataField)[];\n}\n\n/**\n * Warning type categories for MARC parsing errors.\n */\nexport type MarcWarningType =\n | 'invalid_leader'\n | 'invalid_directory'\n | 'invalid_field'\n | 'truncated_record'\n | 'encoding_error'\n | 'malformed_xml'\n | 'missing_element'\n | 'invalid_attribute';\n\n/**\n * A warning generated during MARC record parsing.\n * Warnings indicate non-fatal issues that were encountered and recovered from.\n */\nexport interface MarcWarning {\n readonly type: MarcWarningType;\n readonly message: string;\n readonly position?: number; // Byte position in the record\n readonly tag?: string; // Field tag associated with the warning\n}\n\n/**\n * Options for parsing MARC records.\n */\nexport interface ParseOptions {\n /**\n * If true, throw errors instead of collecting warnings.\n * Default: false\n */\n readonly strict?: boolean;\n\n /**\n * Maximum number of warnings to collect before stopping.\n * Prevents memory issues with severely malformed records.\n * Default: 100\n */\n readonly maxWarnings?: number;\n}\n\n/**\n * Result of parsing a MARC record.\n * Contains the parsed record (if successful) and any warnings encountered.\n */\nexport interface ParseResult {\n readonly record: MarcRecord | null;\n readonly warnings: readonly MarcWarning[];\n}\n\n/**\n * Result of parsing multiple MARC records with warning capture.\n * Each entry pairs a parsed record (or null on failure) with its warnings.\n */\nexport interface ParseBatchResult {\n readonly results: readonly ParseResult[];\n}\n\n/**\n * Result of serializing a single MARC record with warning capture.\n */\nexport interface SerializeRecordResult {\n readonly bytes: Uint8Array;\n readonly warnings: readonly MarcWarning[];\n}\n\n/**\n * Result of serializing multiple MARC records with warning capture.\n * Contains the concatenated bytes and per-record results.\n */\nexport interface SerializeBatchResult {\n readonly bytes: Uint8Array;\n readonly results: readonly SerializeRecordResult[];\n}\n\n/**\n * Type guard to check if a field is a control field.\n *\n * @param field - The field to check\n * @returns True if the field is a control field\n *\n * @example\n * ```typescript\n * if (isControlField(field)) {\n * console.log(field.data); // TypeScript knows field is ControlField\n * }\n * ```\n */\nexport function isControlField(field: ControlField | DataField): field is ControlField {\n return 'data' in field;\n}\n\n/**\n * Type guard to check if a field is a data field.\n *\n * @param field - The field to check\n * @returns True if the field is a data field\n *\n * @example\n * ```typescript\n * if (isDataField(field)) {\n * console.log(field.subfields); // TypeScript knows field is DataField\n * }\n * ```\n */\nexport function isDataField(field: ControlField | DataField): field is DataField {\n return 'subfields' in field;\n}\n"],"mappings":"AA2KA,SAAgB,EAAe,GAAwD;AACrF,SAAO,UAAU;AACnB;AAeA,SAAgB,EAAY,GAAqD;AAC/E,SAAO,eAAe;AACxB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
function t(e){return"data"in e}function n(e){return"subfields"in e}Object.defineProperty(exports,"isControlField",{enumerable:!0,get:function(){return t}});Object.defineProperty(exports,"isDataField",{enumerable:!0,get:function(){return n}});
|
|
2
2
|
|
|
3
|
-
//# sourceMappingURL=types-
|
|
3
|
+
//# sourceMappingURL=types-CsOhH4OF.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CsOhH4OF.cjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Core type definitions for MARC21 records.\n * All types use readonly modifiers to enforce immutability.\n */\n\n/**\n * A subfield within a MARC data field.\n * Contains a single-character code and its associated value.\n *\n * @example\n * ```typescript\n * const subfield: Subfield = { code: 'a', value: 'The Catcher in the Rye' };\n * ```\n */\nexport interface Subfield {\n readonly code: string;\n readonly value: string;\n}\n\n/**\n * A MARC control field (tag 00X).\n * Control fields have no indicators or subfields, only a tag and data.\n *\n * @example\n * ```typescript\n * const controlField: ControlField = { tag: '001', data: 'ocm12345678' };\n * ```\n */\nexport interface ControlField {\n readonly tag: string;\n readonly data: string;\n}\n\n/**\n * A MARC data field (tag 01X-9XX).\n * Data fields have a tag, two indicators, and one or more subfields.\n *\n * @example\n * ```typescript\n * const dataField: DataField = {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [\n * { code: 'a', value: 'The Catcher in the Rye /' },\n * { code: 'c', value: 'J.D. Salinger.' },\n * ],\n * };\n * ```\n */\nexport interface DataField {\n readonly tag: string;\n readonly indicator1: string; // Use ' ' for blank indicator\n readonly indicator2: string; // Use ' ' for blank indicator\n readonly subfields: readonly Subfield[];\n}\n\n/**\n * A complete MARC21 record.\n * Contains a 24-character leader and an array of fields (control or data fields).\n *\n * @example\n * ```typescript\n * const record: MarcRecord = {\n * leader: '00000nam 2200000 4500',\n * fields: [\n * { tag: '001', data: 'ocm12345678' },\n * {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [{ code: 'a', value: 'Title' }],\n * },\n * ],\n * };\n * ```\n */\nexport interface MarcRecord {\n readonly leader: string; // Always 24 characters\n readonly fields: readonly (ControlField | DataField)[];\n}\n\n/**\n * Warning type categories for MARC parsing errors.\n */\nexport type MarcWarningType =\n | 'invalid_leader'\n | 'invalid_directory'\n | 'invalid_field'\n | 'truncated_record'\n | 'encoding_error'\n | 'malformed_xml'\n | 'missing_element'\n | 'invalid_attribute';\n\n/**\n * A warning generated during MARC record parsing.\n * Warnings indicate non-fatal issues that were encountered and recovered from.\n */\nexport interface MarcWarning {\n readonly type: MarcWarningType;\n readonly message: string;\n readonly position?: number; // Byte position in the record\n readonly tag?: string; // Field tag associated with the warning\n}\n\n/**\n * Options for parsing MARC records.\n */\nexport interface ParseOptions {\n /**\n * If true, throw errors instead of collecting warnings.\n * Default: false\n */\n readonly strict?: boolean;\n\n /**\n * Maximum number of warnings to collect before stopping.\n * Prevents memory issues with severely malformed records.\n * Default: 100\n */\n readonly maxWarnings?: number;\n}\n\n/**\n * Result of parsing a MARC record.\n * Contains the parsed record (if successful) and any warnings encountered.\n */\nexport interface ParseResult {\n readonly record: MarcRecord | null;\n readonly warnings: readonly MarcWarning[];\n}\n\n/**\n * Result of parsing multiple MARC records with warning capture.\n * Each entry pairs a parsed record (or null on failure) with its warnings.\n */\nexport interface ParseBatchResult {\n readonly results: readonly ParseResult[];\n}\n\n/**\n * Result of serializing a single MARC record with warning capture.\n */\nexport interface SerializeRecordResult {\n readonly bytes: Uint8Array;\n readonly warnings: readonly MarcWarning[];\n}\n\n/**\n * Result of serializing multiple MARC records with warning capture.\n * Contains the concatenated bytes and per-record results.\n */\nexport interface SerializeBatchResult {\n readonly bytes: Uint8Array;\n readonly results: readonly SerializeRecordResult[];\n}\n\n/**\n * Type guard to check if a field is a control field.\n *\n * @param field - The field to check\n * @returns True if the field is a control field\n *\n * @example\n * ```typescript\n * if (isControlField(field)) {\n * console.log(field.data); // TypeScript knows field is ControlField\n * }\n * ```\n */\nexport function isControlField(field: ControlField | DataField): field is ControlField {\n return 'data' in field;\n}\n\n/**\n * Type guard to check if a field is a data field.\n *\n * @param field - The field to check\n * @returns True if the field is a data field\n *\n * @example\n * ```typescript\n * if (isDataField(field)) {\n * console.log(field.subfields); // TypeScript knows field is DataField\n * }\n * ```\n */\nexport function isDataField(field: ControlField | DataField): field is DataField {\n return 'subfields' in field;\n}\n"],"mappings":"AA2KA,SAAgB,EAAe,EAAwD,CACrF,MAAO,SAAU,CACnB,CAeA,SAAgB,EAAY,EAAqD,CAC/E,MAAO,cAAe,CACxB"}
|
package/dist/types.d.ts
CHANGED
|
@@ -78,7 +78,7 @@ export interface MarcRecord {
|
|
|
78
78
|
/**
|
|
79
79
|
* Warning type categories for MARC parsing errors.
|
|
80
80
|
*/
|
|
81
|
-
export type MarcWarningType = 'invalid_leader' | 'invalid_directory' | 'invalid_field' | 'truncated_record' | 'encoding_error';
|
|
81
|
+
export type MarcWarningType = 'invalid_leader' | 'invalid_directory' | 'invalid_field' | 'truncated_record' | 'encoding_error' | 'malformed_xml' | 'missing_element' | 'invalid_attribute';
|
|
82
82
|
/**
|
|
83
83
|
* A warning generated during MARC record parsing.
|
|
84
84
|
* Warnings indicate non-fatal issues that were encountered and recovered from.
|
|
@@ -113,6 +113,28 @@ export interface ParseResult {
|
|
|
113
113
|
readonly record: MarcRecord | null;
|
|
114
114
|
readonly warnings: readonly MarcWarning[];
|
|
115
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Result of parsing multiple MARC records with warning capture.
|
|
118
|
+
* Each entry pairs a parsed record (or null on failure) with its warnings.
|
|
119
|
+
*/
|
|
120
|
+
export interface ParseBatchResult {
|
|
121
|
+
readonly results: readonly ParseResult[];
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Result of serializing a single MARC record with warning capture.
|
|
125
|
+
*/
|
|
126
|
+
export interface SerializeRecordResult {
|
|
127
|
+
readonly bytes: Uint8Array;
|
|
128
|
+
readonly warnings: readonly MarcWarning[];
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Result of serializing multiple MARC records with warning capture.
|
|
132
|
+
* Contains the concatenated bytes and per-record results.
|
|
133
|
+
*/
|
|
134
|
+
export interface SerializeBatchResult {
|
|
135
|
+
readonly bytes: Uint8Array;
|
|
136
|
+
readonly results: readonly SerializeRecordResult[];
|
|
137
|
+
}
|
|
116
138
|
/**
|
|
117
139
|
* Type guard to check if a field is a control field.
|
|
118
140
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warnings-6yoB06xI.cjs","names":[],"sources":["../src/warnings.ts"],"sourcesContent":["/**\n * Warning system for MARC parsing.\n * Re-exports types and provides utility functions.\n */\n\nimport type { MarcWarning, MarcWarningType } from './types';\n\n/**\n * Create a warning object.\n *\n * @param type - The warning type\n * @param message - The warning message\n * @param position - Optional byte position in the record\n * @param tag - Optional field tag associated with the warning\n * @returns A MarcWarning object\n *\n * @example\n * ```typescript\n * const warning = createWarning(\n * 'invalid_leader',\n * 'Leader length is invalid',\n * 0,\n * undefined\n * );\n * ```\n */\nexport function createWarning(\n type: MarcWarningType,\n message: string,\n position?: number,\n tag?: string\n): MarcWarning {\n return { type, message, position, tag };\n}\n"],"mappings":"AA0BA,SAAgB,EACd,EACA,EACA,EACA,EACa,CACb,MAAO,CAAE,KAAA,EAAM,QAAA,EAAS,SAAA,EAAU,IAAA,CAAI,CACxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warnings-Bt6wvWFe.js","names":[],"sources":["../src/warnings.ts"],"sourcesContent":["/**\n * Warning system for MARC parsing.\n * Re-exports types and provides utility functions.\n */\n\nimport type { MarcWarning, MarcWarningType } from './types';\n\n/**\n * Create a warning object.\n *\n * @param type - The warning type\n * @param message - The warning message\n * @param position - Optional byte position in the record\n * @param tag - Optional field tag associated with the warning\n * @returns A MarcWarning object\n *\n * @example\n * ```typescript\n * const warning = createWarning(\n * 'invalid_leader',\n * 'Leader length is invalid',\n * 0,\n * undefined\n * );\n * ```\n */\nexport function createWarning(\n type: MarcWarningType,\n message: string,\n position?: number,\n tag?: string\n): MarcWarning {\n return { type, message, position, tag };\n}\n"],"mappings":"AA0BA,SAAgB,EACd,GACA,GACA,GACA,GACa;AACb,SAAO;AAAA,IAAE,MAAA;AAAA,IAAM,SAAA;AAAA,IAAS,UAAA;AAAA,IAAU,KAAA;AAAA,EAAI;AACxC"}
|
package/dist/warnings.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "marc-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "TypeScript MARC21 library for Node.js and browsers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
},
|
|
70
70
|
"homepage": "https://github.com/jamesrf/marc-ts#readme",
|
|
71
71
|
"engines": {
|
|
72
|
-
"node": ">=
|
|
72
|
+
"node": ">=24"
|
|
73
73
|
},
|
|
74
74
|
"browser": {
|
|
75
75
|
"buffer": false
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-CJcxHJff.cjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Core type definitions for MARC21 records.\n * All types use readonly modifiers to enforce immutability.\n */\n\n/**\n * A subfield within a MARC data field.\n * Contains a single-character code and its associated value.\n *\n * @example\n * ```typescript\n * const subfield: Subfield = { code: 'a', value: 'The Catcher in the Rye' };\n * ```\n */\nexport interface Subfield {\n readonly code: string;\n readonly value: string;\n}\n\n/**\n * A MARC control field (tag 00X).\n * Control fields have no indicators or subfields, only a tag and data.\n *\n * @example\n * ```typescript\n * const controlField: ControlField = { tag: '001', data: 'ocm12345678' };\n * ```\n */\nexport interface ControlField {\n readonly tag: string;\n readonly data: string;\n}\n\n/**\n * A MARC data field (tag 01X-9XX).\n * Data fields have a tag, two indicators, and one or more subfields.\n *\n * @example\n * ```typescript\n * const dataField: DataField = {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [\n * { code: 'a', value: 'The Catcher in the Rye /' },\n * { code: 'c', value: 'J.D. Salinger.' },\n * ],\n * };\n * ```\n */\nexport interface DataField {\n readonly tag: string;\n readonly indicator1: string; // Use ' ' for blank indicator\n readonly indicator2: string; // Use ' ' for blank indicator\n readonly subfields: readonly Subfield[];\n}\n\n/**\n * A complete MARC21 record.\n * Contains a 24-character leader and an array of fields (control or data fields).\n *\n * @example\n * ```typescript\n * const record: MarcRecord = {\n * leader: '00000nam 2200000 4500',\n * fields: [\n * { tag: '001', data: 'ocm12345678' },\n * {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [{ code: 'a', value: 'Title' }],\n * },\n * ],\n * };\n * ```\n */\nexport interface MarcRecord {\n readonly leader: string; // Always 24 characters\n readonly fields: readonly (ControlField | DataField)[];\n}\n\n/**\n * Warning type categories for MARC parsing errors.\n */\nexport type MarcWarningType =\n | 'invalid_leader'\n | 'invalid_directory'\n | 'invalid_field'\n | 'truncated_record'\n | 'encoding_error';\n\n/**\n * A warning generated during MARC record parsing.\n * Warnings indicate non-fatal issues that were encountered and recovered from.\n */\nexport interface MarcWarning {\n readonly type: MarcWarningType;\n readonly message: string;\n readonly position?: number; // Byte position in the record\n readonly tag?: string; // Field tag associated with the warning\n}\n\n/**\n * Options for parsing MARC records.\n */\nexport interface ParseOptions {\n /**\n * If true, throw errors instead of collecting warnings.\n * Default: false\n */\n readonly strict?: boolean;\n\n /**\n * Maximum number of warnings to collect before stopping.\n * Prevents memory issues with severely malformed records.\n * Default: 100\n */\n readonly maxWarnings?: number;\n}\n\n/**\n * Result of parsing a MARC record.\n * Contains the parsed record (if successful) and any warnings encountered.\n */\nexport interface ParseResult {\n readonly record: MarcRecord | null;\n readonly warnings: readonly MarcWarning[];\n}\n\n/**\n * Type guard to check if a field is a control field.\n *\n * @param field - The field to check\n * @returns True if the field is a control field\n *\n * @example\n * ```typescript\n * if (isControlField(field)) {\n * console.log(field.data); // TypeScript knows field is ControlField\n * }\n * ```\n */\nexport function isControlField(field: ControlField | DataField): field is ControlField {\n return 'data' in field;\n}\n\n/**\n * Type guard to check if a field is a data field.\n *\n * @param field - The field to check\n * @returns True if the field is a data field\n *\n * @example\n * ```typescript\n * if (isDataField(field)) {\n * console.log(field.subfields); // TypeScript knows field is DataField\n * }\n * ```\n */\nexport function isDataField(field: ControlField | DataField): field is DataField {\n return 'subfields' in field;\n}\n"],"mappings":"AA+IA,SAAgB,EAAe,EAAwD,CACrF,MAAO,SAAU,CACnB,CAeA,SAAgB,EAAY,EAAqD,CAC/E,MAAO,cAAe,CACxB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-c4Mo9m9u.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/**\n * Core type definitions for MARC21 records.\n * All types use readonly modifiers to enforce immutability.\n */\n\n/**\n * A subfield within a MARC data field.\n * Contains a single-character code and its associated value.\n *\n * @example\n * ```typescript\n * const subfield: Subfield = { code: 'a', value: 'The Catcher in the Rye' };\n * ```\n */\nexport interface Subfield {\n readonly code: string;\n readonly value: string;\n}\n\n/**\n * A MARC control field (tag 00X).\n * Control fields have no indicators or subfields, only a tag and data.\n *\n * @example\n * ```typescript\n * const controlField: ControlField = { tag: '001', data: 'ocm12345678' };\n * ```\n */\nexport interface ControlField {\n readonly tag: string;\n readonly data: string;\n}\n\n/**\n * A MARC data field (tag 01X-9XX).\n * Data fields have a tag, two indicators, and one or more subfields.\n *\n * @example\n * ```typescript\n * const dataField: DataField = {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [\n * { code: 'a', value: 'The Catcher in the Rye /' },\n * { code: 'c', value: 'J.D. Salinger.' },\n * ],\n * };\n * ```\n */\nexport interface DataField {\n readonly tag: string;\n readonly indicator1: string; // Use ' ' for blank indicator\n readonly indicator2: string; // Use ' ' for blank indicator\n readonly subfields: readonly Subfield[];\n}\n\n/**\n * A complete MARC21 record.\n * Contains a 24-character leader and an array of fields (control or data fields).\n *\n * @example\n * ```typescript\n * const record: MarcRecord = {\n * leader: '00000nam 2200000 4500',\n * fields: [\n * { tag: '001', data: 'ocm12345678' },\n * {\n * tag: '245',\n * indicator1: '1',\n * indicator2: '0',\n * subfields: [{ code: 'a', value: 'Title' }],\n * },\n * ],\n * };\n * ```\n */\nexport interface MarcRecord {\n readonly leader: string; // Always 24 characters\n readonly fields: readonly (ControlField | DataField)[];\n}\n\n/**\n * Warning type categories for MARC parsing errors.\n */\nexport type MarcWarningType =\n | 'invalid_leader'\n | 'invalid_directory'\n | 'invalid_field'\n | 'truncated_record'\n | 'encoding_error';\n\n/**\n * A warning generated during MARC record parsing.\n * Warnings indicate non-fatal issues that were encountered and recovered from.\n */\nexport interface MarcWarning {\n readonly type: MarcWarningType;\n readonly message: string;\n readonly position?: number; // Byte position in the record\n readonly tag?: string; // Field tag associated with the warning\n}\n\n/**\n * Options for parsing MARC records.\n */\nexport interface ParseOptions {\n /**\n * If true, throw errors instead of collecting warnings.\n * Default: false\n */\n readonly strict?: boolean;\n\n /**\n * Maximum number of warnings to collect before stopping.\n * Prevents memory issues with severely malformed records.\n * Default: 100\n */\n readonly maxWarnings?: number;\n}\n\n/**\n * Result of parsing a MARC record.\n * Contains the parsed record (if successful) and any warnings encountered.\n */\nexport interface ParseResult {\n readonly record: MarcRecord | null;\n readonly warnings: readonly MarcWarning[];\n}\n\n/**\n * Type guard to check if a field is a control field.\n *\n * @param field - The field to check\n * @returns True if the field is a control field\n *\n * @example\n * ```typescript\n * if (isControlField(field)) {\n * console.log(field.data); // TypeScript knows field is ControlField\n * }\n * ```\n */\nexport function isControlField(field: ControlField | DataField): field is ControlField {\n return 'data' in field;\n}\n\n/**\n * Type guard to check if a field is a data field.\n *\n * @param field - The field to check\n * @returns True if the field is a data field\n *\n * @example\n * ```typescript\n * if (isDataField(field)) {\n * console.log(field.subfields); // TypeScript knows field is DataField\n * }\n * ```\n */\nexport function isDataField(field: ControlField | DataField): field is DataField {\n return 'subfields' in field;\n}\n"],"mappings":"AA+IA,SAAgB,EAAe,GAAwD;AACrF,SAAO,UAAU;AACnB;AAeA,SAAgB,EAAY,GAAqD;AAC/E,SAAO,eAAe;AACxB"}
|