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

express-query-params

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-query-params - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

1

formats/mongo.js

@@ -33,2 +33,3 @@ const format = require('../lib/format')

else if (format.isLesserThanOrEqual(value)) mongo[key] = { $lte: insertValue }
else if (format.oneOf(value)) mongo[key] = { $in: value.split(',') }
else if (format.isRange(value)) {

@@ -35,0 +36,0 @@ const [ from, to ] = value.split('...')

@@ -39,2 +39,12 @@ const format = require('../lib/format')

if (format.oneOf(value)) {
const oneOf = value.split(',').map(v => cast(v))
const inArguments = oneOf.map((_, i) => `$${values.length + i + 1}`).join(', ')
values.push(...oneOf)
clauses.push(`${key} IN (${inArguments})`)
continue
}
let clause = ''

@@ -41,0 +51,0 @@ let insertValue = cast(trimOperators(value))

4

lib/format.js

@@ -8,2 +8,3 @@ const stringContains = raw => raw[0] === '*' || raw[raw.length - 1] === '*'

const isLesserThanOrEqual = raw => raw.slice(0, 2) === '<='
const oneOf = raw => raw.indexOf(',') > -1

@@ -17,3 +18,4 @@ module.exports = {

isLesserThan(raw) { return isLesserThan(String(raw)) },
isLesserThanOrEqual(raw) { return isLesserThanOrEqual(String(raw)) }
isLesserThanOrEqual(raw) { return isLesserThanOrEqual(String(raw)) },
oneOf(raw) { return oneOf(String(raw)) }
}
{
"name": "express-query-params",
"version": "1.0.0",
"version": "1.0.1",
"description": "Express.js middleware implementing the API Query Spec, converting the params to SQL or a Mongo query",

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

@@ -25,3 +25,4 @@ /* global test expect */

firstName: /Steve$i/,
accountBalance: 25.22
accountBalance: 25.22,
favouriteColours: { $in: [ 'red', 'green', 'blue' ] }
}

@@ -28,0 +29,0 @@

@@ -21,6 +21,9 @@ /* global test expect */

'Steve',
25.22
25.22,
'red',
'green',
'blue'
]
const correctQuery = 'username = $1 AND email LIKE $2 AND age >= $3 AND age <= $4 AND boughtSomethingOn >= $5 AND boughtSomethingOn <= $6 AND createdAt > $7 AND updatedAt < $8 AND friends >= $9 AND followers <= $10 AND banned = $11 AND activated = $12 AND firstName ILIKE $13 AND accountBalance = $14'
const correctQuery = 'username = $1 AND email LIKE $2 AND age >= $3 AND age <= $4 AND boughtSomethingOn >= $5 AND boughtSomethingOn <= $6 AND createdAt > $7 AND updatedAt < $8 AND friends >= $9 AND followers <= $10 AND banned = $11 AND activated = $12 AND firstName ILIKE $13 AND accountBalance = $14 AND favouriteColours IN ($15, $16, $17)'

@@ -27,0 +30,0 @@ test('req.query -> SQL', () => {

@@ -49,1 +49,7 @@ /* global test expect */

})
test('oneOf', () => {
for (const param in query) {
expect(format.oneOf(query[param])).toBe(param === 'favouriteColours')
}
})

@@ -14,3 +14,4 @@ module.exports = {

accountBalance: '25.22',
favouriteColours: 'red,green,blue',
limit: 10
}
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