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 🙏

© 2026 – Pkg Stats / Ryan Hefner

rutil

v0.0.10

Published

Random utilities

Readme

(Deprecated)

These methods will be moved to individual modules that stand on their own.

rutil

A whole bunch of utilities.

Install

Available via Bower

bower install rutil

Available via npm

npm install rutil

Utilities

isObject(obj])

rutil.isObject({}); // true
rutil.isObject([]); // false

isArray(arr)

rutil.isArray([]); // true

merge(obj1, obj2)

var obj1 = {
	foo: 'bar',
	baz: 1234
};

var obj2 = {
	foo: 'qux'
};

var obj3 = rutil.merge(obj1, obj2);

obj3 // {foo: "qux", baz: 1234}

serialize(obj)

var obj = {
	uid: 123,
	t: [
		'foo',
		'bar'
	],
	o: {baz: 'qux'},
	q: 'foo bar'
};

rutil.serialize(obj); // uid=123&t=foo&t=bar&o%5Bbaz%5D=qux&q=foo%20bar

shuffle(arr)

var arr = ['a', 'b', 'c', 'd', 'e', 'f'];

var shuffled = rutil.shuffle(arr);

shuffled // ['c', 'e', 'b', 'd', 'f', 'a']

getParams([url])

// current url: http://example.com/?foo=bar&baz=qux

rutil.getParams(); // {foo: "bar", baz: "qux"}
var url = 'http://example.com/?foo=bar&baz=qux';

rutil.getParms(url) // {foo: "bar", baz: "qux"}

setQueryStringParam(uri, key, val)

var uri = 'http://example.com?foo=bar';

uri = rutil.setQueryStringParam(uri, 'foo', 'qux');

uri // http://example.com?foo=qux

generateUUID()

rutil.generateUUID(); // 049128ed-b16c-4689-90d2-e910860d2797

generateRandomString([length], [str])

rutil.generateRandomString(); // Ne46OxeEbWeDdFSDmwbOq4kfGkoKlMSh

rutil.generateRandomString(16); // mOPJBXXc9MR7nQf8

rutil.generateRandomString(6, '0123456789'); // 388048

random(min, max)

rutil.random(0,9); // 6

hexToRgb(hex)

var hex = '#0077aa';

var rgb = rutil.hexToRgb(hex); // {"r":0,"g":119,"b":170}

rgb.g // 119

getDatesInbetween(dateObj1, dateObj2)

var from = new Date(2013,10,22);
var until = new Date(2013,11,25);

var dates = rutil.getDatesInbetween(from, until);

dates.forEach(function(date) {
  date // obj: Fri Nov 22 2013 00:00:00 GMT-0800 (PST)
});

parseHashtag(str, url)

var string = '#foo #bar';

var linkifiedString = rutil.parseHashtag(string, 'http://twitter.com/search?q={{tag}}');

linkifiedString // <a href="http://twitter.com/search?q=%23foo">#foo</a> <a href="http://twitter.com/search?q=%23bar">#bar</a>

parseUsername(str, url)

var string = '@foo @bar';

var linkifiedString = rutil.parseUsername(string, 'http://twitter.com/{{username}}');

linkifiedString // <a href="http://twitter.com/foo">@foo</a> <a href="http://twitter.com/bar">@bar</a>

parseUrl(str)

var string = 'http://example.com/ http://github.com/';

var linkifiedString = rutil.parseUrl(string);

linkifiedString // <a href="http://example.com/">http://example.com/</a> <a href="http://github.com/">http://github.com/</a>

stripTags(str)

var htmlString = '<p><strong>foo</strong></p>';

var text = rutil.stripTags(htmlString);

text // foo

formatPhone(num)

var phone = 1234567890;

var formattedPhone = rutil.formatPhone(phone);

formattedPhone // (123) 456-7890

isValidEmail(str)

var email = '[email protected]';

rutil.isValidEmail(email); // true

isValidZip(num)

var zip = 12345;

rutil.isValidZip(zip); // true

isValidName(str)

rutil.isValidName('Foo'); // true
rutil.isValidName('Foo*'); // false
rutil.isValidName('Foo1'); // false

isValidUsername(str)

rutil.isValidUsername('foo') // true
rutil.isValidUsername('foo_bar1') // true
rutil.isValidUsername('foo-bar') // false
var zip = '12345-2453';

rutil.isValidZip(zip); // true

isValidMinAge(dateObj, num)

var birthDate = new Date(1998, 02, 20);

rutil.isValidMinAge(birthDate, 18); // true

addCommas(num)

var number = 1234567890.1234;

var numberWithCommas = rutil.addCommas(number);

numberWithCommas // 1,234,567,890.1234

repeat(str, [times])

rutil.repeat('foo'); // foofoo
rutil.repeat('foo', 5); // foofoofoofoofoo

pad(num)

rutil.pad(10); // 10
rutil.pad(9); // 9

capitalize(str, [lowercase])

rutil.capitalize('foo'); // Foo
rutil.capitalize('fooBarQux'); // 'FooBarQux'
rutil.capitalize('fooBarQux', true); // 'Foobarqux'

isMobileDevice([device])

rutil.isMobileDevice(); // bool

rutil.isMobileDevice('ios'); // bool
options: 'iphone', 'ipad', 'ios', 'ios7', 'android', 'blackberry', 'ie', 'opera', 'webos'

createPixel(url)

var url = 'http://example.com/pixel-tracker?id=1234567890';

rutil.createPixel(url); // appends image tag to body

toBool(str)

var string = 'true';

rutil.toBool(string); // true
options: 'true', 'yes', 'on', '1'

sleep(num)

console.log('start sleep');
rutil.sleep(50000);
console.log('This will show after 5 seconds');

More functions

There's a ton more functions that I have not added to this readme yet. You can look at them in the source file or spec test file.

Not documented yet, but can use:

isTruthy
isFalsy
isFunction
functor
preCondition
addEvent
prop
textNode
wrap
append
hasClass
addClass
removeclass
flatten
sum
int
string
compactobject
isEmpty
forOwn
isExisty
isString
isNumber
isBoolean
noop
setAttributes
isValidCoordinate
nth
isIndexed
appendStylesheet
isDateInRange
htmlContents
elementById
remove
createElement
anchor
image
appendScript
pred
comparator
doWhen
result
executeIfHasField
average
reduce
map
filter
size
some
every
identity
complement
toArray
first
rest
last
seperatewords
titleCase
cat
construct
mapcat
butLast

Extend _

To extend the _ when using libraries such as underscore or lodash, pass in rutil._() to the underscore mixin function. Rutil functions will not override underscore functions if they already exist, unless you pass rutil._(true)

_.mixin(rutil._()); // extend underscore

_.isValidEmail('[email protected]'); // use rutil function

Note that you can also use the _u global object instead of rutil.

Test

Using Jasmine for testing

grunt test

Build

grunt build

License

Released under the MIT License.