data manipulation utility
npm install mangler --save
var mangler = require("mangler")
converts an array of objects into a map with key present in those objects
var input = [
{id: 1, val:20},
{id: 1, val:30},
{id: 2, val:40}
]
mangler.mapify(input, "id")
{
1: {id: 1, val:30},
2: {id: 2, val:40}
}
clusters objects with the same keys into arrays
var input = [
{id: 1, val:20},
{id: 1, val:30},
{id: 2, val:40}
]
mangler.arrayMapify(input, "id")
{
1: [
{id: 1, val:20},
{id: 1, val:30}
],
2: [{id: 2, val:40}]
}
removes floating point rounding error
console.log(0.2 + 0.1) // 0.30000000000000004
console.log(mangler.fixed(0.2 + 0.1)) // 0.3
removes properties from an array of objects
var input = [
{
"object": "value",
"killme": true,
"zapme": "yes"
},
{
"object": "value",
"killme": true
}
]
var result = mangler.delProps(input, ["killme", "zapme"])
[
{"object": "value"},
{"object": "value"}
]
returns sanitized string
var result = mangler.sanitizeString("<script>alert(' c&tch n\"')</script>");
"<script>alert(' c&tch n"')</script>"
returns unsanitized string
var result = mangler.unsanitizeString("<script>alert(' c&tch n"')</script>");
"<script>alert(' c&tch n\"')</script>"