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

dango-core

v2.0.0

Published

> Dumpling in japaneese.

Downloads

3

Readme

Dango

Dumpling in japaneese.

POC for functional controllers and route-handlers in express.

npm npm bundle size GitHub npm

What is expected

  • Functional way of writing routers
  • Follow function programming concepts
  • Composition over inheritance

Update v1.0.0

I'm not very familiar with functional programming and it's concepts. I'm learning it now and it turns out the v0.0.2 dango code was not functional at all and it has been scraped see tag v0.0.2. I'll be proposing a new API for dango again. As we have been doing OOP for so long, FP will take some time to be fully understood.

Breaking changes

v2.0.0

  • The router handler ctx is now an object v1.0.0
  • CreateHandler has been scraped
  • CreateController params changed.

Proposed API

Core:

Express wrapper

  • A wrapper on express to inject controllers.
  • Can be used as
import express from 'express';
import { createExpressServer } from 'dango-core';

const app = express();

createExpressServer(app, { controllers: ['./controllers/*.ts'] }).listen(3000, () => {
  console.log('http://localhost:3000');
});
  • controller definition should be a glob path.

Controllers

  • A controller can be created with createController method.
import { createController } from 'dango-core';

export default createController(
  '/',
  [
    {
      path: '/',
      method: 'get',
      handler: ({req, res, params, query}) => {
        res.send('is this working ?');
      },
      middlewares: [
        (req, res, next) => {
          res.send("I'm local");
        },
      ],
    },
  ],
  [
    (req, res, next) => {
      res.send("I'm global");
    },
  ],
);
  • Should be default exported from the controller file.

Routes

This is a low level API which can be used to create routes with proper type definitions for request body,params and query. Can be used with createController for modularity.

  • BREAKING CHANGE

    • v2.0.0 the handler ctx is now an object
  • standalone

  import { createRoute } from 'dango-core';

  const userRoute = createRoute<{ user: string }>({
    path: '/user',
    method: 'options',
    handler: ({req, res, body}) => {
      // proper ts definitions
      req.body.user;
    },
  });
  • with controller
  import { createController } from 'dango-core';

  export default createController('/aa', [userRoute]);
  • With express router style function chaining
import { createRoute } from 'dango-core';

const home = createRoute<{ user: string }>('/')
  .method('get')
  .handler(({ res }) => res.send('OK'));

Middlewares

Global
import express from 'express';
import { createExpressServer } from 'dango-core';
const app = express();

createExpressServer(app, {
  controllers: ['controllers/**.ts'],
  middlewares: [
    (req, res, next) => {
      res.send("I'm global");
    },
  ],
}).listen(4000, () => console.log('http://localhost:4000'));
Controller specific
import { createController } from 'dango-core';

export default createController(
  '/test',
  [
    {
      path: '/yolo',
      method: 'get',
      handler: ({req, res}) => {
        res.send('is this working ?');
      },
    },
  ],
  [
    (req, res, next) => {
      res.send("I'm controller specific");
    },
  ],
);
Route specific
import { createController } from 'dango-core';

export default createController('/test', [
  {
    path: '/yolo',
    method: 'get',
    handler: ({req, res}) => {
      res.send('is this working ?');
    },
    middlewares: [
      (req, res, next) => {
        res.send("I'm route specific");
      },
    ],
  },
]);

Helpers

  • response.sendError

    • send HTTP errors from response with proper intellisense
      import { createController, createRoute } from 'dango-core';
      
      const someRoute = createRoute<{ user: string }>({
        path: '/',
        method: 'get',
        handler: ({req, res, body}) => {
          res.sendError(401,"Nope")
        },
      });
      
      export default createController('/home', [someRoute]);

Packages

| Package | version | | ------- | ----------------------------------------------- | | Core | npm | | Example | NA |