Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Friday updates #18

Merged
merged 8 commits into from
Sep 4, 2020
Next Next commit
Add filter for comma separating arrays across lines
  • Loading branch information
edwardhorsford committed Sep 4, 2020
commit 734135bcd64f376e2cb3dc2dec19a23067fae039
12 changes: 12 additions & 0 deletions app/filters/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ const joinArray = (array, options={}) => {
// Set to be options.delimiter if it doesn't already exist
options.lastDelimiter = options.lastDelimiter || options.delimiter

// Strip trailing space from delimiters and add breaks
if (options.newlines){
options.delimiter = options.delimiter.replace(/\s+$/g, '') + "<br>"
options.lastDelimiter = options.lastDelimiter.replace(/\s+$/g, '') + "<br>"
}

// console.log('Input array is', array)
// Clean up array
array = filters.cleanArray(array)
Expand Down Expand Up @@ -144,6 +150,12 @@ filters.oxfordComma = (items) => filters.joinArray(items, {delimiter:', ', lastD
// A, B, C, D
filters.commaSeparate = (items) => filters.joinArray(items, {delimiter:', '})

// A,
// B,
// C,
// D
filters.commaSeparateLines = (items) => filters.joinArray(items, {delimiter:', ', newlines: true })

// A and B and C and D
filters.andSeparate = (items)=> filters.joinArray(items, {delimiter: ' and '})

Expand Down