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

nano-module

v2019.3.1

Published

Dynamic package manager for javascript applications

Downloads

5

Readme

npm-nano-module

Dynamic package manager for javascript applications

Sometimes you only need a small part of logic that a module provides. Nano modules are just that - modules that only do just about one thing. Like really small modules, a single function (aka method) to be exact.

You can think of each function as a 'mini-package', and nano-module as an additional vitamin supplement to familiar package managers like npm / yarn.

Example:

Say that you need a function to add two numbers together, but you are not interested in the 20 other things a math package might bring with it. Nor the other 12 packages it will bring to the party.

You find the code you need in https://example.com/url/math/addition-1992.js

// a single arrow function
(x, y) => x + y

Your app could import just that spot of logic:

// require nano-module
const ff = require('nano-module')

// url (or local file path) to our dependency
let path = 'https://example.com/url/math/addition-1992.js'

// fetch the function and run it locally
ff(path)(2,5).then((add_result) => console.log(`2 plus 5 equals ${add_result)}`))

Outputs:

2 plus 5 equals 7

A little more

The remote function could be more interesting. Fetched functions can also use nano-module, aliased as ff (fetch function) themselves to retrieve other functions, and those nested functions can do the same etc.. to build an entire dependency tree required to do complex tasks. Or, an entire program can built with nano-modules if you like.

Background

Dependencies often entail breaking changes. Often, especially for small pieces of code, developers prefer to copy or re-invent the wheel to avoid this dependency problem all togehter.

How many megabytes of dependencies does a project have ~ and do you really need to download all the code, even if you only run a subset ?

Semantic versioning makes dependency management a little easier with this convention: _._.x will probably not be a breaking change _.x._ also won't be a breaking change, pinky promise ;) x._._ okay changes will possibly break your code, oops!

However the version number only reflects the interactions with a module/package. Sometimes. The behaviour changes from version to version, and a 0.0.x bump could still be a breaking change anyway.

What we want is to re-use shared code, without pushing breaking changes to unknown consumers, and signal updates that people can opt into. (ex. security, bugfixes and performance improvements) This project is a step in that direction.

Next steps

Function-level dependency resolution, especially dynamically, provides it's own set of challenges and concerns to use over a traditional package manager (ex. npm, yarn).

I suspect the dynamic resolution bit will have to be optional (mainly for security & reliability reasons), and to rather/also create a build tool.

Just as any central repository (Github <3, brew.sh, etc..) can evaporate, that problem is exemplified by having thousands of url based dependencies. Instead of creating yet another package manager central, it would be better to have a p2p-mesh network for sharing code.

Thoughts arount that project:

  • Function identifiers could be a hash of the function, signed by the publisher on a shared ledger.
  • A mechanism to enable the mesh to additionaly share optimized javascript, python, and eventually compiled language components.
  • Who knows, maybe pure functions could be memoized globally..