Skip to content

reagent/scratch-stats

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Scratch Stats

A simple package to fetch project stats from the publicly available Scratch API. This is published as a TypeScript package, but can be used from Javascript as well.

Installation

$ yarn add scratch-stats

Usage

There are a couple of core resources exposed by the API that this library makes use of: User and Project. The main entry point is the user:

import { Scratch } from 'scratch-stats';

Scratch.user('rebbel16').then((user) => {
  console.log('I am:', user.username);
});

It's possible to chain other queries off of this initial user:

Scratch.user('YO_GIRL_').then(async (user) => {
  console.log('I am:', user.username, '\n');

  const popularProjects = await user.projects({ order: { views: 'DESC' } });

  console.log('Here are my popular projects:\n');

  for (const project of popularProjects) {
    console.log(
      ` * ${project.title} (${project.url}, views: ${project.views})`
    );

    if (project.isRemix) {
      const parent = await project.parent()!;
      const creator = parent.author;

      console.log(
        `    ... a remix of ${parent.title}, created by: ${creator.username}`
      );
    }
  }
});

As well as fetching a project by ID directly:

Scratch.project(441385296).then((project) => {
  console.log('Project');
  console.log(`     Title: ${project.title}`);
  console.log(`   Created: ${project.createdAt}`);
  console.log(`Created by: ${project.author.username}`);
  console.log(`            ${project.author.url}`);
});

Development

Make sure all dependencies are installed:

$ yarn install

You can test the installation by running:

$ yarn test

This package has a single external dependency (Axios) for providing HTTP connectivity. When adding tests, follow the existing patterns for faking these external connections.

When creating a release, ensure that the generated package contains the expected files:

$ yarn build && yarn pack && tar tzf scratch-stats*.tgz

About

Client library for interacting with the Scratch v 3.0 API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published