Last active
November 19, 2022 20:10
-
-
Save westc/1db1f19c0b9e676fd1638ddad9c93e99 to your computer and use it in GitHub Desktop.
getApexString() - Takes a string and returns the corresponding Apex (Salesforce) string. If string ends up being too long for one line it will be shown as a multiple line expression using String.join().
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getApexString(string, maxOneLinerLength=80) { | |
var normal = "'" + JSON.stringify(string).slice(1, -1).replace(/\\"/g, '"').replace(/'/g, "\\'") + "'"; | |
return (normal.length > maxOneLinerLength && string.indexOf('\n') >= 0) | |
? "String.join(new String[] {\n\t" + normal.replace(/\\[^n]|(\\n)/g, (m, isNewline) => isNewline ? "',\n\t'" : m) + "\n}, '\\n')" | |
: normal; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// Where the JS code lies | |
"files": ["getApexString.js"], | |
// Name of the function responsable for transforming the input into the output. | |
"transform": "getApexString", | |
// Arguments that will be passed to the function by name. | |
"params": [ | |
{ | |
"name": "maxOneLinerLength", | |
"label": "Maximum Length of a One-liner", | |
"type": "number", | |
"min": 3, | |
"step": 1, | |
"value": 80 | |
} | |
], | |
// Input setup | |
"input": { "language": "text" }, | |
// Output setup | |
"output": { "language": "apex" }, | |
// Type of YourJS IO-App | |
"type": "split" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the corresponding IO App:
https://yourjs.com/gist-io/1db1f19c0b9e676fd1638ddad9c93e99