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

@vimlet/commons

v2.7.25

Published

Provide utilities for common tasks such as, file compression, file download, OS integration, exec, etc

Downloads

164

Readme

Provides a cross environment standardized API for common used functions.

This module is a constant effort of improvement to achieve a stable and flexible, free open-source solution, for common case developing needs.

Currently supporting:

  • OS
  • Run
  • Request
  • Compress
  • Util
  • Progress

You can access the source code at vimlet/commons

Instalation:

  • Via NPM: npm install @vimlet/commons

Basic usage:

const commons = require("@vimlet/commons");

var src = require("path").join(__dirname, "resources/compress/pack");
var dst = require("path").join(__dirname, "resources/compress/file.zip");

commons.compress.pack(src, dst, "zip", null, function(error) {
    if(error) {
        console.log("Fail");
    } else {
        console.log("Success");
    }
});

Compress

compress.pack(file, dest, options, doneHandler)

Compress.

  • file: Source file or directory.
  • dest: Destination file.
  • options:
  1. packHandler: Progression callback. function(error, entry, entrySize, totalSize, totalCount).
  2. outputHandler: Default output callback function(out), redirects stdout when provided.
  3. format: Compression format (zip, tar, tgz).
  • doneHandler: Default done callback function(error, data).

compress.unpack(file, dest, options, doneHandler)

Uncompress.

  • file: Source file or directory.
  • dest: Destination folder.
  • options:
  1. unpackHandler: Progression callback. function(error, entry, entrySize, totalSize, totalCount).
  2. outputHandler: Default output callback function(out), redirects stdout when provided.
  3. format: Compression format (zip, tar, tgz).
  • doneHandler: Default done callback function(error, data).

Copy

copy.copy(include, output, options, callback);

Copy files in given pattern.

  • include: Directory to look for files.
  • output: Directory where files will be written.
  • options:
  1. exclude: Used to skip files that you don't want to copy.
  2. clean: Empty output directory before copy.
  • callback.

copy.watch(include, output, options);

Watch for file changes in given pattern. Watch for file changes in given pattern.

  • include: Directory to look for files.
  • output: Directory where files will be written.
  • options:
  1. exclude: Used to skip files that you don't want to copy.
  2. clean: Empty output directory before copy.

Io

io.getFiles(dir, options)

Get files from directory. Return an array of objects like:

{
    root: "Root path",
    files: "Array with paths to files"
}
  • dir: Array of patterns to search or single pattern.
  • options:
  1. exclude: patterns to exclude from search.
  2. ignoreExtension: ignore file extensions.

io.absoluteFiles(index)

Get files from index object. Return an array of absolute paths.

  • index: Object with root and relative paths.

io.getRootFromPattern(pattern)

Get root folder from a given pattern.

io.isDirectory(path)

Return true if path is a path to a directory, false if it is a path to a file.

io.getFileSize(path)

Return the size of the file in bytes.

io.deleteFolderRecursive(folderPath, callback) io.deleteFolderRecursiveSync(folderPath)

Delete a folder and all its content.

io.isInPattern(filePath, pattern, options)

Return true if given file belongs to given pattern. False if not.

  • options:
  1. exlude: files to exclude from search.

io.writeToDisk(output, data, callback)

Write data to disk.

  • output: Path to write the file.
  • data: Data to write.

io.getCommonBasePath(paths)

Return a path that all given paths have in common.

  • paths: String with multiple paths to compare.

Os

os.isWindows()

os.isLinux()

os.isMac()

os.is64Bit()

os.getUnixUserProfile()

os.setUserEnvironmentVariable(key, value, callback)

Sets environment variables without admin privileges.

  • key: Enviroment variable key.
  • value: Enviroment variable value.
  • callback

os.addToUserPath(value, callback)

Sets path variables without admin privileges.

  • value: Path value to append.
  • callback

os.killProcessByName(name, options, callback)

Kill a process by its name.

  • name: Name of the process to be killed.
  • options:
  1. execHandler: Default output callback function(out), redirects stdout when provided.
  • callback

os.createSymlink(dest, src, options, callback)

Creates a symbolic link without admin privileges.

  • dest: Symlink destination path.
  • src: Symlink source path.
  • options:
  1. execHandler: Default output callback function(out), redirects stdout when provided.
  • callback

os.findExec(binary, callback)

Asserts if a command is accessible from the command line.

  • binary: Symlink destination path.
  • callback

Progress

progress.paintProgress(value, outputHandler)

Prints progress at a given percent.

  • value: Progress percent.
  • outputHandler: Default output callback function(out), redirects stdout when provided.

progress.showProgress(value, options, outputHandler)

Prints progress percent by value and total and returns the percent.

  • value: Current progress value.
  • options:
  1. paintProgress: Function that actually does the painting.
  2. total: Total progress value.
  • outputHandler: Default output callback function(out), redirects stdout when provided.

progress.progressHandler(total, max, options, mainOutputHandler)

Handle progress painting avoiding duplicated output of the same progress.

  • total: Total percent value.
  • max:Provide a virtual limit that avoids printing over this value.
  • options:
  1. paintProgress: Function that actually does the painting.
  • mainOutputHandler: Default output callback function(out), redirects stdout when provided.

Request

request.download(url, dest, options, doneHandler)

Downloads a file.

  • url: The URL source to download.
  • dest: he place where the downloaded file will be stored.
  • options:
  1. downloadHandler: A progress callback function(received, total, statusCode).
  2. outputHandler: Default output callback function(out), redirects stdout when provided.
  • doneHandler: Default done callback function(error, status).

Run

run.exec(command, options, doneHandler)

Runs a file or command and streams its output.

  • command: File or command to be executed.
  • options:
  1. execHandler: Default output callback function(out, error), redirects stdout when provided.
  2. args: Executable arguments(string[]).
  3. workingDirectory: The path from where the executable will run.
  • doneHandler: Default done callback function(error, exitCode).

run.fetch(command, options, doneHandler)

Runs a file or command and buffers its output.

  • command: File or command to be executed.
  • options:
  1. args: Executable arguments(string[]).
  2. workingDirectory: The path from where the executable will run.
  • doneHandler: Default done callback function(error, exitCode).

License

This project is under MIT License. See LICENSE for details.