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

@herii/node-utilities

v1.2.8

Published

Multiple utilities for node.js projects. Including common utilities, useful for all kinds of projects.

Downloads

13

Readme

Node utilities

This package may be used in node.js projects.

What are the available utilities?

There are a lot of common functionalities, some may be useful for you, and some may not. This project is oriented for any kind of apps, specially modern ones.

How to install?

    npm i @herii/node-utilities

How to use

1. You can import the whole utilities

    const utilities = require("@herii/node-utilities")
    utilities.utilityName(arguments) // example, calling a utility named utilityName

2. You can import only what you need (Recommended)

    const {utilityName} = require("@herii/node-utilities")
    utilityName(args) // call utility

Utilities List

random_number(n)

Example:
        console.log('4 digits', random_number(4)) // Output: 6090
        console.log('6 digits', random_number(6)) // Output: 105388
        console.log('10 digits', random_number(10)) // Output: 1000004099

today(timezone)

    today('America/Argentina/Buenos_Aires') // output: 09/09/2021

dateReverse(date)

    dateReverse(today('America/Argentina/Buenos_Aires')) // output: 2021-09-09

getDateStr(date,iso, timezone)

You can call the function to get a string in a specific language.

    getDateStr("2021/08/02", "es-MX")

Output: lunes, 2 de agosto de 2021

You could optionally add a third parameter "timezone".

    getDateStr("2021/08/02", "es-AR", "America/Argentina/Buenos_Aires")

items_needed(total, max_capacity)

    items_needed(10,4); // Output is 3. We need 3 cars or items.

This function can be used to determine how many rooms you need to host people in a hotel, etc.

get_percentage_value(number, percentage)

    // What is 10% of 100?
    get_percentage_value(100, 10) // Output: 10

minusPercentage(number, percentage)

days_difference(dates)

    days_difference(dates) // dates is an array of dates.

currencyFormat(amount, currency, iso)

Example: currencyFormat(123456.789, 'EUR', 'de-DE') // Output: 123.456,79 €

location

Don't forget this is an object of methods, to use it:

    const {location} = require("@herii/node-utils")
    const {getState} = location 
    console.log(getState(address_components))

Or you can:

    const {location} = require("@herii/node-utils")
    console.log(location.getState(address_components))

The methods contained inside of location are:

getColloquial(address_components)

Returns the colloquial name of the location. Eg: Area 51

getState(address_components, level)

Get the state from address_components (Default level is 1).
Sometimes google has:

  1. administrative_area_level_1
  2. administrative_area_level_2

You can specify level (1 or 2, etc) adding the argument level.

    // Example
    const state2 = getState(address_components, 2) // Returns value at administrative_area_level_2
    const state1 = getState(address_components, 1) // Returns value at administrative_area_level_1

getStreetNumber(address_components)

Get street number from address_components

getPostalCode(address_components)

Get postal code from address_components

getCity(address_components)

Get the city from address_components

getCountry(address_components)

Get the country from address_components

getRoute(address_components)

Get the route from address_components

getSubLocality(address_components, level)

Get the sublocality from address_components (Default level is 1)

Sometimes google has:

  1. sublocality_1

  2. sublocality_2 You can specify level (1 or 2, etc) adding the argument level.

     // Example
     const state2 = getSubLocality(address_components, 2) // Returns value at sublocality_level_2
     const state1 = getSubLocality(address_components, 1) // Returns value at sublocality_level_1

getShort(address_components)

Get a short description of the address.

// Example:
const address = getShort(address_components)
console.log(address) // outputs: City, State, Country.

getLong(address_components)

Get a long description of the address

getMiddle(address_components)

Get a not so long description (without the colloquial name of the place)


Structure of address_components

address_components

        [
                {
                    "long_name": "bajo derecha",
                    "short_name": "bajo derecha",
                    "types": [
                        "subpremise"
                    ]
                },
                {
                    "long_name": "24",
                    "short_name": "24",
                    "types": [
                        "street_number"
                    ]
                },
                {
                    "long_name": "Calle Álvarez de Castro",
                    "short_name": "Calle Álvarez de Castro",
                    "types": [
                        "route"
                    ]
                },
                {
                    "long_name": "Almería",
                    "short_name": "Almería",
                    "types": [
                        "locality",
                        "political"
                    ]
                },
                {
                    "long_name": "Almería",
                    "short_name": "AL",
                    "types": [
                        "administrative_area_level_2",
                        "political"
                    ]
                },
                {
                    "long_name": "Andalucía",
                    "short_name": "AN",
                    "types": [
                        "administrative_area_level_1",
                        "political"
                    ]
                },
                {
                    "long_name": "España",
                    "short_name": "ES",
                    "types": [
                        "country",
                        "political"
                    ]
                },
                {
                    "long_name": "04002",
                    "short_name": "04002",
                    "types": [
                        "postal_code"
                    ]
                }
            ]