Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@yalovich/dom

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yalovich/dom

Dom is a JavaScript wrapper built for making DOM interactions easy and intuitive when working with JS Vanilla.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
20
increased by1900%
Maintainers
1
Weekly downloads
 
Created
Source

DOM interactions as natural language

npm version

Dom is a JavaScript wrapper built for making DOM interactions easy and intuitive when working with JS Vanilla.

The project intends to turn working with DOM to natural as a human language --- for example --- querying an element from the DOM and adding a "transition end" listener turns from:

let elm = document.querySelector(".selector");
let prefixes = ["webkitTransitionEnd", "transitionend"];

prefixes.map(prefix => elm.addEventListener(prefix,  () => {}, false));

to:

(new Dom).transitionEnd(".selector", () => {});

Installation

npm install --save @yalovich/dom

Usage

import { Dom } from "@yalovich/dom";

class App
{
    constructor() {
        this.dom = new Dom;
    }

    init() {
        this.dom.animationEnd('.selector', event => this.dom.addClass(event.target, 'ready'));
    }
}

API Reference

MethodDescription
.elm(selector)Document.querySelector shortcut. Performing a single DOM query for an element.
.elms(selector)Document.querySelectorAll shortcut. Performing a DOM query for plural elements.
.fromTop(selector)Returns element's distance from the viewport top edge.
.clientRect(selector)Return DOMRect object for the supplied element
.absTop(selector)Returns the element's absolute distance from the document top
.absLeft(selector)Returns the element's absolute distance from the document left edge
.scrollTo(distance, duration)Scroll viewport to the assigned point
.css(elm, key, value)Add CSS property to an element
.cookie(name, value, numberOfdays)Creating a cookie
.addListener(selector, eventName, callback)EventTarget.addEventListener() shortcut. Add an event listener to an element or elements.
.removeListener(selector, eventName, callback)EventTarget.removeEventListener() shortcut. Remove an event listener to an element or elements.
.animationEnd(selector, callback)Add "animationend" event listener
.transitionEnd(selector, callback)Add "transitionend" event listener
.toggleClass(selector, className)classList.toggle() shortcut. Toggle CSS class to/from an element
.addClass(selector, className)classList.add() shortcut. Add CSS class to an element (one or many)
.removeClass(selector, className)classList.remove() shortcut. Remove CSS class from an element (one or many)
.pathLen(selector)SVGPathElement.getTotalLength() shortcut. Returns the user agent's computed value for the total length of the path in user units.
.height(selector)Returns the element computed height as number
.heightCenter(selector)Returns element height center point
.width(selector)Returns the element computed width as number
.widthCenter(element)Returns element width center point
.hide(selector, softHide = false)Hide element using CSS >> display: none;
.show(selector, displayType = "block")Show element using CSS >> display: block
.is(selector)Inquiry helper for boolean features. See .is Inquery
.input(selector)Inquiry helper for input handling. See .input Inquery
getter .scrollTopReturns scrolling distance from the top.
getter .winWidthReturns the window inner width
getter .winHeightReturns the window inner height

The .is() Inquery

Making DOM elemnts available to

The .input() Inquery

More info here

Contributions or Suggestions

Any help is most welcomed to turn the Vanilla DOM interactions more concise and intuitive. Create pull requests, or contact me at idan.yalovich@gmail.com.

License

Copyright 2020 Idan Yalovich

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Package last updated on 19 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc