Options
All
  • Public
  • Public/Protected
  • All
Menu

Module panacea-browser

Index

BOM Functions

  • copyToClipboardAsync(str: string): Promise<void>
  • Copies a string to the clipboard, returning a promise that resolves when the clipboard's contents have been updated.

    example
    copyToClipboardAsync('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard.
    
    since

    0.1.5

    Parameters

    • str: string

      The string to copy.

    Returns Promise<void>

    A promise that resolves when the clipboard has been updated.

  • currentURL(): string
  • detectDeviceType(): "Mobile" | "Desktop"
  • Detects whether the page is being viewed on a mobile device or a desktop.

    example
    detectDeviceType(); // 'Mobile' or 'Desktop'
    
    since

    0.1.1

    Returns "Mobile" | "Desktop"

    'Mobile' or 'Desktop'

  • detectLanguage(defaultLang?: string): string
  • Detects the preferred language of the current user.

    example
    detectLanguage(); // 'nl-NL'
    
    since

    0.1.2

    Parameters

    • defaultLang: string = "US"

      The default language to use if none is found.

    Returns string

    The language preferred by the user or the default language if none is found.

  • getProtocol(): string
  • getSelectedText(): undefined | string
  • Gets the currently selected text.

    example
    getSelectedText(); // 'Lorem ipsum'
    
    since

    0.1.1

    Returns undefined | string

    The currently selected text.

  • getURLParameters(url: string): {}
  • Creates an object containing the parameters of the current URL.

    example
    getURLParameters('google.com'); // {}
    getURLParameters('http://url.com/page?name=Adam&surname=Smith');
    // {name: 'Adam', surname: 'Smith'}
    since

    0.1.6

    deprecated

    since 0.1.8 - Use import { getURLParameters } from panacea-core.

    Parameters

    • url: string

      The URL to parse.

    Returns {}

    An object containing the parameters of the current URL.

    • [key: string]: string
  • httpDelete(url: string | URL, callback: (request: XMLHttpRequest) => void, err?: (request: XMLHttpRequest, event: ProgressEvent<EventTarget>) => void): void
  • Makes a DELETE request to the passed URL.

    example
    httpDelete('https://jsonplaceholder.typicode.com/posts/1', request => {
    console.log(request.responseText);
    }); // Logs: {}
    since

    0.1.2

    Parameters

    • url: string | URL

      URL to send the DELETE request to.

    • callback: (request: XMLHttpRequest) => void

      Callback to handle the response.

        • (request: XMLHttpRequest): void
        • Parameters

          • request: XMLHttpRequest

          Returns void

    • err: (request: XMLHttpRequest, event: ProgressEvent<EventTarget>) => void = console.error

      Callback to handle an error.

        • (request: XMLHttpRequest, event: ProgressEvent<EventTarget>): void
        • Parameters

          • request: XMLHttpRequest
          • event: ProgressEvent<EventTarget>

          Returns void

    Returns void

  • httpGet(url: string | URL, callback: (responseText: string) => void, err?: (request: XMLHttpRequest, event: ProgressEvent<EventTarget>) => void): void
  • Makes a GET request to the passed URL.

    example
    httpGet(
    'https://jsonplaceholder.typicode.com/posts/1',
    console.log
    );
    since

    0.1.3

    Parameters

    • url: string | URL

      The URL to make the request to.

    • callback: (responseText: string) => void

      The callback to invoke when the request completes

        • (responseText: string): void
        • Parameters

          • responseText: string

          Returns void

    • err: (request: XMLHttpRequest, event: ProgressEvent<EventTarget>) => void = console.error

      The callback to invoke if the request fails

        • (request: XMLHttpRequest, event: ProgressEvent<EventTarget>): void
        • Parameters

          • request: XMLHttpRequest
          • event: ProgressEvent<EventTarget>

          Returns void

    Returns void

  • httpPost(url: string | URL, data: string, callback: (responseText: string) => void, err?: (request: XMLHttpRequest, event: ProgressEvent<EventTarget>) => void): void
  • Makes a POST request to the passed URL.

    example
    const newPost = {
    userId: 1,
    id: 1337,
    title: 'Foo',
    body: 'bar bar bar'
    };
    const data = JSON.stringify(newPost);
    httpPost(
    'https://jsonplaceholder.typicode.com/posts',
    data,
    console.log
    );
    since

    0.1.3

    Parameters

    • url: string | URL

      URL to send the request to.

    • data: string

      Data to send.

    • callback: (responseText: string) => void

      Callback to invoke when the request completes.

        • (responseText: string): void
        • Parameters

          • responseText: string

          Returns void

    • err: (request: XMLHttpRequest, event: ProgressEvent<EventTarget>) => void = console.error

      Callback to invoke when an error occurs.

        • (request: XMLHttpRequest, event: ProgressEvent<EventTarget>): void
        • Parameters

          • request: XMLHttpRequest
          • event: ProgressEvent<EventTarget>

          Returns void

    Returns void

  • httpPut(url: string | URL, data: string, callback: (request: XMLHttpRequest) => void, err?: (request: XMLHttpRequest, event: ProgressEvent<EventTarget>) => void): void
  • Makes a PUT request to the passed URL.

    example
    const password = 'fooBaz';
    const data = JSON.stringify({
    id: 1,
    title: 'foo',
    body: 'bar',
    userId: 1
    });
    httpPut('https://jsonplaceholder.typicode.com/posts/1', data, request => {
    console.log(request.responseText);
    });
    since

    0.1.3

    Parameters

    • url: string | URL

      The URL to make the request to.

    • data: string

      The data to send as the request body.

    • callback: (request: XMLHttpRequest) => void

      The callback to invoke when the request completes.

        • (request: XMLHttpRequest): void
        • Parameters

          • request: XMLHttpRequest

          Returns void

    • err: (request: XMLHttpRequest, event: ProgressEvent<EventTarget>) => void = console.error

      The callback to invoke when an error occurs.

        • (request: XMLHttpRequest, event: ProgressEvent<EventTarget>): void
        • Parameters

          • request: XMLHttpRequest
          • event: ProgressEvent<EventTarget>

          Returns void

    Returns void

  • httpsRedirect(): void
  • Redirects the page to HTTPS if it's currently in HTTP.

    example
    httpsRedirect();
    // If you are on http://mydomain.com, you are redirected to https://mydomain.
    since

    0.1.3

    Returns void

  • isLocalStorageEnabled(): boolean
  • isSessionStorageEnabled(): boolean
  • prefersDarkColorScheme(): boolean
  • Checks if the user color scheme preference is dark.

    example
    prefersDarkColorScheme(); // true
    
    since

    0.1.1

    Returns boolean

    true if the user color scheme preference is dark.

  • prefersLightColorScheme(): boolean
  • Checks if the user color scheme preference is light.

    example
    prefersLightColorScheme(); // true
    
    since

    0.1.1

    Returns boolean

    true if the user color scheme preference is light.

  • redirect(url: string, asLink?: boolean): void
  • Redirects to a specified URL.

    example
    redirect('https://google.com');
    
    since

    0.1.1

    Parameters

    • url: string

      The URL to redirect to.

    • asLink: boolean = true

      Whether to attempt to create a link to the URL.

    Returns void

  • runAsync(fn: (args?: any) => any): Promise<unknown>
  • Runs a function in a separate thread by using a Web Worker, allowing long running functions to not block the UI.

    example
    const longRunningFunction = () => {
    let result = 0;
    for (let i = 0; i < 1000; i++)
    for (let j = 0; j < 700; j++)
    for (let k = 0; k < 300; k++) result = result + i + j + k;

    return result;
    };
    runAsync(longRunningFunction).then(console.log); // 209685000000
    runAsync(() => 10 ** 3).then(console.log); // 1000
    let outsideVariable = 50;
    runAsync(() => typeof outsideVariable).then(console.log); // 'undefined'
    since

    0.1.6

    Parameters

    • fn: (args?: any) => any

      The function to run.

        • (args?: any): any
        • Parameters

          • Optional args: any

          Returns any

    Returns Promise<unknown>

    A promise which resolves to the return value of the function.

  • supportsTouchEvents(): boolean

Crypto Functions

  • hashBrowser(value: string): Promise<string>
  • Creates a hash for a value using the SHA-256 algorithm. Returns a promise.

    example
    hashBrowser(
    JSON.stringify({ a: 'a', b: [1, 2, 3, 4], foo: { c: 'bar' } })
    ).then(console.log);
    // '04aa106279f5977f59f9067fa9712afc4aedc6f5862a8defc34552d8c7206393'
    since

    0.1.0

    Parameters

    • value: string

      The value to hash.

    Returns Promise<string>

    A promise that resolves to the hash of the value.

DOM Functions

  • addClass(el: HTMLElement, className: string): void
  • Adds a class to an HTML element.

    example
    addClass(document.querySelector('p'), 'special');
    // The paragraph will now have the 'special' class
    since

    0.1.2

    Parameters

    • el: HTMLElement

      The element to add the class to.

    • className: string

      The class to add.

    Returns void

    The element with the class added.

  • addEventListenerAll(targets: EventTarget[], type: string, listener: null | EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void
  • Attaches an event listener to all the provided targets.

    example
    addEventListenerAll(document.querySelectorAll('a'), 'click', () =>
    console.log('Clicked a link')
    );
    // Logs 'Clicked a link' whenever any anchor element is clicked
    since

    0.1.5

    Parameters

    • targets: EventTarget[]

      The targets to add the event listener to.

    • type: string

      The type of event.

    • listener: null | EventListenerOrEventListenerObject

      The listener.

    • Optional options: boolean | EventListenerOptions

      The options.

    Returns void

  • addMultipleListeners(el: EventTarget, types: string[], listener: null | EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void
  • Adds multiple event listeners with the same handler to an element.

    example
    addMultipleListeners(
    document.querySelector('.my-element'),
    ['click', 'mousedown'],
    () => { console.log('hello!') }
    );
    since

    0.1.6

    Parameters

    • el: EventTarget

      Element to add listeners to.

    • types: string[]

      Types of events to add.

    • listener: null | EventListenerOrEventListenerObject

      Event listener.

    • Optional options: boolean | EventListenerOptions

      Event listener options.

    Returns void

  • addStyles(el: HTMLElement, styles: Partial<CSSStyleDeclaration>): Partial<CSSStyleDeclaration>
  • Adds the provided styles to the given HTML element.

    example
    addStyles(document.getElementById('my-element'), {
    background: 'red',
    color: '#ffff00',
    fontSize: '3rem'
    });
    since

    0.1.3

    Parameters

    • el: HTMLElement

      The element to add styles to.

    • styles: Partial<CSSStyleDeclaration>

      The styles to add.

    Returns Partial<CSSStyleDeclaration>

  • arrayToHTMLList(arr: string[], listID: string): void
  • Converts the given array elements into <li> tags and appends them to the list of the given id.

    example
    arrayToHTMLList(['item 1', 'item 2'], 'myListID');
    
    since

    0.1.5

    Parameters

    • arr: string[]

      The array of elements to be converted.

    • listID: string

      The id of the list to which the elements should be appended.

    Returns void

  • bottomVisible(): boolean
  • copyToClipboard(str: string): void
  • Copies a string to the clipboard. Only works as a result of user action (i.e. inside a click event listener).

    example
    copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard.
    
    alpha
    since

    0.1.5

    Parameters

    • str: string

      The string to copy.

    Returns void

  • createElement(str: string): null | Element
  • Creates an element from a string (without appending it to the document). If the given string contains multiple elements, only the first one will be returned.

    example
    const el = createElement(
    `<div class="container">
    <p>Hello!</p>
    </div>`
    );
    console.log(el.className); // 'container'
    since

    0.1.1

    Parameters

    • str: string

      The string to create the element from.

    Returns null | Element

    The created element, only the first one will be returned.

  • elementContains(parent: Element, child: Element): boolean
  • Checks if the parent element contains the child element.

    example
    elementContains(
    document.querySelector('head'),
    document.querySelector('title')
    );
    // true
    elementContains(document.querySelector('body'), document.querySelector('body'));
    // false
    since

    0.1.0

    Parameters

    • parent: Element

      The parent element.

    • child: Element

      The child element.

    Returns boolean

    true if the parent element contains the child element, otherwise false.

  • elementIsFocused(el: Element): boolean
  • Checks if the given element is focused.

    example
    elementIsFocused(el); // true if the element is focused
    
    since

    0.1.0

    Parameters

    • el: Element

      Element to check.

    Returns boolean

    True if the element is focused.

  • elementIsVisibleInViewport(el: Element, partiallyVisible?: boolean): boolean
  • Checks if the element specified is visible in the viewport.

    example
    // e.g. 100x100 viewport and a 10x10px element at position {top: -1, left: 0, bottom: 9, right: 10}
    elementIsVisibleInViewport(el); // false - (not fully visible)
    elementIsVisibleInViewport(el, true); // true - (partially visible)
    since

    0.1.0

    Parameters

    • el: Element

      Element to check.

    • partiallyVisible: boolean = false

      Omit the second argument to determine if the element is entirely visible, or specify true to determine if it is partially visible.

    Returns boolean

    True if the element is visible in the viewport.

  • findClosestAnchor(node: Node): null | Node
  • Finds the anchor node closest to the given node, if any.

    example
    findClosestAnchor(document.querySelector('a > span')); // a
    
    since

    0.1.2

    Parameters

    • node: Node

      The node to search from.

    Returns null | Node

    The anchor node if found, or null if not.

  • findClosestMatchingNode(node: Element, selector: string): null | Element
  • Finds the closest matching node starting at the given node.

    example
    findClosestMatchingNode(document.querySelector('span'), 'body'); // body
    
    since

    0.1.1

    Parameters

    • node: Element

      Starting node

    • selector: string

      Selector to match

    Returns null | Element

    Closest node or null

  • formToObject(form: HTMLFormElement): {}
  • Encodes a set of form elements as an object.

    example
    formToObject(document.querySelector('#form'));
    // { email: 'test@email.com', name: 'Test Name' }
    since

    0.1.5

    Parameters

    • form: HTMLFormElement

      The form element

    Returns {}

    An object representing the form values.

    • fullscreen(mode?: boolean, el?: string): Promise<void>
    • Opens or closes an element in fullscreen mode.

      example
      fullscreen(); // Opens `body` in fullscreen mode
      fullscreen(false); // Exits fullscreen mode
      since

      0.1.0

      Parameters

      • mode: boolean = true

        The mode to open the element in.

      • el: string = "body"

        The element to open in fullscreen mode.

      Returns Promise<void>

    • getAncestors(el: HTMLElement): HTMLElement[]
    • Returns all the ancestors of an element from the document root to the given element.

      example
      getAncestors(document.querySelector('nav'));
      // [document, html, body, header, nav]
      since

      0.1.3

      Parameters

      • el: HTMLElement

        The element to get the ancestors of.

      Returns HTMLElement[]

      The ancestors of the element.

    • getElementsBiggerThanViewport(): Element[]
    • getImages(el: HTMLElement, includeDuplicates?: boolean): (null | string)[]
    • Fetches all images from within an element and puts them into an array.

      example
      getImages(document, true); // ['image1.jpg', 'image2.png', 'image1.png', '...']
      getImages(document, false); // ['image1.jpg', 'image2.png', '...']
      since

      0.1.4

      Parameters

      • el: HTMLElement

        Element to search for images.

      • includeDuplicates: boolean = false

        Whether to include duplicate images or not.

      Returns (null | string)[]

      An array of all images in the element.

    • getParentsUntil(el: Node, selector: string): Element[]
    • Finds all the ancestors of an element up until the element matched by the specified selector.

      example
      getParentsUntil(document.querySelector('#home-link'), 'header');
      // [header, nav, ul, li]
      since

      0.1.4

      Parameters

      • el: Node

        Element to start from

      • selector: string

        Stop at this element

      Returns Element[]

      The matched elements

    • getScrollPosition(el?: Element | Window): { x: number; y: number }
    • Returns the scroll position of the current page.

      example
      getScrollPosition(); // {x: 0, y: 200}
      
      since

      0.1.2

      Parameters

      • el: Element | Window = window

        Optional element to measure.

      Returns { x: number; y: number }

      The scroll position of the current page.

      • x: number
      • y: number
    • getSiblings(el: Node): Node[]
    • Returns an array containing all the siblings of the given element.

      example
      getSiblings(document.querySelector('head')); // ['body']
      
      since

      0.1.5

      Parameters

      • el: Node

        The element to get all the siblings from.

      Returns Node[]

      An array of all the element's siblings.

    • getStyle(el: HTMLElement, ruleName: "accentColor" | "alignContent" | "alignItems" | "alignSelf" | "alignmentBaseline" | "all" | "animation" | "animationDelay" | "animationDirection" | "animationDuration" | "animationFillMode" | "animationIterationCount" | "animationName" | "animationPlayState" | "animationTimingFunction" | "appearance" | "aspectRatio" | "backfaceVisibility" | "background" | "backgroundAttachment" | "backgroundBlendMode" | "backgroundClip" | "backgroundColor" | "backgroundImage" | "backgroundOrigin" | "backgroundPosition" | "backgroundPositionX" | "backgroundPositionY" | "backgroundRepeat" | "backgroundSize" | "baselineShift" | "blockSize" | "border" | "borderBlock" | "borderBlockColor" | "borderBlockEnd" | "borderBlockEndColor" | "borderBlockEndStyle" | "borderBlockEndWidth" | "borderBlockStart" | "borderBlockStartColor" | "borderBlockStartStyle" | "borderBlockStartWidth" | "borderBlockStyle" | "borderBlockWidth" | "borderBottom" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderColor" | "borderEndEndRadius" | "borderEndStartRadius" | "borderImage" | "borderImageOutset" | "borderImageRepeat" | "borderImageSlice" | "borderImageSource" | "borderImageWidth" | "borderInline" | "borderInlineColor" | "borderInlineEnd" | "borderInlineEndColor" | "borderInlineEndStyle" | "borderInlineEndWidth" | "borderInlineStart" | "borderInlineStartColor" | "borderInlineStartStyle" | "borderInlineStartWidth" | "borderInlineStyle" | "borderInlineWidth" | "borderLeft" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRadius" | "borderRight" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderStartEndRadius" | "borderStartStartRadius" | "borderStyle" | "borderTop" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "borderWidth" | "bottom" | "boxShadow" | "boxSizing" | "breakAfter" | "breakBefore" | "breakInside" | "captionSide" | "caretColor" | "clear" | "clip" | "clipPath" | "clipRule" | "color" | "colorInterpolation" | "colorInterpolationFilters" | "colorScheme" | "columnCount" | "columnFill" | "columnGap" | "columnRule" | "columnRuleColor" | "columnRuleStyle" | "columnRuleWidth" | "columnSpan" | "columnWidth" | "columns" | "contain" | "content" | "counterIncrement" | "counterReset" | "counterSet" | "cssFloat" | "cssText" | "cursor" | "direction" | "display" | "dominantBaseline" | "emptyCells" | "fill" | "fillOpacity" | "fillRule" | "filter" | "flex" | "flexBasis" | "flexDirection" | "flexFlow" | "flexGrow" | "flexShrink" | "flexWrap" | "float" | "floodColor" | "floodOpacity" | "font" | "fontFamily" | "fontFeatureSettings" | "fontKerning" | "fontOpticalSizing" | "fontSize" | "fontSizeAdjust" | "fontStretch" | "fontStyle" | "fontSynthesis" | "fontVariant" | "fontVariantAlternates" | "fontVariantCaps" | "fontVariantEastAsian" | "fontVariantLigatures" | "fontVariantNumeric" | "fontVariantPosition" | "fontVariationSettings" | "fontWeight" | "gap" | "grid" | "gridArea" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridColumn" | "gridColumnEnd" | "gridColumnGap" | "gridColumnStart" | "gridGap" | "gridRow" | "gridRowEnd" | "gridRowGap" | "gridRowStart" | "gridTemplate" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "hyphens" | "imageOrientation" | "imageRendering" | "inlineSize" | "inset" | "insetBlock" | "insetBlockEnd" | "insetBlockStart" | "insetInline" | "insetInlineEnd" | "insetInlineStart" | "isolation" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lightingColor" | "lineBreak" | "lineHeight" | "listStyle" | "listStyleImage" | "listStylePosition" | "listStyleType" | "margin" | "marginBlock" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInline" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "marker" | "markerEnd" | "markerMid" | "markerStart" | "mask" | "maskType" | "maxBlockSize" | "maxHeight" | "maxInlineSize" | "maxWidth" | "minBlockSize" | "minHeight" | "minInlineSize" | "minWidth" | "mixBlendMode" | "objectFit" | "objectPosition" | "offset" | "offsetAnchor" | "offsetDistance" | "offsetPath" | "offsetRotate" | "opacity" | "order" | "orphans" | "outline" | "outlineColor" | "outlineOffset" | "outlineStyle" | "outlineWidth" | "overflow" | "overflowAnchor" | "overflowWrap" | "overflowX" | "overflowY" | "overscrollBehavior" | "overscrollBehaviorBlock" | "overscrollBehaviorInline" | "overscrollBehaviorX" | "overscrollBehaviorY" | "padding" | "paddingBlock" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInline" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "pageBreakAfter" | "pageBreakBefore" | "pageBreakInside" | "paintOrder" | "perspective" | "perspectiveOrigin" | "placeContent" | "placeItems" | "placeSelf" | "pointerEvents" | "position" | "quotes" | "resize" | "right" | "rotate" | "rowGap" | "rubyPosition" | "scale" | "scrollBehavior" | "scrollMargin" | "scrollMarginBlock" | "scrollMarginBlockEnd" | "scrollMarginBlockStart" | "scrollMarginBottom" | "scrollMarginInline" | "scrollMarginInlineEnd" | "scrollMarginInlineStart" | "scrollMarginLeft" | "scrollMarginRight" | "scrollMarginTop" | "scrollPadding" | "scrollPaddingBlock" | "scrollPaddingBlockEnd" | "scrollPaddingBlockStart" | "scrollPaddingBottom" | "scrollPaddingInline" | "scrollPaddingInlineEnd" | "scrollPaddingInlineStart" | "scrollPaddingLeft" | "scrollPaddingRight" | "scrollPaddingTop" | "scrollSnapAlign" | "scrollSnapStop" | "scrollSnapType" | "scrollbarGutter" | "shapeImageThreshold" | "shapeMargin" | "shapeOutside" | "shapeRendering" | "stopColor" | "stopOpacity" | "stroke" | "strokeDasharray" | "strokeDashoffset" | "strokeLinecap" | "strokeLinejoin" | "strokeMiterlimit" | "strokeOpacity" | "strokeWidth" | "tabSize" | "tableLayout" | "textAlign" | "textAlignLast" | "textAnchor" | "textCombineUpright" | "textDecoration" | "textDecorationColor" | "textDecorationLine" | "textDecorationSkipInk" | "textDecorationStyle" | "textDecorationThickness" | "textEmphasis" | "textEmphasisColor" | "textEmphasisPosition" | "textEmphasisStyle" | "textIndent" | "textOrientation" | "textOverflow" | "textRendering" | "textShadow" | "textTransform" | "textUnderlineOffset" | "textUnderlinePosition" | "top" | "touchAction" | "transform" | "transformBox" | "transformOrigin" | "transformStyle" | "transition" | "transitionDelay" | "transitionDuration" | "transitionProperty" | "transitionTimingFunction" | "translate" | "unicodeBidi" | "userSelect" | "verticalAlign" | "visibility" | "webkitAlignContent" | "webkitAlignItems" | "webkitAlignSelf" | "webkitAnimation" | "webkitAnimationDelay" | "webkitAnimationDirection" | "webkitAnimationDuration" | "webkitAnimationFillMode" | "webkitAnimationIterationCount" | "webkitAnimationName" | "webkitAnimationPlayState" | "webkitAnimationTimingFunction" | "webkitAppearance" | "webkitBackfaceVisibility" | "webkitBackgroundClip" | "webkitBackgroundOrigin" | "webkitBackgroundSize" | "webkitBorderBottomLeftRadius" | "webkitBorderBottomRightRadius" | "webkitBorderRadius" | "webkitBorderTopLeftRadius" | "webkitBorderTopRightRadius" | "webkitBoxAlign" | "webkitBoxFlex" | "webkitBoxOrdinalGroup" | "webkitBoxOrient" | "webkitBoxPack" | "webkitBoxShadow" | "webkitBoxSizing" | "webkitFilter" | "webkitFlex" | "webkitFlexBasis" | "webkitFlexDirection" | "webkitFlexFlow" | "webkitFlexGrow" | "webkitFlexShrink" | "webkitFlexWrap" | "webkitJustifyContent" | "webkitLineClamp" | "webkitMask" | "webkitMaskBoxImage" | "webkitMaskBoxImageOutset" | "webkitMaskBoxImageRepeat" | "webkitMaskBoxImageSlice" | "webkitMaskBoxImageSource" | "webkitMaskBoxImageWidth" | "webkitMaskClip" | "webkitMaskComposite" | "webkitMaskImage" | "webkitMaskOrigin" | "webkitMaskPosition" | "webkitMaskRepeat" | "webkitMaskSize" | "webkitOrder" | "webkitPerspective" | "webkitPerspectiveOrigin" | "webkitTextFillColor" | "webkitTextStroke" | "webkitTextStrokeColor" | "webkitTextStrokeWidth" | "webkitTransform" | "webkitTransformOrigin" | "webkitTransformStyle" | "webkitTransition" | "webkitTransitionDelay" | "webkitTransitionDuration" | "webkitTransitionProperty" | "webkitTransitionTimingFunction" | "webkitUserSelect" | "whiteSpace" | "widows" | "width" | "willChange" | "wordBreak" | "wordSpacing" | "wordWrap" | "writingMode" | "zIndex"): string
    • Retrieves the value of a CSS rule for the specified element.

      example
      getStyle(document.querySelector('p'), 'fontSize'); // '16px'
      
      since

      0.1.2

      Parameters

      • el: HTMLElement

        The element to get the style for.

      • ruleName: "accentColor" | "alignContent" | "alignItems" | "alignSelf" | "alignmentBaseline" | "all" | "animation" | "animationDelay" | "animationDirection" | "animationDuration" | "animationFillMode" | "animationIterationCount" | "animationName" | "animationPlayState" | "animationTimingFunction" | "appearance" | "aspectRatio" | "backfaceVisibility" | "background" | "backgroundAttachment" | "backgroundBlendMode" | "backgroundClip" | "backgroundColor" | "backgroundImage" | "backgroundOrigin" | "backgroundPosition" | "backgroundPositionX" | "backgroundPositionY" | "backgroundRepeat" | "backgroundSize" | "baselineShift" | "blockSize" | "border" | "borderBlock" | "borderBlockColor" | "borderBlockEnd" | "borderBlockEndColor" | "borderBlockEndStyle" | "borderBlockEndWidth" | "borderBlockStart" | "borderBlockStartColor" | "borderBlockStartStyle" | "borderBlockStartWidth" | "borderBlockStyle" | "borderBlockWidth" | "borderBottom" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderColor" | "borderEndEndRadius" | "borderEndStartRadius" | "borderImage" | "borderImageOutset" | "borderImageRepeat" | "borderImageSlice" | "borderImageSource" | "borderImageWidth" | "borderInline" | "borderInlineColor" | "borderInlineEnd" | "borderInlineEndColor" | "borderInlineEndStyle" | "borderInlineEndWidth" | "borderInlineStart" | "borderInlineStartColor" | "borderInlineStartStyle" | "borderInlineStartWidth" | "borderInlineStyle" | "borderInlineWidth" | "borderLeft" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRadius" | "borderRight" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderStartEndRadius" | "borderStartStartRadius" | "borderStyle" | "borderTop" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "borderWidth" | "bottom" | "boxShadow" | "boxSizing" | "breakAfter" | "breakBefore" | "breakInside" | "captionSide" | "caretColor" | "clear" | "clip" | "clipPath" | "clipRule" | "color" | "colorInterpolation" | "colorInterpolationFilters" | "colorScheme" | "columnCount" | "columnFill" | "columnGap" | "columnRule" | "columnRuleColor" | "columnRuleStyle" | "columnRuleWidth" | "columnSpan" | "columnWidth" | "columns" | "contain" | "content" | "counterIncrement" | "counterReset" | "counterSet" | "cssFloat" | "cssText" | "cursor" | "direction" | "display" | "dominantBaseline" | "emptyCells" | "fill" | "fillOpacity" | "fillRule" | "filter" | "flex" | "flexBasis" | "flexDirection" | "flexFlow" | "flexGrow" | "flexShrink" | "flexWrap" | "float" | "floodColor" | "floodOpacity" | "font" | "fontFamily" | "fontFeatureSettings" | "fontKerning" | "fontOpticalSizing" | "fontSize" | "fontSizeAdjust" | "fontStretch" | "fontStyle" | "fontSynthesis" | "fontVariant" | "fontVariantAlternates" | "fontVariantCaps" | "fontVariantEastAsian" | "fontVariantLigatures" | "fontVariantNumeric" | "fontVariantPosition" | "fontVariationSettings" | "fontWeight" | "gap" | "grid" | "gridArea" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridColumn" | "gridColumnEnd" | "gridColumnGap" | "gridColumnStart" | "gridGap" | "gridRow" | "gridRowEnd" | "gridRowGap" | "gridRowStart" | "gridTemplate" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "hyphens" | "imageOrientation" | "imageRendering" | "inlineSize" | "inset" | "insetBlock" | "insetBlockEnd" | "insetBlockStart" | "insetInline" | "insetInlineEnd" | "insetInlineStart" | "isolation" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lightingColor" | "lineBreak" | "lineHeight" | "listStyle" | "listStyleImage" | "listStylePosition" | "listStyleType" | "margin" | "marginBlock" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInline" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "marker" | "markerEnd" | "markerMid" | "markerStart" | "mask" | "maskType" | "maxBlockSize" | "maxHeight" | "maxInlineSize" | "maxWidth" | "minBlockSize" | "minHeight" | "minInlineSize" | "minWidth" | "mixBlendMode" | "objectFit" | "objectPosition" | "offset" | "offsetAnchor" | "offsetDistance" | "offsetPath" | "offsetRotate" | "opacity" | "order" | "orphans" | "outline" | "outlineColor" | "outlineOffset" | "outlineStyle" | "outlineWidth" | "overflow" | "overflowAnchor" | "overflowWrap" | "overflowX" | "overflowY" | "overscrollBehavior" | "overscrollBehaviorBlock" | "overscrollBehaviorInline" | "overscrollBehaviorX" | "overscrollBehaviorY" | "padding" | "paddingBlock" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInline" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "pageBreakAfter" | "pageBreakBefore" | "pageBreakInside" | "paintOrder" | "perspective" | "perspectiveOrigin" | "placeContent" | "placeItems" | "placeSelf" | "pointerEvents" | "position" | "quotes" | "resize" | "right" | "rotate" | "rowGap" | "rubyPosition" | "scale" | "scrollBehavior" | "scrollMargin" | "scrollMarginBlock" | "scrollMarginBlockEnd" | "scrollMarginBlockStart" | "scrollMarginBottom" | "scrollMarginInline" | "scrollMarginInlineEnd" | "scrollMarginInlineStart" | "scrollMarginLeft" | "scrollMarginRight" | "scrollMarginTop" | "scrollPadding" | "scrollPaddingBlock" | "scrollPaddingBlockEnd" | "scrollPaddingBlockStart" | "scrollPaddingBottom" | "scrollPaddingInline" | "scrollPaddingInlineEnd" | "scrollPaddingInlineStart" | "scrollPaddingLeft" | "scrollPaddingRight" | "scrollPaddingTop" | "scrollSnapAlign" | "scrollSnapStop" | "scrollSnapType" | "scrollbarGutter" | "shapeImageThreshold" | "shapeMargin" | "shapeOutside" | "shapeRendering" | "stopColor" | "stopOpacity" | "stroke" | "strokeDasharray" | "strokeDashoffset" | "strokeLinecap" | "strokeLinejoin" | "strokeMiterlimit" | "strokeOpacity" | "strokeWidth" | "tabSize" | "tableLayout" | "textAlign" | "textAlignLast" | "textAnchor" | "textCombineUpright" | "textDecoration" | "textDecorationColor" | "textDecorationLine" | "textDecorationSkipInk" | "textDecorationStyle" | "textDecorationThickness" | "textEmphasis" | "textEmphasisColor" | "textEmphasisPosition" | "textEmphasisStyle" | "textIndent" | "textOrientation" | "textOverflow" | "textRendering" | "textShadow" | "textTransform" | "textUnderlineOffset" | "textUnderlinePosition" | "top" | "touchAction" | "transform" | "transformBox" | "transformOrigin" | "transformStyle" | "transition" | "transitionDelay" | "transitionDuration" | "transitionProperty" | "transitionTimingFunction" | "translate" | "unicodeBidi" | "userSelect" | "verticalAlign" | "visibility" | "webkitAlignContent" | "webkitAlignItems" | "webkitAlignSelf" | "webkitAnimation" | "webkitAnimationDelay" | "webkitAnimationDirection" | "webkitAnimationDuration" | "webkitAnimationFillMode" | "webkitAnimationIterationCount" | "webkitAnimationName" | "webkitAnimationPlayState" | "webkitAnimationTimingFunction" | "webkitAppearance" | "webkitBackfaceVisibility" | "webkitBackgroundClip" | "webkitBackgroundOrigin" | "webkitBackgroundSize" | "webkitBorderBottomLeftRadius" | "webkitBorderBottomRightRadius" | "webkitBorderRadius" | "webkitBorderTopLeftRadius" | "webkitBorderTopRightRadius" | "webkitBoxAlign" | "webkitBoxFlex" | "webkitBoxOrdinalGroup" | "webkitBoxOrient" | "webkitBoxPack" | "webkitBoxShadow" | "webkitBoxSizing" | "webkitFilter" | "webkitFlex" | "webkitFlexBasis" | "webkitFlexDirection" | "webkitFlexFlow" | "webkitFlexGrow" | "webkitFlexShrink" | "webkitFlexWrap" | "webkitJustifyContent" | "webkitLineClamp" | "webkitMask" | "webkitMaskBoxImage" | "webkitMaskBoxImageOutset" | "webkitMaskBoxImageRepeat" | "webkitMaskBoxImageSlice" | "webkitMaskBoxImageSource" | "webkitMaskBoxImageWidth" | "webkitMaskClip" | "webkitMaskComposite" | "webkitMaskImage" | "webkitMaskOrigin" | "webkitMaskPosition" | "webkitMaskRepeat" | "webkitMaskSize" | "webkitOrder" | "webkitPerspective" | "webkitPerspectiveOrigin" | "webkitTextFillColor" | "webkitTextStroke" | "webkitTextStrokeColor" | "webkitTextStrokeWidth" | "webkitTransform" | "webkitTransformOrigin" | "webkitTransformStyle" | "webkitTransition" | "webkitTransitionDelay" | "webkitTransitionDuration" | "webkitTransitionProperty" | "webkitTransitionTimingFunction" | "webkitUserSelect" | "whiteSpace" | "widows" | "width" | "willChange" | "wordBreak" | "wordSpacing" | "wordWrap" | "writingMode" | "zIndex"

        The name of the CSS rule.

      Returns string

      The value of the CSS rule.

    • getVerticalOffset(el: HTMLElement): number
    • Finds the distance from a given element to the top of the document.

      example
      getVerticalOffset('.my-element'); // 120
      
      since

      0.1.1

      Parameters

      • el: HTMLElement

        Element to find the distance from.

      Returns number

      The distance from the top of the document to the element.

    • hasClass(el: HTMLElement, className: string): boolean
    • Checks if the given element has the specified class.

      example
      hasClass(document.querySelector('p.special'), 'special'); // true
      
      since

      0.1.3

      Parameters

      • el: HTMLElement

        The element to check.

      • className: string

        The class to check for.

      Returns boolean

      true if the element has the class, false otherwise.

    • hide(...el: HTMLElement[]): void
    • Hides all the elements specified.

      example
      hide(...document.querySelectorAll('img')); // Hides all <img> elements on the page
      
      since

      0.1.5

      Parameters

      • Rest ...el: HTMLElement[]

        The elements to hide.

      Returns void

    • injectCSS(css: string): HTMLStyleElement
    • Injects the given CSS code into the current document

      example
      injectCSS('body { background-color: #000 }');
      // '<style>body { background-color: #000 }</style>'
      since

      0.1.2

      Parameters

      • css: string

        The CSS code to inject

      Returns HTMLStyleElement

      The created style element

    • insertAfter(el: Element, text: string): void
    • Inserts an HTML string after the end of the specified element.

      example
      insertAfter(document.getElementById('myId'), '<p>after</p>');
      // <div id="myId">...</div><p>after</p>
      since

      0.1.1

      Parameters

      • el: Element

        The element to insert the string after.

      • text: string

        The HTML string to insert.

      Returns void

      The element.

    • insertBefore(el: Element, text: string): void
    • Inserts an HTML string before the start of the specified element.

      example
      insertBefore(document.getElementById('myId'), '<p>before</p>');
      // <p>before</p><div id="myId">...</div>
      since

      0.1.1

      Parameters

      • el: Element

        The element to insert the string before.

      • text: string

        The HTML string to insert.

      Returns void

      The element.

    • isBrowserTabFocused(): boolean
    • Checks if the browser tab of the page is focused.

      example
      isBrowserTabFocused(); // true or false
      
      since

      0.1.0

      Returns boolean

      True if the browser tab is focused, false otherwise.

    • listenOnce<K>(el: HTMLElement, evt: K, fn: (this: HTMLElement, evt: HTMLElementEventMap[K]) => any): void
    • listenOnce<K>(el: Window, evt: K, fn: (this: Window, ev: WindowEventMap[K]) => any): void
    • Adds an event listener to an element that will only run the callback the first time the event is triggered.

      example
      listenOnce(
      document.getElementById('my-id'),
      'click',
      () => console.log('Hello world')
      ); // 'Hello world' will only be logged on the first click
      since

      0.1.2

      Type parameters

      • K: keyof HTMLElementEventMap

      Parameters

      • el: HTMLElement

        The element to add the event listener to.

      • evt: K

        The event to listen for.

      • fn: (this: HTMLElement, evt: HTMLElementEventMap[K]) => any

        The callback to run when the event is triggered.

          • (this: HTMLElement, evt: HTMLElementEventMap[K]): any
          • Parameters

            • this: HTMLElement
            • evt: HTMLElementEventMap[K]

            Returns any

      Returns void

    • Adds an event listener to an element that will only run the callback the first time the event is triggered.

      example
      listenOnce(
      document.getElementById('my-id'),
      'click',
      () => console.log('Hello world')
      ); // 'Hello world' will only be logged on the first click
      since

      0.1.2

      Type parameters

      • K: keyof WindowEventMap

      Parameters

      • el: Window

        The element to add the event listener to.

      • evt: K

        The event to listen for.

      • fn: (this: Window, ev: WindowEventMap[K]) => any

        The callback to run when the event is triggered.

          • (this: Window, ev: WindowEventMap[K]): any
          • Parameters

            • this: Window
            • ev: WindowEventMap[K]

            Returns any

      Returns void

    • nodeListToArray(nodeList: NodeList): Node[]
    • Converts a NodeList to an array.

      example
      nodeListToArray(document.childNodes); // [ <!DOCTYPE html>, html ]
      
      since

      0.1.4

      Parameters

      • nodeList: NodeList

        the NodeList to convert

      Returns Node[]

      an array of Nodes

    • observeMutations(element: Node, callback: (mutation: MutationRecord) => void, options?: MutationObserverInit): MutationObserver
    • Creates a new MutationObserver and runs the provided callback for each mutation on the specified element.

      example
      const obs = observeMutations(document, console.log);
      // Logs all mutations that happen on the page
      obs.disconnect();
      // Disconnects the observer and stops logging mutations on the page
      since

      0.1.5

      Parameters

      • element: Node

        Element to observe.

      • callback: (mutation: MutationRecord) => void

        Callback to run for each mutation.

          • (mutation: MutationRecord): void
          • Parameters

            • mutation: MutationRecord

            Returns void

      • Optional options: MutationObserverInit

        Options for the observer.

      Returns MutationObserver

      The new MutationObserver instance.

    • off<K>(el: HTMLElement, evt: K, handler: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void
    • off<K>(el: Window, evt: K, handler: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | EventListenerOptions): void
    • Removes an event listener from an element.

      example
      const fn = () => console.log('!');
      document.body.addEventListener('click', fn);
      off(document.body, 'click', fn); // no longer logs '!' upon clicking on the page
      since

      0.1.2

      Type parameters

      • K: keyof HTMLElementEventMap

      Parameters

      • el: HTMLElement

        The element to remove the event listener from.

      • evt: K

        The event name.

      • handler: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any
          • (this: HTMLElement, ev: HTMLElementEventMap[K]): any
          • Parameters

            • this: HTMLElement
            • ev: HTMLElementEventMap[K]

            Returns any

      • Optional options: boolean | EventListenerOptions

      Returns void

    • Removes an event listener from an element.

      example
      const fn = () => console.log('!');
      document.body.addEventListener('click', fn);
      off(document.body, 'click', fn); // no longer logs '!' upon clicking on the page
      since

      0.1.2

      Type parameters

      • K: keyof WindowEventMap

      Parameters

      • el: Window

        The element to remove the event listener from.

      • evt: K

        The event name.

      • handler: (this: Window, ev: WindowEventMap[K]) => any
          • (this: Window, ev: WindowEventMap[K]): any
          • Parameters

            • this: Window
            • ev: WindowEventMap[K]

            Returns any

      • Optional options: boolean | EventListenerOptions

      Returns void

    • on<K>(el: HTMLElement, evt: K, fn: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, opts?: { options?: boolean | AddEventListenerOptions; target?: string }): (e: HTMLElementEventMap[K]) => void
    • on<K>(el: Window, evt: K, fn: (this: Window, ev: WindowEventMap[K]) => any, opts?: { options?: boolean | AddEventListenerOptions; target?: string }): (e: WindowEventMap[K]) => void
    • Adds an event listener to an element with the ability to use event delegation.

      example
      const fn = () => console.log('!');
      on(document.body, 'click', fn); // logs '!' upon clicking the body
      on(document.body, 'click', fn, { target: 'p' });
      // logs '!' upon clicking a `p` element child of the body
      on(document.body, 'click', fn, { options: true });
      // use capturing instead of bubbling
      since

      0.1.2

      Type parameters

      • K: keyof HTMLElementEventMap

      Parameters

      • el: HTMLElement

        The element to add the event listener to.

      • evt: K

        The event to listen for.

      • fn: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any

        The function to run when the event is triggered.

          • (this: HTMLElement, ev: HTMLElementEventMap[K]): any
          • Parameters

            • this: HTMLElement
            • ev: HTMLElementEventMap[K]

            Returns any

      • Optional opts: { options?: boolean | AddEventListenerOptions; target?: string }

        The options to use when binding the event listener.

        • Optional options?: boolean | AddEventListenerOptions
        • Optional target?: string

      Returns (e: HTMLElementEventMap[K]) => void

      The function to remove the event listener from the element.

        • (e: HTMLElementEventMap[K]): void
        • Parameters

          • e: HTMLElementEventMap[K]

          Returns void

    • Adds an event listener to an element with the ability to use event delegation.

      example
      const fn = () => console.log('!');
      on(document.body, 'click', fn); // logs '!' upon clicking the body
      on(document.body, 'click', fn, { target: 'p' });
      // logs '!' upon clicking a `p` element child of the body
      on(document.body, 'click', fn, { options: true });
      // use capturing instead of bubbling
      since

      0.1.2

      Type parameters

      • K: keyof WindowEventMap

      Parameters

      • el: Window

        The element to add the event listener to.

      • evt: K

        The event to listen for.

      • fn: (this: Window, ev: WindowEventMap[K]) => any

        The function to run when the event is triggered.

          • (this: Window, ev: WindowEventMap[K]): any
          • Parameters

            • this: Window
            • ev: WindowEventMap[K]

            Returns any

      • Optional opts: { options?: boolean | AddEventListenerOptions; target?: string }

        The options to use when binding the event listener.

        • Optional options?: boolean | AddEventListenerOptions
        • Optional target?: string

      Returns (e: WindowEventMap[K]) => void

      The function to remove the event listener from the element.

        • (e: WindowEventMap[K]): void
        • Parameters

          • e: WindowEventMap[K]

          Returns void

    • onClickOutside(element: Node, callback: () => void): void
    • Runs the callback whenever the user clicks outside of the specified element.

      example
      onClickOutside('#my-element', () => console.log('Hello'));
      // Will log 'Hello' whenever the user clicks outside of #my-element
      since

      0.1.3

      Parameters

      • element: Node

        The element to listen to for clicks.

      • callback: () => void

        The callback to call when the user clicks.

          • (): void
          • Returns void

      Returns void

    • prefix(prop: "accentColor" | "alignContent" | "alignItems" | "alignSelf" | "alignmentBaseline" | "all" | "animation" | "animationDelay" | "animationDirection" | "animationDuration" | "animationFillMode" | "animationIterationCount" | "animationName" | "animationPlayState" | "animationTimingFunction" | "appearance" | "aspectRatio" | "backfaceVisibility" | "background" | "backgroundAttachment" | "backgroundBlendMode" | "backgroundClip" | "backgroundColor" | "backgroundImage" | "backgroundOrigin" | "backgroundPosition" | "backgroundPositionX" | "backgroundPositionY" | "backgroundRepeat" | "backgroundSize" | "baselineShift" | "blockSize" | "border" | "borderBlock" | "borderBlockColor" | "borderBlockEnd" | "borderBlockEndColor" | "borderBlockEndStyle" | "borderBlockEndWidth" | "borderBlockStart" | "borderBlockStartColor" | "borderBlockStartStyle" | "borderBlockStartWidth" | "borderBlockStyle" | "borderBlockWidth" | "borderBottom" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderColor" | "borderEndEndRadius" | "borderEndStartRadius" | "borderImage" | "borderImageOutset" | "borderImageRepeat" | "borderImageSlice" | "borderImageSource" | "borderImageWidth" | "borderInline" | "borderInlineColor" | "borderInlineEnd" | "borderInlineEndColor" | "borderInlineEndStyle" | "borderInlineEndWidth" | "borderInlineStart" | "borderInlineStartColor" | "borderInlineStartStyle" | "borderInlineStartWidth" | "borderInlineStyle" | "borderInlineWidth" | "borderLeft" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRadius" | "borderRight" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderStartEndRadius" | "borderStartStartRadius" | "borderStyle" | "borderTop" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "borderWidth" | "bottom" | "boxShadow" | "boxSizing" | "breakAfter" | "breakBefore" | "breakInside" | "captionSide" | "caretColor" | "clear" | "clip" | "clipPath" | "clipRule" | "color" | "colorInterpolation" | "colorInterpolationFilters" | "colorScheme" | "columnCount" | "columnFill" | "columnGap" | "columnRule" | "columnRuleColor" | "columnRuleStyle" | "columnRuleWidth" | "columnSpan" | "columnWidth" | "columns" | "contain" | "content" | "counterIncrement" | "counterReset" | "counterSet" | "cssFloat" | "cssText" | "cursor" | "direction" | "display" | "dominantBaseline" | "emptyCells" | "fill" | "fillOpacity" | "fillRule" | "filter" | "flex" | "flexBasis" | "flexDirection" | "flexFlow" | "flexGrow" | "flexShrink" | "flexWrap" | "float" | "floodColor" | "floodOpacity" | "font" | "fontFamily" | "fontFeatureSettings" | "fontKerning" | "fontOpticalSizing" | "fontSize" | "fontSizeAdjust" | "fontStretch" | "fontStyle" | "fontSynthesis" | "fontVariant" | "fontVariantAlternates" | "fontVariantCaps" | "fontVariantEastAsian" | "fontVariantLigatures" | "fontVariantNumeric" | "fontVariantPosition" | "fontVariationSettings" | "fontWeight" | "gap" | "grid" | "gridArea" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridColumn" | "gridColumnEnd" | "gridColumnGap" | "gridColumnStart" | "gridGap" | "gridRow" | "gridRowEnd" | "gridRowGap" | "gridRowStart" | "gridTemplate" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "hyphens" | "imageOrientation" | "imageRendering" | "inlineSize" | "inset" | "insetBlock" | "insetBlockEnd" | "insetBlockStart" | "insetInline" | "insetInlineEnd" | "insetInlineStart" | "isolation" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lightingColor" | "lineBreak" | "lineHeight" | "listStyle" | "listStyleImage" | "listStylePosition" | "listStyleType" | "margin" | "marginBlock" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInline" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "marker" | "markerEnd" | "markerMid" | "markerStart" | "mask" | "maskType" | "maxBlockSize" | "maxHeight" | "maxInlineSize" | "maxWidth" | "minBlockSize" | "minHeight" | "minInlineSize" | "minWidth" | "mixBlendMode" | "objectFit" | "objectPosition" | "offset" | "offsetAnchor" | "offsetDistance" | "offsetPath" | "offsetRotate" | "opacity" | "order" | "orphans" | "outline" | "outlineColor" | "outlineOffset" | "outlineStyle" | "outlineWidth" | "overflow" | "overflowAnchor" | "overflowWrap" | "overflowX" | "overflowY" | "overscrollBehavior" | "overscrollBehaviorBlock" | "overscrollBehaviorInline" | "overscrollBehaviorX" | "overscrollBehaviorY" | "padding" | "paddingBlock" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInline" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "pageBreakAfter" | "pageBreakBefore" | "pageBreakInside" | "paintOrder" | "perspective" | "perspectiveOrigin" | "placeContent" | "placeItems" | "placeSelf" | "pointerEvents" | "position" | "quotes" | "resize" | "right" | "rotate" | "rowGap" | "rubyPosition" | "scale" | "scrollBehavior" | "scrollMargin" | "scrollMarginBlock" | "scrollMarginBlockEnd" | "scrollMarginBlockStart" | "scrollMarginBottom" | "scrollMarginInline" | "scrollMarginInlineEnd" | "scrollMarginInlineStart" | "scrollMarginLeft" | "scrollMarginRight" | "scrollMarginTop" | "scrollPadding" | "scrollPaddingBlock" | "scrollPaddingBlockEnd" | "scrollPaddingBlockStart" | "scrollPaddingBottom" | "scrollPaddingInline" | "scrollPaddingInlineEnd" | "scrollPaddingInlineStart" | "scrollPaddingLeft" | "scrollPaddingRight" | "scrollPaddingTop" | "scrollSnapAlign" | "scrollSnapStop" | "scrollSnapType" | "scrollbarGutter" | "shapeImageThreshold" | "shapeMargin" | "shapeOutside" | "shapeRendering" | "stopColor" | "stopOpacity" | "stroke" | "strokeDasharray" | "strokeDashoffset" | "strokeLinecap" | "strokeLinejoin" | "strokeMiterlimit" | "strokeOpacity" | "strokeWidth" | "tabSize" | "tableLayout" | "textAlign" | "textAlignLast" | "textAnchor" | "textCombineUpright" | "textDecoration" | "textDecorationColor" | "textDecorationLine" | "textDecorationSkipInk" | "textDecorationStyle" | "textDecorationThickness" | "textEmphasis" | "textEmphasisColor" | "textEmphasisPosition" | "textEmphasisStyle" | "textIndent" | "textOrientation" | "textOverflow" | "textRendering" | "textShadow" | "textTransform" | "textUnderlineOffset" | "textUnderlinePosition" | "top" | "touchAction" | "transform" | "transformBox" | "transformOrigin" | "transformStyle" | "transition" | "transitionDelay" | "transitionDuration" | "transitionProperty" | "transitionTimingFunction" | "translate" | "unicodeBidi" | "userSelect" | "verticalAlign" | "visibility" | "webkitAlignContent" | "webkitAlignItems" | "webkitAlignSelf" | "webkitAnimation" | "webkitAnimationDelay" | "webkitAnimationDirection" | "webkitAnimationDuration" | "webkitAnimationFillMode" | "webkitAnimationIterationCount" | "webkitAnimationName" | "webkitAnimationPlayState" | "webkitAnimationTimingFunction" | "webkitAppearance" | "webkitBackfaceVisibility" | "webkitBackgroundClip" | "webkitBackgroundOrigin" | "webkitBackgroundSize" | "webkitBorderBottomLeftRadius" | "webkitBorderBottomRightRadius" | "webkitBorderRadius" | "webkitBorderTopLeftRadius" | "webkitBorderTopRightRadius" | "webkitBoxAlign" | "webkitBoxFlex" | "webkitBoxOrdinalGroup" | "webkitBoxOrient" | "webkitBoxPack" | "webkitBoxShadow" | "webkitBoxSizing" | "webkitFilter" | "webkitFlex" | "webkitFlexBasis" | "webkitFlexDirection" | "webkitFlexFlow" | "webkitFlexGrow" | "webkitFlexShrink" | "webkitFlexWrap" | "webkitJustifyContent" | "webkitLineClamp" | "webkitMask" | "webkitMaskBoxImage" | "webkitMaskBoxImageOutset" | "webkitMaskBoxImageRepeat" | "webkitMaskBoxImageSlice" | "webkitMaskBoxImageSource" | "webkitMaskBoxImageWidth" | "webkitMaskClip" | "webkitMaskComposite" | "webkitMaskImage" | "webkitMaskOrigin" | "webkitMaskPosition" | "webkitMaskRepeat" | "webkitMaskSize" | "webkitOrder" | "webkitPerspective" | "webkitPerspectiveOrigin" | "webkitTextFillColor" | "webkitTextStroke" | "webkitTextStrokeColor" | "webkitTextStrokeWidth" | "webkitTransform" | "webkitTransformOrigin" | "webkitTransformStyle" | "webkitTransition" | "webkitTransitionDelay" | "webkitTransitionDuration" | "webkitTransitionProperty" | "webkitTransitionTimingFunction" | "webkitUserSelect" | "whiteSpace" | "widows" | "width" | "willChange" | "wordBreak" | "wordSpacing" | "wordWrap" | "writingMode" | "zIndex"): null | string
    • Prefixes a CSS property based on the current browser.

      example
      prefix('appearance');
      // 'appearance' on a supported browser, otherwise 'webkitAppearance', 'mozAppearance', 'msAppearance' or 'oAppearance'
      alpha
      since

      0.1.5

      Parameters

      • prop: "accentColor" | "alignContent" | "alignItems" | "alignSelf" | "alignmentBaseline" | "all" | "animation" | "animationDelay" | "animationDirection" | "animationDuration" | "animationFillMode" | "animationIterationCount" | "animationName" | "animationPlayState" | "animationTimingFunction" | "appearance" | "aspectRatio" | "backfaceVisibility" | "background" | "backgroundAttachment" | "backgroundBlendMode" | "backgroundClip" | "backgroundColor" | "backgroundImage" | "backgroundOrigin" | "backgroundPosition" | "backgroundPositionX" | "backgroundPositionY" | "backgroundRepeat" | "backgroundSize" | "baselineShift" | "blockSize" | "border" | "borderBlock" | "borderBlockColor" | "borderBlockEnd" | "borderBlockEndColor" | "borderBlockEndStyle" | "borderBlockEndWidth" | "borderBlockStart" | "borderBlockStartColor" | "borderBlockStartStyle" | "borderBlockStartWidth" | "borderBlockStyle" | "borderBlockWidth" | "borderBottom" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderColor" | "borderEndEndRadius" | "borderEndStartRadius" | "borderImage" | "borderImageOutset" | "borderImageRepeat" | "borderImageSlice" | "borderImageSource" | "borderImageWidth" | "borderInline" | "borderInlineColor" | "borderInlineEnd" | "borderInlineEndColor" | "borderInlineEndStyle" | "borderInlineEndWidth" | "borderInlineStart" | "borderInlineStartColor" | "borderInlineStartStyle" | "borderInlineStartWidth" | "borderInlineStyle" | "borderInlineWidth" | "borderLeft" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRadius" | "borderRight" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderStartEndRadius" | "borderStartStartRadius" | "borderStyle" | "borderTop" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "borderWidth" | "bottom" | "boxShadow" | "boxSizing" | "breakAfter" | "breakBefore" | "breakInside" | "captionSide" | "caretColor" | "clear" | "clip" | "clipPath" | "clipRule" | "color" | "colorInterpolation" | "colorInterpolationFilters" | "colorScheme" | "columnCount" | "columnFill" | "columnGap" | "columnRule" | "columnRuleColor" | "columnRuleStyle" | "columnRuleWidth" | "columnSpan" | "columnWidth" | "columns" | "contain" | "content" | "counterIncrement" | "counterReset" | "counterSet" | "cssFloat" | "cssText" | "cursor" | "direction" | "display" | "dominantBaseline" | "emptyCells" | "fill" | "fillOpacity" | "fillRule" | "filter" | "flex" | "flexBasis" | "flexDirection" | "flexFlow" | "flexGrow" | "flexShrink" | "flexWrap" | "float" | "floodColor" | "floodOpacity" | "font" | "fontFamily" | "fontFeatureSettings" | "fontKerning" | "fontOpticalSizing" | "fontSize" | "fontSizeAdjust" | "fontStretch" | "fontStyle" | "fontSynthesis" | "fontVariant" | "fontVariantAlternates" | "fontVariantCaps" | "fontVariantEastAsian" | "fontVariantLigatures" | "fontVariantNumeric" | "fontVariantPosition" | "fontVariationSettings" | "fontWeight" | "gap" | "grid" | "gridArea" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridColumn" | "gridColumnEnd" | "gridColumnGap" | "gridColumnStart" | "gridGap" | "gridRow" | "gridRowEnd" | "gridRowGap" | "gridRowStart" | "gridTemplate" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "hyphens" | "imageOrientation" | "imageRendering" | "inlineSize" | "inset" | "insetBlock" | "insetBlockEnd" | "insetBlockStart" | "insetInline" | "insetInlineEnd" | "insetInlineStart" | "isolation" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lightingColor" | "lineBreak" | "lineHeight" | "listStyle" | "listStyleImage" | "listStylePosition" | "listStyleType" | "margin" | "marginBlock" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInline" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "marker" | "markerEnd" | "markerMid" | "markerStart" | "mask" | "maskType" | "maxBlockSize" | "maxHeight" | "maxInlineSize" | "maxWidth" | "minBlockSize" | "minHeight" | "minInlineSize" | "minWidth" | "mixBlendMode" | "objectFit" | "objectPosition" | "offset" | "offsetAnchor" | "offsetDistance" | "offsetPath" | "offsetRotate" | "opacity" | "order" | "orphans" | "outline" | "outlineColor" | "outlineOffset" | "outlineStyle" | "outlineWidth" | "overflow" | "overflowAnchor" | "overflowWrap" | "overflowX" | "overflowY" | "overscrollBehavior" | "overscrollBehaviorBlock" | "overscrollBehaviorInline" | "overscrollBehaviorX" | "overscrollBehaviorY" | "padding" | "paddingBlock" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInline" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "pageBreakAfter" | "pageBreakBefore" | "pageBreakInside" | "paintOrder" | "perspective" | "perspectiveOrigin" | "placeContent" | "placeItems" | "placeSelf" | "pointerEvents" | "position" | "quotes" | "resize" | "right" | "rotate" | "rowGap" | "rubyPosition" | "scale" | "scrollBehavior" | "scrollMargin" | "scrollMarginBlock" | "scrollMarginBlockEnd" | "scrollMarginBlockStart" | "scrollMarginBottom" | "scrollMarginInline" | "scrollMarginInlineEnd" | "scrollMarginInlineStart" | "scrollMarginLeft" | "scrollMarginRight" | "scrollMarginTop" | "scrollPadding" | "scrollPaddingBlock" | "scrollPaddingBlockEnd" | "scrollPaddingBlockStart" | "scrollPaddingBottom" | "scrollPaddingInline" | "scrollPaddingInlineEnd" | "scrollPaddingInlineStart" | "scrollPaddingLeft" | "scrollPaddingRight" | "scrollPaddingTop" | "scrollSnapAlign" | "scrollSnapStop" | "scrollSnapType" | "scrollbarGutter" | "shapeImageThreshold" | "shapeMargin" | "shapeOutside" | "shapeRendering" | "stopColor" | "stopOpacity" | "stroke" | "strokeDasharray" | "strokeDashoffset" | "strokeLinecap" | "strokeLinejoin" | "strokeMiterlimit" | "strokeOpacity" | "strokeWidth" | "tabSize" | "tableLayout" | "textAlign" | "textAlignLast" | "textAnchor" | "textCombineUpright" | "textDecoration" | "textDecorationColor" | "textDecorationLine" | "textDecorationSkipInk" | "textDecorationStyle" | "textDecorationThickness" | "textEmphasis" | "textEmphasisColor" | "textEmphasisPosition" | "textEmphasisStyle" | "textIndent" | "textOrientation" | "textOverflow" | "textRendering" | "textShadow" | "textTransform" | "textUnderlineOffset" | "textUnderlinePosition" | "top" | "touchAction" | "transform" | "transformBox" | "transformOrigin" | "transformStyle" | "transition" | "transitionDelay" | "transitionDuration" | "transitionProperty" | "transitionTimingFunction" | "translate" | "unicodeBidi" | "userSelect" | "verticalAlign" | "visibility" | "webkitAlignContent" | "webkitAlignItems" | "webkitAlignSelf" | "webkitAnimation" | "webkitAnimationDelay" | "webkitAnimationDirection" | "webkitAnimationDuration" | "webkitAnimationFillMode" | "webkitAnimationIterationCount" | "webkitAnimationName" | "webkitAnimationPlayState" | "webkitAnimationTimingFunction" | "webkitAppearance" | "webkitBackfaceVisibility" | "webkitBackgroundClip" | "webkitBackgroundOrigin" | "webkitBackgroundSize" | "webkitBorderBottomLeftRadius" | "webkitBorderBottomRightRadius" | "webkitBorderRadius" | "webkitBorderTopLeftRadius" | "webkitBorderTopRightRadius" | "webkitBoxAlign" | "webkitBoxFlex" | "webkitBoxOrdinalGroup" | "webkitBoxOrient" | "webkitBoxPack" | "webkitBoxShadow" | "webkitBoxSizing" | "webkitFilter" | "webkitFlex" | "webkitFlexBasis" | "webkitFlexDirection" | "webkitFlexFlow" | "webkitFlexGrow" | "webkitFlexShrink" | "webkitFlexWrap" | "webkitJustifyContent" | "webkitLineClamp" | "webkitMask" | "webkitMaskBoxImage" | "webkitMaskBoxImageOutset" | "webkitMaskBoxImageRepeat" | "webkitMaskBoxImageSlice" | "webkitMaskBoxImageSource" | "webkitMaskBoxImageWidth" | "webkitMaskClip" | "webkitMaskComposite" | "webkitMaskImage" | "webkitMaskOrigin" | "webkitMaskPosition" | "webkitMaskRepeat" | "webkitMaskSize" | "webkitOrder" | "webkitPerspective" | "webkitPerspectiveOrigin" | "webkitTextFillColor" | "webkitTextStroke" | "webkitTextStrokeColor" | "webkitTextStrokeWidth" | "webkitTransform" | "webkitTransformOrigin" | "webkitTransformStyle" | "webkitTransition" | "webkitTransitionDelay" | "webkitTransitionDuration" | "webkitTransitionProperty" | "webkitTransitionTimingFunction" | "webkitUserSelect" | "whiteSpace" | "widows" | "width" | "willChange" | "wordBreak" | "wordSpacing" | "wordWrap" | "writingMode" | "zIndex"

        The unprefixed property name.

      Returns null | string

      The prefixed property name.

    • removeClass(el: HTMLElement, className: string): void
    • Removes a class from an HTML element.

      example
      removeClass(document.querySelector('p.special'), 'special');
      // The paragraph will not have the 'special' class anymore
      since

      0.1.2

      Parameters

      • el: HTMLElement

        The HTML element.

      • className: string

        The name of the class to remove.

      Returns void

    • removeElement(el: Element): Element
    • Removes an element from the DOM.

      example
      removeElement(document.querySelector('#my-element'));
      // Removes #my-element from the DOM
      since

      0.1.0

      Parameters

      • el: Element

        The element to remove.

      Returns Element

      The element that was removed.

    • removeEventListenerAll(targets: EventTarget[], type: string, listener: null | EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void
    • Detaches an event listener from all the provided targets.

      example
      const linkListener = () => console.log('Clicked a link');
      document.querySelector('a').addEventListener('click', linkListener);
      removeEventListenerAll(document.querySelectorAll('a'), 'click', linkListener);
      since

      0.1.5

      Parameters

      • targets: EventTarget[]

        The targets from which to remove the event listener.

      • type: string

        The type of event.

      • listener: null | EventListenerOrEventListenerObject

        The listener.

      • Optional options: boolean | EventListenerOptions

        The options.

      Returns void

    • renderElement(__namedParameters: { props?: Record<string, any>; type?: string }, container: Node): void
    • Renders the given DOM tree in the specified DOM element.

      example
      const myElement = {
      type: 'button',
      props: {
      type: 'button',
      className: 'btn',
      onClick: () => alert('Clicked'),
      children: [{ props: { nodeValue: 'Click me' } }]
      }
      };

      renderElement(myElement, document.body);
      since

      0.1.6

      Parameters

      • __namedParameters: { props?: Record<string, any>; type?: string }
        • Optional props?: Record<string, any>
        • Optional type?: string
      • container: Node

        The DOM element to render into.

      Returns void

    • scrollToTop(): void
    • Smooth-scrolls to the top of the page.

      example
      scrollToTop(); // Smooth-scrolls to the top of the page
      
      since

      0.1.2

      Returns void

    • serializeForm(form: HTMLFormElement): string
    • Encodes a set of form elements as a query string.

      example
      serializeForm(document.querySelector('#form'));
      // email=test%40email.com&name=Test%20Name
      since

      0.1.6

      Parameters

      • form: HTMLFormElement

        The form elements to serialize.

      Returns string

      A query string representing the form.

    • setStyle(el: HTMLElement, rule: number | typeof iterator | "accentColor" | "alignContent" | "alignItems" | "alignSelf" | "alignmentBaseline" | "all" | "animation" | "animationDelay" | "animationDirection" | "animationDuration" | "animationFillMode" | "animationIterationCount" | "animationName" | "animationPlayState" | "animationTimingFunction" | "appearance" | "aspectRatio" | "backfaceVisibility" | "background" | "backgroundAttachment" | "backgroundBlendMode" | "backgroundClip" | "backgroundColor" | "backgroundImage" | "backgroundOrigin" | "backgroundPosition" | "backgroundPositionX" | "backgroundPositionY" | "backgroundRepeat" | "backgroundSize" | "baselineShift" | "blockSize" | "border" | "borderBlock" | "borderBlockColor" | "borderBlockEnd" | "borderBlockEndColor" | "borderBlockEndStyle" | "borderBlockEndWidth" | "borderBlockStart" | "borderBlockStartColor" | "borderBlockStartStyle" | "borderBlockStartWidth" | "borderBlockStyle" | "borderBlockWidth" | "borderBottom" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderColor" | "borderEndEndRadius" | "borderEndStartRadius" | "borderImage" | "borderImageOutset" | "borderImageRepeat" | "borderImageSlice" | "borderImageSource" | "borderImageWidth" | "borderInline" | "borderInlineColor" | "borderInlineEnd" | "borderInlineEndColor" | "borderInlineEndStyle" | "borderInlineEndWidth" | "borderInlineStart" | "borderInlineStartColor" | "borderInlineStartStyle" | "borderInlineStartWidth" | "borderInlineStyle" | "borderInlineWidth" | "borderLeft" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRadius" | "borderRight" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderStartEndRadius" | "borderStartStartRadius" | "borderStyle" | "borderTop" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "borderWidth" | "bottom" | "boxShadow" | "boxSizing" | "breakAfter" | "breakBefore" | "breakInside" | "captionSide" | "caretColor" | "clear" | "clip" | "clipPath" | "clipRule" | "color" | "colorInterpolation" | "colorInterpolationFilters" | "colorScheme" | "columnCount" | "columnFill" | "columnGap" | "columnRule" | "columnRuleColor" | "columnRuleStyle" | "columnRuleWidth" | "columnSpan" | "columnWidth" | "columns" | "contain" | "content" | "counterIncrement" | "counterReset" | "counterSet" | "cssFloat" | "cssText" | "cursor" | "direction" | "display" | "dominantBaseline" | "emptyCells" | "fill" | "fillOpacity" | "fillRule" | "filter" | "flex" | "flexBasis" | "flexDirection" | "flexFlow" | "flexGrow" | "flexShrink" | "flexWrap" | "float" | "floodColor" | "floodOpacity" | "font" | "fontFamily" | "fontFeatureSettings" | "fontKerning" | "fontOpticalSizing" | "fontSize" | "fontSizeAdjust" | "fontStretch" | "fontStyle" | "fontSynthesis" | "fontVariant" | "fontVariantAlternates" | "fontVariantCaps" | "fontVariantEastAsian" | "fontVariantLigatures" | "fontVariantNumeric" | "fontVariantPosition" | "fontVariationSettings" | "fontWeight" | "gap" | "grid" | "gridArea" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridColumn" | "gridColumnEnd" | "gridColumnGap" | "gridColumnStart" | "gridGap" | "gridRow" | "gridRowEnd" | "gridRowGap" | "gridRowStart" | "gridTemplate" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "hyphens" | "imageOrientation" | "imageRendering" | "inlineSize" | "inset" | "insetBlock" | "insetBlockEnd" | "insetBlockStart" | "insetInline" | "insetInlineEnd" | "insetInlineStart" | "isolation" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lightingColor" | "lineBreak" | "lineHeight" | "listStyle" | "listStyleImage" | "listStylePosition" | "listStyleType" | "margin" | "marginBlock" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInline" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "marker" | "markerEnd" | "markerMid" | "markerStart" | "mask" | "maskType" | "maxBlockSize" | "maxHeight" | "maxInlineSize" | "maxWidth" | "minBlockSize" | "minHeight" | "minInlineSize" | "minWidth" | "mixBlendMode" | "objectFit" | "objectPosition" | "offset" | "offsetAnchor" | "offsetDistance" | "offsetPath" | "offsetRotate" | "opacity" | "order" | "orphans" | "outline" | "outlineColor" | "outlineOffset" | "outlineStyle" | "outlineWidth" | "overflow" | "overflowAnchor" | "overflowWrap" | "overflowX" | "overflowY" | "overscrollBehavior" | "overscrollBehaviorBlock" | "overscrollBehaviorInline" | "overscrollBehaviorX" | "overscrollBehaviorY" | "padding" | "paddingBlock" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInline" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "pageBreakAfter" | "pageBreakBefore" | "pageBreakInside" | "paintOrder" | "perspective" | "perspectiveOrigin" | "placeContent" | "placeItems" | "placeSelf" | "pointerEvents" | "position" | "quotes" | "resize" | "right" | "rotate" | "rowGap" | "rubyPosition" | "scale" | "scrollBehavior" | "scrollMargin" | "scrollMarginBlock" | "scrollMarginBlockEnd" | "scrollMarginBlockStart" | "scrollMarginBottom" | "scrollMarginInline" | "scrollMarginInlineEnd" | "scrollMarginInlineStart" | "scrollMarginLeft" | "scrollMarginRight" | "scrollMarginTop" | "scrollPadding" | "scrollPaddingBlock" | "scrollPaddingBlockEnd" | "scrollPaddingBlockStart" | "scrollPaddingBottom" | "scrollPaddingInline" | "scrollPaddingInlineEnd" | "scrollPaddingInlineStart" | "scrollPaddingLeft" | "scrollPaddingRight" | "scrollPaddingTop" | "scrollSnapAlign" | "scrollSnapStop" | "scrollSnapType" | "scrollbarGutter" | "shapeImageThreshold" | "shapeMargin" | "shapeOutside" | "shapeRendering" | "stopColor" | "stopOpacity" | "stroke" | "strokeDasharray" | "strokeDashoffset" | "strokeLinecap" | "strokeLinejoin" | "strokeMiterlimit" | "strokeOpacity" | "strokeWidth" | "tabSize" | "tableLayout" | "textAlign" | "textAlignLast" | "textAnchor" | "textCombineUpright" | "textDecoration" | "textDecorationColor" | "textDecorationLine" | "textDecorationSkipInk" | "textDecorationStyle" | "textDecorationThickness" | "textEmphasis" | "textEmphasisColor" | "textEmphasisPosition" | "textEmphasisStyle" | "textIndent" | "textOrientation" | "textOverflow" | "textRendering" | "textShadow" | "textTransform" | "textUnderlineOffset" | "textUnderlinePosition" | "top" | "touchAction" | "transform" | "transformBox" | "transformOrigin" | "transformStyle" | "transition" | "transitionDelay" | "transitionDuration" | "transitionProperty" | "transitionTimingFunction" | "translate" | "unicodeBidi" | "userSelect" | "verticalAlign" | "visibility" | "webkitAlignContent" | "webkitAlignItems" | "webkitAlignSelf" | "webkitAnimation" | "webkitAnimationDelay" | "webkitAnimationDirection" | "webkitAnimationDuration" | "webkitAnimationFillMode" | "webkitAnimationIterationCount" | "webkitAnimationName" | "webkitAnimationPlayState" | "webkitAnimationTimingFunction" | "webkitAppearance" | "webkitBackfaceVisibility" | "webkitBackgroundClip" | "webkitBackgroundOrigin" | "webkitBackgroundSize" | "webkitBorderBottomLeftRadius" | "webkitBorderBottomRightRadius" | "webkitBorderRadius" | "webkitBorderTopLeftRadius" | "webkitBorderTopRightRadius" | "webkitBoxAlign" | "webkitBoxFlex" | "webkitBoxOrdinalGroup" | "webkitBoxOrient" | "webkitBoxPack" | "webkitBoxShadow" | "webkitBoxSizing" | "webkitFilter" | "webkitFlex" | "webkitFlexBasis" | "webkitFlexDirection" | "webkitFlexFlow" | "webkitFlexGrow" | "webkitFlexShrink" | "webkitFlexWrap" | "webkitJustifyContent" | "webkitLineClamp" | "webkitMask" | "webkitMaskBoxImage" | "webkitMaskBoxImageOutset" | "webkitMaskBoxImageRepeat" | "webkitMaskBoxImageSlice" | "webkitMaskBoxImageSource" | "webkitMaskBoxImageWidth" | "webkitMaskClip" | "webkitMaskComposite" | "webkitMaskImage" | "webkitMaskOrigin" | "webkitMaskPosition" | "webkitMaskRepeat" | "webkitMaskSize" | "webkitOrder" | "webkitPerspective" | "webkitPerspectiveOrigin" | "webkitTextFillColor" | "webkitTextStroke" | "webkitTextStrokeColor" | "webkitTextStrokeWidth" | "webkitTransform" | "webkitTransformOrigin" | "webkitTransformStyle" | "webkitTransition" | "webkitTransitionDelay" | "webkitTransitionDuration" | "webkitTransitionProperty" | "webkitTransitionTimingFunction" | "webkitUserSelect" | "whiteSpace" | "widows" | "width" | "willChange" | "wordBreak" | "wordSpacing" | "wordWrap" | "writingMode" | "zIndex" | "getPropertyPriority" | "getPropertyValue" | "item" | "removeProperty" | "setProperty", val: null | string): void
    • Sets the value of a CSS rule for the specified HTML element.

      example
      setStyle(document.querySelector('p'), 'fontSize', '20px');
      // The first <p> element on the page will have a font-size of 20px
      since

      0.1.1

      Parameters

      • el: HTMLElement

        The element to set the style for.

      • rule: number | typeof iterator | "accentColor" | "alignContent" | "alignItems" | "alignSelf" | "alignmentBaseline" | "all" | "animation" | "animationDelay" | "animationDirection" | "animationDuration" | "animationFillMode" | "animationIterationCount" | "animationName" | "animationPlayState" | "animationTimingFunction" | "appearance" | "aspectRatio" | "backfaceVisibility" | "background" | "backgroundAttachment" | "backgroundBlendMode" | "backgroundClip" | "backgroundColor" | "backgroundImage" | "backgroundOrigin" | "backgroundPosition" | "backgroundPositionX" | "backgroundPositionY" | "backgroundRepeat" | "backgroundSize" | "baselineShift" | "blockSize" | "border" | "borderBlock" | "borderBlockColor" | "borderBlockEnd" | "borderBlockEndColor" | "borderBlockEndStyle" | "borderBlockEndWidth" | "borderBlockStart" | "borderBlockStartColor" | "borderBlockStartStyle" | "borderBlockStartWidth" | "borderBlockStyle" | "borderBlockWidth" | "borderBottom" | "borderBottomColor" | "borderBottomLeftRadius" | "borderBottomRightRadius" | "borderBottomStyle" | "borderBottomWidth" | "borderCollapse" | "borderColor" | "borderEndEndRadius" | "borderEndStartRadius" | "borderImage" | "borderImageOutset" | "borderImageRepeat" | "borderImageSlice" | "borderImageSource" | "borderImageWidth" | "borderInline" | "borderInlineColor" | "borderInlineEnd" | "borderInlineEndColor" | "borderInlineEndStyle" | "borderInlineEndWidth" | "borderInlineStart" | "borderInlineStartColor" | "borderInlineStartStyle" | "borderInlineStartWidth" | "borderInlineStyle" | "borderInlineWidth" | "borderLeft" | "borderLeftColor" | "borderLeftStyle" | "borderLeftWidth" | "borderRadius" | "borderRight" | "borderRightColor" | "borderRightStyle" | "borderRightWidth" | "borderSpacing" | "borderStartEndRadius" | "borderStartStartRadius" | "borderStyle" | "borderTop" | "borderTopColor" | "borderTopLeftRadius" | "borderTopRightRadius" | "borderTopStyle" | "borderTopWidth" | "borderWidth" | "bottom" | "boxShadow" | "boxSizing" | "breakAfter" | "breakBefore" | "breakInside" | "captionSide" | "caretColor" | "clear" | "clip" | "clipPath" | "clipRule" | "color" | "colorInterpolation" | "colorInterpolationFilters" | "colorScheme" | "columnCount" | "columnFill" | "columnGap" | "columnRule" | "columnRuleColor" | "columnRuleStyle" | "columnRuleWidth" | "columnSpan" | "columnWidth" | "columns" | "contain" | "content" | "counterIncrement" | "counterReset" | "counterSet" | "cssFloat" | "cssText" | "cursor" | "direction" | "display" | "dominantBaseline" | "emptyCells" | "fill" | "fillOpacity" | "fillRule" | "filter" | "flex" | "flexBasis" | "flexDirection" | "flexFlow" | "flexGrow" | "flexShrink" | "flexWrap" | "float" | "floodColor" | "floodOpacity" | "font" | "fontFamily" | "fontFeatureSettings" | "fontKerning" | "fontOpticalSizing" | "fontSize" | "fontSizeAdjust" | "fontStretch" | "fontStyle" | "fontSynthesis" | "fontVariant" | "fontVariantAlternates" | "fontVariantCaps" | "fontVariantEastAsian" | "fontVariantLigatures" | "fontVariantNumeric" | "fontVariantPosition" | "fontVariationSettings" | "fontWeight" | "gap" | "grid" | "gridArea" | "gridAutoColumns" | "gridAutoFlow" | "gridAutoRows" | "gridColumn" | "gridColumnEnd" | "gridColumnGap" | "gridColumnStart" | "gridGap" | "gridRow" | "gridRowEnd" | "gridRowGap" | "gridRowStart" | "gridTemplate" | "gridTemplateAreas" | "gridTemplateColumns" | "gridTemplateRows" | "height" | "hyphens" | "imageOrientation" | "imageRendering" | "inlineSize" | "inset" | "insetBlock" | "insetBlockEnd" | "insetBlockStart" | "insetInline" | "insetInlineEnd" | "insetInlineStart" | "isolation" | "justifyContent" | "justifyItems" | "justifySelf" | "left" | "letterSpacing" | "lightingColor" | "lineBreak" | "lineHeight" | "listStyle" | "listStyleImage" | "listStylePosition" | "listStyleType" | "margin" | "marginBlock" | "marginBlockEnd" | "marginBlockStart" | "marginBottom" | "marginInline" | "marginInlineEnd" | "marginInlineStart" | "marginLeft" | "marginRight" | "marginTop" | "marker" | "markerEnd" | "markerMid" | "markerStart" | "mask" | "maskType" | "maxBlockSize" | "maxHeight" | "maxInlineSize" | "maxWidth" | "minBlockSize" | "minHeight" | "minInlineSize" | "minWidth" | "mixBlendMode" | "objectFit" | "objectPosition" | "offset" | "offsetAnchor" | "offsetDistance" | "offsetPath" | "offsetRotate" | "opacity" | "order" | "orphans" | "outline" | "outlineColor" | "outlineOffset" | "outlineStyle" | "outlineWidth" | "overflow" | "overflowAnchor" | "overflowWrap" | "overflowX" | "overflowY" | "overscrollBehavior" | "overscrollBehaviorBlock" | "overscrollBehaviorInline" | "overscrollBehaviorX" | "overscrollBehaviorY" | "padding" | "paddingBlock" | "paddingBlockEnd" | "paddingBlockStart" | "paddingBottom" | "paddingInline" | "paddingInlineEnd" | "paddingInlineStart" | "paddingLeft" | "paddingRight" | "paddingTop" | "pageBreakAfter" | "pageBreakBefore" | "pageBreakInside" | "paintOrder" | "perspective" | "perspectiveOrigin" | "placeContent" | "placeItems" | "placeSelf" | "pointerEvents" | "position" | "quotes" | "resize" | "right" | "rotate" | "rowGap" | "rubyPosition" | "scale" | "scrollBehavior" | "scrollMargin" | "scrollMarginBlock" | "scrollMarginBlockEnd" | "scrollMarginBlockStart" | "scrollMarginBottom" | "scrollMarginInline" | "scrollMarginInlineEnd" | "scrollMarginInlineStart" | "scrollMarginLeft" | "scrollMarginRight" | "scrollMarginTop" | "scrollPadding" | "scrollPaddingBlock" | "scrollPaddingBlockEnd" | "scrollPaddingBlockStart" | "scrollPaddingBottom" | "scrollPaddingInline" | "scrollPaddingInlineEnd" | "scrollPaddingInlineStart" | "scrollPaddingLeft" | "scrollPaddingRight" | "scrollPaddingTop" | "scrollSnapAlign" | "scrollSnapStop" | "scrollSnapType" | "scrollbarGutter" | "shapeImageThreshold" | "shapeMargin" | "shapeOutside" | "shapeRendering" | "stopColor" | "stopOpacity" | "stroke" | "strokeDasharray" | "strokeDashoffset" | "strokeLinecap" | "strokeLinejoin" | "strokeMiterlimit" | "strokeOpacity" | "strokeWidth" | "tabSize" | "tableLayout" | "textAlign" | "textAlignLast" | "textAnchor" | "textCombineUpright" | "textDecoration" | "textDecorationColor" | "textDecorationLine" | "textDecorationSkipInk" | "textDecorationStyle" | "textDecorationThickness" | "textEmphasis" | "textEmphasisColor" | "textEmphasisPosition" | "textEmphasisStyle" | "textIndent" | "textOrientation" | "textOverflow" | "textRendering" | "textShadow" | "textTransform" | "textUnderlineOffset" | "textUnderlinePosition" | "top" | "touchAction" | "transform" | "transformBox" | "transformOrigin" | "transformStyle" | "transition" | "transitionDelay" | "transitionDuration" | "transitionProperty" | "transitionTimingFunction" | "translate" | "unicodeBidi" | "userSelect" | "verticalAlign" | "visibility" | "webkitAlignContent" | "webkitAlignItems" | "webkitAlignSelf" | "webkitAnimation" | "webkitAnimationDelay" | "webkitAnimationDirection" | "webkitAnimationDuration" | "webkitAnimationFillMode" | "webkitAnimationIterationCount" | "webkitAnimationName" | "webkitAnimationPlayState" | "webkitAnimationTimingFunction" | "webkitAppearance" | "webkitBackfaceVisibility" | "webkitBackgroundClip" | "webkitBackgroundOrigin" | "webkitBackgroundSize" | "webkitBorderBottomLeftRadius" | "webkitBorderBottomRightRadius" | "webkitBorderRadius" | "webkitBorderTopLeftRadius" | "webkitBorderTopRightRadius" | "webkitBoxAlign" | "webkitBoxFlex" | "webkitBoxOrdinalGroup" | "webkitBoxOrient" | "webkitBoxPack" | "webkitBoxShadow" | "webkitBoxSizing" | "webkitFilter" | "webkitFlex" | "webkitFlexBasis" | "webkitFlexDirection" | "webkitFlexFlow" | "webkitFlexGrow" | "webkitFlexShrink" | "webkitFlexWrap" | "webkitJustifyContent" | "webkitLineClamp" | "webkitMask" | "webkitMaskBoxImage" | "webkitMaskBoxImageOutset" | "webkitMaskBoxImageRepeat" | "webkitMaskBoxImageSlice" | "webkitMaskBoxImageSource" | "webkitMaskBoxImageWidth" | "webkitMaskClip" | "webkitMaskComposite" | "webkitMaskImage" | "webkitMaskOrigin" | "webkitMaskPosition" | "webkitMaskRepeat" | "webkitMaskSize" | "webkitOrder" | "webkitPerspective" | "webkitPerspectiveOrigin" | "webkitTextFillColor" | "webkitTextStroke" | "webkitTextStrokeColor" | "webkitTextStrokeWidth" | "webkitTransform" | "webkitTransformOrigin" | "webkitTransformStyle" | "webkitTransition" | "webkitTransitionDelay" | "webkitTransitionDuration" | "webkitTransitionProperty" | "webkitTransitionTimingFunction" | "webkitUserSelect" | "whiteSpace" | "widows" | "width" | "willChange" | "wordBreak" | "wordSpacing" | "wordWrap" | "writingMode" | "zIndex" | "getPropertyPriority" | "getPropertyValue" | "item" | "removeProperty" | "setProperty"

        The name of the CSS rule.

      • val: null | string

        The value to set the rule to.

      Returns void

    • show(...el: HTMLElement[]): void
    • Shows all the elements specified.

      example
      show(...document.querySelectorAll('img'));
      // Shows all <img> elements on the page
      since

      0.1.5

      Parameters

      • Rest ...el: HTMLElement[]

        The elements to show.

      Returns void

    • smoothScroll(element: string): void
    • Smoothly scrolls the element on which it's called into the visible area of the browser window.

      example
      smoothScroll('#fooBar'); // scrolls smoothly to the element with the id fooBar
      smoothScroll('.fooBar');
      // scrolls smoothly to the first element with a class of fooBar
      since

      0.1.1

      Parameters

      • element: string

        The element to scroll into the visible area of the browser window.

      Returns void

    • toggleClass(el: Element, className: string): boolean
    • Toggles a class for an HTML element.

      example
      toggleClass(document.body, 'active');
      
      since

      0.1.1

      Parameters

      • el: Element

        The target element.

      • className: string

        The class to toggle.

      Returns boolean

      The element.

    • triggerEvent<T>(el: Element, eventType: string, detail?: T): boolean
    • Triggers a specific event on a given element, optionally passing custom data.

      example
      triggerEvent(document.getElementById('myId'), 'click');
      triggerEvent(document.getElementById('myId'), 'click', { username: 'bob' });
      since

      0.1.2

      Type parameters

      • T

      Parameters

      • el: Element

        Element to trigger the event on.

      • eventType: string

        Name of the event to trigger.

      • Optional detail: T

        Optional data to pass as detail to the event.

      Returns boolean

      true if the event was successfully triggered.

    Random Functions

    • UUIDGeneratorBrowser(): string

    String Functions

    • byteSize(str: string): number
    • 返回字符串的长度(以字节为单位)

      remarks

      将给定的字符串转换为 Blob 对象。

      使用 Blob.size 获取字符串的长度(以字节为单位)

      example
       byteSize('你好') // 6
      
      since

      0.1.0

      Parameters

      • str: string

        要计算的字符串

      Returns number

      字符串的长度(以字节为单位)

    • toCurrency(n: number, currency: string, LanguageFormat?: string): string
    • Takes a number and returns it in the specified currency formatting.

      example
      toCurrency(123456.789, 'EUR');
      // €123,456.79 | currency: Euro | currencyLangFormat: Local
      toCurrency(123456.789, 'USD', 'en-us');
      // $123,456.79 | currency: US Dollar | currencyLangFormat: English (United States)
      toCurrency(123456.789, 'USD', 'fa');
      // ۱۲۳٬۴۵۶٫۷۹ ؜$ | currency: US Dollar | currencyLangFormat: Farsi
      toCurrency(322342436423.2435, 'JPY');
      // ¥322,342,436,423 | currency: Japanese Yen | currencyLangFormat: Local
      toCurrency(322342436423.2435, 'JPY', 'fi');
      // 322 342 436 423 ¥ | currency: Japanese Yen | currencyLangFormat: Finnish
      since

      0.1.0

      Parameters

      • n: number

        the number to format

      • currency: string

        the currency to use

      • Optional LanguageFormat: string

        the language format to use

      Returns string

      the formatted currency string