https://github.com/roppa/mr-lister
https://github.com/roppa/mr-lister
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/roppa/mr-lister
- Owner: roppa
- Created: 2016-06-07T21:18:11.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-08T08:52:20.000Z (almost 10 years ago)
- Last Synced: 2024-12-07T09:27:21.377Z (over 1 year ago)
- Language: JavaScript
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#Lister
[](https://travis-ci.org/roppa/lister)
##Convert a POJO, Array, or JSON object into an html or markdown list
This started as a template helper - taking a nested JSON object and presenting it as an unordered list.
Mr Lister is a function, that takes a value and an optional config object:
```
lister(value[, options])
```
##Example
```
let lister = require('mr-lister');
let myObject = { a: 1, b: 2, c: { aa: 1.1, bb: 2.2, cc: { aaa: 3.3 } } };
process.stdout.write(myObject);
```
Which would print out a nested HTML unordered list, with key/values separated with a colon:
```
- a: 1
- b: 2
- c:
- aa: 1.1
- bb: 2.2
- cc:
- aaa: 3.3
```
Config example:
```
{
format: 'ol',
ulClass: 'my-ul-class'
liClass: 'my-li-class'
}
```
Format can be ul (default), ol, or md for markdown.
An 'ulClass' can be specified for a class to be added to each ul, ol.
An 'liClass' can be specified for a class to be added to each li.
Classes used with markdown are ignored.
##Testing
Just run ```mocha```.