wishthis/node_modules/yamljs/lib/Dumper.js
2022-01-21 09:28:41 +01:00

53 lines
1.8 KiB
JavaScript

// Generated by CoffeeScript 1.12.4
var Dumper, Inline, Utils;
Utils = require('./Utils');
Inline = require('./Inline');
Dumper = (function() {
function Dumper() {}
Dumper.indentation = 4;
Dumper.prototype.dump = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) {
var i, key, len, output, prefix, value, willBeInlined;
if (inline == null) {
inline = 0;
}
if (indent == null) {
indent = 0;
}
if (exceptionOnInvalidType == null) {
exceptionOnInvalidType = false;
}
if (objectEncoder == null) {
objectEncoder = null;
}
output = '';
prefix = (indent ? Utils.strRepeat(' ', indent) : '');
if (inline <= 0 || typeof input !== 'object' || input instanceof Date || Utils.isEmpty(input)) {
output += prefix + Inline.dump(input, exceptionOnInvalidType, objectEncoder);
} else {
if (input instanceof Array) {
for (i = 0, len = input.length; i < len; i++) {
value = input[i];
willBeInlined = inline - 1 <= 0 || typeof value !== 'object' || Utils.isEmpty(value);
output += prefix + '-' + (willBeInlined ? ' ' : "\n") + this.dump(value, inline - 1, (willBeInlined ? 0 : indent + this.indentation), exceptionOnInvalidType, objectEncoder) + (willBeInlined ? "\n" : '');
}
} else {
for (key in input) {
value = input[key];
willBeInlined = inline - 1 <= 0 || typeof value !== 'object' || Utils.isEmpty(value);
output += prefix + Inline.dump(key, exceptionOnInvalidType, objectEncoder) + ':' + (willBeInlined ? ' ' : "\n") + this.dump(value, inline - 1, (willBeInlined ? 0 : indent + this.indentation), exceptionOnInvalidType, objectEncoder) + (willBeInlined ? "\n" : '');
}
}
}
return output;
};
return Dumper;
})();
module.exports = Dumper;