Skip to content

Commit

Permalink
Mark stringify now omits comma.
Browse files Browse the repository at this point in the history
  • Loading branch information
henry-luo committed Dec 11, 2018
1 parent b6c85fe commit 9661501
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions mark.js
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,7 @@ MARK.parse = (function() {
// Mark stringify will not quote keys where appropriate
MARK.stringify = function(obj, options) {
"use strict";

var indentStep, indentStrs, space, omitComma;
let indentStep, indentStrs, space; // omitComma;

function indent(num, noNewLine) {
if (num >= indentStrs.length) { // expand the cached indent strs
Expand All @@ -875,7 +874,7 @@ MARK.stringify = function(obj, options) {

// option handling
if (options) {
omitComma = options.omitComma;
// omitComma = options.omitComma;
space = options.space;
indentStrs = [''];
if (space) {
Expand Down Expand Up @@ -984,7 +983,7 @@ MARK.stringify = function(obj, options) {
buffer += res;
}
if (i < value.length-1) {
buffer += omitComma ? ' ':',';
buffer += ' '; // omitComma ? ' ':',';
} else if (indentStep) {
buffer += "\n";
}
Expand Down Expand Up @@ -1072,7 +1071,8 @@ MARK.stringify = function(obj, options) {
let res = _stringify(value[prop]);
if (res !== undefined) {
let key = MARK.isName(prop) ? prop : escapeString(prop);
buffer += (hasAttr ? (omitComma ? ' ':', '):(nonEmpty ? ' ':''))+ key +":"+ res;
buffer += (hasAttr ? ' ' // (omitComma ? ' ':', ')
:(nonEmpty ? ' ':''))+ key +":"+ res;
hasAttr = true; nonEmpty = true;
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/stringify-mark.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function stringArrayBuffer(str) {

test('Stringify JSON object', function(assert) {
assert.equal(Mark.stringify(Mark.parse(`{a:12.4, b:true, c:false, d:'str', e:null, g:1, h:[1,2,3], i:-12, j:[], k:{}, l:'', m:"", n:0, p:1e-2}`)),
`{a:12.4, b:true, c:false, d:"str", e:null, g:1, h:[1,2,3], i:-12, j:[], k:{}, l:"", m:"", n:0, p:0.01}`, "Stringify JSON object");
`{a:12.4 b:true c:false d:"str" e:null g:1 h:[1 2 3] i:-12 j:[] k:{} l:"" m:"" n:0 p:0.01}`, "Stringify JSON object");
assert.end() ;
});

Expand All @@ -27,19 +27,19 @@ test('Stringify Mark object', function(assert) {
// undefined value handling
var t = {obj:undefined};
assert.equal(Mark.stringify(t), '{}', "Stringify undefined property");
assert.equal(Mark.stringify([1, null, undefined]), '[1,null,null]', "Stringify undefined value in array");
assert.equal(Mark.stringify([1, null, undefined]), '[1 null null]', "Stringify undefined value in array");
// JSON inside Mark
assert.equal(Mark.stringify(Mark.parse('{div {width:10}}')), '{div {width:10}}', "Stringify {div {width:10}}");
// stringify with identation
assert.equal(Mark.stringify(Mark.parse('{div width:10 (!--comment--) "test" {br}}'), {space:' '}), '{div width:10 \n (!--comment--) \n "test" \n {br}\n}', "Stringify with identation");
// stringify omitting comma
assert.equal(Mark.stringify(Mark.parse('{div width:10 height:"15px" margin:[5 10 10 5]}'), {omitComma:true}), '{div width:10 height:"15px" margin:[5 10 10 5]}', "Stringify without comma");
assert.equal(Mark.stringify(Mark.parse('{div width:10, height:"15px", margin:[5 10 10 5]}')), '{div width:10 height:"15px" margin:[5 10 10 5]}', "Stringify without comma");

// stringify base64 data
assert.equal(Mark.stringify(stringArrayBuffer('Hello')), '{:SGVsbG8=}', "Stringify binary data 'hello'");
assert.equal(Mark.stringify(stringArrayBuffer('Hello worlds!')), '{:SGVsbG8gd29ybGRzIQ==}', "Stringify binary data 'Hello worlds!'");
var doc = Mark('doc', {mime:'text/html', data:stringArrayBuffer("<h1>Mark binary!</h1>")});
assert.equal(Mark.stringify(doc), '{doc mime:"text/html", data:{:PGgxPk1hcmsgYmluYXJ5ITwvaDE+}}', "Stringify nested binary data");
assert.equal(Mark.stringify(doc), '{doc mime:"text/html" data:{:PGgxPk1hcmsgYmluYXJ5ITwvaDE+}}', "Stringify nested binary data");

// stringify base85 data
var bin = stringArrayBuffer('hello'); bin.encoding = 'a85';
Expand Down

0 comments on commit 9661501

Please sign in to comment.