GithubHelp home page GithubHelp logo

benjycui / jsonml.js Goto Github PK

View Code? Open in Web Editor NEW
11.0 11.0 8.0 19 KB

JsonML-related tools for losslessly converting between XML/HTML and JSON, including mixed-mode XML. http://jsonml.org

License: MIT License

JavaScript 100.00%

jsonml.js's People

Contributors

benjycui avatar pgoldrbx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jsonml.js's Issues

utils.appendChild mutates child fragment

When calling utils.appendChild with a child fragment, the fragment is mutated, resulting in an empty array.

const jml = ['div'];
const fragment = ['', 'hello world'];
utils.appendChild(jml, fragment);
// jml === ['div', 'hello world']
// fragment === []

Ideally, the fragment should not be mutated.
See discussion: #5 (comment)

isRaw is undefined when calling utils.appendChild

Original comments: #5 (comment)

Calling utils.appendChild with a raw element throws an error.

const html = require('jsonml.js/lib/html');
const utils = require('jsonml.js/lib/utils');

const jml = ['div']
const rawEl = html.raw('foo');
utils.appendChild(jml, rawEl); // TypeError: exports.isRaw is not a function

Indeed, exports.isRaw is not defined within utils.js. It is, however, defined within html.js. So, the fix should be fairly straightforward.

Why does utils.appendChild allow an empty parent array?

When writing tests for the utils methods, I came across some logic that was confusing:
https://github.com/benjycui/jsonml.js/blob/master/lib/utils.js#L132

} else if (child || !parent.length) {
  // append
  parent.push(child);

This allows for some unclear behavior, particularly when allowing exception for a parent with no length.

  1. append a child to an empty parent array
const jml = [];
utils.appendChild(jml, '');
// jml === ['']
const jml = []; 
utils.appendChild(jml, ['p', 'hello']);
// jml === [ ['p', 'hello'] ]

Is this a real use case or an edge case bug? I'm guessing this would never be desired and should probably not be allowed.

Open to contribution?

Hey @benjycui,

I'm using this module in some libraries and applications and it's been helpful. I'd like to contribute back and help with the maintenance of the project. Are you accepting contributions at this time? Where is the best place to begin? It looks like there's a need for complete test coverage, eslint cleanup, and documentation. If you're interested, we could begin opening issues to track this work.

I've gone ahead and opened a few PRs that should help move things along:

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.