Git Product home page Git Product logo

pretty-data's People

Contributors

dordille avatar legomushroom avatar vkiryukhin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pretty-data's Issues

JSON pretty-printer doesn't handle strings well

This value
{"key": "{ "string": "that looks like json" }"}

Should print like:

{
    "key": "{ \"string\": \"that looks like json\" }"
}

But looks like this instead

{
    "key": "
    {
        \"string\": \"that looks like json\" 
    }"
}

Why not just use the pretty-printer that's built into the language? I don't see any advantage to the regex over the native prettifier.

JSON.stringify(JSON.parse(str), null, '  ');

Global leak of maxdeep and ix still in 0.40.0 on npm

If you install pretty-data via npm, it still contains the global leak that was fixed in 7131e11. pretty-data needs a version bump and a publish to npm that actually contains the fix, as it will cause any unit testing that looks for global leaks to fail.

XML: Indentation is wrong after self closing tag

The prettify works great until it meets self closing tag.

Seems the module treats the self closing tag as an ordinary open tag. The immediate tag following it will be unnecessarily indented.

Affected version: 0.40.1

Expected result:

<body rid="1534525716" 
  xmlns="http://jabber.org/protocol/httpbind" sid="2c944b0e-b4a2-4bde-ab49-18f5e6527a72">
  <message to="[email protected]" type="chat" 
    xmlns="jabber:client">
    <active 
      xmlns="http://jabber.org/protocol/chatstates"/>
  </message>
  <message from="[email protected]" to="[email protected]" type="chat" 
    xmlns="jabber:client" id="[email protected]:1462355916836">
    <active 
      xmlns="http://jabber.org/protocol/chatstates"/>
    <body>1</body>
    <request 
      xmlns="urn:xmpp:receipts"/>
    <request 
      xmlns="urn:maaii:receipts:server"/>
  </message>
</body>

Actual result:

<body rid="1534525716" 
  xmlns="http://jabber.org/protocol/httpbind" sid="2c944b0e-b4a2-4bde-ab49-18f5e6527a72">
  <message to="[email protected]" type="chat" 
    xmlns="jabber:client">
    <active 
      xmlns="http://jabber.org/protocol/chatstates"/>
    </message>
    <message from="[email protected]" to="[email protected]" type="chat" 
      xmlns="jabber:client" id="[email protected]:1462355916836">
      <active 
        xmlns="http://jabber.org/protocol/chatstates"/>
        <body>1</body>
        <request 
          xmlns="urn:xmpp:receipts"/>
          <request 
            xmlns="urn:maaii:receipts:server"/>
          </message>
        </body>

Newlines are not trimmed in xmlmin

See test:

it('should trim xml input', function () {
  var xml = '\n<a>data</a>\n';
  var result = pd.xmlmin(xml);
  expect(result).toBe('<a>data</a>');
});

It doesn't pass because xmlmin doesn't trim newline characters.

XML pretty-print: Several pretty-print runs create additional newlines in each run

It's due to the namespace attribute: if a XML file contains a namespace attribute then each iteration of a pretty-print run adds a newline \n to the result file. I've adjusted the pretty-data/test/test_xml.js to show the issue:

var xml = '<?xml version="1.0" encoding="UTF-8" ?>      <!DOCTYPE foo SYSTEM "Foo.dtd"><a>          <b>bbb</b>   <!-- comment --><c/><d><soapenv:Envelope xmlns:soapenv="http://xxx" xmlns:xsd="http://yyy" xmlns:xsi="http://zzz"></soapenv>       </d><e>        <![CDATA[ <z></z> ]]></e><f><g></g></f></a>';
var pp_xml  = require('../pretty-data').pd.xml(xml);
var pp2_xml  = require('../pretty-data').pd.xml(pp_xml);
var pp3_xml  = require('../pretty-data').pd.xml(pp2_xml);

console.log('\n==============================================================================\n');
console.log('\n/*------- Original XML string: -------*/\n\n' + xml + '\n');
console.log('\n/*------- Beautified XML -------------*/\n\n' + pp_xml  + '\n');
console.log('\n/*------- Beautified twice XML -------------*/\n\n' + pp2_xml  + '\n');
console.log('\n/*------- Beautified 3 times XML -------------*/\n\n' + pp3_xml  + '\n');
console.log('\n===============================================================================\n');

Result:

/*------- Beautified XML -------------*/

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE foo SYSTEM "Foo.dtd">
<a>
  <b>bbb</b>
  <!-- comment -->
  <c/>
  <d>
    <soapenv:Envelope
      xmlns:soapenv="http://xxx"
      xmlns:xsd="http://yyy"
      xmlns:xsi="http://zzz">
    </soapenv>
  </d>
  <e>
    <![CDATA[ <z></z> ]]>
  </e>
  <f>
    <g></g>
  </f>
</a>


/*------- Beautified twice XML -------------*/

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE foo SYSTEM "Foo.dtd">
<a>
  <b>bbb</b>
  <!-- comment -->
  <c/>
  <d>
    <soapenv:Envelope

      xmlns:soapenv="http://xxx"

      xmlns:xsd="http://yyy"

      xmlns:xsi="http://zzz">
    </soapenv>
  </d>
  <e>
    <![CDATA[ <z></z> ]]>
  </e>
  <f>
    <g></g>
  </f>
</a>


/*------- Beautified 3 times XML -------------*/

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE foo SYSTEM "Foo.dtd">
<a>
  <b>bbb</b>
  <!-- comment -->
  <c/>
  <d>
    <soapenv:Envelope


      xmlns:soapenv="http://xxx"


      xmlns:xsd="http://yyy"


      xmlns:xsi="http://zzz">
    </soapenv>
  </d>
  <e>
    <![CDATA[ <z></z> ]]>
  </e>
  <f>
    <g></g>
  </f>
</a>

I expect that the 2nd and 3rd application of the pretty-print to this XML does not change the XML anymore. One application should be sufficient.

I've found this issue in version 0.40.0.

JSON broken with special strings ~#~

The current JSON beautifier implementation relies on special strings used in regular expressions.
This makes it not generic as shown by the following test case.

Test case:
{ "a~#~{~#~b": "a~#~{~#~b" }

Currently broken output:

{
    "a~#~
    {
        ~#~b":"a~#~
        {
            ~#~b"
        }

JSON minifying is too aggressive and alters strings

If you use characters like square brackets ([]) or curly braces ({}) within a string, the surrounding whitespaces will be trimmed even tho strings shouldn't be altered.
e.g.

const s = '{ "foo": " {{ bar }} " }'
pd.jsonmin(s)
// '{"foo":"{{bar}}"}'

When minifying json with strings containing brackets, spaces are trimmed

Hi there!
I've played around with gulp-pretty-data which wraps this library and I found an issue when minifying json files when a string contains brackets like this:

{
  "welcome": "text before {{variable}} text after"
}

Is converted to:

{"welcome":"text before{{variable}}text after"}

Instead of (note spaces between {{variable}}):

{"welcome":"text before {{variable}} text after"}

Is there a way to fix this? I've created an issue on gulp plugin, but I agree with author that the issue should be created here.

Thank you!

Invalid new line inserted in CDATA block

For some reason the following code will lead to extra new line:

var prettyData = require("pretty-data")
console.log(prettyData.pd.xml("<foo><![CDATA[X\n<? <]]></foo>"));

This should format as

<foo>
  <![CDATA[X
<? <]]>
</foo>

but instead formats as

<foo>
  <![CDATA[X

<? <]]>
</foo>

Variables not defined well for ES6

Changes required:

As you can see maxdeep and ix need to be setup a little better. No big deal.

function pp() {
this.shift = ['\n']; // array of shifts
this.step = ' ', // 2 spaces
this.maxdeep = 100; // nesting level
var ix = 0;

// initialize array with shifts //
for(ix=0;ix<this.maxdeep;ix++){
	this.shift.push(this.shift[ix]+this.step); 
}

};

XML namespaces gets double newlines

First off, a major THANKS for your module. It is super useful!

<StandardBusinessDocument
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader">

Running this through:

const formattedXml = pd.xml(xmlOut);
 console.log(formattedXml);

Gives:

<StandardBusinessDocument
  
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xmlns="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader">

This might not be against XML specifications per se but it is not very "pretty"....

XML: Minify does strip whitespace within element

pretty-data currently does not seem to strip whitespace within XML Elements.

Example:

<Something xmlns="a.b.c"
        xmlns:a="a.b.c.d"
        xmlns:b="a.b.c.d.e.f.g">
</Something>

ends up as:

<Something xmlns="a.b.c"
        xmlns:a="a.b.c.d"
        xmlns:b="a.b.c.d.e.f.g"></Something>

instead of

<Something xmlns="a.b.c" xmlns:a="a.b.c.d" xmlns:b="a.b.c.d.e.f.g"></Something>

I can't see any valid restriction on this. Should be savely possible.

BR
Chris

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.