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

@nuuf/chink2

v0.3.0

Published

Chain string objects together parent>child style

Downloads

2

Readme

chink2

Chain string objects together parent>child style

import {
  create, // Creates a new entity
  add, // Adds an entity to a list and a parent if specified, or to root if using root
  remove, // Deletes an entity from the list, removing all descendants
  swap, // Swaps two entities
  update, // Updates the data of an entity
  find, // Returns a parsed entity, finding it by ID
  inject, // Injects an entity into the list binding it to a sibling
  switchParent, // Connects an entity to a different parent
  addToParent, // Connects an entity to a parent
  ejectFromParent, // Removes the connection between parent and child, or switches the parent to root if using root
  getChildren, // Returns a list of all the children of an entity
  getChildrenParsed, // Returns a list of all the children (parsed) of an entity
  getRootEntities, // Returns a list of all the children of the root entity (if using root)
  getRootEntitiesParsed, // Returns a list of all the children (parsed) of the root entity (if using root)
  hasParent, // Checks if the entity has a parent without parsing it
  crunchList, // Removes all null entities and updates all indices
  bindList, // Binds a list so that you do not have to pass it every time
  getPath, // Returns an object with arrays containing the path of a value to the first parent
  generateListStructure // Renders a string of the list structure
} from '@nuuf/chink2';

  const list = [];

  bindList( list );
  // setting root enables automatic add to root if no parent is specified
  // the reason for using a root entity is simply for performance when using inject
  setRoot();
  add( create( 'myData', 'myEntity' ) );
  
  add( create() );

  add( create( null, 'myParent' ) );
  add( create( null, 'myChild' ), find( 'myParent' ) );
  add( create( null, 'myNewParent' ) );

  // add() uses addToParent() if entity has a parent or if it is already in the list
  // and addToParent() uses switchParent() if the entity has a parent

  // in this case the same as addToParent() and switchParent()
  add( find( 'myChild' ), find( 'myNewParent' ) ); 

  remove( find( 'myParent' ) );

  remove( JSON.parse( list[ 2 ] ) );

  swap( find( 'myEntity' ), find( 'myChild' ) );

  // throws error
  // remove( find( 'root' ) );

  inject( create( null, 'injected before' ), find( 'myChild' ) );
  inject( create( null, 'injected after' ), find( 'myChild' ), true );

  ejectFromParent( find( 'myEntity' ) );

  // logs a rendered string for visualisation
  console.log( generateListStructure() );
  // Can be used to collect data like getPath(entity, attributes[])
  // Where attributes is something like ['key1', 'key2'] in entity.data[key1/key2]
  console.log( getPath( find( 'myEntity' ) ) );