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 🙏

© 2026 – Pkg Stats / Ryan Hefner

modular-rest-toolkit

v0.1.8

Published

a set of tools for working on an API

Readme

Modular-Rest-Toolkit

is a group of tools for developing Rest-APIs.

Methods:

  1. reply: generate an structured Object as a response for clients.
  2. validateObject: validate an object by given fields.
  3. createNavigator: return an object with navigator properties.
  4. saveFromLink: save file from a URL.
  5. removeFile : remove a file.
  6. sleep : return a promse wich could waite for milliseconds.

Install

Install using npm:

npm i modular-rest-toolkit --save
const tools = require('modular-rest-toolkit');

1. reply generating structured json

this tool will generate a simple structure based on 3 type of reply data, message, error. each reply has two property: status, detail; here is how to generate a reply:


// base parameters
tools.reply(status, detail);

// generate a success state
tools.reply('s', {'d': ['product1', 'product2']});
/*
    {
        'status': 'success',
        'data'  : ['product1', 'product2'],
    }
*/

status options

| passing char | result | | ------------ | ------ | | s | success | | f | fail | | e | error |

detail options

| passing char | result | | ------------ | ------ | | {d: ''} | {data: ''} | | {e: ''} | {error: ''} | | {m: ''} | {message: ''} |

2. validateObject

this tool could be useful for forms to validate required fields. here is how to generate a reply:

//== check form object to figure out 'name phone' fields are not null. ==
let form = {
    'name'  : 'navid',
    'family': 'your family',
    'phone' : null,
    'city'  : 'your city'
};

// simple validation
let validated = tools.validateObject(form, 'name phone');
// returned {isValid: false, requires: ['phone']}


// precise validation
let option = {
    name    : '',           // could has any value except null
    phone   : '',           // could has any value except null
    city    ; 'c1 c2 c3',   // could has only one of these values.
};
let validated2 = tools.validateObject(form, option);
// returned {isValid: false, requires: ['phone', 'city']}

3. 'createNavigator'

this is a tool for create a navigator object with "pages, page, from, to" properties. it would be useful when you have a service which provides items troughout pages.

let totalItems = 100;
let itemPerPage = 10;
let page = 1;

let navigator = tools.createNavigator(totalItems, itemPerPage, page),
/* 
    {
        // total pages & current page
        pages: 10, page: 1,

        //for selecting items from 0 to 10
        from: 0, to: 10,
    }
*/

4. saveFromLink

tools.saveFromLink(url, saveAs);

5. removeFile

tools.removeFile(path);

6. sleep

let ms = 1000;
await tools.sleep(ms).then();

thank you for using Modular-Rest-toolkit :)