Skip to content

Commit

Permalink
Merge pull request #223 from APIs-guru/master
Browse files Browse the repository at this point in the history
Add option to specify max line width.
  • Loading branch information
Vitaly Puzrin committed Nov 23, 2015
2 parents 54e4dc3 + 51fc541 commit 73419ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ options:
- `schema` _(default: `DEFAULT_SAFE_SCHEMA`)_ specifies a schema to use.
- `sortKeys` _(default: `false`)_ - if `true`, sort keys when dumping YAML. If a
function, use the function to sort the keys.
- `lineWidth` _(default: `80`)_ - set max line width.

styles:

Expand Down
9 changes: 8 additions & 1 deletion lib/js-yaml/dumper.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ function State(options) {
this.flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
this.sortKeys = options['sortKeys'] || false;
this.lineWidth = options['lineWidth'] || 80;

this.implicitTypes = this.schema.compiledImplicit;
this.explicitTypes = this.schema.compiledExplicit;
Expand Down Expand Up @@ -256,7 +257,13 @@ function writeScalar(state, object, level, iskey) {
longestLine = 0;

indent = state.indent * level;
max = 80;
max = state.lineWidth;
if (max === -1) {
// Replace -1 with biggest ingeger number according to
// http://ecma262-5.com/ELS5_HTML.htm#Section_8.5
max = 9007199254740991;
}

if (indent < 40) {
max -= indent;
} else {
Expand Down

0 comments on commit 73419ba

Please sign in to comment.