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/str-match.svg?style=flat-square)](https://www.npmjs.org/package/str-match)
|
9 | [![Donate](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square)](https://paypal.me/Kikobeats)
|
10 |
|
11 | > Organizes and maintains your JSON files readable.
|
12 |
|
13 | ![](http://i.imgur.com/2qNLC48.png)
|
14 |
|
15 | **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:
|
16 |
|
17 | - Lints the JSON to be sure that it is in a valid format.
|
18 | - 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`...
|
19 | - Organizes the JSON by moving the most important properties to the top.
|
20 | - 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).
|
21 | - Can be configured not to sort the arrays or objects at one or more user specified keys.
|
22 | - Can use a user-provided compare function to define the sort order.
|
23 |
|
24 | You 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 ♥.
|
25 |
|
26 | ## Install
|
27 |
|
28 | ```bash
|
29 | npm install finepack -g
|
30 | ```
|
31 |
|
32 | ## Usage
|
33 |
|
34 | ### CLI
|
35 |
|
36 | ```
|
37 | $ finepack
|
38 |
|
39 | Organizes and maintains your JSON files readable.
|
40 |
|
41 | Usage
|
42 | $ finepack <fileJSON> [options]
|
43 |
|
44 | options:
|
45 | --no-validate disable validation mode.
|
46 | --no-color disable colors in the output.
|
47 | --sort-ignore-object-at don't sort object(s) at these comma separated key(s).
|
48 | --sort-ignore-array-at don't sort array(s) at these comma separated key(s).
|
49 | --version output the current version.
|
50 |
|
51 | examples:
|
52 | finepack package.json
|
53 | finepack bower.json --no-validate
|
54 | ```
|
55 |
|
56 | ### API
|
57 |
|
58 | To use **Finepack** inside your NodeJS project, just install it as a normal dependency.
|
59 |
|
60 | ```js
|
61 | const fs = require('fs')
|
62 | const path = require('path')
|
63 | const finepack = require('finepack')
|
64 | const filepath = path.resolve('./package.json')
|
65 | const filename = path.basename(filepath)
|
66 | const filedata = fs.readFileSync(filepath, {encoding: 'utf8'})
|
67 |
|
68 | const options = {
|
69 | filename: filename, // To customize the output messages, but it is not necessary.
|
70 | validate: false, // To enable (or not) keys validation (false by default).
|
71 | color: false, // To enable (or not) the colorization of the output (false by default).
|
72 | sortOptions: {
|
73 | // Here you can set the options supported by the sort module that is used internally.
|
74 | // SEE: https://github.com/Kikobeats/sort-keys-recursive#options
|
75 | }
|
76 | }
|
77 |
|
78 | finepack(filedata, options, function (err, output, messages) {
|
79 | if (err) throw err
|
80 | // if your JSON is malformed then you have an err
|
81 | })
|
82 | ```
|
83 |
|
84 | ## License
|
85 |
|
86 | MIT © [Kiko Beats](http://www.kikobeats.com)
|