strong-params
Advanced tools
Comparing version 0.7.0 to 0.7.1
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 () { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
31307
18
805
129
0