0.0.1 • Published 4 months ago

autotypex v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

autotypex šŸš€

Automatically infer TypeScript types from JavaScript objects!

autotypex is a lightweight CLI tool and NPM package that dynamically analyzes JavaScript/JSON files and generates TypeScript type definitions. Perfect for developers migrating from JS to TS or handling dynamic data structures.


šŸ“ŗ Installation

Using Yarn

yarn add autotypex

Using NPM

npm install autotypex

Or, run it directly via npx:

npx autotypex <file.json>

šŸš€ Usage

CLI Usage

npx autotypex <file.json> [options]

Example: Inferring a Type from a JSON File

Given sample.json:

{
  "id": 1,
  "name": "Alice",
  "isActive": true
}

Run:

npx autotypex sample.json

šŸ‘‰ Output:

type InferredType =  {
	 id: number;
	 name: string;
	 isActive: boolean;
}

Custom Type Name

npx autotypex sample.json --name UserType

šŸ‘‰ Output:

type UserType =  {
	 id: number;
	 name: string;
	 isActive: boolean;
}

Saving Output to a .d.ts File

npx autotypex sample.json --name UserType --save

šŸ‘‰ Creates types/UserType.d.ts with:

type UserType =  {
	 id: number;
	 name: string;
	 isActive: boolean;
}

Working with JavaScript Files

If sample.js contains:

module.exports = {
  id: 1,
  name: "Alice",
  isActive: true
};

Run:

npx autotypex sample.js

šŸ‘‰ Output:

type InferredType =  {
	 id: number;
	 name: string;
	 isActive: boolean;
}

šŸ›  Available Options

OptionDescription
-n, --nameSpecify the TypeScript type name (default: InferredType).
-s, --saveSave the output as a .d.ts file inside types/.
-f, --formatFormat the output (default: true, can be false).

šŸ“Œ Programmatic Usage

const { inferType } = require("autotypex");

const obj = { id: 1, name: "Alice", isActive: true };
console.log(inferType(obj));

šŸ‘‰ Output:

type InferredType =  {
	 id: number;
	 name: string;
	 isActive: boolean;
}

šŸ License

MIT License Ā© 2025 Rashad


🌟 Contributing

Contributions are welcome! Feel free to submit an issue or pull request.

šŸš€ Happy Coding!

0.0.1

4 months ago

1.0.0

4 months ago