infer-values
v1.0.2
Published
Leveraging `replacer` parameter of `JSON.stringify`.
Readme
Beware, It is really trivial and slow
JSON.parse(JSON.stringify()) is not really fast or efficient, but stringify has convenient replacer parameter
Useful for converting request query values to integers and booleans
Lets say you have lots of stuff in query
app.get('/query', (req, res) => res.send(req.query))
app.get('/infer', (req, res) => res.send(inferValues(req.query)))GET /sign?url=https%3A%2F%2Fsource.unsplash.com%2Ffeatured%2F500x500&resize%5Bwidth%5D=200&resize%5Bheight%5D=150&resize%5BwithoutEnlargement%5D=true&output%5Bquality%5D=6&output%5Bformat%5D=jpegwill output
{
"url": "https://source.unsplash.com/featured/500x500",
"resize": {
"width": "200",
"height": "150",
"withoutEnlargement": "true"
},
"output": {
"quality": "6",
"format": "jpeg"
}
}GET /infer?...
{
"url": "https://source.unsplash.com/featured/500x500",
"resize": {
"width": 200,
"height": 150,
"withoutEnlargement": true
},
"output": {
"quality": 6,
"format": "jpeg"
}
}