@aperturesyndicate/synx
v3.5.2
Published
SYNX: The Active Data Format. Faster than JSON, cheaper for AI tokens, built-in logic.
Maintainers
Readme
SYNX for JS/TS — @aperturesyndicate/synx
The official JavaScript & TypeScript parser for the SYNX format.
Install
npm install @aperturesyndicate/synxUsage
const Synx = require('@aperturesyndicate/synx');
// Load from file
const data = Synx.loadSync('config.synx');
console.log(data.server.port); // 8080
// Parse from string
const data2 = Synx.parse('name Wario\nage 30');
console.log(data2.name); // "Wario"TypeScript
import Synx from '@aperturesyndicate/synx';
interface Config {
server: { port: number; host: string };
app_name: string;
}
const data = Synx.loadSync<Config>('config.synx');
console.log(data.server.port); // typed as numberAPI
| Method | Description |
|---|---|
| Synx.parse<T>(text, options?) | Parse a .synx string → object |
| Synx.loadSync<T>(path, options?) | Load & parse file (sync) |
| Synx.load<T>(path, options?) | Load & parse file (async, returns Promise) |
| Synx.stringify(obj, active?) | Serialize object → .synx string |
Options
{
basePath?: string; // For :include resolution
env?: Record<string, string>; // Override env vars
region?: string; // For :geo ("RU", "US", etc.)
strict?: boolean; // Throw on INCLUDE_ERR/WATCH_ERR/CALC_ERR/CONSTRAINT_ERR
}strict: true enables fail-fast behavior for production: marker runtime errors throw instead of silently remaining in the output object as error strings.
CLI
Install globally:
npm install -g @aperturesyndicate/synxCommands
# Convert to JSON/YAML/TOML/.env
synx convert config.synx --format json
synx convert config.synx --format yaml > values.yaml
synx convert config.synx --format toml
synx convert config.synx --format env > .env
# Validate (strict mode, for CI/CD)
synx validate config.synx --strict
# Watch for changes
synx watch config.synx --format json
synx watch config.synx --exec "nginx -s reload"
# Extract JSON Schema from constraints
synx schema config.synxExport Formats
Convert parsed SYNX to other formats programmatically:
const config = Synx.loadSync('config.synx');
Synx.toJSON(config); // JSON (pretty)
Synx.toJSON(config, false); // JSON (compact)
Synx.toYAML(config); // YAML
Synx.toTOML(config); // TOML
Synx.toEnv(config); // KEY=VALUE
Synx.toEnv(config, 'PREFIX'); // PREFIX_KEY=VALUEFile Watcher
const handle = Synx.watch('config.synx', (config, error) => {
if (error) return console.error(error);
console.log('Config reloaded:', config);
}, { strict: true });
handle.close(); // stop watchingSchema Export
Extract constraints as JSON Schema:
const schema = Synx.schema(`
!active
app_name[required, min:3, max:30] TotalWario
volume[min:0, max:100, type:int] 75
`);
// { "$schema": "...", "properties": { "app_name": { ... } }, "required": ["app_name"] }Other Languages
- Python — synx-format on PyPI
- Rust — synx on crates.io
cargo add synxuse synx::Synx; let data = Synx::load("config.synx")?; println!("{}", &data["server"]["port"]);
License
MIT — © APERTURESyndicate
