Coder Social home page Coder Social logo

Comments (7)

scriptcoded avatar scriptcoded commented on August 29, 2024 4

I'm modifying config files for another program using this library, and I'd ideally want to stay true to their formatting, and they don't use underscores. Also, I can see a few cases where underscores might be confusing, such as with port numbers. It's a great feature for readability, but I don't think toggling it would be a bad idea.

from iarna-toml.

iarna avatar iarna commented on August 29, 2024 2

I'm honestly surprised that you think it would be more editable/readable without separators. That said, using thousands separators versus ten thousand separators betrays my biases.

I'm hesitant to add configuration to the stringifier, but I have to admit that this is probably the place for it.

from iarna-toml.

dsolanorush avatar dsolanorush commented on August 29, 2024 1

@scriptcoded - All fair points. I went ahead and forked the @nuxtjs/netlify-files repo and applied a simple regex replace to the stringified TOML output. Quick and dirty, but works well for my specific use case.

from iarna-toml.

dsolanorush avatar dsolanorush commented on August 29, 2024

@iarna This package is being used in @nuxtjs/netlify-files to stringify the netlify.toml config, and it completely breaks things due to the addition of underscores for things like port numbers and dimensions. I see this has been around for 2+ years at this point, but is there any chance this could be made configurable as others have suggested?

from iarna-toml.

scriptcoded avatar scriptcoded commented on August 29, 2024

(whoa it sure was a while ago I was active here 😅)

@iarna I'm looking through the code to see if I could create a simple PR for adding options to the stringify function, but seeing as that part of the library consists of 25 different stringifier functions calling each other recursively, it would result in a lot of passing around of that options object.

One idea I have to solve this would be to have a Stringifier class (seeing as classes are already being used in the code base) that sets the configuration in the constructor. The public API could still remain the same, with TOML.stringify and TOML.stringify.value simply instantiating a new Stringifier and executing the appropriate method on that instance. The Stringifier class could of course optionally also be exported, though I'm not sure this would be necessary.

What are your thoughts? Keep it fully functional and pass around config? Convert to class? Maybe even skip implementing options altogether?

from iarna-toml.

dsolanorush avatar dsolanorush commented on August 29, 2024

I suppose a good question would be: what's the benefit of injecting the underscore as a thousands separator? Simply for improved readability? Seems like altering a value during conversion wouldn't be a desired (nor expected) effect in the first place. Certainly was not expected in my case.

That said, sounds like @scriptcoded has a reasonable suggestion with the class approach.

from iarna-toml.

scriptcoded avatar scriptcoded commented on August 29, 2024

@dsolanorush Yup, I agree that having no separator by default would make a lot of sense. In a perfect would I'd argue formatting should be kept upon parsing and stringification, but unfortunately that's practically impossible if you want the parsed output to be a simple object representing only the data contained. I think #42 has some relevant information regarding that topic.

All that being said, removing the separator from the formatted output could mess with other dependents, just as it does in reverse for @nuxtjs/netlify-files. It is a public API after all. To me the change seems too minor to justify a major version bump. Maybe it can be kept in mind for a future breaking release.

from iarna-toml.

Related Issues (20)

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.