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

MALjs

v0.1.0

Published

Promise based json api wrapper for the MAL (myanimelist) api

Downloads

21

Readme

MALjs

A promise based json api wrapper for the MAL (myanimelist) api. http://myanimelist.net/modules.php?go=api

This api has not been tested in production environments. To use the MAL api in your browser you are required to be whitelisted as discussed in this topic.

Support

All api requests return promises, if you are using in the browser instead of nodejs, use a Promise polyfill where neccesarry. For browsers that don't support ES6 see the ES5 file in the es5/ directory.

Usage

To use it in node install the dependencies with npm install --production and require the mal.js file.

To use in the browser include the es5 file and load a promise polyfill if neccesarry.

To make manga calls, replace anime with manga.

// for node require the file first: const MALjs = require('./mal');

// create an new api instance with your myanimelist user name and password
const mal = new MALjs('MAL username', 'MAL password');

// search my animelist
mal.anime.search('search string')
  .then(result => result) // contains the json result on success
  .catch(err => err); // contains an error message if the request fails

// Get the authenticated users animelist
mal.anime.list()
  .then(result => result)
  .catch(err => err);

// adds an anime to the list
mal.anime.add('71', { // '71' is the animes ID (retrieved from search())
  episode: "1",
  status: "6", // 1/watching, 2/completed, 3/onhold, 4/dropped, 6/plantowatch
  score: "7"
})
  .then(result => result)
  .catch(err => err);

// Updates an anime on the list
mal.anime.update('71', {
  status: "1"
})
  .then(result => result)
  .catch(err => err);

// Deletes an anime from the list
mal.anime.delete('71')
  .then(result => result)
  .catch(err => err);

// Verify the users credentials
api.verifyCredentials()
  .then(result => result)
  .catch(err => err);

Anime values

  • episode. int
  • status. int OR string. 1/watching, 2/completed, 3/onhold, 4/dropped, 6/plantowatch
  • score. int
  • storage_type. int
  • storage_value. float
  • times_rewatched. int
  • rewatch_value. int
  • date_start. date. mmddyyyy
  • date_finish. date. mmddyyyy
  • priority. int
  • enable_discussion. int. 1=enable, 0=disable
  • enable_rewatching. int. 1=enable, 0=disable
  • comments. string
  • fansub_group. string
  • tags. string. tags separated by commas

Manga Values

  • chapter. int
  • volume. int
  • status. *int OR string. 1/reading, 2/completed, 3/onhold, 4/dropped, 6/*plantoread
  • score. int
  • times_reread. int
  • reread_value. int
  • date_start. date. mmddyyyy
  • date_finish. date. mmddyyyy
  • priority. int
  • enable_discussion. int. 1=enable, 0=disable
  • enable_rereading. int. 1=enable, 0=disable
  • comments. string
  • scan_group. string
  • tags. string. tags separated by commas
  • retail_volumes. int

Fun with promises

Since the api uses promises you can use things like chaining and parallel requests.

Chaining requests

var api = new MALjs('MAL username', 'MAL password');

// Make the first request
api.anime.search('Full Metal')
  .then(result => {
    // result.anime.entry contains an array of animes matching the search query
    var animeId =  result.anime[0].id;

    // Make a new request, adding the anime to the users list
    return api.anime.add(animeId);
  })
  .then(result => {
    console.log('Anime added!', result);
  })
  .catch(err => {
    console.log('Something went wrong!', err);
  });

Parallel request

var api = new MALjs('MAL username', 'MAL password');

// Add multiple anime to the users myanimelist.
Promise.all([
  api.anime.add('71'),
  api.anime.add('231'),
  api.anime.add('71')
])
  // When all promises resolve.
  .then(results => {
    console.log('All anime were added!', results);
  })
   // When one promise fails, all fail.
  .catch(err => {
    console.log('Something went wrong!', err);
  });

Build es5 files

Install dependencies with npm install.
Run npm run build to build files.

Testing

NOTE: Tests are run against the live MAL Api, Don't use your actual MAL account if you don't want to alter your list

If you want to test locally run chrome with the --args --disable-web-security --user-data-dir (MACos) commands, becuase MAL has a No-Access-Control-Allow-Origin header set. However keep in mind this will causes browser stability and security issues.

In order to test add the file env.js to the project root with MAL credentials.

// env.js contents
(function() {
  var root = this;

  var env = {
    user: 'username',
    password: 'password',
  };

  if (typeof exports !== 'undefined') {
    if (typeof module !== 'undefined' && module.exports) {
      exports = module.exports = env;
    }
    exports._ENV = env;
  } else {
    root._ENV = env;
  }
}).call(this);

Open test.html in the browser or run node.js in node to execute tests.