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

sarah-lib-utils

v1.1.3

Published

S.A.R.A.H. Library with helpful class

Downloads

15

Readme

S.A.R.A.H. utils lib

Scrutinizer Code Quality Code Coverage Build Status

npm license

npm stat

Library with helpful class for S.A.R.A.H.

Installation

> npm install sarah-lib-utils --save

Usage

S.A.R.A.H. integration

/** your_plugin_name.js */

const sarahLibUtils = require('sarah-lib-utils');
const SarahActionContext = sarahLibUtils.SarahActionContext;
const SarahActionHelper = sarahLibUtils.SarahActionHelper;
const version = sarahLibUtils.version;

exports.action = function (data, callback, config, SARAH) {
    var context = new SarahActionContext(data, callback);
    var helper = new SarahActionHelper(context);
    if (version.isV3()) {
         context.setSARAH(SARAH); // For v3 compatibility
    }
    var monModule = new MyModule();
    monModule.process(helper);
};

Version

Provide helpful methods to deal with Sarah version

// Load
const version = require('sarah-lib-utils/version');
// Helper
var isV3 = version.isV3();
var isV4 = version.isV4();
var sarahVersion = version.get();
if (version.v3 == versionNumber) {
    ...
}
if (version.v4 == sarahVersionNumber) {
    ...
}

Logger

SarahLogger will automatically add the channel in front of the message string

// Load
const SarahLogger = require('sarah-lib-utils/logger');
// Instantiate
var logger = new SarahLogger('channel');
// Helper
var message = 'myMessage';
logger.debug(message); // Will output 'debug: [channel] myMessage'
logger.log(message);   // Will output 'log: [channel] myMessage'
logger.info(message);  // Will output 'info: [channel] myMessage'
logger.warn(message);  // Will output 'warn: [channel] myMessage'
logger.error(message); // Will output 'error: [channel] myMessage'

Action Context

SarahActionContext is a simple wrapper for action data

// Load
const SarahActionContext = require('sarah-lib-utils/actionContext');
// Instantiate
var context = new SarahActionContext(data, callback);
// Setter
context.setSARAH(sarah);
// Getter
context.getData();
context.getCallback();
context.getSARAH();

Action Helper

SarahActionHelper provide helpful methods regarding action for module which want to run in SARAH v3 AND v4

Basics

// Load
const SarahActionHelper = require('sarah-lib-utils/actionHelper');
// Instantiate
var helper = new SarahActionHelper(<SarahActionContext> actionContext);
// helper
helper.speak(tts);
// Getter
helper.getContext();

S.A.R.A.H. module integration

/** MyModule.js */
/**
 * @public
 *
 * @param {object}            data
 * @param {SarahActionHelper} helper
 */
MyModule.prototype.process = function (helper) {
    helper.speak('c\'est partis');
    /** @var {SarahActionContext} context */
    var context = helper.getContext();
    /** @var {object} data */
    var data = context.getData();
    /** @var {callable} callback */
    var callback = context.getCallback();
    /** @var {SARAH} sarah
    var sarah = context.getSARAH();
    
    if (data.action == 'action1') {
       ...
    }
    ...
};

Tests

> npm test

Coverage

> npm run coverage

Then open the coverage/index.js.html file in a browser

EsLint

> npm run eslint

Release History

  • 1.0.0 : Initial release
  • 1.1.0 : Readme badges
  • 1.1.1 : Fix npm version
  • 1.1.2 : Fix npm link
  • 1.1.3 : Fix npm version