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

@vlalg-nimbus/master-tool

v1.0.5

Published

Master Tool - Helpers and Utils functions

Downloads

9

Readme

npm npm Snyk Vulnerabilities for npm package Snyk Vulnerabilities for GitHub Repo

This LIB has several Helpers/Users already created to avoid breaking the head making the same logic.

Functions list

isNumber

Function that checks if the parameter is a number.

masterTool.isNumber(value)

The default value is null and the return is boolean type.

masterTool.isNumber(1) // true
masterTool.isNumber(true) // false
masterTool.isNumber('text') // false
masterTool.isNumber({ a: 1, b: 2}) // false
masterTool.isNumber(null) // false

listener

Function that centralizes the use of addEventListener.

masterTool.listener(scope, event, callback, wantsUntrusted)

Params/Return:

  • Params:
    • scope: The values accepted are window or document, default is document. If you will run on Window or Document.
    • event: The values accepted are the same as type on addEventListener, see the list here.
    • callback: Function to be executed.
    • wantsUntrusted: Default is false. Used to specify whether the event can be triggered by untrusted content, it is an optional option and present in the eventListener.
  • Return: It returns nothing.
// Window
masterTool.listener('window', 'load', () => {
  console.log('Hello my window')
})

// Document
masterTool.listener('document', 'load', () => {
  console.log('Hello my document')
})

// HTML element
const buttonElement = document.querySelector('#close-button')
const cbFunction = () => {
  console.log('Hello my others')
}

masterTool.listener('others', 'load', cbFunction, false, buttonElement)

asyncMapPromise

Function created to do Async in .map of javascript. This function is asynchronous.

masterTool.asyncMapPromise(itens, callback)

Params/Return:

  • Params:
    • itens: array of items, default value is an empty array ([]).
    • callback: Function to be executed.
  • Return: Returns a new array of items, as the callback function returns
const array = ['1', '2', '3', '4']
const cbFunction = (item, index, array) => item === '2'
const newArray = await $masterTool.asyncMapPromise(array, cbFunction)

Obs.: The .map in JavaScript by default will return undefined if there is a conditional logic (if) inside it to return only if the condition passes, needing to run a .filter to clean the unwanted data (undefined), in asyncMapPromise() it works the same, here's an example:

const array = ['1', '2', '3', '4']

// in JavaScript
const newArray = array.map((item, index, array) => {
  if (item === '2') return item
})
console.log(newArray) // [undefined, '2', undefined, undefined]
newArray.filter(item => item !== undefined) // ['2']


// asyncMapPromise()
const newArray2 = await $masterTool.asyncMapPromise(array, (item, index, array) => {
  if (item === '2') return item
})
console.log(newArray2) // [undefined, '2', undefined, undefined]
newArray2.filter(item => item !== undefined) // ['2']

convertHexToRGBA

Function that convert HEX color to RGBA color

masterTool.convertHexToRGBA(hexCode, opacity)

Params/Return:

  • Params:
    • hexCode: Color in hex, can be passed with or without the character #.
    • opacity: RGBA opacity, accepted from 0.0 to 1.0.
  • Return: Returns the color in RGBA.
masterTool.convertHexToRGBA('#fff', '0.3') // rgba(255, 255, 255, 0.3)
masterTool.convertHexToRGBA('fff', '0.3') // rgba(255, 255, 255, 0.3)

initialLetter

Function that returns the initial letters of the string

masterTool.initialLetter(wordsToPickUp)

Params/Return:

  • Params:
    • wordsToPickUp: Text that will be analyzed.
  • Return: Returns all initial letters in uppercase.
masterTool.initialLetter('Text that will be analyzed') // ['T', 'T', 'W', 'B', 'A']

removeSpecialCharacters

Function that removes any special character from a text.

masterTool.removeSpecialCharacters(textToRemove, charactersAllowed)

Params/Return:

  • Params:
    • textoToRemove: Text that will be analyzed.
    • charactersAllowed: Characters that should not be removed.
  • Return: Returns text without special characters.
masterTool.removeSpecialCharacters('Special !@#$ characters.', '.') // Special characters.

trimText

Function that trims (spaces at the beginning and end) the text.

masterTool.trimText(text)

Params/Return:

  • Params:
    • text: Text that will be analyzed.
  • Return: Returns text without spaces at the beginning and end.
masterTool.trimText(' Special !@#$ characters. ')
// " Special !@#$ characters. " to "Special !@#$ characters."

removeSpaceInText

Function that removes all spaces from text.

masterTool.removeSpaceInText(text)

Params/Return:

  • Params:
    • text: Text that will be analyzed.
  • Return: Returns text without spaces.
masterTool.removeSpaceInText(" 'Special !@#$ characters' ")
// " 'Special !@#$ characters' " to "'Special!@#$characters'"

goWhatsapp

Function used to generate a redirect URL for whastapp, both web and app.

masterTool.goWhatsapp(phone, msg, type)

Params/Return:

  • Params:
    • phone: WhatsApp phone number that will be used to start a conversation.
    • msg: Message that will be placed in the text field when opening the WhatsApp conversation.
    • type: Redirection type, web (api or wa) or app (intent).
  • Return: Returns the redirect url.
const msg = 'I would like to know more about product X that is being advertised on the website'

// Example using a fake cell phone from Brazil (São Paulo)
// Country: Brazil - 55
// state: São Paulo - 11
// phone: São Paulo - 911111111
const fakePhone = '5511911111111'

const waType = $masterTool.goWhatsapp(fakePhone, msg, 'wa')
const apiType = $masterTool.goWhatsapp(fakePhone, msg, 'api')
const intentType = $masterTool.goWhatsapp(fakePhone, msg, 'intent')

console.log(waType)
// 'https://wa.me/5511911111111?text=I would like to know more about product X that is being advertised on the website'

console.log(apiType)
// 'https://api.whatsapp.com/send?phone=5511911111111&text=I would like to know more about product X that is being advertised on the website'

console.log(intentType)
// 'intent://send?phone=5511911111111&text=I would like to know more about product X that is being advertised on the website#Intent;scheme=whatsapp;package=com.whatsapp;end'

Example of using the url with window.open() for type wa

isEmpty

Function that checks if a variable is empty.

masterTool.isEmpty(value)

Params/Return:

  • Params:
    • value: Variable to be checked.
  • Return: Returns if a variable is empty.
$masterTool.isEmpty() // true
$masterTool.isEmpty('') // true
$masterTool.isEmpty({}) // true
$masterTool.isEmpty([]) // true
$masterTool.isEmpty(null) // true
$masterTool.isEmpty(undefined) // true

$masterTool.isEmpty('foo') // false
$masterTool.isEmpty(1) // false
$masterTool.isEmpty(true) // false
$masterTool.isEmpty(false) // false
$masterTool.isEmpty({ bao: 'foo'}) // false
$masterTool.isEmpty([1, 2]) // false

fixNullToNumber

Function that turns null into 0.

masterTool.isEmpty(value)

Params/Return:

  • Params:
    • value: Variable to be checked.
  • Return: Returns if a variable is empty.
$masterTool.fixNullToNumber() // 0
$masterTool.fixNullToNumber(null) // 0
$masterTool.fixNullToNumber(undefined) // 0

$masterTool.fixNullToNumber(1) // 1

How to use?

To install
npm i @vlalg-nimbus/master-tool

or

yarn add @vlalg-nimbus/master-tool
To use
import MasterTool from '@vlalg-nimbus/master-tool'

const $masterTool = MasterTool()

$masterTool.funcName()
CDN

Unpkg

https://unpkg.com/@vlalg-nimbus/master-tool/dist/bundle.min.umd.js

License

MIT