extrix-intel
v1.0.0
Published
AI-powered dev tools pack for code explanation, refactoring, test generation, documentation, and schema design
Downloads
105
Maintainers
Readme
Extrix SDK
Features
Code Explanation: Get clear, comprehensive explanations of any code
Smart Refactoring: Refactor code with AI-guided improvements
Test Generation: Automatically generate comprehensive test suites
Documentation Generation: Create README and API documentation
Schema Design: Convert text descriptions to SQL schemas and ERD diagrams
Installation
npm install extrix-intel
Setup
Extrix uses OpenAI's GPT models for AI-powered features. You need an OpenAI API key to use this package.
Option 1: Environment Variable (Recommended)
export OPENAI_API_KEY='your-api-key-here'
Option 2: Pass API Key Directly
import { DevTools } from 'extrix';
const dev = new DevTools({
apiKey: 'your-api-key-here'
});
Optional: Configure Model
const dev = new DevTools({
apiKey: 'your-api-key-here',
model: 'gpt-4-turbo-preview' // default
});
Usage
1. Explain Code
Get detailed explanations of any code snippet or file.
import { DevTools } from 'extrix';
const dev = new DevTools();
// Explain code snippet
const result = await dev.explain(`
function fibonacci(n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}
`);
console.log(result.explanation);
// Or explain from file
const fileResult = await dev.explain('./src/complex-logic.js');
console.log(fileResult.explanation);
2. Refactor Code
Refactor code with specific goals in mind.
const result = await dev.refactor(
`
function calc(a, b, op) {
if (op === 'add') return a + b;
if (op === 'sub') return a - b;
if (op === 'mul') return a * b;
if (op === 'div') return a / b;
}
`,
'Use strategy pattern and add error handling'
);
console.log(result.refactored);
console.log(result.response); // Explanation of changes
3. Generate Tests
Automatically create comprehensive test suites.
const code = `
export function validateEmail(email) {
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return regex.test(email);
}
`;
const result = await dev.generateTests(code, {
framework: 'Jest' // optional, auto-detected
});
console.log(result.tests);
// Save tests to file
await dev.saveOutput(result.tests, './tests/validateEmail.test.js');
4. Generate Documentation
Create README or API documentation.
// Generate README
const readme = await dev.generateDocs('./src/index.js', {
type: 'README'
});
console.log(readme.documentation);
await dev.saveOutput(readme.documentation, './README.md');
// Generate API docs
const apiDocs = await dev.generateDocs('./src/api.js', {
type: 'API'
});
console.log(apiDocs.documentation);
5. Schema from Text (Killer Feature!)
Convert natural language descriptions into SQL schemas and ERD diagrams.
const schema = await dev.schemaFromText(`
I need a blog system with users, posts, and comments.
Users can write multiple posts.
Each post can have many comments.
Comments are written by users.
Track timestamps for everything.
`);
console.log('SQL Schema:');
console.log(schema.sql);
console.log('\nERD Diagram (Mermaid):');
console.log(schema.erd);
// Save outputs
await dev.saveOutput(schema.sql, './schema.sql');
await dev.saveOutput(schema.erd, './erd.md');
You can also specify the SQL dialect:
const schema = await dev.schemaFromText(
'E-commerce system with products, orders, and customers',
{ dialect: 'mysql' }
);
API Reference
new DevTools(config)
Create a new DevTools instance.
Parameters:
config.apiKey(string, optional): OpenAI API key. Falls back toOPENAI_API_KEYenv varconfig.model(string, optional): OpenAI model to use. Default:'gpt-4-turbo-preview'
dev.explain(code, options)
Explain code functionality.
Parameters:
code(string): Code snippet or file pathoptions.language(string, optional): Programming language (auto-detected if not provided)
Returns: Object with { code, language, explanation, source }
dev.refactor(code, goal, options)
Refactor code with a specific goal.
Parameters:
code(string): Code snippet or file pathgoal(string): Refactoring goal/objectiveoptions.language(string, optional): Programming language (auto-detected if not provided)
Returns: Object with { original, refactored, language, goal, response, source }
dev.generateTests(code, options)
Generate test suite for code.
Parameters:
code(string): Code snippet or file pathoptions.language(string, optional): Programming language (auto-detected)options.framework(string, optional): Testing framework (auto-detected based on language)
Returns: Object with { code, tests, language, framework, response, source }
dev.generateDocs(pathOrCode, options)
Generate documentation.
Parameters:
pathOrCode(string): Code snippet or file pathoptions.type(string, optional): 'README' or 'API'. Default: 'README'options.language(string, optional): Programming language (auto-detected)
Returns: Object with { code, documentation, language, type, source }
dev.schemaFromText(text, options)
Generate SQL schema and ERD from text description.
Parameters:
text(string): Natural language description of database requirementsoptions.dialect(string, optional): SQL dialect ('postgresql', 'mysql', 'sqlite'). Default: 'postgresql'options.includeERD(boolean, optional): Include ERD diagram. Default:true
Returns: Object with { description, sql, erd, dialect, response }
dev.saveOutput(content, filePath)
Save output to file.
Parameters:
content(string): Content to savefilePath(string): Destination file path
Returns: Object with { saved, path }
Supported Languages
JavaScript / TypeScript
Python
Java
Go
Rust
Ruby
PHP
SQL
And more (auto-detected)
Examples
Check the examples/ directory for more usage examples:
basic-usage.js- Basic feature demonstrationstest-all.js- Comprehensive testing example
Requirements
Node.js >= 16.0.0
OpenAI API key
Error Handling
try {
const result = await dev.explain(code);
console.log(result.explanation);
} catch (error) {
if (error.message.includes('API key')) {
console.error('Please set your OpenAI API key');
} else {
console.error('Error:', error.message);
}
}
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
For issues and questions, please open an issue on GitHub.
