An open API service indexing awesome lists of open source software.

https://github.com/iaseth/tsj-cli


https://github.com/iaseth/tsj-cli

cli interface json node types typescript

Last synced: 6 months ago
JSON representation

Awesome Lists containing this project

README

          

# tsj-cli

**tsj-cli** is a lightweight CLI tool that generates TypeScript interfaces or type aliases from a JSON file.

๐Ÿ“ฆ NPM: [`tsj-cli`](https://www.npmjs.com/package/tsj-cli)
๐Ÿ’ป GitHub: [iaseth/tsj-cli](https://github.com/iaseth/tsj-cli)

## โœจ Features

- Generates TypeScript `interface` or `type` from JSON
- Supports custom indentation: 2 spaces (default), 4 spaces, or tabs
- Simple command-line usage
- Minimal and dependency-free output

## ๐Ÿš€ Installation

```bash
npm i -g tsj-cli@latest
```

## ๐Ÿ›  Usage

```bash
tsj [--type | --interface] [--tabs | --spaces]
```

### Examples

```bash
tsj user.json # default: interface, 2 spaces
tsj user.json --type # generates a type alias
tsj user.json --spaces # uses 4 spaces for indentation
tsj user.json --tabs # uses tabs instead
tsj user.json --type --tabs # type alias with tab indentation
```

### Input (`user.json`)

```json
{
"id": 1,
"name": "Alice",
"isAdmin": false,
"tags": ["dev", "ts"],
"profile": {
"age": 30,
"location": "Earth"
}
}
```

### Output (`interface`)

```ts
interface User {
id: number;
name: string;
isAdmin: boolean;
tags: string[];
profile: {
age: number;
location: string;
};
}
```

## ๐Ÿ“ Project Structure

```bash
tsj-cli/
โ”œโ”€โ”€ src/ # Source code (written in TypeScript)
โ”œโ”€โ”€ dist/ # Transpiled JavaScript output
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .npmignore
โ””โ”€โ”€ README.md
```

## ๐Ÿงช Development

```bash
# Install dependencies
npm install

# Build
npm run build

# Test locally
ts-node src/index.ts data.json --type --tabs

# Link globally for local use
npm link
tsj data.json --interface
```

## ๐Ÿ“ License

MIT ยฉ [iaseth](https://github.com/iaseth)