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

starter-kit-utils

v0.0.3

Published

Simpler API + 1 dependency for common create- prompt q's

Downloads

7

Readme

Starter Kit Utils

Simpler API and only one dependency for common create- style packages and starter kits' prompt q's.

Documentation

checkPath

This function checks if something is on the path, like which. It takes three arguments, name, a string, the name of the thing to look for, envPath, a string, variable to use instead of process.env, insensitive, a boolean, should the path check be insensitive.

If the third argument, insensitive is not given, it is set to whether we are on windows.

Example:

var { checkPath } = require('starter-kit-utils');
checkPath('node').then(console.log.bind(console)); // '/usr/local/bin/node'

checkManagers

This function will check if any of the files in the directories in the environment PATH variable insensitively match npm or yarn, or their Windows variants, npm.exe or yarn.exe.

It takes no arguments, and returns an object with two properties: { yarn: Boolean, npm: Boolean }.

Example:

var { checkManagers } = require('starter-kit-utils');
checkManagers().then(console.log.bind(console));
// { npm: '/usr/local/bin/npm', yarn: '/home/toor/.yarn/bin/yarn' }

getAuthorInfo

This function will try to find remotes in the local git configuration and user's name and email from the global configuration. This populates the author and repository fields.

Example:

var { getAuthorInfo } = require('starter-kit-utils');
getAuthorInfo().then(console.log.bind(console));
// { author: 'David Ankin <[email protected]>' }

updateJSON

This is the equivalent of doing something like
Object.assign({}, { new: data }); but on a physical file. This function takes first argument the file path, and the rest of the arguments are passed to Object#assign.

Example:

$ echo '{"a":5}' > file.json
$ node
> var { updateJSON } = require('starter-kit-utils');
> JSON.parse(fs.readFileSync('file.json', 'utf8'));
// { a: 5 }
> updateJSON('file.json', { a: undefined, b: 5, c: [ 5 ]})
.then(console.log.bind(console));
// { a: undefined, b: 5, c: [ 5 ] }
$ cat file.json
// {b:5,c:[5]}

addDeps

This function will take the dependencies in the getDeps format and put them into a manifest, taking arguments, object, deps, dev or not.

Example:

var { addDeps } = require('starter-kit-utils');
var a = {};
addDeps(a, [ { name: 'dotenv', version: '1.0.0' } ], true);
console.log(a); // { devDpendencies: { dotenv: '1.0.0' } }

a = {};
addDeps(a, [ { name: 'dotenv', version: '1.0.0' } ]);
console.log(a); // { dependencies: { dotenv: '1.0.0' } }

getDeps

This function will actually query the npm repository via pacote, as follows:

async function getDeps(deps) {
  return await Promise.all(deps.map(async dep => {
    return {
      name: dep,
      version: (await pacote.manifest(dep)).version
    };
  }));
}

For example:

var { getDeps } = require('starter-kit-utils');
getDeps(['dotenv', 'express']).then(console.log.bind(console));
// [ { name: 'dotenv', version: '8.2.0' },
//   { name: 'express', version: '4.17.1' } ]

renderFolder

Takes a folder with ejs templates and renders them with locals. Takes three arguments, from, to, and locals.

It will create the directories in the destination like mkdir -p.

It looks like this:

async function renderFolder(templateDir, destDir, locals) {
  var l = await generateCopyList(templateDir);
  var d = path.join.bind(path, destDir), n = path.dirname.bind(path);
  await Promise.all(l.map(f => mkdirp(n(d(f.relativeTo)))));
  await Promise.all(l.map(f => renderFile(f.from, d(f.relativeTo), locals)));
}

TODO, add example tests with broken symlinks

Utility Functions

The ones based on the fs module are to avoid the warnings when using require('fs').promise.

|Name|Args|Description| |-|-|-| |copyFile|...args|Returns a promise for the results of passing the ...args to fs.copyFile| |readdir|string path|Returns a promise for the results of fs.readdir| |readFile|...args|Returns a promise for the results of passing the ...args to fs.readFile| |writeFile|...args|Returns a promise for the results of passing the ...args to fs.writeFile| |unlink|...args|Returns a promise for the results of passing the ...args to fs.unlink| |exists|string path|Returns a promise for true of fs.access does not error| |stat|...args|Returns a promise for the results of passing the ...args to fs.stat|