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

jazzy-utility

v1.3.1

Published

A small utility library

Downloads

14

Readme

Jazzy Utility

Build Status Coverage Status Dependencies Version

A small utility library for use with... Well anything really.

Table of contents

  1. Installation
  2. Stash
  3. doAllAsync
  4. doAllCallbacks
  5. drill
  6. deleteArrayElement
  7. randomInt
  8. randomArrayElement
  9. randomArrayElements
  10. extractRandomArrayElements
  11. Workflow
  12. Report Bug

Installation

Installing

npm install 'jazzy-utility'

Importing

Cjs

const jazzy-utility = require('jazzy-utility');
const Stash = jazzy-utility.Stash;

Es Module

import {Stash} from 'jazzy-utility';

Stash

A class that you can place data in and it returns an id as an integer. The data can then be retrieved with the integer. Particularly useful when interacting with external systems where a reference is required to relate a response to a query.

class Stash()

Methods: put(any value) => text id see(text id) => any value take(text id) => any value replace(text id, any value) => void size() => int size isEmpty() => boolean result clear() => void iterate(function forEachFunction(any item)) => void

Usage:

const myStash = new Stash();
const myId = myStash.put('My Message');
console.log(myStash.see(myId)); // output 'My Message'
console.log(myStash.size()); // output 1
myStash.take(myId);
console.log(myStash.isEmpty()); // output true

doAllAsync

function doAllCallbacks(array array, function forEachFunction, function thenFunction) => void

Usage:

const urls = ['www.someurl.com/path', 'www.someurl.com/path', 'www.someurl.com/path'];
const data = new Array(urls.length);

await doAllAsync(urls, async (url, index) => {
  response = await fetch(url);
  if(!response.ok) throw new Error('Request Failed');
  const data[index] = response.text();
});

console.log(data)

doAllCallbacks

function doAllCallbacks(array array, function forEachFunction, function thenFunction) => void

Usage:

const displayDelayedMessage = (delay, message, cb) => {
  setTimeout(() => {
    console.log(message);
    cb();
  }, delay)
}

const messages = [
  {delay: '200', text: 'Message 1'},
  {delay: '150', text: 'Message 2'},
  {delay: '100', text: 'Message 3'}
];

doAll(messages, (message, index, done) => {
  displayDelayedMessage(message.delay, message.text, () => {
    done();
  });
}, () => {
  console.log('Job Complete');
});

drill

function drill(array path, object object) => any result

Usage:

const path = ['some', 'path', 'into', 'some', 'object'];
const obj = { some: { path: { into: { some: { object: 'success' } } } } };
console.log(drill(path, obj)); // output: success

deleteArrayElement

function deleteArrayElement(array array, any value) => boolean result

Usage:

const myArr = ['y', 'e', 'l', 'l', 'o'];
deleteArrayElement(myArr, 'l');
console.log(myArr); // output: ['y', 'e', 'l', 'o']

randomInt

function randomInt(int min, int max) => int result

Usage:

console.log(randomInt(0, 5)); // outputs an integer between 0 and 5 inclusive.

randomArrayElement

function randomArrayElement(array array) => any result

Usage:

const myArr = ['y', 'e', 'l', 'l', 'o'];
console.log(randomArrayElement(myArr)); // outputs a random element from the input array.

randomArrayElements

function randomArrayElements(number multiplier, array array) => array result

Usage:

const myArr = [0, 1, 2, 3, 4];
console.log(randomArrayElements(0.4, myArr)); // outputs an array with two random elements.
console.log(myArr.length) // Outputs 5 as original array is not affected.

extractRandomArrayElements

function extractRandomArrayElements((number multiplier, array array) => array result

Usage:

const myArr = [0, 1, 2, 3, 4];
console.log(extractRandomArrayElements(0.4, myArr)); // outputs an array with two random elements.
console.log(myArr.length) // Outputs 3 as 2 elements have been extracted

Workflow

class Workflow()

A class that allows developers to build and dynamically update workflows. This enables developers to build dynamic flows and add steps at runtime making versatile and easily extendable code.

A work flow is made up of tasks which run sequentially; A task object contains an action which is a function, and optionally you can id for searching and an options object:

{
  action: (data, control) => {
    control.next(data);
  },
  options: {
    skipError: true, // task will be skipped if an error is thrown
    unblock: true, // will run the task at the end of the event queue good for spreading load when running cpu heavy workflows
  },
  id: 'some id'
}

You can just pass the action function instead of the task object if you do not requires ids to search or additional options.

Methods: run(data) => void add(Object action) => int insertedIndex insertAfter(function findFunction, Object action) => int insertedIndex insertBefore(function findFunction, Object action) => int insertedIndex findAndDelete(function findFunction) => int deletedIndex

Usage:

const myTask = (taskID) => (arr, control) => {
  arr.push(taskID);
  control.next(arr);
};

const myWorkflow = new Workflow([
  { action: myTask('b'), id: 'b' },
  { action: myTask('c'), id: 'c' }
]);

myWorkflow.add({
  action: myTask('e'), id: 'e'
});

myWorkflow.insertBefore((el) => el.id === 'b', {
  action: myTask('a'), id: 'a'
});

myWorkflow.insertAfter((el) => el.id === 'c', {
  action: myTask('d'), id: 'd'
});

myWorkflow.add(myTask('f'));

myWorkflow.run([], (arr) => {
  console.log(arr) // output: ['a', 'b', 'c', 'd', 'e', 'f']
});

Issues

If you encounter any issues please report them on the Library's Github.