{"id":24493059,"url":"https://github.com/open-node/open-rest-helper-params","last_synced_at":"2025-10-30T14:33:53.097Z","repository":{"id":57315126,"uuid":"66825002","full_name":"open-node/open-rest-helper-params","owner":"open-node","description":null,"archived":false,"fork":false,"pushed_at":"2017-08-17T01:59:14.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-24T15:53:41.151Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/open-node.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-29T08:18:41.000Z","updated_at":"2017-01-23T11:32:14.000Z","dependencies_parsed_at":"2022-09-18T20:51:20.431Z","dependency_job_id":null,"html_url":"https://github.com/open-node/open-rest-helper-params","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-node%2Fopen-rest-helper-params","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-node%2Fopen-rest-helper-params/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-node%2Fopen-rest-helper-params/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-node%2Fopen-rest-helper-params/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-node","download_url":"https://codeload.github.com/open-node/open-rest-helper-params/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243680969,"owners_count":20330152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-21T19:19:00.884Z","updated_at":"2025-10-30T14:33:48.051Z","avatar_url":"https://github.com/open-node.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# open-rest-helper-params\n\nopen-rest 的 helper 插件，用来对 req.params 进行操作处理\n\n[![Build status](https://api.travis-ci.org/open-node/open-rest-helper-params.svg?branch=master)](https://travis-ci.org/open-node/open-rest-helper-params)\n[![codecov](https://codecov.io/gh/open-node/open-rest-helper-params/branch/master/graph/badge.svg)](https://codecov.io/gh/open-node/open-rest-helper-params)\n\n\n# Node version\n\u003cpre\u003e \u003e= 6 \u003c/pre\u003e\n\n# Usage\n\n```bash\nnpm instsall open-rest-helper-params --save\n```\n\n```js\nconst rest = require('open-rest');\nconst params = require('open-rest-helper-params')(rest);\n\n// params Equivalent to rest.helper.params\n\n## params.omit\n从 req.params 上去掉一些参数\n```js\n// keys Array 要从req.params 去掉的参数的名称\nparams.omit(keys);\n\n// return\n// function(req, res, next) { ... };\n\n//or 链式调用\nparams\n  .omit\n  .keys(['name', 'password'])\n  .exec();\n```\n\n## params.required\n判断某些必须的参数是否存在\n\n```js\n// keys Array 要判断的参数名称\n// error 如果不想等报的错误，Error类型, 可选\n\nparams.required(keys, error);\n\n// return\n// function(req, res, next) { ... };\n\n//or 链式调用\nparams\n  .required\n  .keys(['username', 'password'])\n  .error(new restify.MissingParameterError('用户名和密码是必填项')\n  .exec();\n```\n\n## params.map\n根据字典将 req.params 的参数名称做个映射\n\n```js\n// dict Object {key(String) =\u003e value(String)}\n\nparams.map({email: 'username', pwd: 'password'});\n\n// return\n// function(req, res, next) { ... };\n\n//or 链式调用\nparams\n  .map({email: 'user', pwd: 'password'})\n  .exec();\n```\n\n## params.assign\n给指定的 req.params 某个key赋值，可以是静态的值，也可以是动态的值\n\n```js\n// keyPath 从 req.params 上的路径，例如: 'id', 'user.name', 分别代表 req.params.id, req.params.user.name\n// obj 要赋的值\n//    1. {path: 'params.id'} 代表值从 req.params.id 获取\n//    2. {fixed: 20} 代表固定的值\n\n// 静态值\nparams.assign('user.name', {fixed: 'Redstone Zhao'});\n\n// 动态值\nparams.assign('user.name', {path: 'hooks.user.name'});\n\n// return\n// function(req, res, next) { ... };\n\n//or 链式调用\nparams\n  .assign\n  .keyPath('user.name')\n  .obj({path: 'user.role'})\n  .exec();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-node%2Fopen-rest-helper-params","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-node%2Fopen-rest-helper-params","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-node%2Fopen-rest-helper-params/lists"}