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

@appbuckets/rabbit

v0.2.41

Published

AppBuckets Main Utilities Package

Downloads

94

Readme

arrayOf(Identity, ...args)

This function take an Identity as argument and filter the Array that contains all the args.
The function create a new array containing all the arguments that have the same prototypeOf
identity.

Params

  • Identity
    • type: Constructor
    • description: the parameters you can use to filter an array
  • ...args
    • type: any
    • description: any arguments. The function takes all and put into an array to filter.

Examples

arrayOf(String, 20, 15, true, 'string');        // [string]

arrayOf(Number, ['string'], {20, 14}, 20);      // [20]

allAre(Identity, ...args)

This function uses arrayOf() and return true if all the args passed have
the same prototype of Identity.

Params

  • Identity
    • type: Constructor
    • description: the parameter the function uses to filter the array of args.
  • ...args
    • type: any
    • description: The function return true only if all the new array is the same of args array

Examples

allAre(String, 'string', 'string 2', 'string 3');  // true

allAre(String, 'string', 'string 2', 20)           // false

anyIs(Identity, ...args)

This function uses arrayOf() and return true if at least one element of args have
the same prototype of Identity.

Params

  • Identity
    • type: Constructor
    • description: The parameter the function uses to filter the array of args.
  • ...args
    • type: any
    • description: The function return true only if the new array has length greater than zero

Examples

anyIs(String, 20, 14, 'string');        // true

anyIs(String, 20, 14, 60, ['string']);  // false

checkObjectForeignKey(matrixObject, comparisonObject)

Compare an object with a matrix object and check if in the
compared object there is a foreign or unrecognized key.

Params

  • matrixObject
    • type: Object
    • description: Matrix object to compare
  • comparisonObject
    • type: Object
    • description: Object to be compared

Examples

  const obj = { nome: 'Marco', cognome: 'Cavanna' };
  const obj2 = { nome: 'Matteo', cognome: 'Ballarini', età: 20 };


  checkObjectForeignKey(obj, obj2);    // età

escapedRegExp(str)

Create a new Regular Expression using regExpEscape function.

Params

  • str
    • type: string
    • description: the string to pass to regExpEscape function.

getRandomGradient(name, direction, darkTextColor, lightTextColor)

Generate two strings, background and color, you can use in the stylesheet .css.
The function uses a string passed by params, and, if you want to use a text
inside the gradient, the function checks if is better to use a light text or a dark text.

Params

  • name
    • type: string
    • description: The string the function uses to generate the Gradient
  • direction
    • type: string
    • description: The direction of the gradient
    • default: diagonal
  • darkTextColor
    • type: string
    • description: If the generated gradient is light the function apply a Dark Color to the text inside
    • default: rgba(61, 66, 81, .95)
  • lightTextColor
    • type: string
    • description: If the generated gradient is light the function apply a Light Color to the text inside
    • default: hsl(212, 10%, 97%)

Examples

  getRandomGradient('gradientString', 'diagonal');

getRandomToken(length)

Return a Random Generated Token of 12 alphanumeric.

Params

  • length
    • type: number
    • description: value that defines the Token length
    • default: 12

Examples

  getRandomToken(20);     //1n3ABC78z123qDfGH912

getScrollbarSize(recalculate)

Calculate a new size of the scrollbar, only if the user is using a Browser.

Params

  • recalculate
    • type: boolean
    • description: if it is true the function recalculate the size of the scrollbar.
    • default: false

isBrowser()

Check if the user is using a browser.
Return 'true' or 'false'.

isMobile(opts)

Check if the user is usign a mobile device.
If the device is a tablet set as true includeTablets property.

Params

  • opts
    • type: Object
    • description: Contain all the options parameters
    • userAgent
      • type: string
      • description: the string that contain the information of user server
      • default: if no user agent is passed it is picked from the Navigator

isObject(prop)

This function checks if the parameter passed is an Object, if it has it returns true. It controls if the prop param is null, undefined, an array or a class, in this cases it returns false.

Params

  • prop
    • description: the Object passed

isPromiseLike(obj)

Check if the param passed is a promise and if it is an object.
Return 'true' or 'false'

Params

  • obj
    • type: any
    • description: the variable passed to check if it's an object and a promise

isTablet()

Check if the user is using a Tablet, by checking if in the isMobile() function
the includeTablets is true.

isTouch()

Check if the screen is a touchscreen, if it's true enable touchscreen function.

isValidString(prop)

Check if the param passed is a string of, at least, one character;
Return 'true' or 'false'.

Params

  • prop
    • type: any
    • description: passed paramater

Examples

  let str = 'string';
  let num = 20;

  isValidString(str);   //true
  isValidString(num);   //false

mapObjectKeys(obj, base)

This function is called with two params: obj, which is the object you want to map.
base that is the key you want to start the map to. If in the object there is a key
that is an object, the function is re-launched, with the key as base parameter.

Params

  • obj
    • type: object
    • description: the object you want to map.
  • base
    • type: string
    • description: The key from which to start the mapping.

regExpEscape(str)

Get a string and add an escape character next to a special char.

Params

  • str
    • type: string
    • description: the string to escape to

Examples

  regExpEscape('house.garden+2.cat');     // house\.garden\+2\.cat

shallowDiffers(prev, next)

This function check if the two objects passed by arguments differs from each other.
If the two objects are different the function return true, otherwise return false.

Params

  • prev
    • type: Object
    • description: The first object to be compared
  • next
    • type: Object
    • description: The second object to be compared

will(funcResult)

This is an asynchronous function. Get a function result (after it is invoked) and return
the result as an array of two elements: the first one is Promise error (if exists, else null).
the second one is the Promise result.

Params

  • funcResult
    • type: Array\Promise
    • description: If it is an array return Promise.all result; if it is a simple promise return result/error on promise.

AnotherObject

This class permit to create a virtual object that contains all the paramaters you passed.
It contains a lot of Methods that can be used to read, update and modify the Object as if it were a database.

constructor(startingObject)

The constructor function create a new Object using the parameter passed using the
logic as mapObjectKeys function.

Params

  • startingObject
    • type: Object
    • description: The starting Object to create the new one

set(path, value)

This Method adds a new key path and value to tehe _keys array. If the path
already exists it replaces the existance value.

Params

  • path
    • type: string
    • description: The path where the Method add the value
  • value
    • type: any
    • description: The value the Methods will add to the path established
    • default: null

remove(path)

This Method removes, if it exists, a key Path from _key array

Params

  • path
    • type: string
    • description: The path the Method will removes

get(path, options)

This Method return a value in the target Path given

Params

  • path
    • type: string
    • description: the path where the Method search the value
  • options
    • type: Object
    • plain
      • type: boolean
      • description:
      • default: false

concat(_concatPath, obj)

This Method is a way to concat an Object or AnotherObject in a path. It places
an Object in a subpath.

Params

  • _concatPath
    • type: string
    • description: The path to use to concat Object
  • obj
    • type: Object
    • description: Object to concat

merge(obj)

This Method merge an Object on base Path

Params

  • obj
    • type: Object
    • description: Object to merge

build(options)

This Method build an Object(or an Array) using the actual defined key in the _keys array

Params

  • options
    • type: Object
    • description: If no options Object is passed it takes some default options to make the build
    • default: { avoidError = true, _keys = this._keys } = {}
    • avoidError
      • type: Boolean
      • description: An options to avoid the error. If it's true it skips the check
      • default: true
    • _keys_
      • type: array
      • description: The keys used to build the Object taken from _keys array
      • default: this._keys

mapKey({_keys})

This Method returns an Object containing all the keys and all the values

Params

  • _keys_
    • type: array
    • description: The array of keys to map
    • default: this._keys

diff(_object, options)

This Method returns an Object containing only the different keys and values from AnotherObject. It compares the two Objects.

Params

  • obj
    • type: Object
    • description: The Object to compare to AnotherObject
  • options
    • type: Object
    • description: Some options for comparison
    • default: { doubleSide = true }
    • doubleSide
      • type: Boolean
      • description: If it's true the Method will save the new Key found in the Object
      • default: true

clone()

This Method return a cloned AnotherObject


filter($callback, $context)

This Method filter the AnotherObject array, as the Filter array function.
It will actually changes the keys.

Params

  • $callback(key, index, array)
    • type: Function
    • description: The callback function invoked with the mapped parameters
    • key
      • type: Object
      • description: Object containing the key Map
      • default: keyMap
    • index
      • type: Number
      • description: The number representing the Index
      • default: number
    • array
      • type: Array
      • description: The array to map
      • default: Array<KeyMap>
  • $context
    • type: Array
    • description: KeyMap Context
    • default: this._keys

map($callback, $context)

This Method map AnotherObject values. This will actually change keys.

Params

  • $callback(path, value)
    • type: Function
    • description: The callback Function which is invoked with the mapped elements
    • path
      • type: String
      • description:
    • value
      • type: any
      • description: