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