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

zshared

v1.0.11

Published

useful common javascript/typescript utilities I collected over the years

Downloads

3

Readme

zshared

Useful javascript/typescript utilities collected over the years. The utilities relate to handling arrays, objects, strings, time, etc. It can be used on browser/node/deno, it has 0 dependencies and is optimized for performance.

Installation

npm install zshared

The library can be consumed by using either 'require' or 'import' syntax. The libraray is devided to classes, each handles its own area (arrays, strings, etc). Each class name begins with 'Z' and the area (ZArray, ZString, etc).

import { ZTime, ZArray } from 'zshared';

Some examples

Below are some examples, the complete list can be found in the docs. All class functions are static.

Time

await ZTime.sleep(1000);  // wait 1 second

get local/utc time in universal format, local time zone GMT+3

ZTime.utcUniDateTime();     // returns '2020-04-29 17:29:20'
ZTime.localUniDateTime();   // returns '2020-04-29 20:29:20'

convert seconds to display time (hh:mm:ss)

ZTime.seconds2UniTime(3500) // returns '33:20'

Objects

const obj1 = { a: 1, b: 2, c: 3 };
ZObj.clone(obj1);  // returns shallow copy { a: 1, b: 2, c: 3 };
ZObj.clone(obj1, ['a', 'c']);  // pass keys array, returns: { a: 1, c: 3 };
ZObj.areEquals(obj1, { a: 1, b: 2 });  // returns false
ZObj.areEquals(obj1, { a: 1, b: 2, c: 3 });  // returns true

Arrays

items = ['a', 'b', 'a', 'c'];
ZArray.distincts(items);  // returns ['a', 'b', 'c'];
ZArray.deleteItem(items, 'b');  // items is now ['a', 'a', 'c'];
items = ['a', 'b', 'c'];
ZArray.toObj(items);  // returns { a: 'a', b: 'b', c: 'c' };
ZArray.toObj(items, item => '_' + item);  // pass a function, returns { a: '_a', b: '_b', c: '_c' };

convert items array to objects

items = [{ a: 1 }, { b: 2 }]; 
ZArray.toObj(items);  // returns { a: 1, b: 2 };
ZArray.toObj(items, (key, value) => value * 2);  // pass a function, returns { a: 2, b: 4 };

Numbers

ZNumber.thousandsSep(12345);  // returns 12,345 or 12.345, depends on locale

Strings

const str = '2 cats met another cat';
ZString.replaceAll(str, 'cat', 'dog');   // returns '2 dogs met another dog'
ZString.occurrences(str, 'cat');         // returns 2
ZString.initialCapital('good morning');  // returns 'Good morning'
ZString.replaceParams('I say {0} {1} and {0}', 'bla', 'gla);  // returns 'I say bla gla and bla'

logt

the libraray contains also a static function 'logt', it acts like console.log() with a time prefix

logt('some message', 1200, 'another message');  // output: 2020-04-29 23:39:12.397 ==> some message 1200 another message