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

@nefty/use

v0.3.3

Published

A collection of methodes used by NeftyBlocks

Downloads

43

Readme

use

⚡️ Under heavy development. Pin your NPM version!!!! before consumption. ⚡️

Useful methodes we use daily in our projects. Most methodes you probably find in your favorite framework, but we needed something you can use everywhere.

Most functions lack proper checking as we require you to still think about what you are doing.

It's all typed so you should be good to go.

Installation

pnpm install @nefty/use
yarn add @nefty/use

Usage

import { ... } from '@nefty/use';

Methodes

Analytics

Assets

  • useAssetData Get data from a template (WAX api only)
  • useImageUrl Create resized image url from a CID or url (works only for allowed domains)

Network

  • useFetch Some extra ease of use functions on top of fetch, like instant headers, response timing and body and query parsing.
  • useSWR stale-while-revalidate always return data while updating once the time out is over.
  • useRetry Retry useFetch a certain amount of times with a delay between each try.

DOM

  • useAvatar A colorful profile photo based on the account name.
  • useMarkdown A fast and compact markdown parser. (no support for HTML)

Search

  • useSearch A fast search engine with support for typos.

Style

  • useColor Convert a string to a hsla color.

Time

Format

  • useTokenDisplay format a number to a string display, with a max of 8 decimals.

Misc

  • useLog Log to console with a specified type and timestamp all with color coding for better readability.

Wallet

usePosthog

Posthog analytics

import { usePosthog } from '@nefty/use';

// init with extra options
const analytics = usePosthog({
    version: 'v2',
});

// track an event
analytics.track('event-name', {
    // data
});

// identify a user
analytics.identify('user-id');

useAssetData

Get data from a template (WAX api only)

import { useAssetData } from '@nefty/use';

const template = {...};

const asset = useAssetData(template);

if(asset) {
    const { name, img } = asset;
}

useImageUrl

Create resized image url from a CID or url (works only for allowed domains)

import { useImageUrl } from '@nefty/use';

// resize to 100x100 and make it static
useImageUrl('https://example.com/image.png', 100, true);

useFetch

Small wrapper around native fetch to stringify body and parse params as an object (not doing polyfilling)

No need for a try catch, this is done iternaly.

// GET request
import { useFetch } from '@nefty/use';

const { data, error } = await useFetch<DataType>('/api/data', {
    baseUrl: 'https://example.com',
    headers: {
        'Content-Type': 'application/json',
    },
    // params values needs to be of type String
    params: {
        account: 'example',
        filter: 'all',
        limit: '100',
        sort: 'desc',
    },
});

if (error) // do something with the error
else {
    // do something with the data
}
// POST request
import { useFetch } from '@nefty/use';

const { data, error } = await useFetch<DataType>('/api/data', {
    baseUrl: 'https://example.com',
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
    },
    body: {
        account: 'example',
        filter: 'all',
        limit: 100,
        sort: 'desc',
    },
});

if (error) // do something with the error
else {
    // do something with the data
}
// All options
import { useFetch } from '@nefty/use';

const { data, error, header, time } = await useFetch<DataType>('/api/data', {
    baseUrl: 'https://example.com',
});

console.log(header['content-type']); // returns the content-type header
console.log(time); // returns the time it took to fetch the data

useSWR

SWR is a clientside caching (Stall While Revalidate) just to save some bytes and a way to clear the cache and have a new dataset.

import { useSWR } from '@nefty/use';

const forceRefresh = false;

// default timeout is 10 minutes
await useSWR(`unique-name`, () => getData(), 600_000, forceRefresh);

useRetry

Retry useFetch a certain amount of times with a delay between each try.

import { useRetry } from '@nefty/use';

const { data, error, header, time } = await useRetry({
    retries: 3, // default 3
    delay: 1000, // default 1000
    retryOn: ({ error }) => error !== null,
    call: () =>
        useFetch<DataType>('/api/data', {
            baseUrl: 'https://example.com',
        }),
});

useAvatar

Fast and beautiful dynamic avatar based on account name

import { useAvatar } from '@nefty/use';

useAvatar('example'); // returns a svg as a string

useMarkdown

Fast and compact markdown parser see nefty/drawdown for more info

import { useMarkdown } from '@nefty/use';

useMarkdown('example'); // returns a string: <p>example</p>

// with options (source, render as html, class)
useMarkdown('example', true, 'class-name'); // returns a DOM element: <div class="class-name"><p>example</p></div>

useSearch

Fast search engine with support for typos

import { useSearch } from '@nefty/use';

const search = useSearch({
    // simple list of strings
    items: ['example', 'example 2'],
    // OPTIONAL: sorted list of strings per first character (good for many items)
    //  will fallback to items if no results are found to prevent empty results
    sorted_items: {
        a: ['account', 'account 2'],
        e: ['example', 'example 2'],
    },
    // OPTIONAL
    options: {
        distance: 3, // default 3: max distance between characters in a typo
        results_count: 8, // default 8: how many matches to return
        results_count_alt: 32, // default 32: how many alternative results with typos to look up (caped to results_count)
    },
});

const result = search('exa'); // returns [example', 'example 2'],

useColor

String to hsla color

import { useColor } from '@nefty/use';

useColor('example'); // returns a hsla color string

useCountDown

Countdown displayer, in DHMS format

import { useCountDown } from '@nefty/use';

// (start time, current time)
useCountDown(new Date().valueOf() - 1000, new Date().valueOf()); // returns 1S

useTokenDisplay

Format a number to a string display, with a max of 8 decimals (default) and optional fixed decimals (default false)

import { useTokenDisplay } from '@nefty/use';

useTokenDisplay(100, 2); // returns 100

useTokenDisplay(100, 2, true); // returns 100.00

useLog

Log to console with a specified type and timestamp all with color coding for better readability

import { useLog } from '@mvdschee/use';

useLog('example', 'info'); // returns 2024-08-12 11:54:36 [INFO] example

useLog('example', 'warn'); // returns 2024-08-12 11:54:36 [WARN] example

useLog('example', 'error'); // returns 2024-08-12 11:54:36 [ERROR] example

useLog('example', 'status'); // returns 2024-08-12 11:54:36 example

WalletUAL

Wallet management for UAL. not going to go in to much details here, but you can find more info on the UAL

import { WalletUAL, WalletUser } from '@nefty/use/wallet';

const callback = (users: WalletUser[]): void => {};

const wallet_anchor = new Anchor([network], { appName });
const wallet_wax = new Wax([network]);
const wallet_wombat = new Wombat([network], { appName });

const provider = new WalletUAL(callback, [network], appName, [wallet_anchor, wallet_wax, wallet_wombat]);

provider.init();