Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joycollector/groovy-beautify
A simple beautifier which allows formatting and indenting Groovy scripts
https://github.com/joycollector/groovy-beautify
Last synced: 3 months ago
JSON representation
A simple beautifier which allows formatting and indenting Groovy scripts
- Host: GitHub
- URL: https://github.com/joycollector/groovy-beautify
- Owner: joycollector
- License: mit
- Created: 2022-06-25T07:56:12.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-08T20:05:08.000Z (almost 2 years ago)
- Last Synced: 2024-08-07T07:39:27.911Z (3 months ago)
- Language: TypeScript
- Size: 865 KB
- Stars: 9
- Watchers: 1
- Forks: 5
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.MD
Awesome Lists containing this project
README
# groovy-beautify
A simple zero-dependency beautifier which allows formatting and indenting Groovy scripts
# Demo
You can test how it works on the [Demo Website](https://groovy-beautify-web.vercel.app/)
# Installation
npm install groovy-beautify
# Usage
import groovyBeautify from "groovy-beautify";
const groovy = `
def bumpVersion(String target, String version_type, Boolean reset = false) { def
versionMap =
['major':0, 'minor' : 1, 'patch': 2]
def versionArray = target.findAll(/\d+\.\d+\.\d+/)[0].tokenize('.')
try
{ def index = versionMap.get(version_type);
versionArray[index] =versionArray[index].toInteger() + 1
if( reset )
{
for(int i=2;i>index; i--) {
versionArray[i] = 0 } }
} catch( Exception e) { println("Unrecognized version type \\"version_type\\" (should be major, minor or patch)") }
return versionArray.join( '.' )
}
println(bumpVersion('1.2.3', 'minor', true))
`;const formatted = groovyBeautify(groovy);
This will produce the following output
def bumpVersion(String target, String version_type, Boolean reset = false) {
def versionMap = ['major': 0, 'minor': 1, 'patch': 2]
def versionArray = target.findAll(/d+.d+.d+/)[0].tokenize('.')
try {
def index = versionMap.get(version_type);
versionArray[index] = versionArray[index].toInteger() + 1
if (reset)
{
for (int i = 2; i > index; i--) {
versionArray[i] = 0
}
}
} catch (Exception e) {
println("Unrecognized version type \"version_type\" (should be major, minor or patch)")
}
return versionArray.join('.')
}println(bumpVersion('1.2.3', 'minor', true))
# License
You are free to use this in any way you want, in case you find this useful or working for you but you must keep the copyright notice and license. (MIT)
# Credits
* Created by Sergei Kasoverskij,