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

u

v0.1.0

Published

A minimalist, functional utility library designed for embedding into another small program.

Downloads

1,642

Readme

u.js — minimalist utilities

u.js is a minimalist, functional utility library designed for embedding into another small program.

  • Collection utilities that work on both Arrays and Objects (reduce, map)
  • Copying/extending Objects
  • Binding function scope
  • Serializing and deserializing query-string KV pairs
  • Optional polyfills in future.js for the most important JS features missing from older browsers (e.g., Array.map(), Object.keys())

That's it.1 u.js has no dependencies and works in any browser. The code has seen extensive production use, but the tests were part of a bigger project and have not yet been ported.

Why?

u.js is ideal for building a bootstrapper. Several of my projects have been embeddable tools. When your code is going to run in hostile territory, versioning is especially important, but it requires some way to get your versioned code on the page in the first place: a bootstrapper.

A tiny bootstrapper gives your users the flexibility to choose a version, but gives you the power to smooth over implementation assumptions (like changing configuration parameters, embedding-code, or the inevitable bug pasted onto someone's page). So I needed something tiny primarily to parse querystring values and work with collections. It had to come prior to the main program, as the program version could be overriden by configuration!

API

u.reduce(o, fn, [acc], [cxt=o])

As Array.prototype.reduce(), but for both Object and Arrays.

Invokes acc = fn.call(cxt, acc, v, k, o) for each value in the collection, returning the final value of the accumulator. For Arrays, k will be the index.

u.map(o, fn, cxt=o)

As Array.prototype.map(), but for both Object and Arrays.

Invokes fn.call(cxt, v, k, o) for each value in the collection, returning a new collection with the mapped values. (The collection will be an Object or Array based on the type of the input collection.)

u.extend(target, ...donors) -> target

Copies all keys from each donor onto the target object, and then returns it.

u.bind(fn, context, ...args) -> Function

Stub for Function.prototype.bind(): returns a function (...more_args) that when invoked, calls the original function with the supplied context and arguments from both invocations concatenated together:

fn.apply( context, args.concat(more_args) )

u.isArray(o) -> Boolean

Returns whether the input object is an Array; calls Array.isArray(o) if it exists, and a polyfill otherwise.

u.trim(s) -> String

Returns the string with leading and trailing whitespace removed.

u.toKV(o, delimiter='&') -> String

Serializes an object into a string of "form-encoded" key-value pairs, applying one layer of URL-encoding.

u.fromKV(q, delimiter='&') -> Object

Deserializes "form-encoded" key-value pairs (removing one layer of URL-encoding), and returning an object of their values. Note that repeated values in the serialized string will clobber each other.

u.setCookie(k, v, [expires, [path, [domain, [doc]]]]) -> Object

Sets a cookie, returning an updated map from cookie key to value.

By default, the cookie will be set for all paths on the current domain using the current document, expiring on a distant date:

  • expires: 'Sun, 24-Mar-2024 11:11:11 GMT'
  • path: '/'
  • domain: doc.domain
  • doc: window.document

Feedback

Open a ticket at github, or send me email.

[1]: u.js does not provide any DOM manipulation; check out Zepto.js if you need to fiddle with DOM elements.