@@ -2,38 +2,38 @@ import {decode, encode} from 'uint8-to-base64';
22import type { IssuePageInfo , IssuePathInfo , RepoOwnerPathInfo } from './types.ts' ;
33import { toggleElemClass , toggleElem } from './utils/dom.ts' ;
44
5- // transform /path/to/file.ext to /path/to
5+ /** transform /path/to/file.ext to /path/to */
66export function dirname ( path : string ) : string {
77 const lastSlashIndex = path . lastIndexOf ( '/' ) ;
88 return lastSlashIndex < 0 ? '' : path . substring ( 0 , lastSlashIndex ) ;
99}
1010
11- // transform /path/to/file.ext to file.ext
11+ /** transform /path/to/file.ext to file.ext */
1212export function basename ( path : string ) : string {
1313 const lastSlashIndex = path . lastIndexOf ( '/' ) ;
1414 return lastSlashIndex < 0 ? path : path . substring ( lastSlashIndex + 1 ) ;
1515}
1616
17- // transform /path/to/file.ext to .ext
17+ /** transform /path/to/file.ext to .ext */
1818export function extname ( path : string ) : string {
1919 const lastSlashIndex = path . lastIndexOf ( '/' ) ;
2020 const lastPointIndex = path . lastIndexOf ( '.' ) ;
2121 if ( lastSlashIndex > lastPointIndex ) return '' ;
2222 return lastPointIndex < 0 ? '' : path . substring ( lastPointIndex ) ;
2323}
2424
25- // test whether a variable is an object
25+ /** test whether a variable is an object */
2626export function isObject ( obj : any ) : boolean {
2727 return Object . prototype . toString . call ( obj ) === '[object Object]' ;
2828}
2929
30- // returns whether a dark theme is enabled
30+ /** returns whether a dark theme is enabled */
3131export function isDarkTheme ( ) : boolean {
3232 const style = window . getComputedStyle ( document . documentElement ) ;
3333 return style . getPropertyValue ( '--is-dark-theme' ) . trim ( ) . toLowerCase ( ) === 'true' ;
3434}
3535
36- // strip <tags> from a string
36+ /** strip <tags> from a string */
3737export function stripTags ( text : string ) : string {
3838 return text . replace ( / < [ ^ > ] * > ? / g, '' ) ;
3939}
@@ -62,27 +62,27 @@ export function parseIssuePageInfo(): IssuePageInfo {
6262 } ;
6363}
6464
65- // parse a URL, either relative '/path' or absolute 'https://localhost/path'
65+ /** parse a URL, either relative '/path' or absolute 'https://localhost/path' */
6666export function parseUrl ( str : string ) : URL {
6767 return new URL ( str , str . startsWith ( 'http' ) ? undefined : window . location . origin ) ;
6868}
6969
70- // return current locale chosen by user
70+ /** return current locale chosen by user */
7171export function getCurrentLocale ( ) : string {
7272 return document . documentElement . lang ;
7373}
7474
75- // given a month (0-11), returns it in the documents language
75+ /** given a month (0-11), returns it in the documents language */
7676export function translateMonth ( month : number ) {
7777 return new Date ( Date . UTC ( 2022 , month , 12 ) ) . toLocaleString ( getCurrentLocale ( ) , { month : 'short' , timeZone : 'UTC' } ) ;
7878}
7979
80- // given a weekday (0-6, Sunday to Saturday), returns it in the documents language
80+ /** given a weekday (0-6, Sunday to Saturday), returns it in the documents language */
8181export function translateDay ( day : number ) {
8282 return new Date ( Date . UTC ( 2022 , 7 , day ) ) . toLocaleString ( getCurrentLocale ( ) , { weekday : 'short' , timeZone : 'UTC' } ) ;
8383}
8484
85- // convert a Blob to a DataURI
85+ /** convert a Blob to a DataURI */
8686export function blobToDataURI ( blob : Blob ) : Promise < string > {
8787 return new Promise ( ( resolve , reject ) => {
8888 try {
@@ -100,7 +100,7 @@ export function blobToDataURI(blob: Blob): Promise<string> {
100100 } ) ;
101101}
102102
103- // convert image Blob to another mime-type format.
103+ /** convert image Blob to another mime-type format. */
104104export function convertImage ( blob : Blob , mime : string ) : Promise < Blob > {
105105 return new Promise ( async ( resolve , reject ) => {
106106 try {
@@ -143,15 +143,15 @@ export function toAbsoluteUrl(url: string): string {
143143 return `${ window . location . origin } ${ url } ` ;
144144}
145145
146- // Encode an Uint8Array into a URLEncoded base64 string.
146+ /** Encode an Uint8Array into a URLEncoded base64 string. */
147147export function encodeURLEncodedBase64 ( uint8Array : Uint8Array ) : string {
148148 return encode ( uint8Array )
149149 . replace ( / \+ / g, '-' )
150150 . replace ( / \/ / g, '_' )
151151 . replace ( / = / g, '' ) ;
152152}
153153
154- // Decode a URLEncoded base64 to an Uint8Array.
154+ /** Decode a URLEncoded base64 to an Uint8Array. */
155155export function decodeURLEncodedBase64 ( base64url : string ) : Uint8Array {
156156 return decode ( base64url
157157 . replace ( / _ / g, '/' )
0 commit comments