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

asimov-core

v0.4.0

Published

Base classes and toolkit for asimov.js

Downloads

17

Readme

asimov-core

NPM version Code Climate Dependency Status

Base classes and toolkit for asimov.js

How to use

Install from NPM

$ npm install asimov-core

Klass, an EventEmitter class

Klass is a base class, which all other classes build on, and it is itself mostly a wrapper for the EventEmitter in wunderbits.core.

var Klass = require('asimov-core').Klass;

var MyClass = module.exports = Klass.extend({

  'myMethod': function () {
    console.log('Hello world')!
  }
});

Events

If you've worked with Backbone or wunderbits.core before, the API for binding to and triggering events should feel very familiar.

var theThing = new MyClass();

theThing.on('event', function () {
  console.log('stuff done!');
});

theThing.trigger('event');

Assert type and existance

Klass and all of its child classes comes with a convenient method for typechecking.

var MyClass = module.exports = Klass.extend({

  'saveValue': function (anything, value) {
    this.assert('defined', anything, 'Anything must be defined!');
    this.assert('number', value, 'Value must be a number!');
  }
});

Privacy with public interface

A class can implement a public interface by defining an array of method names. Useful for singleton, top-level modules.

var MyClass = Klass.extend({

  'publicMethods': [
    'aMethodName'
  ]
});
var instance = new MyClass();
module.exports = instance.publicInterface();

Logger

The logger class wraps console log to provide namespacing, task durations and more than one log level.

Simple logging

var Logger = require('asimov-core').Logger;
var logger = new Logger();

logger.log('my-app', 'My awesome log message');

Log a pending task

logger.pending('my-app', 'Doing things right now');

Log task duration

var started = new Date();

setTimeout(function () {
  logger.since('my-app', 'And we are done', started);
}, 1000);

Log level low

These logs will only appear if process.env.VERBOSE is true.

logger.low('my-app', 'My debug message');
logger.lowSince('my-app', 'Some task is done', started);

Filesystem

All synchronous filesystem abstraction, providing shortcuts for common use cases.

var Filesystem = require('asimov-core').Filesystem;
var fs = new Filesystem();
  • fs.exists (string path) Check if path exists, returns true or false.
  • fs.cleanDirectory (string path) Recursively delete everything in path.
  • fs.copyDirectoryIfExists (string srcPath, string destPath) If source path exists, copy it to destination and return true. If source path doesn't exist, returns false.
  • fs.findFirstMatch (string grep, array paths) Returns the path of the first file found matching the string grep, or false if no file was found.
  • fs.forceExists (string path) Force a folder path to exist.
  • fs.getStats (string path) Return the stat object for path.
  • fs.isDirectory (string path) Returns true if path is a directory, otherwise false.
  • fs.hasFileExtension (string filename, string extension) Check if filename has the expected extension, returns true or false.
  • fs.readDirectory (string path, function iterator) If path exists, execute iterator with path of each file and return true. If path doesn't exist, returns false.
  • fs.readFile (string path) Read and return file.
  • fs.rebuildDirectory (string path) Delete a folder and recreate it as empty.
  • fs.recursiveDelete (string path) Walks a tree, deletes all files and folders.
  • fs.recursiveForFolders (string path, function iterator) Execute iterator for all folders in path, top down.
  • fs.watchTree (string path, function handler) Watch path for added, removed and modified files using watchdirectory. Returns a function that can be called to stop watching the path.
  • fs.writeFile (string path, value) Write value to file at path.

ChildProcess

A small wrapper for child_process. Documentation coming soon!


Made by Adam Renklint, Berlin 2014. MIT licensed.