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

exclusivejs

v1.0.26

Published

<div class="w-full border-b border-black/10 dark:border-gray-900/50 text-gray-800 dark:text-gray-100 group bg-gray-50 dark:bg-[#444654]"><div class="text-base gap-4 md:gap-6 m-auto md:max-w-2xl lg:max-w-2xl xl:max-w-3xl p-4 md:py-6 flex lg:px-0"><div clas

Downloads

6

Readme

const ExclusiveJs = require('exclusivejs').instance();

ExclusiveJs.setRoutePath("src/routes") // set the path to your routes folder .setApiPrefix("api") // set the prefix for your API routes .setDebugger(true) // enable debugging

.setRoutePath("src/app/routes") // set route path// default route path is src/routes

.connectDocumentation( "/api-docs",swaggerUi.serve,swaggerUi.setup(swaggerDocument) //swagger document ) // serve documentation

.injectPackages() // inject your installed packages

.setValidator({}) // set your validator

ExclusiveJs.init();

This will automatically generate routes for your Express.js app based on the file structure of your src/routes folder.OptionsExclusiveJs provides several options that you can use to configure how your routes are generated:setRoutePath(path)Sets the path to your routes folder. Default value is src/routes.setApiPrefix(prefix)Sets the prefix for your API routes. Default value is api.setDebugger(debug)Enables or disables debugging. Default value is true.injectPackages()Injects your installed packages into your routes. This allows you to use packages in your routes without having to require them in each file. Only compiles packages that are installed, not inbuilt packages.


const AuthController = require("../../controller/auth");
const UserSchema = require("../../model/user");

class AuthRoute {
  #validator;
  #packages;
  #services;
  #models;
  constructor({ packages, models, services }) {
    this.#packages = packages;
    this.#services = services;
    this.#models = models;
  }

   
  "post.login" = async (req, res) => {
    const { walletAddress } = req.body;
    let user = await this.#services.AuthController.login(walletAddress);
    if (!user) return res.status(400).json({ message: "user does not exist" });
    user = { email: user.email, userId: String(user._id) };
    const token = this.#packages.jsonwebtoken.sign(
      user,
      process.env.SECRET_KEY
    );
    return res.status(200).json({ token, user });
  };
  "post.register" = async (req, res) => {
    const { walletAddress, githubLink, linkedInLink, lastName, firstName } =
      req.body;
    let user = await this.#services.AuthController.login(walletAddress);
    if (user) return res.status(400).json({ message: "user does  exist" });

    user = await this.#services.AuthController.createUser(
      walletAddress,
      githubLink,
      linkedInLink,
      lastName,
      firstName
    );

    user = {
      email: user.email,
      userId: String(user._id),
      walletAddress: user.walletAddress,
    };
    const token = this.#packages.jsonwebtoken.sign(
      user,
      process.env.SECRET_KEY
    );
    return res.status(200).json({ token, user });
  };
}

class Validator {
  #validator;
  constructor({ validator }) {
    this.#validator = validator;
  }
  all = () => [];

  "post.login" = () => {
    return [
      this.#validator.ValidatorFactory.createUserValidator(),
      this.#validator.validatorRule,
    ];
  };
}
module.exports = {
  route: AuthRoute,
  middleware: Validator,
  injectableClass: [AuthController],
  injectableModel: [UserSchema], 
};


In the above code we created two route called register and a login routes. this file is assume to be inside the auth folder in the routes folder. any model/database schema that will be used must be injected into the injectableModel same for any services or controller. After doing that, you will then get access to the injected in the constructor. check the bellow code snippet.


constructor({ packages, models, services }) {
  }

model ---> the injected models/repository or database schema
services ---> the injectableClass
packages -->  access to all installed packages that inside your package.json file

Also we have one that is called validator


constructor({ validator }) {
    this.#validator = validator;
  }

Let say your validation file looks like this

const { body, param, validationResult } = require("express-validator");

exports.validatorRule = function (req, res, next) {
  const error = validationResult(req).formatWith(({ msg }) => msg);
  const hasError = !error.isEmpty();
  if (hasError) {
    res.status(422).json({ error: error.array() });
  } else {
    next();
  }
};

class ValidatorFactory {
  static walletAddress = body("walletAddress")
    .isString()
    .withMessage("Provide a wallet address");
  static createUserValidator() {
    return [this.walletAddress];
  }
}

exports.ValidatorFactory = ValidatorFactory;

All you just need to do is to export the whole file and the use the function(setValidator) to set it in the entry file .

  .setValidator(validator)

Incase you have more that one validator file you can export the in a single file like this


const validator = require("../validator");
module.exports = {
  validator,
};

then import into the entry file

let validator = require("../packages/index");

then set

  .setValidator(validator)