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

@gik/tools

v0.2.5

Published

A [tools suite](https://github.com/search?q=tools+user%3Agikmx) for Node / Javascript development.

Downloads

3

Readme

@gik/tools 0.2.5

A tools suite for Node / Javascript development.

Contributors
Supported platforms
  • darwin
  • linux

Table of contents

  • thrower Errors with pretty stack and customizable name.
  • streamer An utility belt for our most common operations with RXJS's Observables.
  • server A minimal webserver using RxJS Observables.
  • populator Allows properties in an object to inherit values from sibling properties.
  • mapper Generates a flattened object containing a map for all the properties
  • logger A wrapper around pino.
  • checker A minimal type-checker for JavaScript purists.
    • is Determine if given value really belongs to the corresponding type.
      • objectEmpty member Determine if an element is an object and has no keys
      • string member Determines if value is really a string.
      • number member Determines if value is really a number.
      • array member Determines if value is really an array.
      • function member Determines if value is really a function.
      • regexp member Determines if value is really a regexp.
      • boolean member Determines if value is really a boolean.
      • object member Determines if value is really an object.
    • props function Validates properties of given object.

thrower

Errors with pretty stack and customizable name.

Parameters
Returns

Error - A custom error instance with a pretty stack.

Example
Thrower('test'); // A standard Error with prettified stack
Thrower(new TypeError('test2')); // Standard TypeError with prettified stack
Thrower('test3', 'TestError'); // Custom TestError with 'test3' as message
Thrower(['hola %s', 'mundo'], 'HelloError'); // HelloError with 'hola mundo' as message
const Err = Thrower('bad boy', 'CanineError', false); // Returns CanineError instance.

▲ Top


streamer

An utility belt for our most common operations with RXJS's Observables.

To do
  • [ ] Add unit tests for all operators.
Members

▲ Top


fromAccess

static property of streamer

Determine if given path is accessible.

Parameters
Returns

StreamBoolean - Wether the file is accessible or not.

▲ Top


fromStat

static property of streamer

Determine statistics about a file system node.

Parameters
Returns

StreamStat - stat object for the node.

Throws
  • Error - When given an invalid node.

▲ Top


fromSpawn

static property of streamer

Spawn a shell command.

Parameters
Returns

StreamOutput - Each chunk of either stdout or stderr data.

▲ Top


fromDirMake

static property of streamer

Creates a directory.

Parameters
Returns

StreamString - The path of the directory that was just created.

Throws
  • Error - When directory cannot be created.

▲ Top


fromDirRequire

static property of streamer

Requires a directory path, if the directory does not exists, it's created.

Parameters
Returns

Array.<StreamString> - The path of the directory.

Throws
  • Error - When requested path exists and is not a directory.

▲ Top


fromDirRead

static property of streamer

Get path of nodes in given directory (non recursively).

Parameters
Returns

Array.<StreamDirNode> - The path of the directory.

Throws
  • Error - When requested path exists and is not a directory.

▲ Top


fromDirReadRecursive

static property of streamer

Get path of nodes in given directory (recursively).

Parameters
Returns

StreamPath - The path of the directory.

Throws
  • Error - When requested path exists and is not a directory.

▲ Top


fromFileRead

static property of streamer

Reads a file from the disk.

Parameters
Returns

Observable.<string> - The contents of the file.

▲ Top


fromFileWrite

static property of streamer

Writes a file on the disk.

Parameters
Returns

Observable.<string> - The future value true if write was succesful.

Throws
  • Error - When the file cannot be written.

▲ Top


server

A minimal webserver using RxJS Observables.

Parameters
Returns

Subscription Observable - if subscription mode was enabled a subscription would be returned, otherwise an observable is returned.

▲ Top


populator

Allows properties in an object to inherit values from sibling properties. This specially useful when creating JSON configuration files.

Parameters
Returns

Object - An object copy with references replaced.

Example
const subject = {
    a: { b: { c: 'world' } },
    d: "hello ${a.b.c}${e}",
    e: "!!!",
    f: ["${e}", "${a.b.c}"]
};
const result = Populator(subject);
// result:
// { a: { b: { c: 'world' } }, d: "hello world!!!", e: "!!!", f: ["!!!", "world"] };

▲ Top


mapper

Generates a flattened object containing a map for all the properties available on subject.

Parameters
Returns

mapperResult - A flattened object.

Throws
  • mapperTypeError
Example
const subject = {
    a: {
        b: {
           d: true,
           e:  {
               g: 'foo'
           }
        },
        f: undefined,
    }
};
const result = Mapper(subject);
// result:
// { 'a.b.d': true, 'a.b.e.g': 'foo', 'a.f': undefined }

▲ Top


logger

A wrapper around pino.

Behaviour
  • When the environment is non-production it will output prettier logs.

  • All calls to error will use @gik/tools-thrower halting the execution when the environment is non-production (ie: development) however, when in production, it will fallback to Pino's default logger.

  • When the environment is set as production it will load extreme-mode adding an even faster approach to logging. (make sure to read the documentation about the caveats)

Parameters
Returns

Types.Instance - A function that you can use for logging.

Throws
  • Types.ParamTypeError - When parameters are not valid.

▲ Top


checker

A minimal type-checker for JavaScript purists.

Members

▲ Top


is

Determine if given value really belongs to the corresponding type.

Members

▲ Top


objectEmpty

static property of checker.is

Determine if an element is an object and has no keys

Parameters
Returns

boolean - Whether the object is empty or not.

▲ Top


string

static property of checker.is

Determines if value is really a string.

Parameters
Returns

boolean - Wheter value is string or not.

▲ Top


number

static property of checker.is

Determines if value is really a number.

Parameters
Returns

boolean - Wheter value is number or not.

▲ Top


array

static property of checker.is

Determines if value is really an array.

Parameters
Returns

boolean - Wheter value is array or not.

▲ Top


function

static property of checker.is

Determines if value is really a function.

Parameters
Returns

boolean - Wheter value is function or not.

▲ Top


regexp

static property of checker.is

Determines if value is really a regexp.

Parameters
Returns

boolean - Wheter value is regexp or not.

▲ Top


boolean

static property of checker.is

Determines if value is really a boolean.

Parameters
Returns

boolean - Wheter value is boolean or not.

▲ Top


object

static property of checker.is

Determines if value is really an object.

Parameters
Returns

boolean - Wheter value is object or not.

▲ Top


props

static method of checker

Validates properties of given object.

Parameters
Returns

Object - The validated subject extended with default values (when applies).

Throws
  • CheckerPropParamError when invalid parameters are passed.
  • CheckerPropDefError when a type definition is invalid.
  • CheckerPropDefTypeError when a type defintiion is not supported.
  • CheckerPropReqError when a required property is not found.
  • CheckerPropTypeError when a property does not match the defintion.
Example
const subject = { a: 1, b: 'hello' z: undefined };
const result = props(subject, {
    a: { type:'number', required:true },
    b: 'string',
    c: { default: new Date() },
    d: { required: false, default: null, map: value => [value, true] },
})
// result:
// { a: 1, b: 'hello', c: '1981-06-23 10:06:08', d: [null, true], z: undefined }

▲ Top