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

common-fn-js

v1.1.1

Published

Common methods I use for nodejs projects

Downloads

6

Readme

common-fn-js

A collection of functions I often use in my node.js projects

I was tired of either rewriting this stuff, or keeping track of different files of different versions - so I figured I would group everything into one public place.

File I/O Methods

Method Name | Description | Signature ------------|---------- | ----------- loadFile | Reads file from given filename, returning promise of that file | (STRING, STRING) -> PROMISE(*) loadText | Loads file as text, returning promise of read text | (STRING) -> PROMISE(STRING) loadJSON | Loads file as JSON, returning promise of read JSON | (STRING) -> PROMISE(JSON) writeFile | Write data to given filename using given encoding, returning a promise of the filename if successful | (STRING, *, STRING) -> PROMISE(STRING) writeText | Writes text to given filename, returning promise of filename | (STRING) -> PROMISE(STRING) writeJSON | Write JSON to given filename, returning promise of filename | (STRING) -> PROMISE(STRING) nameOfFile | Returns filename without path or extension | (STRING) -> PROMISE(STRING) readDir | Returns a promise for an array of paths for the given directory filepath | (STRING) -> PROMISE([STRING]) fileStats | Returns promise of file stats for the given filename | (STRING) -> PROMISE(fs.Stats) listFiles | Returns an array of every file in every subdirectory of given directory filtered by optional file extension | (STRING, STRING) -> PROMISE([STRING])

Functional Programming Methods

Method Name | Description | Signature ------------|---------- | ----------- composeAll | Transforms a list of unary functions into a single unary function | ([FUNCTION]) -> FUNCTION flatten | Returns a single array of elements from an array that may contain other arrays | ([[*]]) -> ([*]) assoc | Binds the given property with the given value to the given object | (STRING, *) -> (OBJECT) -> OBJECT rassoc | "Reverse" assoc operation; takes the object before binding identifier to value of given object | (OBJECT) -> (STRING, *) -> OBJECT foldObj | Reduces the given object to the given accumulator using the given function | (OBJECT, (ACC, KEY, VALUE, OBJECT) -> ACC, ACC) -> ACC

CLI Methods

Method Name | Description | Signature ------------|---------- | ----------- VARGS | Return promise of variable number of argument from command line | ([STRING]) -> PROMISE({STRING:STRING}) log | Prints value to console then returns value | (*) -> * err | Prints value to error then returns value | (*) -> * execAsync | Runs shell command, returning promise of result | (STRING) -> PROMISE(STRING)

Time/Date Methods

Method Name | Description | Signature ------------|---------- | ----------- Timer | Finds the amount of time that's elapsed between a "start" DATE object and an "end" DATE object | (DATE, DATE) -> TIMER timeFormat | Namespace for standarized time formatting methods | OBJECT timeFormat.appendZero | Appends 0 to a month less than 10 | STRING -> STRING timeFormat.printDate | Returns date formatted as mm-dd-yy | (DATE) -> STRING timeFormat.printTime | Returns time formatted as hours:minutes:seconds:milliseconds | (DATE) -> STRING timestamp | Prints formatted timestamp as timeFormat.printDate|timeFormat.printTime | (DATE) -> STRING

Parsing Methods

Method Name | Description | Signature ------------|---------- | ----------- parseArray | Recursively applies function to every element of an array, returning a result | [a], (b, a, NUMBER, [a] -> b, b), b -> b parseObj | Recursively applies function to every property of an object, returning a result | {x:y}, (b, y, x, {x:y}) -> b, b -> b