GithubHelp home page GithubHelp logo

vsc-sort-json-array's Introduction

Sort JSON array

Sorts a json/js array by common property or by custom function and replace the array in-place. Also works for numbers and string arrays. Nested objects and mixed arrays are only supported by custom function.

Demo

  • Sort array of objects ascending or descending by one or more properties to produce a deterministic sort result:
    Sort by property

  • Sort array using custom function:
    Sort by custon function

  • Manage sort modules:
    Sort by custon function

Features

Selecting an array works well with the editor.action.smartSelect.grow keyboard shortcut or a simliar expand-selection shortcut.

Sort number, string or object arrays

String arrays are sorted using the lexicographic order. Number arrays are sorted based on their value. Objects are sorted based on one or more properties. The program will ask until the sort is deterministic. There is command for ascending and descending sort.

Custom sort

Custom sort opens the sort module in another tab. The sort module must be a valid typescript module that exports a sort(a, b): number function. Typing of a and b can be arbitrary. Every time the module is saved, it will be evaluted and applied to the selected array. A preview of the sort function applied to the current array will be displayed in the output view. Any error in the sort module will be displayed as error message. When the sort module (= tab) is closed, it will be applied to the array of the file where the command was triggered.

For older vscode versions: Opening the sort module in another tab only works properly if preview mode is disabled. Set workbench.editor.enablePreview to false. There is also some simple module management, including delete and rename functionality. New sort module will always be named sort.xx.ts.

Technical: Sort modules are stored in the global storage path location for this extension. This is a folder in your vs code config location.

vsc-sort-json-array's People

Contributors

fvclaus avatar

Watchers

James Cloos 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.