Code Monkey home page Code Monkey logo

sf-xml-vscode's Introduction

Salesforce XML Beautifier

This extension formats Salesforce XML files more meaningfully to improve readability and minimize changes.

This extension is powered by the xml2js library with some customizations to implement file-specific indentation requirements, special characters escaping, and a newline character at the end of the XML file.

Algorithm

The sorting algorithm is custom comparator-based sort tailored for Salesforce XML files. This algorithm is inspired by the SwagUp.sf-xml-formatter sorting algorithm using a similar sorting approach.

Overview

  1. Identify Type: Determine if the input is a primitive value (number, string, etc.), an array, or an object.
  2. Generate Identifiers:
    • For primitive values, convert the value to a string.
    • For arrays, recursively generate identifiers for each element and combine them into a single identifier.
    • For objects, recursively generate identifiers for each key-value pair, using a specified set of relevant keys if provided, and combine them into a single identifier.
  3. Custom Comparison: Compare two elements by their generated identifiers to determine their sort order.
  4. Recursive Sorting:
    • For arrays, recursively sort each element and then sort the array based on the custom comparison.
    • For objects, recursively sort the values of each key and create a new object with the sorted keys.
      • Sorted keys are defined in the mappedKeys option in the sortConfig.ts file.
      • Unsorted keys are defined in the unmappedKeys option in the sortConfig.ts file.

It also handles special characters in string values, such as apostrophes, which are escaped when formatted. The algorithm also inserts a newline characters at the end of the XML file.

sf-xml-vscode's People

Contributors

dmoruzzi avatar

Watchers

 avatar  avatar

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.