
Product
Introducing Webhook Events for Pull Request Scans
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
gear-rarity
Advanced tools
Rarity levels for Loot items.
The rarity level of any given item is deducted from its number of occurrences in the total number of Loot items.
Rarity level | Description | Occurrences |
---|---|---|
![]() | Common items appear 375 or more times. | 47.25% - 30,237 items |
![]() | Uncommon items appear less than 375 times. | 12.61% - 8,073 items |
![]() | Rare items appear less than 358 times. | 11.78% - 7,537 items |
![]() | Epic items appear less than 101 times. | 10.29% - 6,587 items |
![]() | Legendary items appear less than 10 times. | 9.67% - 6,189 items |
![]() | Mythic items appear exactly 1 time. | 8.4% - 5,377 items |
npm i --save gear-rarity # npm
yarn add gear-rarity # yarn
pnpm add gear-rarity # pnpm
// RarityLevel goes from 1 (common) to 6 (mythic). See table above for more info.
type RarityLevel = 1 | 2 | 3 | 4 | 5 | 6;
// ColorFn allows to override a color in different places.
type ColorFn = (colorParameters: {
level: RarityLevel; // the rarity level
color: string; // the base color you can override
itemName?: string; // in certain cases the item name will be present
}) => string | void | null; // return a string to override the color
function itemRarity(itemName: string): RarityLevel;
This function returns the rarity level of an item, given its name.
Example:
let rarity = itemRarity('"Golem Roar" Studded Leather Belt of Fury');
console.log(rarity); // 6
function rarityColor(
itemOrRarityLevel: string | RarityLevel,
options?: { colorFn: ColorFn }
): string;
This function returns the color of a rarity level, given an item name or a rarity level.
Example:
let color = rarityColor("Ornate Belt of Perfection");
console.log(color); // "#c13cff"
function rarityDescription(itemOrRarityLevel: string | RarityLevel): string;
This function returns the description of a rarity level, given an item name or a rarity level.
Example:
let levelA = rarityDescription(1);
let levelB = rarityDescription("Studded Leather Boots of Rage");
console.log(levelA); // "Common"
console.log(levelB); // "Legendary"
function rarityImage(
imageOrItems: string | string[],
options?: { colorFn?: ColorFn; displayLevels?: Boolean }
): Promise<string>;
This function generates an image with added rarity levels.
It accepts any of the following:
SVG source of a Loot image.
Data URI representing a Loot image (e.g. as returned by the tokenURI()
method of the Loot contract).
HTTP URL pointing to a Loot image.
Array of items.
The displayLevels
option allows to add levels to the items list.
The colorFn
option allows to override the color of a particular item.
Example with React, use-nft to load the image, and swr to handle the async function:
import { rarityImage } from "gear-rarity";
import { useNft } from "use-nft";
import useSWR from "swr";
function Loot({ tokenId }) {
const { nft } = useNft(LOOT, id);
const { data: image } = useSWR(nft?.image, rarityImage);
return image ? <img src={image} /> : <div>Loading…</div>;
}
The resulting images could look like this:
function rarityImageFromItems(
items: string[],
options: { colorFn?: ColorFn; displayLevels?: Boolean }
): string;
This function is similar to rarityImage, except it only accepts an array of items. It is useful when you already have a list of items, because it returns a string
directly (while rarityImage()
returns a Promise
resolving to a string
).
displayLevels
option allows to add levels to the items list.colorFn
option allows to override the color of a particular item.Example:
import { rarityImageFromItems } from "gear-rarity";
const bag = [
"Grimoire",
'"Woe Bite" Ornate Chestplate of the Fox +1',
"Silk Hood",
"Heavy Belt of Fury",
"Shoes",
"Silk Gloves",
'"Rune Glow" Amulet of Rage',
"Silver Ring",
];
document.body.innerHTML = `
<img src=${rarityImageFromItems(bag)} />
`;
Have a look at the demo app on CodeSandbox to see how it works.
You can also run it from this repository:
# Build gear-rarity
yarn
yarn build
# Run the demo app
cd demo
yarn
yarn dev
MIT
FAQs
Get the rarity level of a DopeWars Gear item
We found that gear-rarity demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.