UNPKG

3.66 kBMarkdownView Raw
1# finepack
2
3![Last version](https://img.shields.io/github/tag/Kikobeats/finepack.svg?style=flat-square)
4[![Build Status](https://img.shields.io/travis/Kikobeats/finepack/master.svg?style=flat-square)](https://travis-ci.org/Kikobeats/finepack)
5[![Coverage Status](https://img.shields.io/coveralls/Kikobeats/finepack.svg?style=flat-square)](https://coveralls.io/github/Kikobeats/finepack)
6[![Dependency status](https://img.shields.io/david/Kikobeats/finepack.svg?style=flat-square)](https://david-dm.org/Kikobeats/finepack)
7[![Dev Dependencies Status](https://img.shields.io/david/dev/Kikobeats/finepack.svg?style=flat-square)](https://david-dm.org/Kikobeats/finepack#info=devDependencies)
8[![NPM Status](https://img.shields.io/npm/dm/finepack.svg?style=flat-square)](https://www.npmjs.org/package/finepack)
9
10> Organizes and maintains your JSON files readable.
11
12![](http://i.imgur.com/2qNLC48.png)
13
14**Finepack** is a tool to keep your JSON files organized, especially if you are creating an open source project and want to be sure that your files have all the information that is required or recommended by the main package management systems (like bower or npm). This is what it can do:
15
16- Lints the JSON to be sure that it is in a valid format.
17- Validates the keys to make sure of the existence of required keys such as `name` or `version`, and other important keys such as `homepage`, `main`, `license`...
18- Organizes the JSON by moving the most important properties to the top.
19- Sorts the rest of the keys alphabetically and recursively using the JavaScript [sort](https://mzl.la/1jBtmgE) function (elements are sorted by converting them to strings and comparing strings in Unicode code point order).
20- Can be configured not to sort the arrays or objects at one or more user specified keys.
21- Can use a user-provided compare function to define the sort order.
22
23You can use **Finepack** as a CLI tool or from NodeJS as a library. Based on [fixpack](https://github.com/henrikjoreteg/fixpack) but with a little more ♥.
24
25## Install
26
27```bash
28npm install finepack -g
29```
30
31## Usage
32
33### CLI
34
35```
36$ finepack
37
38 Organizes and maintains your JSON files readable.
39
40 Usage
41 $ finepack <fileJSON> [options]
42
43 options:
44 --no-validate disable validation mode.
45 --no-color disable colors in the output.
46 --sort-ignore-object-at don't sort object(s) at these comma separated key(s).
47 --sort-ignore-array-at don't sort array(s) at these comma separated key(s).
48 --version output the current version.
49
50 examples:
51 finepack package.json
52 finepack bower.json --no-validate
53```
54
55### API
56
57To use **Finepack** inside your NodeJS project, just install it as a normal dependency.
58
59```js
60const fs = require('fs')
61const path = require('path')
62const finepack = require('finepack')
63const filepath = path.resolve('./package.json')
64const filename = path.basename(filepath)
65const filedata = fs.readFileSync(filepath, { encoding: 'utf8' })
66
67const options = {
68 filename: filename, // To customize the output messages, but it is not necessary.
69 validate: false, // To enable (or not) keys validation (false by default).
70 color: false, // To enable (or not) the colorization of the output (false by default).
71 sortOptions: {
72 // Here you can set the options supported by the sort module that is used internally.
73 // SEE: https://github.com/Kikobeats/sort-keys-recursive#options
74 }
75}
76
77finepack(filedata, options, function (err, output, messages) {
78 if (err) throw err
79 // if your JSON is malformed then you have an err
80})
81```
82
83## License
84
85MIT © [Kiko Beats](http://www.kikobeats.com)