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-web

v3.2.1

Published

manages the d2 manifest in browsers, using IndexedDB

Downloads

99

Readme

@d2api/manifest-web

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 in IndexedDB, 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.

2.0.0 update: most functions are renamed for clarity and to clash less with api calls
2.2.0 update: def function return types were modified, to more correctly refer to valid bungie-api-ts paths
3.0.0 update: bundling cjs/esm separately in hopes of better compatibility. say hi if there are any problems.
3.2.0 update: fixed some issues with bundling and peerDeps causing inappropriate "manifest not loaded" error.
loadDefs({ fallBackToCache: true }) now allows using stored local defs if bungie servers can't be contacted.

// [...] setup here
const myItem = getInventoryItemDef(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 you are really likely to have CORS problems.

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

verbose()
run this if you love console logs. run empty to turn on verbosity, or with a boolean for on/off.

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 loadDefs 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

loadDefs()
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

lookups

getActivityDef('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!

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

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

getAllDefs('Activity') / getAllActivityDefs()
returns an array of all the values in a manifest component, such as, in this example, a list of every DestinyActivityDefinition

getComponent('InventoryItem')
like getAllDefs but returns the whole lookup table object, keyed by hashes

allManifest
an object containing all manifest components which have been fetched

misc exports

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

defLanguages
a list of available manifest languages

examples

basic usage

import { verbose, setApiKey, loadDefs, getInventoryItemDef, getAllDefs, includeTables } from '@d2api/manifest-web';
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 loadDefs();
  // if you made it to this comment, the manifest is ready for use!
  
  const kindledOrchid = getInventoryItemDef(2575506895);
  console.log(kindledOrchid?.displayProperties.description);
  // -> "Find the beauty in the flame."
  
  console.log(getAllDefs('DamageType').length);
  // -> 6
})();