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

@d2api/manifest-node

v2.0.9

Published

manages the manifest on local filesystem, for node applications. for node v18+

Downloads

67

Readme

@d2api/manifest-node

a simple singleton with functions to download, ✨CACHE✨, and access the d2 manifest, with proper component types

this package downloads the manifest and provides functions to retrieve its data. it caches the fetched tables on disk, for faster loads later.

these functions will return accurately typed entries from bungie-api-ts.
so your tsc or IDE of choice should know that a DestinyInventoryItem has an itemCategoryHashes property, and it's an array of numbers.

// [...] setup here
const myItem = getInventoryItem(460688465);
myItem.icon;
// TypeScript error: Property 'icon' does not exist on type 'DestinyInventoryItemDefinition'.ts(2339)

functions/exports

setup

setApiKey('apikey')
you should add an api key or defs download will probably only work intermittently.

setLanguage('en')
sets the language of the manifest to download. doing this alone doesn't trigger a fresh download, you need to load() afterward.

verbose()
run this if you love console logs.

includeTables(['InventoryItem', 'Activity'])
specify which definitions tables should be downloaded and available. you can leave this empty to fetch everything, but do you really need several MB worth of UnlockValues?
see load below for an extra note.

excludeTables(['UnlockValues', 'InventoryItemLite'])
if you realllly want everything, you can specify which definitions tables should be excluded, and download everything else.
prefer using includeTables, but if you're downloading everything, this is a good place to put InventoryItemLite since you'll already have InventoryItem

load()
loads the newest manifest according to what version the API advertises. attempts to use the cached copy if it's up to date. returns a promise that resolves once loading is complete.
THIS CAN BE RE-RUN

  • to download additional data after adding more components with includeTables
  • to check for manifest version updates
  • to switch to a new language

loadLocal()
SYNCHRONOUSLY loads the most recent available LOCAL copy of the requested tables

this uses NO INTERNET: it won't check available version, update data, or download tables if they're missing, so...
use sparingly and under specific circumstances, like when you KNOW you've already pre-loaded the manifest

returns true if it managed to load all the requested tables

lookups

getActivity('2656947700')
performs a lookup of a known activity hash. this example returns the type DestinyActivityDefinition | undefined, because the hash might not be valid.
optional chaining will serve you well here, or you can live dangerously with a non-null assertion!

get('Activity', 2656947700)
a more generic def getter, which accepts table names as string literals. this returns the same data as the above example.

getInventoryItem(2575506895) / getDamageType(3373582085)
same as getActivity, but for other tables/data types. there's 50+ of these functions, i am not going to list them all here, that's what intellisense is for.

getAll('Activity')
returns an array of all the values in a manifest component, such as DestinyActivityDefinition

getComponent('InventoryItem')
like getAll but returns the whole object, keyed by hashes

allManifest
an object containing all manifest components which have been fetched

loadedVersion
the manifest version currently loaded in memory. the version that you'll get information from if you get() an entry

examples

basic usage

import { verbose, setApiKey, load, getInventoryItem, getAll, includeTables } from '@d2api/manifest-node';
verbose(); // make the client chatty. if you want.
setApiKey('hahahoho');
includeTables(['InventoryItem', 'DamageType']);

async () => {
  // checks the API for the current version.
  // loads our cached copy if it's up to date, or downloads a new one from bungie
  await load();
  // if you made it to this comment, the manifest is ready for use!
  
  const kindledOrchid = getInventoryItem(2575506895);
  console.log(kindledOrchid?.displayProperties.description);
  // -> "Find the beauty in the flame."
  
  console.log(getAll('DamageType').length);
  // -> 6
}