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

rabbit-box

v2.0.3

Published

`rabbit-box` is a library that aims to simplify development and improve the user experience by providing a variety of useful features.

Downloads

6

Readme

rabbit-box

rabbit-box is a library that aims to simplify development and improve the user experience by providing a variety of useful features.

Features

  • For developers:
    • Specify the type of input required from users
    • Accept certain values (NOT IMPLEMENTED)
    • Set default values
    • Provide shortcuts for users
  • For users:
    • Easily provide values using various methods:
      • Pass arguments normally
      • Use object destructuring
      • Use key shortcuts

Usage:

For developers:

to start , import and initialize class and set parameters

import RabbitBox from 'rabbit-box'

const rabbit = new RabbitBox(<params go here>);

Parameters

Pass values as strings.

const rabbit = new RabbitBox("pizza","lemon");

if you want to add default values, you should pass as an object

const rabbit = new RabbitBox({"pizza":5,"lemon":10});

also you can pass them in multiple objects

const rabbit = new RabbitBox({"pizza":5},{"lemon":10});

shortcuts

if you want to add shortcut, provide it inside string and split with | or ,:

const rabbit = new RabbitBox("pizza|p","lemon,l");
const rabbit = new RabbitBox({"pizza|p":5,"lemon,l":10});

types

if you wanna set allowed types, do this:

const rabbit = new RabbitBox("pizza|p:<string|number>","lemon,l:<int>");
const rabbit = new RabbitBox({"pizza|p:<string,number>:":5,"lemon,l:<int>":10});

also you can put them first

const rabbit = new RabbitBox("<string|number>:pizza|p");

required

if you want to make specific parameter to be required, so it cannot be undefined, you can make it by putting ! in the beginning

const rabbit = new RabbitBox("!pizza|p:<string|number>")

For users:

First thing user need todo , is to know keys inside "values" and their variations, which you set. Then, they

how to

imagine you as a developer set this parameters:

const rabbit = new RabbitBox("pizza|p:<string|number>","lemon|l:<int>");

by position

user can provide parameters by a position

const result = rabbit.make(5,10);

output:

{pizza:5,lemon:10}

by key or variations

const result = rabbit.make({"p":5,"lemon":10);

output:

{pizza:5,lemon:10}

by range

you can specify range. You can make with numbers, or using shortcuts,

const result1 = rabbit.make({"0:1":5);
const result2 = rabbit.make({"p:l":10);
result1 will be {pizza:5,lemon:5}
result2 will be {pizza:10,lemon:10}

Also you can provide negative numbers, or put first value bigger than second. Also you can provide no range, or only 1 position

const result1 = rabbit.make({":":8); //will set 8 to all values
const result2 = rabbit.make({":l":12); //will set 12 to all from 0 to `lemon`
const result3 = rabbit.make({"l:":12); //will set 12 to all from last element to zero

types

there will be an error if types wont match. Also i added few additional types: array,int and char

Why

When you have a function that takes a lot of parameters, has default values, and requires some parameters to be of a specific type, it can become cumbersome to write all the necessary checks for them.

For example, consider the following function:

function performAction(param1, param2, param3, param4, param5, param6 = 'default value') {
  if (!param5) return new Error('param5 is a required parameter');
  if (typeof param1 !== 'string' || typeof param2 !== 'number') {
    return new Error('param1 must be a string and param2 must be a number');
  }
  if (!param3 || !param4) {
    return new Error('param3 and param4 are required parameters');
  }
  // Do something with the parameters here
  return 'Action performed successfully';
}

Using this function can be a bit cumbersome for the user. They need to provide the values in a specific order, and they must wrap the function call in a try-catch block to handle any errors.

try {
  const result = performAction('hello', 42, true, [1, 2, 3], 'required value');
  console.log(result);
  // Output: "Action performed successfully"
} catch (error) {
  console.error(error);
}

One way to make this function more user-friendly is to use object destructuring. This allows the user to specify the values they want to pass to the function in an object, rather than as separate arguments.

function performAction({param1, param2, param3, param4, param5, param6 = 'default value'} = {}) {
  if (!param5) return new Error('param5 is a required parameter');
  if (typeof param1 !== 'string' || typeof param2 !== 'number') {
    return new Error('param1 must be a string and param2 must be a number');
  }
  if (!param3 || !param4) {
    return new Error('param3 and param4 are required parameters');
  }
  // Do something with the parameters here
  return 'Action performed successfully';
}

This approach solves the issue of having to provide values in a specific order and allows the user to specify only the values they want to pass to the function. However, it can still be a bit cumbersome if the function only has one required parameter, as the user still needs to provide an object with that one value.

function doSomething({param1, param2, param3, param4} = {}) {
  if (!param1) {
    return new Error('param1 is a required parameter');
  }
  // Do something with the parameters here
  return 'Action performed successfully';
}

In this case, the user needs to provide an object with at least one property in order to pass the required parameter to the function.

doSomething({param1: "Hello World"});

This can be a bit inconvenient. rabbit-box aims to solve this problem by allowing the user to provide values in a more flexible and concise way.

For example, rather than having to type out the full parameter names, the user can use key shortcuts to specify the values they want to pass to the function.

doSomething({p1: "Hello World"});

Additionally, if the user wants to provide the same value for multiple parameters, they can do so using a shorthand syntax.

doSomething({'p1:p3': "Hello World"});

Alternatively, the user can specify the values they want to pass to the function using their positions rather than their names.

doSomething({"0:2":"Hello World"});

Awesome!

So , this library helps to solve all of this problems...and more! 🤫 It is comfortable to use both for users and developers.