npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@kodexa/kodexa-document

v8.0.19857160443

Published

TypeScript models for Kodexa Document

Readme

Kodexa Document TypeScript SDK

A TypeScript implementation of the Kodexa Document model for working with structured documents.

Installation

npm install @kodexa/kodexa-document

Overview

The Kodexa Document TypeScript SDK provides a comprehensive framework for working with structured documents. It enables developers to create, load, manipulate, and query documents with a hierarchical node structure. The SDK offers a powerful selector language (similar to XPath) for extracting specific content from documents based on complex criteria.

Key Features

  • Create and manipulate hierarchical document structures
  • Add, update, and remove content nodes and features
  • Query documents using a powerful selector language
  • Tag content for classification and extraction
  • Track document processing steps
  • Store and retrieve external data

Usage Examples

Creating a Document

import { Document, DocumentMetadata } from '@kodexa/kodexa-document';

// Create a new document
const document = new Document(new DocumentMetadata());

// Create a root node
const rootNode = document.createNode('root', 'Root content');
document.contentNode = rootNode;

// Add child nodes
rootNode.addChild(document.createNode('paragraph', 'This is a paragraph'));
rootNode.addChild(document.createNode('paragraph', 'This is another paragraph'));

Creating a Document from Text

import { Document } from '@kodexa/kodexa-document';

// Create a document from text
const document = Document.fromText('Hello World');

Querying Documents

import { Document } from '@kodexa/kodexa-document';

// Create a document with some content
const document = Document.fromText('Hello World');

// Select nodes using selectors
const nodes = document.select('//text');

// Select the first matching node
const firstNode = document.selectFirst('//text');

Adding Features to Nodes

import { Document } from '@kodexa/kodexa-document';

// Create a document with some content
const document = Document.fromText('Hello World');

// Add a feature to the root node
document.contentNode?.addFeature('metadata', 'language', 'en');

// Get features
const features = document.contentNode?.getFeatures();

Tagging Content

import { Document } from '@kodexa/kodexa-document';

// Create a document with some content
const document = Document.fromText('Hello World');

// Tag the content
document.contentNode?.tag('important', { confidence: 0.95 });

// Get tags
const tags = document.contentNode?.getTags();

API Reference

Document

The main class for working with documents.

  • constructor(metadata?: DocumentMetadata, source?: SourceMetadata, ref?: string): Create a new document
  • static fromText(text: string): Create a document from text
  • createNode(nodeType: string, content?: string, virtual?: boolean): Create a new content node
  • select(selector: string, params?: Record<string, any>): Select nodes using a selector
  • selectFirst(selector: string, params?: Record<string, any>): Select the first matching node
  • getRoot(): Get the root node of the document
  • getSteps(): Get the processing steps
  • setSteps(steps: Array<ProcessingStep>): Set the processing steps
  • getExternalData(): Get external data
  • setExternalData(externalData: Record<string, any>): Set external data

ContentNode

Represents a node in the document hierarchy.

  • constructor(document: Document, nodeType: string, id?: number, content?: string): Create a new content node
  • getParent(): Get the parent node
  • getChildren(): Get child nodes
  • addChild(child: ContentNode, index?: number): Add a child node
  • removeChild(contentNode: ContentNode): Remove a child node
  • addFeature(featureType: string, name: string, value: any): Add a feature to the node
  • getFeatures(): Get all features
  • getFeature(featureType: string, name: string): Get a specific feature
  • tag(name: string, options?: any): Add a tag to the node
  • getTags(): Get all tags
  • getTag(name: string): Get tags by name
  • removeTag(name: string): Remove a tag
  • select(selector: string, params?: Record<string, any>): Select nodes using a selector

ContentFeatureClass

Represents a feature associated with a content node.

  • constructor(featureType: string, name: string, value: any): Create a new feature
  • getValue(): Get the feature value
  • toString(): Get a string representation of the feature
  • toDict(): Convert the feature to a dictionary

Tag

Represents a tag applied to a content node.

  • constructor(start?: number, end?: number, value?: string, uuid?: string, data?: any): Create a new tag
  • toDict(): Convert the tag to a dictionary

Running Tests

To run the tests:

# From the lib/typescript directory
npm install
npm test

Building the Package

To build the package:

# From the lib/typescript directory
npm run build

License

ISC