Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

strong-params

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strong-params - npm Package Compare versions

Comparing version 0.7.0 to 0.7.1

lib/parameter-missing-error.js

3

lib/index.js
module.exports = {
koaMiddleware: require('./middlewares/koa'),
expressMiddleware: require('./middlewares/express'),
Parameters: require('./parameters')
Parameters: require('./parameters'),
ParameterMissingError: require('./parameter-missing-error')
}

@@ -12,2 +12,3 @@ /**

var _ = require('lodash')
var ParameterMissingError = require('./parameter-missing-error')

@@ -107,3 +108,3 @@ /**

var param = Parameters.clone(this._fetch(key))
if (!param) throw new Error('param `' + key + '` required')
if (!param) throw new ParameterMissingError('param `' + key + '` required')
if (!(param instanceof Parameters)) throw new Error('param `' + key + '` is not a Parameters instance')

@@ -110,0 +111,0 @@ return param

{
"name": "strong-params",
"version": "0.7.0",
"version": "0.7.1",
"description": "Rails-style strong parameters for javascript projects. (e.g. Express, Koa)",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -112,2 +112,14 @@ # strong-params

### Errors
```js
// ParameterMissingError
try {
params.require('missingKey')
} catch(err) {
err instanceof ParameterMissingError // -> true
err instanceof Error // -> true
}
```
Look [Rails Strong Parameters specification](http://edgeguides.rubyonrails.org/action_controller_overview.html#strong-parameters) for more information.

@@ -114,0 +126,0 @@

@@ -6,2 +6,3 @@ /* global beforeEach, describe, it */

var Parameters = require('..').Parameters
var ParameterMissingError = require('..').ParameterMissingError
var PRIMITIVE_TYPES = [Boolean, Number, String, function Null () {

@@ -111,3 +112,23 @@ this.valueOf = function () { return null }

describe('instance methods', function () {})
describe('instance methods', function () {
describe('require', function () {
var params
beforeEach(function () {
params = new Parameters({ requiredKey: {} })
})
describe('when required key passed', function () {
it('should return instance of parameters', function () {
params.require('requiredKey').should.be.a.instanceOf(Parameters)
})
})
describe('when required key not passed', function () {
it('should throw instance of ParameterMissingError with error message', function () {
var requireFunction = function () {
params.require('missingKey')
}
should.throws(requireFunction, ParameterMissingError, 'param `missingKey` required')
})
})
})
})

@@ -114,0 +135,0 @@ describe('operations', function () {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc