skycosmic_parser 0.0.6 copy "skycosmic_parser: ^0.0.6" to clipboard
skycosmic_parser: ^0.0.6 copied to clipboard

A CLI tool to parse and generate code for SkyCosmic projects.

Skycosmic Parser #

A powerful CLI tool to generate robust, "anti-null-safety" Dart models from API JSON responses. It automatically handles null values, nested objects, and lists, ensuring your application never crashes due to unexpected nulls.

Features #

  • Anti-Null Safety: Generates models where fields are nullable but fromJson methods safely handle nulls and missing keys.
  • Automatic Type Inference: Detects types (int, double, bool, String, List, Map) from your JSON data.
  • Nested Class Generation: Automatically detects nested objects and generates separate classes for them.
  • Token Support: Easily pass authentication tokens for protected API endpoints.
  • CLI & Programmatic Usage: Use it from the command line or import the library in your Dart scripts.

Installation #

Activate the package globally using:

dart pub global activate skycosmic_parser

Usage #

CLI Command #

The primary way to use Skycosmic Parser is via the command line.

Syntax

GET Request

skycosmic get <url> [token]

POST Request

skycosmic post <url> [token] <payload>

(Alias: skycosmic pos ...)

Arguments

  • <url>: The full API URL.
  • [token]: (Optional) Bearer token.
  • <payload>: (POST only) JSON string body.

Examples

GET (Public)

skycosmic get https://jsonplaceholder.typicode.com/todos/1

GET (With Token)

skycosmic get https://api.example.com/profile my-secret-token

POST (With Payload)

skycosmic post https://api.example.com/users '{"name": "John"}'

POST (Token + Payload)

skycosmic post https://api.example.com/orders my-token '{"productId": 123}'

Output #

The tool automatically infers the filename from the URL (e.g., .../users -> lib/models/users.dart).

Programmatic Usage #

You can also use the parser in your own Dart code:

import 'package:skycosmic_parser/skycosmic_parser.dart';

void main() {
  final jsonData = {'id': 1, 'name': 'Test'};
  final generator = ModelGenerator('MyModel');
  final code = generator.generate(jsonData);
  print(code);
}

Generated Code Example #

The tool generates easy-to-use models like this:

class ApiResponse {
  final int? userId;
  final int? id;
  final String? title;
  final bool? completed;

  ApiResponse({
    this.userId,
    this.id,
    this.title,
    this.completed,
  });

  factory ApiResponse.fromJson(Map<String, dynamic> json) {
    return ApiResponse(
      userId: json['userId'],
      id: json['id'],
      title: json['title'],
      completed: json['completed'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'userId': userId,
      'id': id,
      'title': title,
      'completed': completed,
    };
  }
}

License #

MIT

1
likes
145
points
154
downloads

Publisher

unverified uploader

Weekly Downloads

A CLI tool to parse and generate code for SkyCosmic projects.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

args, dart_style, dio, path, recase

More

Packages that depend on skycosmic_parser