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

picu

v0.3.1

Published

PICU is Carbon's [Node] Utilities

Downloads

7

Readme

PICU Circle CI

PICU is Carbon's [Node] Utilities

Utilities will be added as they are needed.

NPM

npm install picu --save

Arrays

var arrayUtils = require('picu').array;

.inbetween

Injects a new value inbetween each cell

var a = [1, 2, 3];
var b = arrayUtils.inbetween(a, 'x');
// b -> [1, 'x', 2, 'x', 3]

.shuffle

Shuffles an array

var a = [1, 2, 3];
var b = arrayUtils.shuffle(a);
// b -> [3, 1, 2]

Functions

var functionUtils = require('picu').function;

.curry

Creates a new function, based on a target function

var mainFunc = function(a, b, c) {
  return a + '.' + b + '.' + c;
};

mainFunc('x', 'y', 'z'); // 'x.y.z'

var newFunc = functionUtils.curry(mainFunc, 'A', 'O');

newFunc('K'); // 'A.O.K'

.queueUntilReady

Returns a convenient function which will queue all callbacks until some async logic is ready

var resources;

// this function must be `done` before any callback for `getNextResource` will be fired
function getAllResources(done) {
  // assume pullS3Resources will pull a lot of resources from S3, and is therefore slow
  pullS3Resources(function(err, result) {
    resources = result;
    done();
  });
}

// getNextResource will now be a function that takes a callback
var getNextResource = functionUtils.queueUntilReady(getAllResources, function(callback) {
  callback(null, resources.shift());
});

// using it
getNextResource(function(err, resource) {
  console.log(resource);
});

getNextResource(function(err, resource) {
  console.log(resource);
});

// getNextResource can be called before getAllResources is `done`, but callbacks to getNextResource will be queued until getAllResources is `done`
// once getAllResources is `done`, any future call to getNextResource will fire immediately

Strings

var stringUtils = require('picu').string;

.pluralize

Pluralizes a string, based on some input number

stringUtils.pluralize(1, 'dog{s}'); // dog
stringUtils.pluralize(2, 'dog{s}'); // dogs
stringUtils.pluralize(1, 'g{oo|ee}se'); // 'goose'
stringUtils.pluralize(2, 'g{oo|ee}se'); // 'geese'
stringUtils.pluralize('0 g{oo|ee}se'); // '0 geese'
stringUtils.pluralize(2, 'There were {#} dog{s}'); // 'There were 2 dogs'

.capitalize

Simply capitalizes the first letter of a string

stringUtils.capitalize('warren'); // 'Warren'

.pad

Pads (on the right) a string

stringUtils.pad('hello', 10); // 'hello     '
stringUtils.pad('hello', 10, '~'); // 'hello~~~~~'

.replace

Replaces text in a template with passed values

stringUtils.replace('{{valet}} will {{action}} your car', {
  valet: 'Tom M.'
  action: 'pick up'
});
// -> 'Tom M. will pick up your car'

stringUtils.replace('~valet~ will ~action~ your car', {
  valet: 'Tom M.',
  action: 'pick up'
}, /~([^~]+)~/g);
// -> 'Tom M. will pick up your car'

stringUtils.replace('You are assigned to pick up {{ownership(name)}} car', {
  name: 'Jess',
  ownership: function(name) {
    return name.substr(-1) === 's' ? name + '\'' : name + '\'s';
  }
});
// -> 'You are assigned to pick up Jess\' car'

.hexToRgb

Converts a hex color value to an array of [R, G, B]

stringUtils.hexToRgb('ae76fa'); // [ 174, 118, 250 ]

.ensureHexColor

Ensures a color string is a 6 character hash color

stringUtils.ensureHexColor('#f0f0f0'); // -> '#f0f0f0'
stringUtils.ensureHexColor('f0f0f0'); // -> '#f0f0f0'
stringUtils.ensureHexColor('#f0f0f0', true); // -> 'f0f0f0'
stringUtils.ensureHexColor('ba7'); // -> '#bbaa77'

.hexToInt

Converts a hex string to an integer

stringUtils.hexToInt('#f09fa6'); // -> 15769510
stringUtils.hexToInt('#f03'); // -> 16711731

.escapeRegExp

Escapes a string so it can be used in new RegExp(str)

var prepared = stringUtils.escapeRegExp('+2 people. +3 cars');
// prepared = '\\+2 people\\. \\+3 cars'
var expr = new RegExp(prepared);

Numbers

var numberUtils = require('picu').number;

.intToHex

Converts a integer to a hex string

numberUtils.intToHex(15769510); // -> #f09fa6

.random

Gives a random number between a min & max (inclusive) with an optional precision

numberUtils.random(33, 77); // -> 64
numberUtils.random(33, 77); // -> 33
numberUtils.random(33, 77); // -> 70

numberUtils.random(77, 33); // -> 77
numberUtils.random(77, 33); // -> 49
numberUtils.random(77, 33); // -> 51

numberUtils.random(1, 100, 4); // -> 12.8431

Objects

var objectUtils = require('picu').object;

.extend

Given an object, update or add keys on another (deeply)

var result = objectUtils.extend({ a: 12, b: 35 }, { b: 99, z: 404 });
// result = { a: 12, b: 99, z: 404 };
// first object is modified