Migrated to ESLint

This commit is contained in:
squidfunk
2021-02-07 17:43:13 +01:00
parent 4744d5f3f0
commit 208c9ac3fd
65 changed files with 1968 additions and 393 deletions

View File

@@ -34,7 +34,7 @@ import { mapTo } from "rxjs/operators"
* automatically updated when a new document is emitted. This enabled features
* like instant loading.
*
* @return Document subject
* @returns Document subject
*/
export function watchDocument(): Subject<Document> {
const document$ = new ReplaySubject<Document>()

View File

@@ -0,0 +1,5 @@
{
"rules": {
"jsdoc/require-jsdoc": "off"
}
}

View File

@@ -32,7 +32,7 @@
* @param selector - Query selector
* @param node - Node of reference
*
* @return Element or nothing
* @returns Element or nothing
*/
export function getElement<T extends keyof HTMLElementTagNameMap>(
selector: T, node?: ParentNode
@@ -56,7 +56,7 @@ export function getElement<T extends HTMLElement>(
* @param selector - Query selector
* @param node - Node of reference
*
* @return Element
* @returns Element
*/
export function getElementOrThrow<T extends keyof HTMLElementTagNameMap>(
selector: T, node?: ParentNode
@@ -80,7 +80,7 @@ export function getElementOrThrow<T extends HTMLElement>(
/**
* Retrieve the currently active element
*
* @return Element or nothing
* @returns Element or nothing
*/
export function getActiveElement(): HTMLElement | undefined {
return document.activeElement instanceof HTMLElement
@@ -96,7 +96,7 @@ export function getActiveElement(): HTMLElement | undefined {
* @param selector - Query selector
* @param node - Node of reference
*
* @return Elements
* @returns Elements
*/
export function getElements<T extends keyof HTMLElementTagNameMap>(
selector: T, node?: ParentNode
@@ -121,7 +121,7 @@ export function getElements<T extends HTMLElement>(
*
* @param tagName - Tag name
*
* @return Element
* @returns Element
*/
export function createElement<T extends keyof HTMLElementTagNameMap>(
tagName: T

View File

@@ -36,7 +36,7 @@ import { getActiveElement } from "../_"
* @param value - Whether the element should be focused
*/
export function setElementFocus(
el: HTMLElement, value: boolean = true
el: HTMLElement, value = true
): void {
if (value)
el.focus()
@@ -51,7 +51,7 @@ export function setElementFocus(
*
* @param el - Element
*
* @return Element focus observable
* @returns Element focus observable
*/
export function watchElementFocus(
el: HTMLElement

View File

@@ -44,7 +44,7 @@ export interface ElementOffset {
*
* @param el - Element
*
* @return Element offset
* @returns Element offset
*/
export function getElementOffset(el: HTMLElement): ElementOffset {
return {
@@ -60,7 +60,7 @@ export function getElementOffset(el: HTMLElement): ElementOffset {
*
* @param el - Element
*
* @return Element offset observable
* @returns Element offset observable
*/
export function watchElementOffset(
el: HTMLElement

View File

@@ -92,7 +92,7 @@ const observer$ = defer(() => of(
*
* @param el - Element
*
* @return Element size
* @returns Element size
*/
export function getElementSize(el: HTMLElement): ElementSize {
return {
@@ -106,7 +106,7 @@ export function getElementSize(el: HTMLElement): ElementSize {
*
* @param el - Element
*
* @return Element size
* @returns Element size
*/
export function getElementContentSize(el: HTMLElement): ElementSize {
return {
@@ -127,7 +127,7 @@ export function getElementContentSize(el: HTMLElement): ElementSize {
*
* @param el - Element
*
* @return Element size observable
* @returns Element size observable
*/
export function watchElementSize(
el: HTMLElement

View File

@@ -44,7 +44,7 @@ export interface Key {
*
* @param el - Element
*
* @return Test result
* @returns Test result
*/
export function isSusceptibleToKeyboard(el: HTMLElement): boolean {
switch (el.tagName) {
@@ -66,7 +66,7 @@ export function isSusceptibleToKeyboard(el: HTMLElement): boolean {
/**
* Watch keyboard
*
* @return Keyboard observable
* @returns Keyboard observable
*/
export function watchKeyboard(): Observable<Key> {
return fromEvent<KeyboardEvent>(window, "keydown")

View File

@@ -34,7 +34,7 @@ import { BehaviorSubject, Subject } from "rxjs"
* tracked without setting them and `Location` is a singleton which represents
* the current location.
*
* @return URL
* @returns URL
*/
export function getLocation(): URL {
return new URL(location.href)
@@ -54,7 +54,7 @@ export function setLocation(url: URL): void {
/**
* Watch location
*
* @return Location subject
* @returns Location subject
*/
export function watchLocation(): Subject<URL> {
return new BehaviorSubject<URL>(getLocation())

View File

@@ -23,8 +23,7 @@
import { Observable, fromEvent, of } from "rxjs"
import { filter, map, share, startWith, switchMap } from "rxjs/operators"
import { createElement } from "browser"
import { getElement } from "~/browser/element"
import { createElement, getElement } from "~/browser"
/* ----------------------------------------------------------------------------
* Functions
@@ -33,7 +32,7 @@ import { getElement } from "~/browser/element"
/**
* Retrieve location hash
*
* @return Location hash
* @returns Location hash
*/
export function getLocationHash(): string {
return location.hash.substring(1)
@@ -61,7 +60,7 @@ export function setLocationHash(hash: string): void {
/**
* Watch location hash
*
* @return Location hash observable
* @returns Location hash observable
*/
export function watchLocationHash(): Observable<string> {
return fromEvent<HashChangeEvent>(window, "hashchange")
@@ -76,7 +75,7 @@ export function watchLocationHash(): Observable<string> {
/**
* Watch location target
*
* @return Location target observable
* @returns Location target observable
*/
export function watchLocationTarget(): Observable<HTMLElement> {
return watchLocationHash()

View File

@@ -32,7 +32,7 @@ import { filter, map, mapTo, startWith } from "rxjs/operators"
*
* @param query - Media query
*
* @return Media observable
* @returns Media observable
*/
export function watchMedia(query: string): Observable<boolean> {
const media = matchMedia(query)
@@ -46,7 +46,7 @@ export function watchMedia(query: string): Observable<boolean> {
/**
* Watch print mode, cross-browser
*
* @return Print observable
* @returns Print observable
*/
export function watchPrint(): Observable<void> {
return merge(

View File

@@ -44,8 +44,8 @@ export type Toggle =
* Toggle map
*/
const toggles: Record<Toggle, HTMLInputElement> = {
drawer: getElementOrThrow(`[data-md-toggle=drawer]`),
search: getElementOrThrow(`[data-md-toggle=search]`)
drawer: getElementOrThrow("[data-md-toggle=drawer]"),
search: getElementOrThrow("[data-md-toggle=search]")
}
/* ----------------------------------------------------------------------------
@@ -57,7 +57,7 @@ const toggles: Record<Toggle, HTMLInputElement> = {
*
* @param name - Toggle
*
* @return Toggle value
* @returns Toggle value
*/
export function getToggle(name: Toggle): boolean {
return toggles[name].checked
@@ -86,7 +86,7 @@ export function setToggle(name: Toggle, value: boolean): void {
*
* @param name - Toggle
*
* @return Toggle value observable
* @returns Toggle value observable
*/
export function watchToggle(name: Toggle): Observable<boolean> {
const el = toggles[name]

View File

@@ -69,7 +69,7 @@ interface WatchAtOptions {
/**
* Watch viewport
*
* @return Viewport observable
* @returns Viewport observable
*/
export function watchViewport(): Observable<Viewport> {
return combineLatest([
@@ -88,7 +88,7 @@ export function watchViewport(): Observable<Viewport> {
* @param el - Element
* @param options - Options
*
* @return Viewport observable
* @returns Viewport observable
*/
export function watchViewportAt(
el: HTMLElement, { viewport$, header$ }: WatchAtOptions

View File

@@ -45,7 +45,7 @@ export interface ViewportOffset {
* On iOS Safari, viewport offset can be negative due to overflow scrolling.
* As this may induce strange behaviors downstream, we'll just limit it to 0.
*
* @return Viewport offset
* @returns Viewport offset
*/
export function getViewportOffset(): ViewportOffset {
return {
@@ -70,7 +70,7 @@ export function setViewportOffset(
/**
* Watch viewport offset
*
* @return Viewport offset observable
* @returns Viewport offset observable
*/
export function watchViewportOffset(): Observable<ViewportOffset> {
return merge(

View File

@@ -42,7 +42,7 @@ export interface ViewportSize {
/**
* Retrieve viewport size
*
* @return Viewport size
* @returns Viewport size
*/
export function getViewportSize(): ViewportSize {
return {
@@ -56,7 +56,7 @@ export function getViewportSize(): ViewportSize {
/**
* Watch viewport size
*
* @return Viewport size observable
* @returns Viewport size observable
*/
export function watchViewportSize(): Observable<ViewportSize> {
return fromEvent(window, "resize", { passive: true })

View File

@@ -81,7 +81,7 @@ interface WatchOptions<T extends WorkerMessage> {
* @param worker - Web worker
* @param options - Options
*
* @return Worker message observable
* @returns Worker message observable
*/
export function watchWorker<T extends WorkerMessage>(
worker: Worker, { tx$ }: WatchOptions<T>
@@ -90,8 +90,8 @@ export function watchWorker<T extends WorkerMessage>(
/* Intercept messages from worker-like objects */
const rx$ = fromEvent<MessageEvent>(worker, "message")
.pipe<T>(
map(({ data }) => data)
)
map(({ data }) => data)
)
/* Send and receive messages, return hot observable */
return tx$