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

kratos-core

v1.3.1

Published

kratos-core is an open-source, elegant and battery-included Minecraft Launcher API module written in TypeScript in order to be the based of KratosLauncher

Downloads

32

Readme

kratos-core is an open-source, elegant and battery-included Minecraft Launcher API module written in TypeScript in order to be the based of KratosLauncher.

Node.js CI npm GitHub issues

Features

  • Allow to fetch, download, and search with fast access to minecraft manifest file.
  • versioning in Minecraft with zero-configuration and simple line of code.
  • Support workspace module, to reduce file system

Install

kratos-core was built on Node version 14.17. npm

npm i kratos-core

yarn

yarn add kratos-core

Usage

Version

Fetch the manifest

The manifest included inside version module, which contains a VersionManager class to manage version.

const kratos = require("kratos-core");

// Fetch the manifest from mojang server and print it to console
kratos.version.fetchVersionManifest().then((versionManager) => {
  console.log(versionManager.getRawManifest());

  // Get the package info
  console.log(versionManager.getPackageInfo("1.8"));
  // {
  //   id: '1.8',
  //   type: 'release',
  //   url: 'https://piston-meta.mojang.com/v1/packages/9eb165eef46294062d8698c8a78e8ac914949e7a/1.8.json',
  //   time: '2021-12-15T15:44:13+00:00',
  //   releaseTime: '2014-09-02T08:24:35+00:00',
  //   sha1: '9eb165eef46294062d8698c8a78e8ac914949e7a',
  //   complianceLevel: 0
  // }
});

Handle the version package

versionManager
  // Get the latest version package info of Minecraft
  .getLatestReleasePackageInfo()
  // Download the package using package info url
  .fetchPackage()
  .then((packageManager) => {
    // Get a list of libraries for platform
    // Platform: 'linux' | 'macos' | 'windows'
    packageManager.getLibraries({
      platform: "macos",
    });

    // Returns the raw version package as an object
    packageManager.getVersionPackage();
  });

Download

Create a download

Download a HTTP response by using node-fetch fetch method. The function startDownload() it designing the be able to pass node-fetch options as needed.

// Create a download for the file 'https://piston-meta.mojang.com/v1/packages/9eb165eef46294062d8698c8a78e8ac914949e7a/1.8.json' at destination 1.8.json
const downloadProcess = kratos.download.createDownloadProcess({
  destination: "1.8.json",
  url: new URL(
    "https://piston-meta.mojang.com/v1/packages/9eb165eef46294062d8698c8a78e8ac914949e7a/1.8.json"
  ),
});

// Start downloading the file, logging out if download success
downloadProcess
  .startDownload()
  .then((info) => {
    console.log(
      `Successfully download the 1.8.json file at "${info.destination}"`
    );
  })
  .catch((err) => {
    // Do something with error
  });

// OR you can replace it by async/await
await downloadProcess.startDownload();

// passing node-fetch fetch options
await downloadProcess.startDownload({ follow: 5 }); // Only follow 5 redirect steps

DownloadProgress

It is possible to observe the progress of current downloading process by using DownloadProgress

// Create a new progress
const progress = new kratos.download.DownloadProgress();

// It passing the `data` stream event with buffer
progress.on("progress", (chunk) => {
  console.log(`downloading ${chunk.length} bytes...`);
});
progress.on("error", () => {
  /**
   * Handle downloading error
   */
});

progress.on("finish", () => {
  /**
   * Handle post-download stage
   */
});

// Create a download for the file 'https://piston-meta.mojang.com/v1/packages/9eb165eef46294062d8698c8a78e8ac914949e7a/1.8.json' at destination 1.8.json
const downloadProcess = kratos.download.createDownloadProcess(
  {
    destination: "1.8.json",
    url: new URL(
      "https://piston-meta.mojang.com/v1/packages/9eb165eef46294062d8698c8a78e8ac914949e7a/1.8.json"
    ),
  },
  {
    progress,
  }
);

await downloadProcess.startDownload();

DownloadHashObservation

Sometimes, it is required to calculate the checksum value, kratos-core have a built-in class to handle hashing the file. It is call DownloadHashObservation

// Create a new hash observation, the algorithm is changable
const hashObservation = new kratos.download.DownloadHashObservation("sha1");

// Create a download for the file 'https://piston-meta.mojang.com/v1/packages/9eb165eef46294062d8698c8a78e8ac914949e7a/1.8.json' at destination 1.8.json
const downloadProcess = kratos.download.createDownloadProcess(
  {
    destination: "1.8.json",
    url: new URL(
      "https://piston-meta.mojang.com/v1/packages/9eb165eef46294062d8698c8a78e8ac914949e7a/1.8.json"
    ),
  },
  {
    hashObservation,
  }
);

downloadProcess.startDownload().then(() => {
  const checksum = hashObservation.digest().toString("hex");
  console.log(
    `The hash of the file is ${checksum}`
    // actual: 9eb165eef46294062d8698c8a78e8ac914949e7a
    // expect: 9eb165eef46294062d8698c8a78e8ac914949e7a
  );
  console.log(checksum === "9eb165eef46294062d8698c8a78e8ac914949e7a"); // true
});

Environment

This module was built on top of Bun.sh, which is a fast JavaScript runtime. However, NodeJS is a better option when you want to develop this module for cross-platform. Since, the requirement to certain build, run, and publish this module is:

  • Node >= 14.17.6
  • npm >= 8.4.1

License

Free to contributing, fixing, and using the code to your project. This module was release under MIT license.

MIT