@@ -136,20 +136,42 @@ export const githubRepos = {
136136 sveltejs : [ ...new Set ( repositories . flatMap ( ( [ , { repos } ] ) => repos . map ( r => r . repoName ) ) ) ]
137137} ;
138138
139+ /**
140+ * A utility function to only keep unique items in
141+ * an array, based on the uniqTransform parameter.
142+ *
143+ * @param arr the input array
144+ * @param uniqTransform the transformation function
145+ * to make items unique
146+ * @returns the filtered array, containing only unique items
147+ *
148+ * @see {@link https://stackoverflow.com/a/70503699/12070367|Original implementation }
149+ */
150+ function uniq < T , U > ( arr : T [ ] , uniqTransform : ( item : T ) => U ) {
151+ const track = new Set < U > ( ) ;
152+ return arr . filter ( item => {
153+ const value = uniqTransform ( item ) ;
154+ return track . has ( value ) ? false : track . add ( value ) ;
155+ } ) ;
156+ }
157+
139158/**
140159 * Get a list of objects containing
141160 * the repo owner, the repo name, and the
142161 * associated transformation function to
143162 * transform a release tag name into a package
144163 * name.
145164 */
146- export const transformationRepos = repositories . flatMap ( ( [ , { repos } ] ) =>
147- repos . map ( r => ( {
148- owner : "sveltejs" ,
149- repoName : r . repoName ,
150- tagToName : ( tag : string ) => {
151- const [ name ] = r . metadataFromTag ( tag ) ;
152- return name ;
153- }
154- } ) )
165+ export const transformationRepos = uniq (
166+ repositories . flatMap ( ( [ , { repos } ] ) =>
167+ repos . map ( r => ( {
168+ owner : "sveltejs" ,
169+ repoName : r . repoName ,
170+ tagToName : ( tag : string ) => {
171+ const [ name ] = r . metadataFromTag ( tag ) ;
172+ return name ;
173+ }
174+ } ) )
175+ ) ,
176+ item => item . repoName
155177) ;
0 commit comments