File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 2020export function linkify < D , T > (
2121 text : string ,
2222 data : Record < string , D > ,
23- callback : ( name : string , data : D ) => T ,
23+ callback : ( name : string , data : D , index : number ) => T ,
2424) : Array < string | T > {
25- return text . split ( WORD_SEPARATORS ) . map ( word => ( data [ word ] == null ? word : callback ( word , data [ word ] ) ) ) ;
25+ return text
26+ . split ( WORD_SEPARATORS )
27+ . map ( ( word , idx ) => ( data [ word ] == null ? word : callback ( word , data [ word ] , idx ) ) ) ;
2628}
29+
2730const WORD_SEPARATORS = / ( [ \[ \] < > ( ) | : . , ] + ) / g;
2831
29- /** Slugify a string: "Really Cool Heading!" => "really-cool-heading-" */
32+ /**
33+ * Slugify a string: "Really Cool Heading!" => "really-cool-heading-"
34+ */
3035export function slugify ( str : string ) {
3136 return str . toLowerCase ( ) . replace ( / [ ^ \w . \/ ] / g, "-" ) ;
3237}
You can’t perform that action at this time.
0 commit comments