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

@kathondvla/display-responsibilities

v1.0.22

Published

This module converts an array of /responsibilities into an array of strings

Downloads

2

Readme

display-responsibilities

This is a module that converts an array of /responsibilities into an array of strings.

Installing

Installation is simple using npm :

$ cd [your_project]
$ npm install --save display-responsibilities

#About

The main idea of this module is to receive all /responsibilities of a person and transform it into an array of strings. The returned strings indicates how those responsibilities have to be displayed in all apps. In this way we will see the same displayed pattern for person responsibilities in all our apps. The module is NOT in charge of solving all necessary dependencies like getting organisation's names, position's names, etc. So you need to provide a function that make all api calls.

Usage

Start by requiring the module in your code.

var DisplayResponsibilities = require('display-responsibilities');

Then instantiate a client:

var client = new DisplayResponsibilities();

Now we are ready to start converting responsibilities.

Function Definitions

Below is a description of the different types of functions that you can use. It describes the inputs and outputs of the different functions. Most of these function return a Q promise.

convertToStrings (responsibilities,getFromApi,callback)

This is a q promise method and it allows you to transform /responsibilities objects into an array of strings to be displayed on a screen. It will also receive a function as a parameter where you have to solve all api calls inside. This getFromApi could be a q promise function and should looks like:

 // href ~ /organisations/uuid

function getFromApi(href){
    
    var deferred = Q.defer();

    var baseUrl = "http://api.vsko.be";

    var completeURL = baseUrl+href;
    
    var config = {
        // ... user, pass, headers ...
    };

    needle.get(completeURL,config,function(error,response) {

        if (error) {
            return deferred.reject(error);
        }

        deferred.resolve(response.body);
    });

    return deferred.promise;
};

or you can use a callback function too:

function getFromApi(href,callback){

    var firstPart = "http://api.vsko.be";

    var config = {
        // ... user, pass, headers ...
    };

    var completeURL = firstPart+href;

    needle.get(completeURL,config,function(error,response) {

        if (error) {
            callback(error);
        }else{
            callback(undefined,response.body);
        }
    });

}

If you are using the module in client side (like Angular.js) your getFromApi function could be:

function getFromApi(href){

    var deferred = $q.defer();

    var firstPart = "http://api.vsko.be";

    var completeURL = firstPart+href;

    $http.get(completeURL,{
          crossDomain: true,
        })
        .success(function(data) {
          deferred.resolve(data);
        })
        .error(function(error) {
            deferred.reject(err)
        });

    return deferred.promise;
};

Then you can use "convertToStrings" function as a promise:

client.convertToStrings(responsibilities,getFromApi)
    .then(function(responsibilities){
    
        responsibilities.forEach(function(stringResponsibility){
            console.log(stringResponsibility);
        });
    });

or with a callback way:

client.convertToStrings(responsibilities,getFromApi,function(error,response){

    if(!error){
        response.forEach(function(stringResponsibility){
            console.log(stringResponsibility);
        });
    }
});

Tests

We use mocha for testing. Inside test folder you will see a file called config.sample.json that looks like:

{
    "needleRetry": {
        "fullDocument": false
    },
    "needle": {
        "username": "user",
        "password": "pass",
        "open_timeout": 0,
        "decode_response": false,
        "follow_max": 100,
        "headers": { "TOKEN": "pass"}
    },
    "retry": {
        "retries": 3
    }
}

You need to rename it as config.json and change "user", "pass" and {"TOKEN" : "pass"} in order test to run ok. Finally to run test just do:

$ npm test

and you will see:

#Converting simple responsibilities
    ✓ should include customPositionTitle in response
    ✓ should exclude not active responsibilities
    ✓ should expand subResponsibilities

#Converting responsibilities
    ✓ should return 13 strings for Dominic
    ✓ should return 7 strings (4 Diary + 3 others) for Dirk
    ✓ should return 12 strings (6 Diary + 8 others) for Rita
    ✓ should return 4 strings (2 Diary + 5 others) for Nadine
    ✓ should return 2 string (1 Diary + 5 others) for Gerda
    ✓ should return 3 strings (1 Diary + 2 others) for Ann D.
    ✓ should return 15 strings (5 Diary + 10 others) for Ann L.
    ✓ should return 3 string (1 Diary + 2 others) for Alain
    ✓ should return 2 string (1 Diary + 9 others) for Bart

#Converting responsibilities in boundary cases
    ✓ should be rejected if no parameters are passed
    ✓ should be rejected if undefined responsibilities are passed
    ✓ should be rejected if responsibilities parameter is not an array
    ✓ should be rejected if responsibilities parameter is null
    ✓ should NOT be rejected if responsibilities is an empty array
    ✓ should be rejected for empty function is passed
    ✓ should be rejected if no getFromApi function is passed
    ✓ should NOT be rejected if getFromApi is not a promise, but a regular callback function
    
20 passing