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

open-rest-helper-params

v1.0.0

Published

Controller helper params for open-rest or restify, Used to get instance from Model

Downloads

8

Readme

open-rest-helper-params

open-rest 的 helper 插件,用来对 req.params 进行操作处理

Build status codecov

Node version

Usage

npm instsall open-rest-helper-params --save
const rest = require('open-rest');
const params = require('open-rest-helper-params')(rest);

// params Equivalent to rest.helper.params

## params.omit
从 req.params 上去掉一些参数
```js
// keys Array 要从req.params 去掉的参数的名称
params.omit(keys);

// return
// function(req, res, next) { ... };

//or 链式调用
params
  .omit
  .keys(['name', 'password'])
  .exec();

params.required

判断某些必须的参数是否存在

// keys Array 要判断的参数名称
// error 如果不想等报的错误,Error类型, 可选

params.required(keys, error);

// return
// function(req, res, next) { ... };

//or 链式调用
params
  .required
  .keys(['username', 'password'])
  .error(new restify.MissingParameterError('用户名和密码是必填项')
  .exec();

params.map

根据字典将 req.params 的参数名称做个映射

// dict Object {key(String) => value(String)}

params.map({email: 'username', pwd: 'password'});

// return
// function(req, res, next) { ... };

//or 链式调用
params
  .map({email: 'user', pwd: 'password'})
  .exec();

params.assign

给指定的 req.params 某个key赋值,可以是静态的值,也可以是动态的值

// keyPath 从 req.params 上的路径,例如: 'id', 'user.name', 分别代表 req.params.id, req.params.user.name
// obj 要赋的值
//    1. {path: 'params.id'} 代表值从 req.params.id 获取
//    2. {fixed: 20} 代表固定的值

// 静态值
params.assign('user.name', {fixed: 'Redstone Zhao'});

// 动态值
params.assign('user.name', {path: 'hooks.user.name'});

// return
// function(req, res, next) { ... };

//or 链式调用
params
  .assign
  .keyPath('user.name')
  .obj({path: 'user.role'})
  .exec();