File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 11import slugify from "@sindresorhus/slugify" ;
22
3+ export const SLUG_PRESERVE_UNICODE = false ;
34export const SLUG_SEPARATOR = "_" ;
45
56interface ProcessorOptions {
@@ -83,3 +84,22 @@ export function unicode_safe_processor(
8384 } , [ ] as string [ ] )
8485 . join ( separator ) ;
8586}
87+
88+ export function make_session_slug_processor ( {
89+ preserve_unicode = SLUG_PRESERVE_UNICODE ,
90+ separator = SLUG_SEPARATOR ,
91+ } ) {
92+ const processor = preserve_unicode
93+ ? unicode_safe_processor
94+ : url_safe_processor ;
95+ const seen = new Set ( ) ;
96+
97+ return function ( url : string ) {
98+ const slug = processor ( url , { separator } ) ;
99+
100+ if ( seen . has ( slug ) ) throw new Error ( `Duplicate slug ${ slug } ` ) ;
101+ seen . add ( slug ) ;
102+
103+ return slug ;
104+ } ;
105+ }
You can’t perform that action at this time.
0 commit comments