PlantUML Transpiler
raw JSON → 1.0.0 verified Fri May 01 auth: no javascript
A Node.js library (v1.0.0, MIT) that converts PlantUML class diagrams into code for Java, C#, Python, Ruby, Kotlin, JavaScript, and TypeScript. Supports classes, interfaces, enums, abstract classes, generics, visibility modifiers, static/final members, and package/namespace handling. Key differentiators: multi-language output from a single PlantUML source, language-specific idioms, and type system mapping. Actively maintained with monthly releases.
Common errors
error TypeError: PlantUMLTranspiler is not a constructor ↓
cause Wrong import style; default export used as named export.
fix
Use 'import PlantUMLTranspiler from 'plantuml-transpiler'' or 'const { default: PlantUMLTranspiler } = require('plantuml-transpiler')'
error Unsupported target language: ruby (use java, csharp, python, ruby, kotlin, javascript, typescript) ↓
cause Language string mismatch; case-sensitive or unsupported language.
fix
Use lowercase language name: 'java', 'csharp', 'python', 'ruby', 'kotlin', 'javascript', or 'typescript'
error SyntaxError: Unexpected token (expected 'class', 'interface', 'enum', ...) ↓
cause Invalid PlantUML syntax in diagram.
fix
Ensure PlantUML starts with @startuml and ends with @enduml, and follows PlantUML class diagram syntax.
Warnings
gotcha PlantUML syntax must be valid; invalid diagrams produce errors. Use a parser or lint first. ↓
fix Validate PlantUML with a PlantUML parser before transpiling.
breaking v1.0.0 is the first stable release; API may change in minor versions before 2.0. ↓
fix Pin dependency to ^1.0.0 and test on upgrade.
deprecated CommonJS usage is deprecated; future versions may drop support. ↓
fix Switch to ES module imports: import PlantUMLTranspiler from 'plantuml-transpiler'
gotcha TypeScript source exports are type-only; runtime types not available in JavaScript. ↓
fix Use TypeScript or run tsc to generate declarations.
Install
npm install plantuml-transpiler yarn add plantuml-transpiler pnpm add plantuml-transpiler Imports
- PlantUMLTranspiler wrong
const PlantUMLTranspiler = require('plantuml-transpiler')correctimport PlantUMLTranspiler from 'plantuml-transpiler' - PlantUMLTranspiler wrong
const PlantUMLTranspiler = require('plantuml-transpiler')correctconst { default: PlantUMLTranspiler } = require('plantuml-transpiler') - TranspilerOptions wrong
import { TranspilerOptions } from 'plantuml-transpiler'correctimport type { TranspilerOptions } from 'plantuml-transpiler' - SupportedLanguage wrong
import SupportedLanguage from 'plantuml-transpiler'correctimport { SupportedLanguage } from 'plantuml-transpiler'
Quickstart
import PlantUMLTranspiler from 'plantuml-transpiler';
const transpiler = new PlantUMLTranspiler();
const plantUmlCode = `
@startuml
class User {
-id: int
-name: String
+User(id: int, name: String)
+getId(): int
+getName(): String
}
interface UserService {
+findById(id: int): User
+save(user: User): void
}
class UserServiceImpl {
-userRepository: UserRepository
+UserServiceImpl(userRepository: UserRepository)
+findById(id: int): User
+save(user: User): void
}
UserServiceImpl ..|> UserService
UserServiceImpl --> UserRepository
@enduml
`;
const javaCode = transpiler.transpile(plantUmlCode, 'java');
console.log(javaCode);
const tsCode = transpiler.transpile(plantUmlCode, 'typescript');
console.log(tsCode);