• Public
  • Public/Protected
  • All


Node utility library.

npm version CircleCI codecov Patreon ko-fi


zeelib is a collection of utility functions. Think Lodash, but for Node. See the docs for details.

Example usage:

import * as z from 'zeelib'

if (!module.parent) {
  z.termPrompt('do the thing?')
    .then((yes) => {
      if (yes) {
        console.log(z.colorize.blue('said yes!'))

If you're using Node require, you'll need to access default:

const zeelib = require('zeelib')



Type aliases


NodeError: object & Error


Res: object

Type declaration

  • address: string
  • family: number



SEPARATOR: ";" | ":" = process.platform === 'win32' ? ';' : ':'

Const env

env: ProcessEnv = (typeof process !== 'undefined' && process.env) || {}

Const file

file: WriteStream = createWriteStream(`${__dirname}/${fn}`, { flags: 'w' })

Const fn

fn: string = process.argv[2] || process.env.ERR_FILE || 'err.log'


Const atob

  • atob(str: string): string
  • window.atob for node and browser


    • str: string

    Returns string

Const average

  • average(xs: number[]): number

Const btoa

  • btoa(str: string): string
  • window.btoa for node and browser


    • str: string

    Returns string

Const colorize

  • colorize(): __type

Const cols

  • cols(color: string, text: string): string
  • Basic set of fns to add colors to console output in Node.


    bold, italic, underline, inverse, white, grey, black, blue, cyan, green, magenta, red, yellow


    • color: string
    • text: string

    Returns string

Const consoleClear

  • consoleClear(): void

Const dir

  • dir(obj: any): void
  • console.dir with colors by default in Node


    • obj: any

    Returns void

Const execute

  • execute(cmd: string): void
  • Like a standalone npm run that obeys npm bin


    • cmd: string

    Returns void

Const fileExists

  • fileExists(filePath: string): boolean
  • Returns bool based on if passed path exists


    • filePath: string

    Returns boolean

Const findPort

  • findPort(port: number, cb: function): void
  • Find next open port


    • port: number
    • cb: function
        • (x: Error | null, y?: number): void
        • Parameters

          • x: Error | null
          • Optional y: number

          Returns void

    Returns void

Const getArgs

  • getArgs(): string[]
  • Like Haskell's getArgs, but for Node

    Returns string[]

Const getBasename

  • getBasename(str?: string): string
  • basename for Node


    • Default value str: string = ""

    Returns string

Const getFileExt

  • getFileExt(str: string): string
  • Get the file extension for a given file


    • str: string

    Returns string

Const getFreeDisk

  • getFreeDisk(): number

Const getFreeMemory

  • getFreeMemory(): number

Const getGlobal

  • getGlobal(): __type
  • Gets the global for your current context.

    Returns __type

Const getLoadAverage

  • getLoadAverage(): number

Const getLocalIp

  • getLocalIp(): Promise<string>

Const getMemoryUsage

  • getMemoryUsage(): number

Const getNodeModules

  • getNodeModules(): string[]

Const getStdin

  • getStdin(f: function): void
  • Get stdin and do something with it.


    • f: function
        • (a: string): void
        • Parameters

          • a: string

          Returns void

    Returns void

Const getTerminalColumns

  • getTerminalColumns(): number

Const getTerminalRows

  • getTerminalRows(): number

Const getTerminalSize

  • getTerminalSize(): object
  • Returns size of the current terminal

    Returns object

    columns, rows

    • columns: number
    • rows: number

Const getUserHome

  • getUserHome(): string

Const getUserShell

  • getUserShell(): string
  • Get the current user's shell, or an empty string on shell-less platforms

    Returns string

Const hasColor

  • hasColor(): boolean
  • Returns true if the current terminal supports color

    Returns boolean

Const id

  • id<A>(a: A): A
  • id

    Type parameters

    • A


    • a: A

    Returns A

Const isColor

  • isColor(): boolean

Const isDirectory

  • isDirectory(filePath: string): boolean
  • Returns true if the path is a directory


    • filePath: string

    Returns boolean

Const isFile

  • isFile(filePath: string): boolean
  • Returns true if the path is a file


    • filePath: string

    Returns boolean

Const isHiddenFile

  • isHiddenFile(file: string): boolean

Const isInstalled

  • isInstalled(pkgName: string): boolean
  • Returns true if the passed node_module name is installed


    • pkgName: string

    Returns boolean

Const isJson

  • isJson(str: string): boolean
  • Returns true if the string is valid JSON


    • str: string

    Returns boolean

Const isRoot

  • isRoot(): boolean
  • Check if current process is running as root.

    Returns boolean

Const isSymLink

  • isSymLink(filePath: string): boolean
  • Returns true if path is a symlink


    • filePath: string

    Returns boolean

Const isWin

  • isWin(): boolean

Const logWithInfo

  • logWithInfo(str?: string): void
  • console.log with hostname and PID info


    • Default value str: string = ""

    Returns void

Const mv

  • mv(oldPath: string, newPath: string, cb: function): void
  • Parameters

    • oldPath: string
    • newPath: string
    • cb: function
        • (x?: any): any
        • Parameters

          • Optional x: any

          Returns any

    Returns void

Const noop

  • noop(): void

Const open

  • open(args: string, opts: __type, cb: Function): void
  • Opens things. Works on Linux, Mac, and Windows


    • args: string
    • opts: __type
    • cb: Function

    Returns void

Const readFileSync

  • readFileSync(str: string): string | void

Const readJson

  • readJson<A>(file: string, cb: function): void
  • Read json file, parse it, call cb with obj or err

    Type parameters

    • A


    • file: string
    • cb: function
        • (x?: Error, y?: A): void
        • Parameters

          • Optional x: Error
          • Optional y: A

          Returns void

    Returns void

Const readJsonSync

  • readJsonSync(file: string): string

Const removeBOM

  • removeBOM(content: string): string
  • The same as what's in Node's module (see lib/internal/module). Remove byte order marker. This catches EF BB BF (the UTF-8 BOM) because the buffer-to-string conversion in fs.readFileSync() translates it to FEFF, the UTF-16 BOM.


    • content: string

    Returns string

Const removeExtension

  • removeExtension(s?: string): string

Const resolveFiles

  • resolveFiles(ls: string[]): string[]
  • Resolve a list of paths


    • ls: string[]

    Returns string[]

Const safeDecodeURI

  • safeDecodeURI(str: string): string

Const safeDecodeURIComponent

  • safeDecodeURIComponent(str: string): string

Const sleep

  • sleep(ms: number): Promise<void>
  • Simple sleep.

    You can await it, or .then it


    • ms: number

    Returns Promise<void>

Const tap

  • tap(msg: string): (Anonymous function)
  • Log a value to console, and return that value


    • msg: string

    Returns (Anonymous function)

Const termPrompt

  • termPrompt(question: string, isYesDefault?: boolean): Promise<boolean>
  • Create a simple y/n prompt for the terminal

    Adapted from create-react-app's prompt


    • question: string
    • Default value isYesDefault: boolean = false

    Returns Promise<boolean>

Const touch

  • touch(filePath: string, contents?: string): void
  • Make a file if it doesn't exist already


    • filePath: string
    • Default value contents: string = ""

    Returns void

Const watchFile

  • watchFile(filePath: string, cb: function): void
  • Watch a file for changes, and call the function


    • filePath: string
    • cb: function
        • (event: string, filename: string): void
        • Parameters

          • event: string
          • filename: string

          Returns void

    Returns void

Const withInfo

  • withInfo(str?: string): string

Const writeError

  • writeError(data: string): void
  • Use instead of console.error()

    Logs to file and stdout both


    • data: string

    Returns void

Const writeJson

  • writeJson(file: string, data: any, indent?: number | function, cb?: function): void
  • Write JSON from a stringifiable value


    • file: string
    • data: any
    • Default value indent: number | function = 2
    • Optional cb: function
        • (y: Error | void): void
        • Parameters

          • y: Error | void

          Returns void

    Returns void

Const writeJsonSync

  • writeJsonSync<A>(file: string, data: A, indent?: number): void
  • Write JSON from a stringifiable value, sync

    Type parameters

    • A


    • file: string
    • data: A
    • Default value indent: number = 2

    Returns void


  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc