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

@tenk/engine

v4.2.0

Published

A recursive stacking algorithm that can be used in the browser / a backend service to produce only the metadata for your project.

Downloads

9

Readme

@tenk/engine

A recursive stacking algorithm that can be used in the browser / a backend service to produce only the metadata for your project.

Install

npm i @tenk/engine

Usage

import tenk from "@tenk/engine";

const metadata = tenk([
  {
    name: "Background",
    elements: [
      { name: "Red" },
      { name: "Blue" },
      { name: "Rare", weight: 0.1 }
    ],
    attribute: (layer) => ({
      trait_type: 'Bg',
      value: layer.selectedElement.name
    })
  },
  {
    name: "Body",
    elements: [
      { name: "Big" },
      { name: "Medium" },
      { name: "Small" },
    ]
  },
  {
    name: "Hair",
    elements: [
      { name: "Long" },
      { name: "Medium" },
      { name: "Short" },
    ]
  }
]);
/*
 [
   { 
     "name": "1",
      "attributes": [
        { "trait_type": "Bg", "value": "Red" },
        { "trait_type": "Body", "value": "Medium" },
        { "trait_type": "Hair", "value": "Short" }
      ]
    },
    ... other tokens
  ]
*/

Layer


  • name
  • elements
  • attribute

name

The layer name

elements

A list of elements

attribute(layer: Layer, tokenLayers: Layer[], dna: string): Attribute | null;

Use this function to customize a layer's attribute.

tenk([
  {
    name: "Headwear_Baseball Cap",
    attribute: (layer, _tokenLayers, dna) => ({
      trait_type: 'Baseball Cap',
      value: layer.selectedElement.name,
      dna
    })
  },
])

If you need to omit a layer's attribute you can return null.

tenk([
  {
    name: "Character Outline",
    attribute: (layer) => null
  },
])

Options


  • brokenRuleThreshold
  • duplicateThreshold
  • size
  • modifyLayers
  • modifyMetadata

brokenRuleThreshold: number

If you have rules set on your layers like cannotAccompany or mustAccompany this is the amount of times the collection algorithm is allowed to break those rules before it exits.

duplicateThreshold: number

If the collection algorithm creates more than this amount of duplicate tokens, it will exit.

size: number

This is the size limit of the collection. Defaults is 10,000.

modifyLayers(tokenLayers: Layer[], tokenId: number, allLayers: Layer[]): Layer[]

This is a function that you can define that will allow you to alter the chosen layers for any specific token. For example:

tenk(layers, {
  modifyLayers(tokenLayers, tokenId, allLayers) {
    const specialBgIdx = tokenLayers.findIndex(layer => layer.name === 'Special Background')
    if (specialBgIdx > -1) {
      const specialElement = allLayers.find(layer => layer.name === "Special Element")
      tokenLayers.splice(specialElement, 0, specialElement);
    }
    return tokenLayers;
  }
})

modifyMetadata(tokenId: number, attributes: Attribute[], tokenLayers: Layer[], dna: string): Metadata

This function will allow you to modify each token's metadata. For example:

tenk(layers, {
  modifyMetadata(tokenId, attributes, tokenLayers, dna) {
    return {
      name: `Tank #${tokenId}`,
      description: someGeneratedDescription(tokenId, dna)
    }
  }
})