mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Enable random and suffix options
This commit is contained in:
parent
cf7667eba6
commit
32adc18c0f
1 changed files with 15 additions and 3 deletions
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue