A javascript utility library
This library serves for (students) data visualization projects. It provides some data manipulation functions and other utility functions to make the life of javascript programming a bit easier. It's just a set of convenience functions, not a framework.
In this context "data" always refers to a JSON representation of a table, which is an array of simple objects like:
let superheroes = [
{Name:"A-Bomb", Height:203, Weight:441},
{Name:"Abe Sapien", Height:191, Weight:65},
{Name:"Abin Sur", Height:185, Weight:90},
{Name:"Abomination", Height:203, Weight:441},
{Name:"Absorbing Man", Height:193, Weight:122},
...
]
This kind of JSON is usually generated if you convert a CSV-file to JSON. The original CSV of the example above would look like this:
Name,Height,Weight
A-Bomb,203,441
Abe Sapien,191,65
Abin Sur,185,90
Abomination,203,441
Absorbing Man,193,122
...
We will refer to the column titles (e.g. Name
, Height
, Weight
) as properties or props and to the rows as data objects or entries.
Either copy ./src/gmynd.js
to your project folder or install it in any node.js project:
npm install gmynd
Load the functions into your node script:
const gmynd = require("gmynd");
sortData(data, props)
groupData(data, props)
-> object
cumulateData(data, props, [calculations])
-> newData
mergeData(data1, data2, prop1, [prop2])
-> newData
intersectData(baseData, filterData, prop1, [prop2])
-> newData
findAllByValue(data, prop, val)
-> newData
findFirstByValue(data, prop, val)
-> object
deleteIncompleteData(data, props, [emptyValues])
-> newData
deleteDuplicateData(data, prop, [keepFirst])
-> newData
filterPropType(data, prop, allowedType)
-> newData
convertPropToNumber(data, prop, [nullNaNs])
-> newData
convertPropToBoolean(data, prop, [strictMode])
-> newData
addPropPercentage(data, prop, [propName])
-> newData
addPropSegment(data, prop, segmentCount, [start], [end], [propName])
-> newData
addPropRank(data, prop, [propName])
-> newData
arrayFromProps(obj, props, [fallbackVal])
-> array
arrayFromPropsInData(arr, props, propName, [deleteProps], [fallbackVal])
-> newData
renameProps(data, props, names)
-> newData
(or obj
-> newObj
)deleteProps(data, props)
-> newData
(or obj
-> newObj
)dataMin(data, prop)
-> number
dataMax(data, prop)
-> number
dataExtremes(data, prop)
-> object
dataSum(data, prop)
-> number
saveData(data, [filename], [pretty])
arraySum(arr)
-> number
arrayCount(arr, val)
-> number
arrayAverage(arr, [ignoreEmpty])
-> number
arrayLast(arr, [ignoreEmpty])
-> someValue
shuffleArray(arr)
-> array
map(value, low1, high1, low2, high2, [clipping])
-> number
lerp(value1, value2, t)
-> number
clip(value, min, max)
-> number
random(low, high)
-> number
randomInt(low, high)
-> number
radians(degree)
-> number
degrees(radians)
-> number
distance(x1, y1, x2, y2)
-> number
cartesian(radius, angle)
-> object
polar(x, y)
-> object
circleRadius(area)
-> number
circleArea(radius)
-> number
range(start, stop, [step])
-> array
duration(date1, date2)
-> number
weekOfYear(date, [returnYear])
-> number
or array
dayOfYear(date)
-> number
isString(value)
-> boolean
isArray(value)
-> boolean
isObject(value)
-> boolean
version()
-> string
Example data from
https://www.kaggle.com/dannielr/marvel-superheroes
https://ourworldindata.org/age-structure
https://ourworldindata.org/gender-ratio
Suggestions? Bugs? File an issue! :)