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

@appliedblockchain/helpers

v6.0.0

Published

No dependency, single file helpers.

Downloads

766

Readme

Summary

No dependency, single file helpers. Skewed towards ethereum.

Usage

npm i @appliedblockchain/helpers

Api

Table of Contents

addressOfPrivateKey

Parameters

Returns Buffer ethereum address of provided privateKey.

addressOfPublicKey

Returns ethereum address of provided public key.

Parameters

Returns Buffer

blockHashOf

Parameters

  • url string
  • blockNumberOrTag ("earliest" | "latest" | "pending" | number) (optional, default 'latest')
  • timeout number (optional, default defaultTiemout)

Returns Promise<string?> block hash as hex0x string or null from provided ethereum jsonrpc endpoint url in specified timeout; null if timeout has been reached.

booleanOfString

Parses string and returns true for "true", "on", "yes" and "1" strings, false otherwise.

Parameters

Returns boolean

bufferOfHexOrHex0x

Returns Buffer representation of provided hex (ie. "ff") or hex0x (ie. "0xff") string.

Parameters

  • value string

  • Throws any TypeError On invalid input.

bufferOfHex

Parameters

Returns any buffer representation of provided hex string.

bufferOfHex0x

Parameters

Returns Buffer buffer representation of provided hex0x string.

bufferOfUnsigned

Parameters

Returns Buffer the smallest buffer representation of provided safe, unsigned integer number. When input is 0 - empty buffer is returned.

catchOf

Parameters

Returns function (error: Error): T

defaultCmp

Default comparision function.

Parameters

  • x any
  • y any

Returns (-1 | 0 | 1)

eachPromise

Similar to Promise.all but yields after each promise settlement. Exceptions are captured and results are yielded as [ err, result, i ] tuple.

Parameters

Returns AsyncGenerator<[Error?, T?, number], any, any>

evenZeroPaddedOf

Parameters

Returns any input string padded with 0 if length is odd, otherwise returns string as is.

eventuallyTrue

Retries up to n times (roughtly seconds) call to f waiting for true result, which breaks the loop and returns true. If f didn't return true throws last result value.

Parameters

Returns Promise<(true | R)>

fibonacciOf

Yields fibonacci sequence capped to max (default max safe integer).

Parameters

  • max number (optional, default defaultMax)

Returns void

hasKeys

Type: function (any): boolean

Parameters

  • value

Returns any true if value has one or more keys, false otherwise.

heightOf

Parameters

Returns Promise<number> Height of the chain from provided ethereum jsonrpc endpoint url or NaN if timeout has been reached or any other problem occured.

hexOfUnsigned

Parameters

Returns string even/byte-padded, hex string representation of a safe, unsigned number.

hex0xOfUnsigned

Parameters

Returns string 0x-prefixed hex string representation of a safe, unsigned number.

indexedByKey

Parameters

Returns {} transposed entries from xs, indexed by key. Non-unique keys will overwrite previous values. Non-existing keys will be indexed under undefined key.

isLikeDateString

Checks if value looks like YYYY-MM-DD date string.

Parameters

  • value any

Returns boolean

isPending

Returns true if promise has not settled yet, false otherwise.

Parameters

Returns boolean

isSafePositive

Parameters

Returns boolean true if value is safe integer greater than zero, false otherwise.

isSafeUnsigned

Parameters

  • value any

Returns boolean true if value is safe unsigned number, false otherwise.

jsonOfUrl

Type: function (string): Promise<any>

Parameters

  • url

Returns any json from basic http(s) get request on url.

makeRetrace

Captures extra stack trace, usage await foo().catch(makeRetrace()). err argument is being modified with new stack value.

noop

Identity function.

objectOfStrings

Parameters

Returns {} membership object (set) for provided list of elements (strings).

racePromises

Like Promise.race but doen't complain about unhandled rejections that happen after race has settled.

Parameters

Returns Promise<any>

randomUint32

Returns number random unsigned integer that fits 32 bits.

shSync

Executes simple shell command.

Parameters

  • cmd string
  • $1 {trim: boolean?} (optional, default {})
    • $1.trim (optional, default true)

sortedDifference

Computes xs - ys difference in linear time between two, unique, ascending arrays of values. Comparision function can be flipped for descending arrays. Leaks values of arrays in thrown error.

Parameters

  • xs Array<T>
  • ys Array<T>
  • cmp function (T, T): (-1 | 0 | 1) (optional, default defaultCmp)

Returns Array<T>

sortedIntersection

Computes intersection in linear time between two, unique, ascending arrays of values. Comparision function can be flipped for descending arrays. Leaks values of arrays in thrown error.

Parameters

  • xs Array<T>
  • ys Array<T>
  • cmp function (T, T): (-1 | 0 | 1) (optional, default defaultCmp)

Returns Array<T>

defaultTimeout

Expire cached nonces after 12 seconds.

spread

Spread n calls to f function ms milliseconds apart.

Parameters

Returns Promise<Array<any>>

stopOfMonitor

Creates monitor similar to setInterval but allows single execution at a time only. Concurrent invocation attempts are ignored.

Parameters

  • f function (): Promise<any>
  • milliseconds number (optional, default 1*1000)

Returns any stop function.

timeoutOf

Parameters

  • milliseconds number
  • message string (optional, default `Timeout of ${String(milliseconds)}ms exceeded.`)
  • code (number | string) (optional, default '@appliedblockchain/helpers/timeout')

Returns any cancellable, rejecting timeout promise.

License

MIT License

Copyright 2019 Applied Blockchain

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.