🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@nldoc/types

Package Overview
Dependencies
Maintainers
3
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nldoc/types

NLdoc's Type Definitions for Document Specification

latest
npmnpm
Version
4.0.64
Version published
Weekly downloads
88
1000%
Maintainers
3
Weekly downloads
 
Created
Source

NLdoc Document Specification Types

pipeline status coverage report Latest Release NPM Version

TypeScript type definitions and validation schemas for the NLdoc Document Specification. This library provides runtime type validation using Zod schemas, ensuring type safety for document processing and validation.

Overview

This package provides:

  • Type Definitions: Complete TypeScript types for all NLdoc document resources
  • Runtime Validation: Zod schemas for validating document structures at runtime
  • Test Utilities: Helpers for testing document validation and processing
  • Resource Types: Comprehensive types for all document elements (Document, Asset, Footnote, etc.)

The types are designed to work seamlessly with the NLdoc Document Specification and provide both compile-time type safety and runtime validation capabilities.

Getting Started

Prerequisites

  • Node.js >= 22.0.0 < 23.0.0
  • npm >= 10.0.0 < 12.0.0

Installation

Install the package via npm:

npm install @nldoc/types

Or using yarn:

yarn add @nldoc/types

Basic Usage

import { Document, Asset, Footnote } from '@nldoc/types';

// Type-safe document creation
const document: Document = {
  type: 'Document',
  // ... other document properties
};

// Runtime validation
try {
  const validatedDocument = await Document.parseAsync(documentData);
  console.log('Document is valid:', validatedDocument);
} catch (error) {
  console.error('Validation failed:', error);
}

Runtime Validation

The package exports Zod schemas for runtime validation:

import { Document } from '@nldoc/types';

// Validate and parse document data
const result = Document.safeParse(documentData);

if (result.success) {
  // TypeScript knows result.data is a valid Document
  console.log('Valid document:', result.data);
} else {
  // Handle validation errors
  console.error('Validation errors:', result.error.issues);
}

Development

Local Setup

  • Clone the repository:

    git clone https://gitlab.com/logius/nldoc/lib/typescript/types.git
    cd types
    
  • Install dependencies:

    npm install
    
  • Build the project:

    npm run build
    

Available Scripts

  • npm run test - Run the test suite with Vitest and coverage
  • npm run test:watch - Run tests in watch mode with coverage
  • npm run build - Compile TypeScript to JavaScript
  • npm run build:check - Type check without emitting files
  • npm run lint - Lint the codebase using ESLint
  • npm run format - Format code using Prettier
  • npm run format:check - Check code formatting
  • npm run fix - Auto-fix linting and formatting issues
  • npm run commit - Use conventional commits with Commitizen

Type Definitions

The package exports TypeScript types for all NLdoc document resources:

Core Resources

  • Document: The root document container
  • Asset: External resources (images, files, etc.)
  • Footnote: Document footnotes and references

Text Elements

  • Heading: Document headings (H1-H6)
  • Paragraph: Text paragraphs with inline content
  • Text: Plain text content
  • Link: Hyperlinks

Structural Elements

  • Table: Tables with headers, rows, and cells
  • OrderedList/UnorderedList: Numbered and bulleted lists
  • DefinitionList: Term-definition pairs
  • BlockQuotation: Quoted content blocks
  • Preformatted: Pre-formatted text blocks

Media Elements

  • Image: Image resources with metadata

Writing New Types

When adding new types, they should be added to src/resources.ts. All types are contained in one file because some have recursive dependencies on others, which prevents breaking them into separate files while maintaining proper import relationships.

See Zod's documentation on recursive types for more information.

Testing

The types are tested against a comprehensive collection of valid and invalid examples from the NLdoc document specification. Test examples are automatically downloaded on first test run.

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

Tests validate:

  • Type correctness for valid document examples
  • Proper rejection of invalid document structures
  • Schema validation accuracy
  • Cross-reference integrity

Contributing

We welcome contributions! Please ensure:

  • All tests pass (npm test)
  • Code is properly formatted (npm run format:check)
  • Linting rules are followed (npm run lint)
  • Type checking passes (npm run build:check)
  • Use conventional commits (npm run commit)

License

This project is licensed under the European Union Public License 1.2 - see LICENSE for details.

Acknowledgements

FAQs

Package last updated on 20 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts