Akore

raw JSON →
2.2.0 verified Fri May 01 auth: no javascript

Akore is a powerful transpiler maker for JavaScript/TypeScript, currently at version 2.2.0. It provides a robust framework for parsing, analyzing, and transforming code, allowing developers to build custom transpilers with ease. Key differentiators include an extensible architecture with concepts like Schema, Registry, Lexer, and BaseTranspiler, and support for both JavaScript and TypeScript. Release cadence is not specified but appears active with recent updates. It requires Node.js >=16 and npm >=8. Compared to alternatives like Babel or SWC, Akore focuses on simplifying the creation of custom transpiler pipelines rather than being a pre-built transpiler.

error Error: The Schema identifier must be a string.
cause Passing a non-string value as the first argument to new Schema() before v2.1.0.
fix
Ensure first argument is a string: new Schema('mySchema', { type: 'string' }).
error TypeError: registry.get is not a function
cause Using an older version where Registry did not extend Map; the API was different.
fix
Update to akore ^2.0.0 and use registry.set/get as Map methods.
error SyntaxError: Named export 'Transpiler' not found.
cause Importing 'Transpiler' which was renamed to 'BaseTranspiler' in v2.
fix
Change import to: import { BaseTranspiler } from 'akore'.
error Cannot find module 'akore' or its corresponding type declarations.
cause Akore is ESM-only; using require() in a CommonJS project or missing 'type': 'module' in package.json.
fix
Set 'type': 'module' in package.json or use dynamic import: const akore = await import('akore').
breaking Version 2.0.0 dropped CommonJS support; require() throws a runtime error.
fix Switch to ESM imports: use 'import' statements and ensure package.json has 'type': 'module'.
breaking Version 2.0.0 renamed 'Transpiler' class to 'BaseTranspiler'. Old imports break.
fix Replace all 'import { Transpiler }' with 'import { BaseTranspiler }'.
deprecated Schema constructor argument order changed in v2.1.0: 'identifier' and 'schema' swapped.
fix Use new Schema('identifier', schemaObject) pattern instead of Schema(schemaObject, 'identifier').
gotcha Lexer must be subclassed; the base class throws an error if tokenize is not overridden.
fix Always extend Lexer and implement the tokenize method returning an array of tokens.
gotcha Registry inherits from Map but get() returns Schema | undefined; TypeScript strict mode requires null checks.
fix Use optional chaining: registry.get('key')?.validate(data) or check for undefined.
npm install akore
yarn add akore
pnpm add akore

Demonstrates creating a Schema, Registry, custom Lexer, and BaseTranspiler to transpile a simple number token.

import { Schema, Registry, BaseTranspiler, Lexer } from 'akore';

// Create a schema for a simple language
const numberSchema = new Schema('number', { type: 'number' });

// Create a registry and register schemas
const registry = new Registry();
registry.set('number', numberSchema);

// Define a custom lexer (minimal example)
class MyLexer extends Lexer {
  tokenize(code) {
    // Simplified tokenization
    if (code === '42') {
      return [{ type: 'number', value: 42 }];
    }
    return [];
  }
}

// Create a transpiler using the registry
const transpiler = new BaseTranspiler(registry);

// Example code to transpile
const code = '42';
const tokens = new MyLexer().tokenize(code);
const result = tokens.map(t => t.value).join(' ');
console.log(result); // Output: 42