Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

beauty-amp-core

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

beauty-amp-core - npm Package Compare versions

Comparing version 0.3.5 to 0.3.6

50

beauty-amp-core.js

@@ -6,2 +6,3 @@ const _ = require('lodash');

// set defaults:
let setup = {

@@ -16,4 +17,4 @@ ampscript: {

editor: {
insertSpaces: true,
tabSize: 4
insertSpaces: true
// tabSize: 4
}

@@ -108,6 +109,17 @@ };

* Format code.
* @param {Array} lines text of your code as an Array.
* @return {String} Code as string. [subject to future change]
* Lines are broken on "\n".
* @param {Array|String} lines text of your code.
* @return {Array|String} Formatted code. Array or string based on the initial input.
*/
beautify(lines) {
let isArray;
if (typeof(lines) === 'string') {
isArray = false;
lines = lines.split('\n');
} else if (Array.isArray(lines)) {
isArray = true;
} else {
throw "Unsuported 'lines' data type.";
}
// Cut blanks lines from start and end:

@@ -126,3 +138,7 @@ logger.log("getCodeBlocks");

// TODO: change me:
return newLines.join("\n");
if (isArray) {
return newLines.join("\n").split("\n");
} else {
return newLines.join("\n");
}
},

@@ -139,16 +155,14 @@

setup(ampscript, editor, logs) {
// default:
// setup.ampscript = {
// capitalizeAndOrNot:true,
// capitalizeIfFor:true,
// capitalizeSet:true,
// capitalizeVar:true,
// maxParametersPerLine: 4
// };
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;
}
// // default:
// setup.editor = {
// insertSpaces: true,
// tabSize: 4
// };
if (editor) {
setup.editor.insertSpaces = editor.insertSpaces === true ? true : false;
// setup.editor.tabSize = _.isInteger(editor.tabSize) ? editor.tabSize : 4;
}

@@ -155,0 +169,0 @@ logger.setup(logs);

{
"name": "beauty-amp-core",
"version": "0.3.5",
"version": "0.3.6",
"description": "Beautify (prettify) AMPscript for Marketing Cloud - prettifying library only.",

@@ -5,0 +5,0 @@ "publisher": "FiB",

@@ -8,3 +8,3 @@ # BEAUTY AMP CORE

```
> npm install readme -g
> npm install --save beauty-amp-core
```

@@ -30,5 +30,10 @@

const result = beautifier.beautify(lines);
console.log(result);
console.log(result); // returns code as an array
```
### beautify(lines)
Format code. Lines are broken on `"\n"`.
`lines`: __Array|String__ - text of your code
`return`: __{Array|String}__ Formatted code. Array or string based on the initial input.
## Setup

@@ -48,4 +53,3 @@

const editor = {
insertSpaces: true,
tabSize: 4
insertSpaces: true
};

@@ -52,0 +56,0 @@ // logs trough console only for the moment.

@@ -11,2 +11,51 @@ const beautifier = require('../beauty-amp-core');

test("Array as input", () => {
let testCase = [`<h1>My Test Case:</h1>`,
`%%[ VAR @lang `,
`If (@lang == 'EN') then Output("Hello World!")`,
`Else`,
` Output("Ciao!")`,
`endif`,
`]%%`
];
let testRes = [`<h1>My Test Case:</h1>`,
`%%[`,
` VAR @lang`,
` IF (@lang == 'EN') THEN`,
` Output("Hello World!")`,
` ELSE`,
` Output("Ciao!")`,
` ENDIF`,
`]%%`,
``];
const res = beautifier.beautify(testCase);
expect(Array.isArray(res)).toBeTruthy();
expect(res).toStrictEqual(testRes);
});
test("Array as string", () => {
let testCase = `<h1>My Test Case:</h1>
%%[ VAR @lang If (@lang == 'EN') then Output("Hello World!")
Else
Output("Ciao!")
endif ]%%`;
let testRes = `<h1>My Test Case:</h1>
%%[
VAR @lang
IF (@lang == 'EN') THEN
Output("Hello World!")
ELSE
Output("Ciao!")
ENDIF
]%%
`;
const res = beautifier.beautify(testCase);
expect(typeof(res)).toBe('string');
expect(res).toBe(testRes);
});
test("NEXT in string test", () => {

@@ -27,3 +76,3 @@

const testRes = `<h1>broken by the "next"</h1>
let testRes = `<h1>broken by the "next"</h1>
%%[

@@ -44,5 +93,7 @@ VAR @FullCtaUrl

testCase = testCase.split('\n');
testRes = testRes.split('\n');
const res = beautifier.beautify(testCase);
expect(res).toBe(testRes);
expect(Array.isArray(res)).toBeTruthy();
expect(res).toStrictEqual(testRes);
});

@@ -83,7 +134,4 @@

testCase = testCase.split('\n');
const res = beautifier.beautify(testCase);
expect(res).toBe(testRes);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc