@ninjalib/util
TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published

Ninja util library

A bunch of utilities for use on the browser, server or both

Note: Requires node v19.6.0 for testing

Features

  • Minimal dependencies
  • Easy to use

Usage

Import util and start using straight away:

import util from '@ninjalib/util';

if (!util.isNode()) {
    throw new Error('This code must be run on the server');
}

Docs

Shared

isBrowser

Returns true if in a browser/client context

if (util.isBrowser()) {
    throw new Error('This code can only be run on the server');
}

isNode

Returns true if in a server context

if (util.isNode()) {
    throw new Error('This code can only be run on the client');
}

Client

Server

loadEnv

Loads environment files into process.env, similar to dotenv package

Parameters:

  • filePath?: path to the env file (defaults to current working directory)
  • force?: forcefully overwrites existing environment variables (defaults to false)
// call this as early in your application as possible
util.loadEnv();

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.5.0
    1
    • latest

Version History

Package Sidebar

Install

npm i @ninjalib/util

Weekly Downloads

1

Version

0.5.0

License

ISC

Unpacked Size

113 kB

Total Files

60

Last publish

Collaborators

  • ninjainshade