This file catalogs every public export from @git-stunts/trailer-codec so you can confidently import, configure, and extend the codec.
- Deprecated convenience wrapper around
new TrailerCodec().decode(message). UseTrailerCodecinstances instead. (to be removed in v3.0) - Input: a raw commit payload (title, optional body, trailers) as a string.
- Output:
{ title: string, body: string, trailers: Record<string, string> }wherebodyis trimmed viaformatBodySegment(see below) and trailer keys are normalized to lowercase. - Throws
TrailerCodecErrorsubclasses (e.g.,TrailerNoSeparatorError,TrailerValueInvalidError, orCommitMessageInvalidError) for invalid titles, missing blank lines, oversized messages, or malformed trailers.
-- Deprecated convenience wrapper around new TrailerCodec().encode(payload). Use TrailerCodec instances instead. (to be removed in v3.0)
- Builds a
GitCommitMessageunder the hood and returns the canonical string. Trailers are converted from plain objects toGitTrailerinstances via the default factory (seeGitTrailerbelow).
- Shared helper for
decodeMessageto trim whitespace while optionally keeping a trailing newline when you plan to write the body back into a template.
- Returns
{ decodeMessage, encodeMessage }bound to the injectedTrailerCodecServiceinstance; a new service is created when none is provided. - Supports
bodyFormatOptions(forwarded toformatBodySegment) and is useful for advanced/test wiring.
- Creates a new
TrailerCodecService, builds aTrailerCodec, and returns it so you can callencodeMessage()/decodeMessage()without manually wiring services.
- Constructor opts:
{ service = new TrailerCodecService(), bodyFormatOptions }. - Exposes
decodeMessage(input)/decode(input)andencodeMessage(payload)/encode(payload)methods that delegate tocreateMessageHelpers(). - The
decode()andencode()methods are convenience aliases added in v2.1.0.
createConfiguredCodec({ keyPattern, keyMaxLength, parserOptions, formatters, bodyFormatOptions } = {})
- Creates a schema bundle via
createGitTrailerSchemaBundle, aTrailerParser, and aTrailerCodecService, then exposes{ service, helpers, decodeMessage, encodeMessage }. - Use this when you need custom trailer patterns, parser tweaks, formatter hooks, or tightly controlled key lengths.
new GitCommitMessage(
payload: { title: string; body?: string; trailers?: GitTrailerInput[] },
options?: { trailerSchema?: ReturnType<typeof getDefaultTrailerSchemaBundle>['schema']; formatters?: { titleFormatter?: (value: string) => string; bodyFormatter?: (value: string) => string } }
);- Validates via
GitCommitMessageSchema, normalizes title/body with optional formatters, and convertstrailerstoGitTrailerinstances. toString()returns a Git-style commit string (title, optional body, blank line, trailers).
- Accepts
(key: string, value: string, schema = GitTrailerSchema). - Validates using
GitTrailerSchemaand normalizes the key to lowercase and the value to a trimmed string. - Throws
TrailerInvalidErrororTrailerValueInvalidErrorwhen the provided key/value fail schema validation.
- Core decode/encode logic; see
docs/SERVICE.mdfor how the pipeline is wired. - Constructor options:
schemaBundle: result ofcreateGitTrailerSchemaBundle({ keyPattern, keyMaxLength })(defaults:keyPattern=[A-Za-z0-9_-]+,keyMaxLength=100, see the schema section below).trailerFactory: function that instantiates trailers (defaults toGitTrailer).parser: instance ofTrailerParser.messageNormalizer,titleExtractor,bodyComposer: helper classes that normalize lines, extract the title, and compose the body.formatters: optional{ titleFormatter, bodyFormatter }that run before serialization.
decode(message)enforces message size, normalizes lines, extracts the title, splits body/trailers withTrailerParser, composes the body, builds trailers withtrailerFactory, and constructs aGitCommitMessage.encode(messageEntity)accepts either aGitCommitMessageinstance or a plain payload object, validates it againstGitCommitMessageSchema, and returns the canonical commit string produced by the entity.
- Constructor takes
{ keyPattern = TRAILER_KEY_RAW_PATTERN_STRING }. split(lines)finds where the trailer block begins (walks backward, validates the blank-line separator) and returns{ bodyLines, trailerLines }.- Used internally by
TrailerCodecServiceand is injectable for custom parsing strategies.
- Returns
{ schema, keyPattern, keyRegex }with the schema used byGitTrailerandGitCommitMessage. - Default
keyPatternis[A-Za-z0-9_-]+andkeyMaxLengthdefaults to100.
- Exported from the default schema bundle; use them to keep custom parsers aligned with validation rules.
- Base error type used throughout the codec (
index.jsre-exports it). - Signature:
(message: string, meta: Record<string, unknown> = {}).
| Error | Thrown by | Meaning |
|---|---|---|
TrailerTooLargeError |
MessageNormalizer.guardMessageSize (called by TrailerCodecService.decode and the exported decodeMessage) |
Message exceeds the 5 MB guard in MessageNormalizer. |
TrailerNoSeparatorError |
TrailerParser.split / TrailerCodecService.decode when the blank-line guard fails |
A trailer block was found without a blank line separating it from the body (see TrailerParser). |
TrailerValueInvalidError |
GitTrailer via GitTrailerSchema.parse when constructing trailers |
A trailer value violated the GitTrailerSchema (e.g., contained \n). |
TrailerInvalidError |
GitTrailer via GitTrailerSchema.parse when constructing trailers |
Trailer key or value failed validation (GitTrailerSchema). |
CommitMessageInvalidError |
GitCommitMessage via GitCommitMessageSchema.parse (triggered by TrailerCodecService.decode or encode) |
The GitCommitMessageSchema rejected the title/body/trailers combination. |