Socket
Socket
Sign inDemoInstall

aws-lambda-middleware

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-lambda-middleware - npm Package Compare versions

Comparing version 0.8.2 to 0.8.3

18

index.js

@@ -11,3 +11,3 @@ const Middleware = require('./src/Middleware')

return PropTypes.makeRule({
validType: (value) => {
validType: (value, isDefaultValue) => {
return typeof value === 'string'

@@ -31,4 +31,4 @@ },

return PropTypes.makeRule({
validType: (value) => {
if (typeof value === 'string') {
validType: (value, isDefaultValue) => {
if (!isDefaultValue && typeof value === 'string') {
return /^-*[0-9]*[\.]*[0-9]+$/.test(value) && !/^0[0-9]+/.test(value) && !/^-0[0-9]+/.test(value) && !(value.length === 1 && value === '-')

@@ -55,4 +55,4 @@ } else {

return PropTypes.makeRule({
validType: (value) => {
if (typeof value === 'string') {
validType: (value, isDefaultValue) => {
if (!isDefaultValue && typeof value === 'string') {
return /^-*[0-9]+$/.test(value) && !/^0[0-9]+/.test(value) && !/^-0[0-9]+/.test(value) && !(value.length === 1 && value === '-')

@@ -79,4 +79,4 @@ } else {

return PropTypes.makeRule({
validType: (value) => {
return typeof value === 'string' ? /^(true|false)$/.test(value) : typeof value === 'boolean'
validType: (value, isDefaultValue) => {
return !isDefaultValue && typeof value === 'string' ? /^(true|false)$/.test(value) : typeof value === 'boolean'
},

@@ -101,3 +101,3 @@ validRequired: (value) => {

return PropTypes.makeRule({
validType: (value) => {
validType: (value, isDefaultValue) => {
return Array.isArray(value)

@@ -114,3 +114,3 @@ },

return PropTypes.makeRule({
validType: (value) => {
validType: (value, isDefaultValue) => {
return common.isObject(value)

@@ -117,0 +117,0 @@ },

{
"name": "aws-lambda-middleware",
"version": "0.8.2",
"version": "0.8.3",
"engines": {

@@ -12,3 +12,3 @@ "node": ">=8.3.0"

"eslint-plugin-node": "^11.1.0",
"eslint-plugin-import": "^2.25.0"
"eslint-plugin-import": "^2.25.1"
},

@@ -15,0 +15,0 @@ "scripts": {

@@ -232,15 +232,27 @@ # aws-lambda-middleware

//It overrides the existing string rule.
get string () {
return PropTypes.makeRule({
//Valid function to check data type
validType: (value) => {
return typeof value === 'string'
get number () {
return PropTypes.makeRule({
/**
* Valid function to check data type
* @param {*} value
* @param {Boolean} isDefaultValue Returns true when validating the value type set as the default.
* */
validType: (value, isDefaultValue) => {
if (!isDefaultValue && typeof value === 'string') {
return /^-*[0-9]*[\.]*[0-9]+$/.test(value) && !/^0[0-9]+/.test(value) && !/^-0[0-9]+/.test(value) && !(value.length === 1 && value === '-')
} else {
return typeof value === 'number'
}
},
//Valid function to check if it is required
validRequired: (value) => {
return value.length > 0
return !isNaN(value)
},
//A function that converts the value of Paramers when it is incorrectly converted to a string. (Set only when necessary)
convert: (value) => {
return String(value)
if (typeof value === 'string') {
return Number(value)
} else {
return value
}
}

@@ -251,5 +263,5 @@ })

//Multiple settings are possible at once
get number () {
return PropTypes.makeRule({
validType: (value) => {
get string () {
return PropTypes.makeRule({
validType: (value, isDefaultValue) => {
return ...

@@ -277,4 +289,5 @@ },

#### 0.8.2
#### 0.8.3
- PropTypes.*.default, Added ability to set the value returned from a function as a default value.
- Validate value type set as default
- body parser improvements

@@ -281,0 +294,0 @@ - PropTypes.addRules bug fix

@@ -18,4 +18,2 @@ const { URLSearchParams } = require('url')

} else {
result = true
for (const key in value) {

@@ -26,3 +24,5 @@ result = false

}
} else if (typeof value === 'boolean' || typeof value === 'number' || value) {
} else if (typeof value === 'number') {
result = isNaN(value)
} else if (typeof value === 'boolean' || value) {
result = false

@@ -29,0 +29,0 @@ }

@@ -25,4 +25,12 @@ const common = require('./common')

makeRule ({ validType, validRequired, convert } = {}) {
const invalid = (propName, value) => {
if (typeof validType === 'function' && !common.isEmpty(value) && !validType(value)) {
const invalid = (propName, value, isDefaultValue) => {
let isEmpty = false
if (isDefaultValue) {
isEmpty = !(['boolean', 'number', 'string', 'undefined'].includes(typeof value) || value)
} else {
isEmpty = common.isEmpty(value)
}
if (typeof validType === 'function' && !isEmpty && !validType(value, isDefaultValue)) {
return `invalid parameter type '${propName}'`

@@ -82,3 +90,3 @@ }

//valid type
if (invalid(propName, value)) {
if (invalid(propName, value, true)) {
const invalidMsg = `'${propName}' default value type error`

@@ -85,0 +93,0 @@ common.error(`${invalidMsg}, -value:`, value, ' -type:', typeof value)

@@ -27,3 +27,3 @@ const { Middleware, PropTypes } = require('../index')

username: PropTypes.string.isRequired,
address: PropTypes.string.default(''),
address: PropTypes.integer.default(),
photos: PropTypes.array.default((event) => [Date.now()])

@@ -30,0 +30,0 @@ }

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