let output = {}
const inputData = {
exampleText1: `XXX USD worth of unlocked NEAR Tokens
XXX USD worth of NEAR Token lockup with a 18 month linear release schedule.
XXX USD worth of unlocked NEAR Tokens
XXX USD worth of NEAR Token lockup with a 18 month linear release schedule`,
exampleText2: `XXX USD worth of unlocked NEAR Tokens
XXX USD worth of NEAR Token lockup with a 18 month linear release schedule.
XXX USD worth of unlocked NEAR Tokens
XXX USD worth of NEAR Token lockup with a 18 month linear release schedule`,
exampleText3: `XXX USD worth of unlocked NEAR Tokens
XXX USD worth of NEAR Token lockup with a 18 month linear release schedule.
XXX USD worth of unlocked NEAR Tokens
XXX USD worth of NEAR Token lockup with a 18 month linear release schedule`,
exampleText4: `XXX USD worth of unlocked NEAR Tokens
XXX USD worth of NEAR Token lockup with a 18 month linear release schedule.
XXX USD worth of unlocked NEAR Tokens
XXX USD worth of NEAR Token lockup with a 18 month linear release schedule`,
exampleText5: `XXX USD worth of unlocked NEAR Tokens
XXX USD worth of NEAR Token lockup with a 18 month linear release schedule.
XXX USD worth of unlocked NEAR Tokens
XXX USD worth of NEAR Token lockup with a 18 month linear release schedule`,
}
// ====== Zapier Code Step =============
// Very sloppy code for modifying newline values between platforms
// Destructure input values
const i1 = inputData.exampleText1
const i2 = inputData.exampleText2
const i3 = inputData.exampleText3
const i4 = inputData.exampleText4
const i5 = inputData.exampleText5
// add more as follows:
// const i6 = inputData.exampleText6
//* If you add any additional inputs, add them to the array below
const inputValueArray = [i1,i2,i3,i4,i5,/*i6*/]
// Add more options to this array if needed
// Don't modify the spacing on index 1
const targetPlatformNewlineChars = [`
`, // index 0
"\\n", // index 1
"<br />", // index 2
]
// EDITABLE
const options = {
// OPTION: How does the current platform delimit new lines?
currentPlatformNewlineChar: "\n",
// OPTIONS (1-3): single, double, or triple space lines
linesPerDelimiter: 1,
// (OPTIONS: 0-2): 0 = `...` | 1 = \n | 2 = <br />
targetNlIndex: 1
}
// Extract options because zapier doesn't like obj[key] syntax
const targetNlIndex = options.targetNlIndex
const curNewLine = options.currentPlatformNewlineChar
const linesPerDelimiter = options.linesPerDelimiter
// Set newline string
const nl = targetPlatformNewlineChars[targetNlIndex]
// Function to set line spacing
const lineCount = (ct) => {
let count = ct
const lines = []
if (!ct) count = linesPerDelimiter
for (let i=0;i<count;i++) lines.push(i)
return lines
}
// Function to test if a value is nullish
const testEmpty = (item) => {
return ['', null, undefined].indexOf(item) !== -1
}
// Function to format each input as a separate key/value pair
const formatArrayOfTextBlocks = (inputTextArr) => {
const formattedTextArray = []
inputTextArr.forEach((inputText) => {
const outputText = inputText.split(curNewLine).map((item) => {
const itemIsEmpty = testEmpty(item)
if (itemIsEmpty) return lineCount(linesPerDelimiter * 1)
.map(_item => nl)
.join("")
else return item + lineCount()
.map(_item => nl)
.join("")
})
.join("")
.trim()
.split(nl+nl+nl)
.join(nl+nl)
.trim()
.split(nl)
.filter((item ) => !!item )
.join(nl)
formattedTextArray.push(outputText)
})
// Create empty object
const obj = {}
const objArr = formattedTextArray.forEach(((item, i) => {
// Dynamically generate keys
const key = "item" + (i + 1) + ""
// Create object
obj[key] = item
}))
// Return Object
return obj
}
const outputText = formatArrayOfTextBlocks(inputValueArray)
output = {...outputText}
// Is the same as:
// output = {
// item1: outputText.item1,
// item2: outputText.item2,
// item3: outputText.item3,
// item4: outputText.item4,
// item5: outputText.item5
// };