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

z-util

v3.0.1

Published

A collection of libraries and pretty much anything else I feel like writing.

Downloads

1

Readme

pipeline status

Z-util

Z-util is a collection of libraries and pretty much anything else I feel like writing, it's mostly going to be small things such as simplifying things like interpreting environment info.

All of these libraries can be used by using:

const {DB, is, strore} = require('z-util')

Install

npm install --save z-util

zDB

zDB is essentially a small database that can export and import JSON.

Usage

Initialisation

zDB is a class and as such it needs to be initialised, it can be initialised with a settings object to change the behaviour.

const zDB = new DB({
  saveOnTransaction: true,
  importOnInit: false,
  importOnInitCallback: () => {},
  exportOverwrite: true,
  filePath: resolve('.', 'zDB.json')
})

The settings above are the defaults.

Settings

saveOnTransaction

This is a true/false value. If true then zDB.export will be called after an insert or delete.

importOnInit

This is a true/false value. If true then on initialisation it will look for a JSON file at 'filePath' and import it.

importOnInitCallback

This is a function. This is the callback that is passed to import after initialisation.

exportOverwrite

This it a true/false value. If true than an existing file at 'filePath' will be overwritten, it false then it will be read, and added to the data being exported.

filePath

This is the file that import will read and export will write. It can be changed later by:

zDB.settings.filePath = '/dbPath/zDB.json'

addTable

zDB.addTable('newTable')

Creates a table to be used as a 'where' parameter.

Insert

zDB.insert({
  key, value
}, where)

zDB.insert(key, value)

'where' is the table it will go into, if where is not defined, it goes into a table called 'default'.

Get

const data = zDB.get(key)
const data = zDB.get(key, where)

No explanation really needed, especially if you read insert.

Export

zDB.export()

Exports in JSON to zDB.settings.filePath. Returns a promise.

Import

zDB.import(cb)

Imports JSON from zDB.settings.filePath. Returns a promise.

is

zUtils.is({
  OS: 'Darwin',
  Arch: 'x64',
  Node: '9.2.0'
})

Checks process and returns an object, for example the above call when run on a Mac with Node version 8 would return:

{
  OS: true,
  Arch: true,
  Node: false
}

store

const localStore = new store.NewInstance() //Creates a local instance of store
store.globalStore.set('key', 'value') //Stores key/value in the global store

Store is what is behind zDB, it exports a class and a function, see above.

To get the stored value:

store.globalStore.get('key')

npm

Currently the npm part of this module can only search and requires an API key. You can get the API key from https://libraries.io/api.

search

npm.search('z-util', apiKey) //apiKey only needs to be set once as it is cached

isConnected

I wrote isConnected so that I could run my tests on the bus without getting errors from the npm test. It simply sends an http request to google, if the status code is 200 or 302 it resolves, otherwise it rejects. It returns a promise.

isConnected()
  .then(statusCode => {})
  .catch(err => {})

array

I wrote array because I was bored and thought it could be useful.

contains

if (array.contains(arr, valueToCheckFor)) {}

Returns true if the value is found as an element in the array, currently does not search below the first level of elements. Returns false if it doesn't return true.

flatten

const toFlatten = [
  'hi',
  {key, 'value'},
  ['hi', 'again']
]

const flattenedNoObjs = flatten(toFlatten)
flattenedNoObjs === [
  'hi',
  {key, 'value'},
  'hi',
  'again'
]

const flattenedObjs = flatten(toFlatten, true)
flattenedObjs === [
  'hi',
  'value',
  'hi',
  'again'
]

This flattens arrays and can extract the values out of objects as well. Goes as many levels deep as node's memory stack allows.