Enable random and suffix options

This commit is contained in:
Sam Carlton 2022-06-03 16:56:47 -05:00
parent cf7667eba6
commit 32adc18c0f

View file

@ -1,4 +1,6 @@
// Universal JS imports only // Universal JS imports only
import shuffle from 'just-shuffle'
import { makeSlug } from './slug.js' import { makeSlug } from './slug.js'
export function makeCategorySlug ( categoryName ) { export function makeCategorySlug ( categoryName ) {
@ -262,9 +264,19 @@ export function findCategoryForTagsSet ( tags ) {
return null return null
} }
export function makeSummaryOfListings ({ list, length = 25 } = {}) { const sampleListFormatter = new Intl.ListFormat( 'en', { style: 'long', type: 'unit' })
return list
export function makeSummaryOfListings ({
list,
length = 25,
random = false,
suffix = ', etc...',
} = {}) {
const listToSample = random ? shuffle( list ) : list
const samples = listToSample
.slice(0, length) .slice(0, length)
.map( listing => listing.name ) .map( listing => listing.name )
.join(', ') + ', etc...'
return sampleListFormatter.format( samples ) + suffix
} }