npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

java-ts-definition-generator

v1.1.0

Published

The typescript definition generator for the java-bridge package

Downloads

7

Readme

Java typescript definition generator

This is the typescript definition generator for the java-bridge package. It generates typescript definitions for java classes and interfaces.

It can either be invoked from the command line or used as a library.

Installation

Note: You need to install java-bridge separately

npm install -g java-ts-definition-generator java-bridge

Command line usage

java-ts-gen <output> <classnames..>

Positionals:
  classnames  The fully qualified class name(s) to convert              [string]
  output      The output file                                           [string]

Options:
  --help             Show help                                         [boolean]
  --version          Show version number                               [boolean]
  --classpath, --cp  The classpath to use                               [string]
  --syncSuffix       The sync suffix                                    [string]
  --asyncSuffix      The async suffix                                   [string]
  --customInspect    Whether to enable the 'customInspect' option      [boolean]

Notes

  • The classpath argument can be supplied multiple times to add multiple jars to the classpath
  • Multiple class names can be supplied to generate definitions for multiple classes
  • The generated typescript files will automatically import all classes once the module is loaded.

Examples

Generate definitions for a single class

Generate definitions for the java.lang.String class and all its referenced classes and save them to ./project:

java-ts-gen ./project java.lang.String

This will create a directory called java containing the definitions for the java.lang.String class and all its dependencies all inside subdirectories. The java.lang.String class will be saved to ./project/java/lang/String.ts. Thus, the folder structure of project will look something like this:

.
├── ...
├── java
│   ├── lang
│   │   ├── String.ts
│   │   ├── Object.ts
│   │   └── ...
│   ├── util
│   │   └── ...
│   └── ...
└── ...

Generate definitions for multiple classes

Generate definitions for the java.lang.String and java.util.ArrayList classes and all of their dependencies and save them to ./project:

java-ts-gen ./project java.lang.String java.util.ArrayList

Library usage

import { TypescriptDefinitionGenerator } from 'java-ts-definition-generator';

const generator = new TypescriptDefinitionGenerator([
    'java.lang.String',
    'java.util.List',
]);
// Generate the typescript definitions
await generator.createModuleDeclarations();

// Save the definitions to a directory
await TypescriptDefinitionGenerator.save('./project');

Available generators

The java declaration tree can be generated using two generators:

  • JavaDefinitionGenerator: This generator is the fastest, as it is written in Java. Requires Java 11 or higher.
  • TsDefinitionGenerator: This one is slower than the JavaDefinitionGenerator as it is written in Typescript, but it works with any Java version.

The best generator is automatically picked when instantiating the TypescriptDefinitionGenerator class. If you still want to choose the generator yourself, you can pass an instance of the JavaDefinitionGenerator or TsDefinitionGenerator into the constructor of the TypescriptDefinitionGenerator.