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

@freik/node-utils

v1.6.7

Published

My personal set of utilities for NodeJS

Downloads

123

Readme

node-utils

A set of utilities I use when doing silly stuff in nodejs.

Some of it is completely outdated and unused, but some of it is used by things I'm trying to expose for the music player.

Someday, I'll add some tests for this stuff...

AppConfig

This is a simplistic API for getting and saving 'configuration' data as simple JSON files. It provies synchronous & asynchronous api's to get configuration data (load from a file), and set configuration data (write to a file), as well as a function to get the path to the file for a given piece of data.

For my own silliness of naming, everything comes in lots of names, but they are all completely interchangeable:

// aliases: GetSync, Read, ReadSync, Load, and LoadSync
function Get(name:string) => unknown | void;
// aliases: ReadAsync, LoadAsync
function GetAsync(name:string) => Promise<unknown | void>;

Given a string name, return an optional data type, or a promise containing that (for the Async version).

// aliases: SetSync, Write, WriteSync, Save, SaveSync
function Set(name: string, data: unknown) => void;
// aliases: SaveAsync, WriteAsync
function SetAsync(name: string, data: unknown) => Promise<void>;

Given a string name and an unknown type, saves that value for future Getting.

OpenLocalBrowser

This takes a string URL and tries to open a browser to that location. It currently only works on MacOS and Windows, because I have no idea how to do this on Linux, and only have a Raspberry Pi to do anything that's actually linux (I use WSL for a lovely Ubuntu-ish command line on Windows, but that's not the same thing...)

FileUtil

A few helpful functions:

function size(filePath:string) => number;
function sizeAsync(filePath:string) => Promise<number>;

Return the file size for the string path provided.

function arrayToTextFile(arr:Array<string>, filePath:string) => void;
function arrayToTextFileAsync(arr:Array<string>, filePath:string) => Promise<void>;

Writes the array of strings to the file provided, separated by newlines apropriate for the platform you're on (LF's or CRLF's).

function textFileToArray(filePath:string) => Array<string>;
function textFileToArrayAsync(filePath:string) => Promise<Array<string>>;

Reads the filePath provided and returns the array of lines of text from the file.

PathUtil

A couple helpers for path name creation & manipulation:

function getTemp(name:string, ext:?string) => string;

Given a name, and an optional file extension, return a likely unique path to use as a temp file.

function getExtNoDot(fileName:string) => string;

Returns the file extension of fileName without a leading '.' because that's annoying...

function changeExt(fileName:string, newExt:string) => string;

Switches the file extension to newExt for the path fileName.

ProcUtil

3 helpers for spawning processes.

// Exported from the node-freik-utils module
type spawnResult = {
  output: Array<string>,   // Array of results from stdio output.
  stdout: Buffer | string, // The contents of output[1].
  stderr: Buffer | string, // The contents of output[2].
  signal: string | null,   // The signal that terminated the output
  status: number | null,   // The exit code of the subprocess or
                           // null if the subprocess terminated due to a signal.
  error?: Object           // The error
};

// sO == child_process$spawnOpts
// sSO == child_process$spawnSyncOpts
function spawnAsync(command:string, args: ?Array<string>, options:?sO) => Promise<spawnResult>;
function spawnRes(command:string, args: ?Array<string>, options:?sSO) => boolean;
function spawnResAsync(command:string, args:?Array<string>, options:?sO) => Promise<boolean>;

These three helpers wrap process spawning from node.child_process in self-contained blobs. I'm clearly getting sick of writing documentation...