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
Some examples
Below are some examples, the complete list can be found in the docs.
All class functions are static.
Time
await ZTime.sleep; // wait 1 second
get local/utc time in universal format, local time zone GMT+3
// returns '2020-04-29 17:29:20' // returns '2020-04-29 20:29:20'
convert seconds to display time (hh:mm:ss)
ZTime.seconds2UniTime // returns '33:20'
Objects
const obj1 =
ZObj.areEquals
Arrays
items = ['a', 'b', 'a', 'c'];ZArray.distincts; // returns ['a', 'b', 'c'];ZArray.deleteItem; // items is now ['a', 'a', 'c'];
items = ['a', 'b', 'c'];ZArray.toObj; // returns
convert items array to objects
items = [{ a: 1 },
Numbers
ZNumber.thousandsSep; // returns 12,345 or 12.345, depends on locale
Strings
const str = '2 cats met another cat';ZString.replaceAll; // returns '2 dogs met another dog'ZString.occurrences; // returns 2ZString.initialCapital; // returns 'Good morning'ZString.replaceParams
logt
the libraray contains also a static function 'logt', it acts like console.log() with a time prefix
logt; // output: 2020-04-29 23:39:12.397 ==> some message 1200 another message