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

dev-tips

v1.0.3

Published

This class has small useful functions which you can use on daily bases

Downloads

6

Readme

dev-tips

This is a class with common used functions to simplify developers life. You can use it to improving your workflow on daily based.

Installation

npm install dev-tips --save

Module

import DevTips from 'dev-tips';
const _dt = new DevTips();

Usage

You can use this tiny library for working with array/objects. As a bonus, there is debounce functions inside whiche you can use instead of 'lodash'.

getUnique

This method removes all repeated values and return an array of unique values.

@param array {Array} - array of elements

@return {Array} - new array of unique values

let array = ['t', 1, 3, 4, 1, 'e', 4, 'e', 4, 5];
let result = _dt.getUnique(array);
// => Output:
// ["t", 3, 5]

indexOfAll

This method find all indexes of value in array and return new array with indexes.

@param array {Array} - array of elements

@param value {String/Number/Boolean} - value which index you want to find elements

@return {Array} - new array of indexes

let array = ['t', 1, 3, 4, 1, 'e', 4, 'e', 4, 5];
let result = _dt.indexOfAll(array, 4);
// => Output:
// [3, 6, 8]

removeRepeated

This method removes all repeated values in array and return new array of values without values without settled in function. You can specify any amount of items even if they do not exist.

@param array {Array} - array of elements

@param ...item {String/Number/Boolean} [default = []] - elements which you want to delete

@return {Array} - new array wihout specified values

let array = ['t', 1, 3, 4, 1, 'e', 4, 'e', 4, 5];
let result = _dt.removeRepeated(array, 1, 99, 'e');
// => Output:
// ["t", 3, 4, 4, 4, 5]

removeDoubles

This method finds and removes all duplicate values leaving them in a single instance.

@param array {Array} - array of elements

@return {Array} - new array wihout duplicate values

let array = ['t', 1, 3, 4, 1, 'e', 4, 'e', 4, 5];
let result = _dt.removeDoubles(array);
// => Output:
// ["t", 1, 3, 4, "e", 5]

isEmpty

Method check if Array/Object id empty. If empty it will return true, else false.

@params element {Array/Object} [default = null] - your element

@return {Boolean} - true if empty, false if not

console.log(_dt.isEmpty({})); // => Output: true
console.log(_dt.isEmpty({a: 'test'})); // => Output: false
console.log(_dt.isEmpty([])); // => Output: true
console.log(_dt.isEmpty(['ttt', '777'])); // => Output: false
console.log(_dt.isEmpty(new Array())); // => Output: true
console.log(_dt.isEmpty(new Array('333'))); // => Output: false
console.log(_dt.isEmpty(new Object())); // => Output: true
console.log(_dt.isEmpty(new Object({bar: 'foo'}))); // => Output: false
console.log(_dt.isEmpty(function(){return 'Hello world!'})); // => Output: true

filterBy

Method filter array by object query or callback function. If Object is empty or not an Object/Function, method will return user's array.

If specified object query[1], array will be filtered without deep search. But you can specify function[2] for deep search.

@params array {Array} [default = []] - array of Objects

@params cb {Object/Function} [default = {}] - object/function of queries

@return {Array} - filtered by query array

let array = [
    { name: 'Peter', role: 'member', age: 18,gender: 'male', salary: {gross: 100, amount: 79} },
    { name: 'Julia', role: 'member', age: 23,gender: 'female', salary: {gross: 101, amount: 79} },
    { name: 'Ann', role: 'member', age: 28,gender: 'female', salary: {gross: 100, amount: 99} },
    { name: 'Nordy', role: 'annonym', age: 23,gender: 'female', salary: {gross: 250, amount: 197} },
    { name: 'Sam', role: 'member', age: 19,gender: 'male', salary: {gross: 251, amount: 197} },
    { name: 'Eve', role: 'annonym', age: 42,gender: 'female', salary: {gross: 100, amount: 80} }
];
let result1 = _dt.filterBy(array, { role: 'member', gender: 'female'});
let result2 = _dt.filterBy(array, (el) => {
  return el.role === 'member' && el.salary.gross >= 101
});
// => [1]: [
//      {name: "Putin2", role: "member", gender: "female"}
//      {name: "Putin3", role: "member", gender: "female"}
//    ]
// => [2]: [
//      {name: "Putin2", role: "member", gender: "female"}
//      {name: "Putin3", role: "member", gender: "female"}
//    ]

countBy

Method count array of object by key:value pair or function query. If object is empty, function will return array.length.

You can specify either Object query [1] or function query[2] for deep search.

@params array {Array} [default = []] - array of Objects

@params cb {Object/Function} [default = {}] - object/function of queries

@return {Array} - filtered by query array

let array = [
    { name: 'Peter', role: 'member', age: 18,gender: 'male', salary: {gross: 100, amount: 79} },
    { name: 'Julia', role: 'member', age: 23,gender: 'female', salary: {gross: 101, amount: 79} },
    { name: 'Ann', role: 'member', age: 28,gender: 'female', salary: {gross: 100, amount: 99} },
    { name: 'Nordy', role: 'annonym', age: 23,gender: 'female', salary: {gross: 250, amount: 197} },
    { name: 'Sam', role: 'member', age: 19,gender: 'male', salary: {gross: 251, amount: 197} },
    { name: 'Eve', role: 'annonym', age: 42,gender: 'female', salary: {gross: 100, amount: 80} }
];
let result1 = _dt.countBy(array, { role: 'member', gender: 'female'});
let result2 = _dt.countBy(array, (el) => {
  return el.role === 'member' && el.salary.gross >= 101
});
// => [1]: 2
// => [2]: 2

debounce*

Method debounce delay function {func} execution for a specified time {wait} in milliseconds once. If you want to execute function emergency, you should set this {immediate} params.

@params func {Function} - callback function

@params wait {Number} [default = 0] - waiting time in milliseconds

@params immediate {Boolean} [default = false] - should call function emergency

@return {Function} - callback

function checkResize(){
    _dt.debounce(() => {
        console.log('Window resized');
    }, 1500);
}

window.addEventListener('resize', checkResize)

*debounce wiil hold function execution until you stop, for this example, resizing window. After 1.5 seconds you will see in your console 'Window resized'.