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

util-pack

v1.0.3

Published

Functions to save you time

Downloads

12

Readme

Installation

Using the npm command

npm i util-pack

Overview

This is a growing library of functions for myself to use when coding other projects, hopefully they can help you too.

Disclaimer

Most of the code used here comes from StackOverflow, some are slightly modified for ease of use

Pull a request in Github if you have any functions that can be added it would be really helpful.

Delay

Note that the freeze() function use a while loop to freeze everything you are running

const util = require('util-pack');

// sleep for 3 seconds then do stuff
var ms = 3000;
util.sleep(ms).then(()=>{
    // do stuff
});

// or use a callback
util.sleep(ms,()=>{
    // do stuff
};

// freeze everything with freeze(ms) (not recommended)
util.freeze(ms);
// do stuff

Objects

The assign() function will modify the original objects

const util = require('util-pack');

var objectToChange = {hello: 'world'};

util.assign(objectToChange, 'test.test1.test2', 'testing');
console.log(objectToChange); // {hello: 'new value',test: {test2: 'testing}}

util.fetch(objectToChange,'test.test1.test2') // -> new value

Logging

When using functions in the category you must create a text file first, like log.txt or it will give you an error

const util = require('util-pack');

// log 'Hello World' to './log.txt'
util.log({
    data: 'Hello World', // the data the log
    path: './log.txt', // the path of the file
    date: true // to include date in the log or not (other choices: false)
});

Better Trim

An enhancement to the default trim() function, works with characters and strings

const util = require('util-pack');

// count number of space in the front of a string
util.countFront('    Hello World ', ' '); // -> 4

// count number of 'rr' in the end of string
util.countEnd('rrr grrrrr', 'rr'); // -> 2

// trim out specified characters or string
util.trim('@Hello@World@@@','@'); // -> 'Hello@World'

Date and Time

Basically the same thing as the Date() thing, but more customizable

If you didn't add the required parameters, it will use the default values

const util = require('util-pack');

// get year (default: {type: 'str', format: 'full'})
util.getYear({
    type: 'num', // other choices: 'str'
    format: 'short' // other choices: 'full'
} // -> 21

// get month (default: {type: 'str', format: 'normal'}
util.getMonth({
    type: 'str', // other choices: 'num'
    format: 'short1' // other choices: 'short2', 'full', 'normal'
} // -> 'Aug'

// 'short1' do 'Sept' and 'short2' do 'Sep'

// get day (default: {type: 'str'})
util.getDay({
    type: 'str' // other choices: 'num'
} // -> '22'

// get hour (default: {type: 'str', format: '24'})
util.getHour({
    type: 'str', // other choices: 'num'
    format: '24' // other choices: '12'
} // -> '03'

// get minute (default: {type: 'str'})
util.getMinute({
    type: 'num'
} // -> 22

// get second (default: {type: 'str'})
util.getSecond({
    type: 'str'
} // -> 22

// get millisecond (default: {type: 'str'})
util.getMs(); // -> '223'