Skip to content

uplang/js

Repository files navigation

UP Parser for JavaScript/TypeScript

npm version npm downloads CI License: GPL v3

Official JavaScript/TypeScript implementation of the UP (Unified Properties) language parser.

πŸ“š API Documentation | πŸ§ͺ Test Status | πŸ“– Specification

Universal Support - Works in browsers, Node.js, Deno, and Bun

Features

  • βœ… Full UP Syntax Support - Scalars, blocks, lists, tables, multiline strings
  • βœ… Type Annotations - Parse and preserve type hints (!int, !bool, etc.)
  • βœ… TypeScript - Full type definitions included
  • βœ… Universal - Browser, Node.js, Deno, Bun support
  • βœ… ESM + CommonJS - Both module formats supported
  • βœ… Well-Tested - Comprehensive test suite
  • βœ… Zero Dependencies - No external runtime dependencies
  • βœ… Lightweight - Small bundle size

Requirements

  • Node.js 16+ (for Node.js usage)
  • Modern browser with ES6+ support (for browser usage)

Installation

# npm
npm install @uplang/up

# yarn
yarn add @uplang/up

# pnpm
pnpm add @uplang/up

Quick Start

JavaScript (ESM)

import { Parser } from '@uplang/up';

const parser = new Parser();
const doc = parser.parse(`
    name Alice
    age!int 30
    config {
      debug!bool true
    }
`);

// Access values
console.log(doc.get('name'));  // 'Alice'

// Iterate nodes
for (const node of doc.nodes) {
    console.log(node.key, '=', node.value);
}

TypeScript

import { Parser, Document, Node, Value } from '@uplang/up';

const parser = new Parser();
const doc: Document = parser.parse(input);

const name: string | undefined = doc.getScalar('name');
const config: Map<string, Value> | undefined = doc.getBlock('config');

πŸ“– For detailed examples and tutorials, see QUICKSTART.md

Documentation

API Overview

Core Classes

  • Parser - Main parser for converting UP text into documents
  • Document - Parsed document with convenient access methods
  • Node - Key-value pair with optional type annotation
  • Value - Union type for all value types (scalar, block, list, table)

Basic Usage

import { Parser } from '@uplang/up';

const parser = new Parser();

// Parse string
const doc = parser.parse(upContent);

// Access values
const name = doc.getScalar('name');
const server = doc.getBlock('server');
const tags = doc.getList('tags');

// Iterate all nodes
for (const node of doc.nodes) {
    console.log(node.key, node.type, node.value);
}

See DESIGN.md for complete API documentation and implementation details.

Browser Usage

<script type="module">
  import { Parser } from 'https://cdn.skypack.dev/@uplang/up';

  const parser = new Parser();
  const doc = parser.parse(`
    title "My Config"
    port!int 8080
  `);

  console.log(doc.getScalar('title'));
</script>

Testing

# Run all tests
npm test

# Run with coverage
npm run test:coverage

# Run in watch mode
npm run test:watch

Project Structure

js/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ parser.ts        # Main parser implementation
β”‚   β”œβ”€β”€ types.ts         # TypeScript definitions
β”‚   β”œβ”€β”€ document.ts      # Document class
β”‚   └── index.ts         # Public API exports
β”œβ”€β”€ dist/
β”‚   β”œβ”€β”€ index.js         # CommonJS build
β”‚   β”œβ”€β”€ index.mjs        # ESM build
β”‚   └── index.d.ts       # TypeScript definitions
β”œβ”€β”€ test/
β”‚   └── parser.test.ts   # Comprehensive tests
β”œβ”€β”€ package.json
β”œβ”€β”€ README.md            # This file
β”œβ”€β”€ QUICKSTART.md        # Getting started guide
β”œβ”€β”€ DESIGN.md            # Architecture documentation
└── LICENSE              # GNU GPLv3

Contributing

Contributions are welcome! Please see the main CONTRIBUTING.md for guidelines.

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

Links

Other Implementations

  • Go - Reference implementation
  • Java - Modern Java 21+ with records and sealed types
  • Python - Pythonic implementation with dataclasses
  • Rust - Zero-cost abstractions and memory safety
  • C - Portable C implementation

Support

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published