beauty-amp-core2
Advanced tools
Comparing version 0.4.3 to 0.4.4
@@ -0,1 +1,4 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const prettier = require('prettier'); | ||
@@ -196,15 +199,31 @@ const _ = require('lodash'); | ||
*/ | ||
setup(ampscript, editor, logs) { | ||
if (ampscript) { | ||
setup.ampscript.capitalizeAndOrNot = ampscript.capitalizeAndOrNot === true ? true : false; | ||
setup.ampscript.capitalizeIfFor = ampscript.capitalizeIfFor === true ? true : false; | ||
setup.ampscript.capitalizeSet = ampscript.capitalizeSet === true ? true : false; | ||
setup.ampscript.capitalizeVar = ampscript.capitalizeVar === true ? true : false; | ||
setup.ampscript.maxParametersPerLine = _.isInteger(ampscript.maxParametersPerLine) ? ampscript.maxParametersPerLine : 4; | ||
setup( | ||
ampscript = { capitalizeAndOrNot: true, capitalizeIfFor: true, capitalizeSet: true, capitalizeVar: true, maxParametersPerLine: true }, | ||
editor = { insertSpaces: true, tabSize: 4 }, | ||
logs | ||
) { | ||
let setupJson = lookForSetupFile(); | ||
let amp = ampscript; | ||
let edit = editor; | ||
if (setupJson) { | ||
if (setupJson.ampscript) { | ||
amp = {...amp, ...setupJson.ampscript}; | ||
} | ||
if (setupJson.editor) { | ||
edit = {...edit, ...setupJson.editor}; | ||
} | ||
} | ||
if (editor) { | ||
setup.editor.insertSpaces = editor.insertSpaces === true ? true : false; | ||
setup.editor.tabSize = _.isInteger(editor.tabSize) ? editor.tabSize : 4; | ||
if (amp) { | ||
setup.ampscript.capitalizeAndOrNot = amp.capitalizeAndOrNot === true ? true : false; | ||
setup.ampscript.capitalizeIfFor = amp.capitalizeIfFor === true ? true : false; | ||
setup.ampscript.capitalizeSet = amp.capitalizeSet === true ? true : false; | ||
setup.ampscript.capitalizeVar = amp.capitalizeVar === true ? true : false; | ||
setup.ampscript.maxParametersPerLine = _.isInteger(amp.maxParametersPerLine) ? amp.maxParametersPerLine : 4; | ||
} | ||
if (edit) { | ||
setup.editor.insertSpaces = edit.insertSpaces === false ? false : true; | ||
setup.editor.tabSize = _.isInteger(edit.tabSize) ? edit.tabSize : 4; | ||
setup.htmlOptions.useTabs = !setup.editor.insertSpaces; | ||
@@ -232,2 +251,14 @@ setup.htmlOptions.tabWidth = setup.editor.tabSize; | ||
return x; | ||
} | ||
function lookForSetupFile() { | ||
try { | ||
const path = require('path'); | ||
const setupPath = path.resolve(process.cwd(), './.beautyamp.json'); | ||
let rawdata = fs.readFileSync(setupPath); | ||
return JSON.parse(rawdata); | ||
} catch(err) { | ||
return false; | ||
} | ||
} |
# Change Log | ||
## [0.4.4] - 2023-12-07 | ||
### Changed | ||
- multiline comments improved, | ||
- standalone methods are now formatted as methods, and not merged with keyword, | ||
- new option to use a `.beautyamp.json` file for the setup, | ||
- logger defaults to OFF, | ||
- test cases added. | ||
## [0.4.0] - 2023-12-03 | ||
@@ -4,0 +13,0 @@ |
{ | ||
"name": "beauty-amp-core2", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Beautify (prettify) AMPscript for Marketing Cloud - prettifying library only. Version for further support.", | ||
@@ -5,0 +5,0 @@ "publisher": "fib3", |
@@ -41,10 +41,9 @@ # Beauty AMP Core 2 | ||
Defaults: | ||
You can set the extension as following. | ||
``` javascript | ||
// immutable at the moment: | ||
const ampscript = { | ||
capitalizeAndOrNot:true, | ||
capitalizeIfFor:true, | ||
capitalizeSet:true, | ||
capitalizeVar:true, | ||
capitalizeAndOrNot: true, | ||
capitalizeIfFor: true, | ||
capitalizeSet: true, | ||
capitalizeVar: true, | ||
maxParametersPerLine: 4 | ||
@@ -59,6 +58,24 @@ }; | ||
const logs = { | ||
loggerOn: true // <= disable logging | ||
loggerOn: false // <= disable logging | ||
}; | ||
beautifier.setup(ampscript, editor, logs); | ||
``` | ||
A new experimental feature allows to use a setup file in your project's folder: `.beautyamp.json`: | ||
```json | ||
{ | ||
"ampscript": { | ||
"capitalizeAndOrNot": true, | ||
"capitalizeIfFor": true, | ||
"capitalizeSet": true, | ||
"capitalizeVar": true, | ||
"maxParametersPerLine": 4 | ||
}, | ||
"editor": { | ||
"insertSpaces": true, | ||
"tabSize": 2 | ||
} | ||
} | ||
``` |
const _ = require('lodash'); | ||
const formatters = require('./formatters'); | ||
const Logger = require("./logger"); | ||
@@ -195,3 +194,4 @@ let logger; | ||
logger.log(`${i}:formatMethodLine("${line}")`); | ||
const methodsDetect = /(\%\%\[[\t\ ]*|[\t\ ]*|set[\t\ ]+@\w+[\t\ ]*=[\t\ ]*)(\w+\(.*\))/gi; | ||
const methodsDetect = /(\%\%\[|THEN|ELSE|ENDIF|DO|NEXT|set[\t\ ]+@\w+[\t\ ]*=|)[\t\ ]*(\w+\(.*\))/gi; | ||
// const methodsDetect = /(\%\%\[[\t\ ]*|[\t\ ]*|set[\t\ ]+@\w+[\t\ ]*=[\t\ ]*)(\w+\(.*\))/gi; | ||
// const methodsDetect = /\b([a-zA-Z_$][a-zA-Z0-9_$]*)\s*\((?:[^)(]|\((?:[^)(]|\([^)(]*\))*\))*\)/gi; | ||
@@ -205,3 +205,5 @@ | ||
// return `${p1}${method}`; | ||
return p1.includes('%%[') ? `${p1}\n${method}` : `${p1}${method}`; | ||
return ['\%\%\[', 'THEN', 'ELSE', 'ENDIF', 'DO', 'NEXT'].includes(p1.trim()) | ||
? `${p1}\n${method}` | ||
: `${p1} ${method}`; | ||
}); | ||
@@ -208,0 +210,0 @@ } |
@@ -17,11 +17,9 @@ 'use strict'; | ||
* @param {Object} setup | ||
* {string|Number} logLevel - Log level | ||
* {Boolean = true} loggerOn - enable the logger | ||
* {string} [logLevel=INFO] - Log level | ||
* {Boolean} [loggerOn=false] loggerOn - enable the logger | ||
*/ | ||
setup(setup) { | ||
setup = setup ? setup : {}; | ||
this.on = setup.loggerOn === false ? false : true; | ||
setup(setup = { loggerOn: false, logLevel: 'INFO' }) { | ||
this.on = setup.loggerOn; | ||
this.onValue = this.on; | ||
this.level = typeof(setup.logLevel) === 'string' ? setup.logLevel : 4; | ||
this.level = typeof(setup.logLevel) === 'string' ? setup.logLevel : 'INFO'; | ||
} | ||
@@ -28,0 +26,0 @@ |
@@ -287,2 +287,3 @@ const beautifier = require('../beauty-amp-core'); | ||
test("Comment block indenting bug fix", async () => { | ||
@@ -308,2 +309,43 @@ let testCase = `%%[ v(@AMPscript) | ||
expect(res).toStrictEqual(testRes); | ||
}); | ||
test("Standalone method after keyword", async () => { | ||
let testCase = `%%[ | ||
var @x, @i | ||
/** | ||
* comment 1 | ||
* example 2 | ||
*/ | ||
IF @title == 'Hello World!' THEN | ||
OutputLine(Concat('Hello ', 'World!')) | ||
ENDIF | ||
FOR @i to 3 DO | ||
OutputLine(Concat('Hello', ' ', 'World!')) | ||
SET @x = 'stuff' | ||
NEXT @i | ||
]%%`; | ||
let testRes = ` | ||
%%[ | ||
VAR @x, @i | ||
/** | ||
* comment 1 | ||
* example 2 | ||
*/ | ||
IF @title == 'Hello World!' THEN | ||
OutputLine(Concat('Hello ', 'World!')) | ||
ENDIF | ||
FOR @I TO 3 DO | ||
OutputLine(Concat('Hello', ' ', 'World!')) | ||
SET @x = 'stuff' | ||
NEXT @i | ||
]%% | ||
`; | ||
const res = await beautifier.beautify(testCase); | ||
expect(!Array.isArray(res)).toBeTruthy(); | ||
expect(res).toStrictEqual(testRes); | ||
}); |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
50133
1327
79
0
1