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

json-server-sxtension

v1.0.0

Published

nice additions for json-server in order to support large scale applications

Downloads

5

Readme

json-server-extension

json-server is great for stub server usage but in my opinion there where some caveat that i tried to solve in this package

so what this package gives you

  • [x] splitting to static files - json-server can serve only single file but in medium/large applications it not ideal, by using this package you can split your json object to files
  • [x] dynamic generation - with json server you can generate the whole file now you can create multiple generated objects decoupled each other and even combine static and generated files

Example

init example

const jsonServer = require('json-server');
const _jsonExtender = require('./jsonExtender');

//options:
//fullPath:fullpath for the combined object
//generatedPath:the path where the generated files will be found
//staticPath:the path where the static files will be found
const jsonExtender = new _jsonExtender({filePath:'./db_extends.json',
                                        generatedPath:'./generated',
                                        staticPath:'./static'})

//register accept array of generators or path to the generator scripts
//const funcs =  Object.keys(generators).map(key => generators[key])
jsonExtender.register('./generators');
jsonExtender.generate().then((data)=>{
  console.log(`wow ${data}`);
  var server = jsonServer.create()
  var router = jsonServer.router('./db_extends.json')
  var middlewares = jsonServer.defaults()

  server.use(middlewares)
  server.use(router)
  server.listen(4000, function () {
    console.log('JSON Server is running')
  })

});

generator Example

const amount = 100;
 const func =next =>create => {
    const path = `feed/feedList.json`;
    const data = (amount)=> {
        let temp = [];
        for (let i = 0; i < amount; i++) {
            temp.push({
                    id: `${i}N12134`,
                    newNotificationCount: i * 3,
                    isRead: (i % 2 == 0),
                    isStarMark: (i % 4 == 0),
                    iconType: "SocialNotifications",
                    description: i + ": this is a new  feed ",
                    date: new Date(Date.now()).toLocaleString()
                }
            )
        }
        return temp;
    }
    create({data: {feed: data(amount)}, path: path})
    next(create);

}
module.exports = func;

api

constructor

constructor({filePath:'string',generatedPath:'string, staticPath:'string'})

  • fullPath- fullpath for the combined object
  • generatedPath- the path where the generated files will be found default : './generated'
  • staticPath- the path where the static files will be found default : './static'

register

register('path name') / register([...generator scripts])

  • register('path name') - a path where the generators scripts will be found the package will insatiate the scripts automatically
  • register([...generator scripts]) -array of your generators after requiring them manually

generate

generate(isRun[default:true]) return promise

  • isRun - there is ability to not generate the db.json each time good when you want to save the state after you close the process the promise will recive the same data so you will not have to change the code
  • promise
    • resolve -{files:array of combined files, filePath:the combined file path }
    • reject- error

generator

const func= next =>create => {} - the generator should be initiated as follows first you will have to call for create this is sync function and the for next

  • create({data: {feed: generatedObject}, path: path})
    • data - the generated data where the name of the property will be the routing name in this case feed
    • path - a relative path under the generated path that you set in the constructor where you wish to put the output
  • next(create) - just pass the create function there so it's reference will be passed in the pipeline