UNPKG

array-to-archy

Version:

Convert an array to object structure representation which can be used to archy.

16 lines (12 loc) 360 B
'use strict' const arrayToArchy = (arr, label) => { const _label = label || '--' if(!Array.isArray(arr)) return 'Data is not type array' return { label: _label, nodes: arr.map( (item) => Array.isArray(item) ? arrayToArchy(item, _label) : item.toString() ) } } module.exports = arrayToArchy