open-index/open-npm huggingface dataset:
npm package: @galaxy-dev/metadsl-core
Description: MetaDSL core - Schema definitions, validation, and type system
Latest version: 0.10.9

# @galaxy-dev/metadsl-core

Core package for MetaDSL - provides type definitions, validation, i18n, and expression evaluation.

## Features

- 📝 **TypeScript Types** - Complete DSL schema type definitions
- 🌍 **I18n Engine** - Multi-language translation with fallback
- ✅ **Validation** - Sync/async validation rules
- 🔧 **Expression Engine** - Template expressions `${...}` with built-in functions

## Installation

```bash
pnpm add @galaxy-dev/metadsl-core
```

## Core APIs

### I18n Engine

```typescript
import { I18nEngine } from '@galaxy-dev/metadsl-core';

const i18n = new I18nEngine('zh-CN', 'en-US');

// I18n value (object or string)
i18n.translate({ 'en-US': 'Hello', 'zh-CN': '你好' }); // => '你好'
i18n.translate('Plain string'); // => 'Plain string'

// Switch locale
i18n.setLocale('en-US');
i18n.translate({ 'en-US': 'Hello', 'zh-CN': '你好' }); // => 'Hello'
```

### Expression Engine

```typescript
import { ExpressionEngine } from '@galaxy-dev/metadsl-core';

const engine = new ExpressionEngine({
  functions: {
    // Custom functions
    double: (n: number) => n * 2,
  },
});

const context = { user: { name: 'Alice', age: 25 } };

engine.evaluate('${user.name}', context); // => 'Alice'
engine.evaluate('${user.age >= 18}', context); // => true
engine.evaluate('${double(user.age)}', context); // => 50

// Built-in functions
engine.evaluate('${concat(user.name, " - ", user.age)}', context); // => 'Alice - 25'
engine.evaluate('${format(user.age, "0,0")}', context); // => '25'
```

### Validation

```typescript
import type { ValidationRule } from '@galaxy-dev/metadsl-core';

const validation: ValidationRule = {
  required: 'This field is required',
  min: [3, 'Minimum 3 characters'],
  max: [100, 'Maximum 100 characters'],
  pattern: [/^[a-z]+$/, 'Only lowercase letters'],
};

// Async validation
const asyncValidation: ValidationRule = {
  required: true,
  custom: async (value) => {
    const exists = await checkUsernameExists(value);
    return exists ? 'Username already taken' : null;
  },
};
```

## License

MIT