|
1 |
| -# gulp-props2json |
2 |
| -A Gulp plugin to convert Java .properties to JSON |
| 1 | +#[gulp](https://github.com/gulpjs/gulp)-props2json |
| 2 | + |
| 3 | +[](http://badge.fury.io/js/gulp-props2json) |
| 4 | +[](https://travis-ci.org/ValeryIvanov/gulp-props2json) |
| 5 | +[](https://david-dm.org/ValeryIvanov/gulp-props2json) |
| 6 | + |
| 7 | +> A [Gulp](https://github.com/gulpjs/gulp) plugin to convert [Java .properties](http://en.wikipedia.org/wiki/.properties) to [JSON](http://en.wikipedia.org/wiki/JSON) |
| 8 | +
|
| 9 | + |
| 10 | +## Install |
| 11 | + |
| 12 | +```sh |
| 13 | +npm install --save-dev gulp-props2json |
| 14 | +``` |
| 15 | + |
| 16 | +## Usage |
| 17 | + |
| 18 | +Add this to your `gulpfile.js`: |
| 19 | + |
| 20 | +```js |
| 21 | +var props2json = require('gulp-props2json'); |
| 22 | + |
| 23 | +// Generate a .json file |
| 24 | +gulp.src('./src/*.properties') |
| 25 | + .pipe(props2json()) |
| 26 | + .pipe(gulp.dest('./dist/')) |
| 27 | + |
| 28 | +// Generate a .js file |
| 29 | +gulp.src('./src/*.properties') |
| 30 | + .pipe(props({ outputType: 'js' })) |
| 31 | + .pipe(gulp.dest('./dist/')) |
| 32 | +``` |
| 33 | + |
| 34 | + |
| 35 | +## API |
| 36 | + |
| 37 | +### props2json([options]) |
| 38 | + |
| 39 | + |
| 40 | +#### options.outputType |
| 41 | + |
| 42 | +Type: `String` |
| 43 | + |
| 44 | +Default: `json` |
| 45 | + |
| 46 | +Convert properties to `.js` or `.json` format. |
| 47 | + |
| 48 | +**Note**: To force a `.js` output set this option `js` (without dot). |
| 49 | + |
| 50 | + |
| 51 | +#### options.namespace |
| 52 | + |
| 53 | +Type: `String` |
| 54 | + |
| 55 | +Default: `null` for `.json` output and `props` for `.js` output |
| 56 | + |
| 57 | +The namespace to use when defining properties. Javascript reserved words cannot be used here. |
| 58 | +Invalid identifiers will be adjusted to be valid, and a warning will be printed in the console. |
| 59 | + |
| 60 | + |
| 61 | +#### options.minify |
| 62 | + |
| 63 | +Type: `Boolean` |
| 64 | + |
| 65 | +Default: `true` |
| 66 | + |
| 67 | +By default content `.js` and `.json` content is minified. |
| 68 | +If `.json` output is generated and minification is turned off and no space is defined, then indentation with 2 spaces is used. |
| 69 | +This can be overridden with space option. |
| 70 | +[JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_space_argument) |
| 71 | + |
| 72 | + |
| 73 | +#### options.complexTypes |
| 74 | + |
| 75 | +Type: `Boolean` |
| 76 | + |
| 77 | +Default: `false` |
| 78 | + |
| 79 | +By default every property value is treated as `String`. This option will try to convert every value to `JSON`. |
| 80 | +For example (`String`) `"true"` value will be (`Boolean`) `true`. |
| 81 | +[JSON.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) |
| 82 | + |
| 83 | + |
| 84 | +#### options.nestedProps |
| 85 | + |
| 86 | +Type: `Boolean` |
| 87 | + |
| 88 | +Default: `false` |
| 89 | + |
| 90 | +By default every property key will be treated as it is. But nesting is possible to create complex object. |
| 91 | +If this option is turned on, then dot will be used as nesting delimiter. Nesting delimiter can be overridden with `nestingDelimiter` option. |
| 92 | + |
| 93 | + |
| 94 | +#### options.nestingDelimiter |
| 95 | + |
| 96 | +Type: `String` |
| 97 | + |
| 98 | +Default: `.` |
| 99 | + |
| 100 | +Nesting delimiter to be used with `nestedProps` option. |
| 101 | + |
| 102 | + |
| 103 | +#### options.appendExt |
| 104 | + |
| 105 | +Type: `Boolean` |
| 106 | + |
| 107 | +Default: `false` |
| 108 | + |
| 109 | +Append the extension (`.js` or `.json`) instead of replacing it. |
| 110 | + |
| 111 | +_Useful if the property files does not have an extension._ |
| 112 | + |
| 113 | + |
| 114 | +#### options.space |
| 115 | + |
| 116 | +Type: `Number` or `String` |
| 117 | + |
| 118 | +Default: `null` |
| 119 | + |
| 120 | +Control spacing in the resulting output. It has the same usage as for [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) |
| 121 | + |
| 122 | +_The option is used only when `.json` output is generated._ |
| 123 | + |
| 124 | + |
| 125 | +#### options.replacer |
| 126 | + |
| 127 | +Type: `Function` or `Array` |
| 128 | + |
| 129 | +Default: `null` |
| 130 | + |
| 131 | +Further transform the resulting output. It has the same usage as for [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) |
| 132 | + |
| 133 | +_The option is used only when `.json` output is generated._ |
| 134 | + |
| 135 | + |
| 136 | +## Errors |
| 137 | + |
| 138 | +`gulp-props2json` emits an 'error' event if something goes wrong. |
| 139 | + |
| 140 | +To handle errors across your entire pipeline, see the |
| 141 | +[gulp](https://github.com/gulpjs/gulp/blob/master/docs/recipes/combining-streams-to-handle-errors.md#combining-streams-to-handle-errors) documentation. |
| 142 | + |
| 143 | + |
| 144 | +## License |
| 145 | + |
| 146 | +MIT © [Valery Ivanov](https://github.com/ValeryIvanov/) |
0 commit comments