noggin

Document utilities

Pure functions over NogginDocument. validateDocument and normalizeDocument are the input-boundary defence used by every serializer; documentsEqual / diffDocuments power the change-event pipeline; freezeDocument is what providers hand out so accessors can return references without worrying about consumer mutation.

validateDocument()

function validateDocument(doc: NogginDocument): void;

Validate a document's structural invariants. Throws NogginError with code 'invalid-document' on failure.

Parameters

ParameterType
docNogginDocument

Returns

void

normalizeDocument()

function normalizeDocument(doc: NogginDocument): NogginDocument;

Normalize a parsed document in-place: stamp schemaVersion, normalize notes, strip legacy fields.

Parameters

ParameterType
docNogginDocument

Returns

NogginDocument

documentsEqual()

function documentsEqual(a: NogginDocument, b: NogginDocument): boolean;

Structural equality between two documents. Used by providers to decide whether an external change actually changed anything.

Parameters

ParameterType
aNogginDocument
bNogginDocument

Returns

boolean

diffDocuments()

function diffDocuments(prev: NogginDocument, next: NogginDocument): ItemChange[];

Compute the list of ItemChanges describing the differences between two document snapshots. Pure; doesn't mutate either input. Used by providers to fire onDidChange with a concrete payload.

Parameters

ParameterType
prevNogginDocument
nextNogginDocument

Returns

ItemChange[]

freezeDocument()

function freezeDocument(doc: NogginDocument): NogginDocument;

Deep-freeze a document so accessors can return references without worrying about consumer mutation.

Parameters

ParameterType
docNogginDocument

Returns

NogginDocument