Package Exports
- shorter-js
- shorter-js/dist/shorter-js.esm.js
- shorter-js/dist/shorter-js.min.js
- shorter-js/src/attr/setAttribute
- shorter-js/src/attr/setAttribute.js
- shorter-js/src/boolean/isMobile
- shorter-js/src/boolean/isMobile.js
- shorter-js/src/boolean/support3DTransform
- shorter-js/src/boolean/support3DTransform.js
- shorter-js/src/boolean/supportPassive.js
- shorter-js/src/boolean/supportTouch
- shorter-js/src/boolean/supportTouch.js
- shorter-js/src/boolean/supportTransition.js
- shorter-js/src/class/addClass
- shorter-js/src/class/addClass.js
- shorter-js/src/class/hasClass
- shorter-js/src/class/hasClass.js
- shorter-js/src/class/removeClass
- shorter-js/src/class/removeClass.js
- shorter-js/src/event/off
- shorter-js/src/event/off.js
- shorter-js/src/event/on
- shorter-js/src/event/on.js
- shorter-js/src/event/one.js
- shorter-js/src/get/getDocument
- shorter-js/src/get/getDocument.js
- shorter-js/src/get/getElementStyle
- shorter-js/src/get/getElementStyle.js
- shorter-js/src/get/getWindow
- shorter-js/src/get/getWindow.js
- shorter-js/src/is/isRTL
- shorter-js/src/is/isRTL.js
- shorter-js/src/misc/ArrayFrom
- shorter-js/src/misc/ArrayFrom.js
- shorter-js/src/misc/ObjectAssign
- shorter-js/src/misc/ObjectAssign.js
- shorter-js/src/misc/OriginalEvent
- shorter-js/src/misc/OriginalEvent.js
- shorter-js/src/misc/data
- shorter-js/src/misc/data.js
- shorter-js/src/misc/emulateTransitionEnd
- shorter-js/src/misc/emulateTransitionEnd.js
- shorter-js/src/misc/normalizeOptions
- shorter-js/src/misc/normalizeOptions.js
- shorter-js/src/misc/normalizeValue.js
- shorter-js/src/misc/passiveHandler
- shorter-js/src/misc/passiveHandler.js
- shorter-js/src/misc/reflow.js
- shorter-js/src/misc/timer
- shorter-js/src/misc/timer.js
- shorter-js/src/misc/tryWrapper.js
- shorter-js/src/selectors/closest
- shorter-js/src/selectors/closest.js
- shorter-js/src/selectors/getElementsByClassName
- shorter-js/src/selectors/getElementsByClassName.js
- shorter-js/src/selectors/getElementsByTagName
- shorter-js/src/selectors/getElementsByTagName.js
- shorter-js/src/selectors/querySelector
- shorter-js/src/selectors/querySelector.js
- shorter-js/src/strings/addEventListener
- shorter-js/src/strings/addEventListener.js
- shorter-js/src/strings/ariaExpanded
- shorter-js/src/strings/ariaExpanded.js
- shorter-js/src/strings/keyArrowDown
- shorter-js/src/strings/keyArrowDown.js
- shorter-js/src/strings/keyArrowLeft
- shorter-js/src/strings/keyArrowLeft.js
- shorter-js/src/strings/keyArrowRight
- shorter-js/src/strings/keyArrowRight.js
- shorter-js/src/strings/keyArrowUp
- shorter-js/src/strings/keyArrowUp.js
- shorter-js/src/strings/keyEscape
- shorter-js/src/strings/keyEscape.js
- shorter-js/src/strings/keySpace
- shorter-js/src/strings/keySpace.js
- shorter-js/src/strings/keydownEvent
- shorter-js/src/strings/keydownEvent.js
- shorter-js/src/strings/mouseClickEvents.js
- shorter-js/src/strings/mouseHoverEvents
- shorter-js/src/strings/mouseHoverEvents.js
- shorter-js/src/strings/mouseclickEvent
- shorter-js/src/strings/mouseclickEvent.js
- shorter-js/src/strings/mouseenterEvent
- shorter-js/src/strings/mouseenterEvent.js
- shorter-js/src/strings/mouseleaveEvent
- shorter-js/src/strings/mouseleaveEvent.js
- shorter-js/src/strings/removeEventListener
- shorter-js/src/strings/removeEventListener.js
- shorter-js/src/strings/resizeEvent
- shorter-js/src/strings/resizeEvent.js
- shorter-js/src/strings/touchEvents.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (shorter-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
shorter-js
A small ES6+ library with various JavaScript tools, all ESLint valid, useful for creating light libraries. Featured in KUTE.js, BSN, Navbar.js and other libraries.
- The purpose if the library is to speed up the development workflow, minimize the size of larger libraries by providing a shorter syntax for most used JavaScript API methods, most used strings or other helpful utilities.
- While the library comes with a working build in the
distfolder, that is mainly for build consistency testing.
npm
npm install shorter-jsES6+ Base usage
// import the tool you need
import {supportTransform} from 'shorter-js'
// use the tool in your ES6/ES7 sources
if (supportTransform) {
doSomeAction()
}boolean
- isMobile - checks and preserves the client browser is a on Mobile device
- support3DTransform - checks and preserves the client browser capability for webKit
perspective - supportTouch - checks and preserves the client browser capability for
touchevents - supportPassive - checks and preserves the client browser capability for
passiveevent option - supportTransform - checks and preserves the client browser capability for webKit
transform - supportAnimation - checks and preserves the client browser capability for webKit keyframe
animation - supportTransition - checks and preserves the client browser capability for webKit
transition
// EXAMPLES
import {support3DTransform} from 'shorter-js'
// filter myAction to supported browsers
if (support3DTransform) {
myAction()
}class
- addClass - add a class to a target Element
- removeClass - remove a class from a target Element
- hasClass - checks the existence of a class for a target Element
// EXAMPLES
import {addClass,removeClass,hasClass} from 'shorter-js'
// add a class
addClass(targetElement,'className')
// remove a class
removeClass(targetElement,'className')
// check for a class
if (hasClass(targetElement,'className')) {
myAction()
}event
- on - attach an event handler to a specific target Element
- off - detach an event handler from a specific target Element
- one - attach an event handler to a specific target Element, and detach when complete
// EXAMPLES
import {on,off,one,passiveHandler} from 'shorter-js'
// attach a passive mousedown eventHandler
on(targetElement,'click',eventHandler,passiveHandler)
// detach a passive mouseup eventHandler
off(targetElement,'mouseup',eventHandler,passiveHandler)
// attach a single instance passive touchstart eventHandler
one(targetElement,'touchstart',eventHandler,passiveHandler)misc
- emulateAnimationEnd - utility to execute a callback function when
animationendevent is triggered, or execute the callback right after for legacy browsers - emulateTransitionEnd - utility to execute a callback function when
transitionendevent is triggered, or execute the callback right after for legacy browsers - getElementAnimationDuration - returns the
animationDurationproperty of aanimationproperty - getElementAnimationDelay - returns the
animationDelayproperty of ananimationproperty - getElementTransitionDuration - returns the
transitionDurationproperty of atransitionproperty - getElementTransitionDelay - returns the
transitionDelayproperty of atransitionproperty - isElementInScrollRange - a quick utility that checks if a target Element surface is scrolled within the visible area of the window
- isElementInViewport - a quick utility that checks if a target Element is scrolled fully into visible window area, might not be useful for elements larger in size than the window itself, the above might be more useful
- passiveHandler - a constant that preserves a standard handler
optionswithpassive: true eventoption used - queryElement - a simple utility to check if a certain item is an Element or a selector string, and if a selector string find the FIRST Element and return it
- normalizeOptions - a cool utility to normalize and crosscheck JavaScript options and their DATA API counterparts for various web components; supports namespaced options like
data-NAMESPACE-option="value"; priority: JavaScript options > DATA API options > default options - tryWrapper - a simple
try()andcatch()wrapper for functions, with option to preffix the error logs, poiting out the source of the errors - reflow - because
element.offsetHeight;won't validate on ESLint.
// EXAMPLES
import {queryElement,emulateTransitionEnd,normalizeOptions} from 'shorter-js'
// get some target
let targetElement = queryElement('.mySelectorClass');
// emulateTransitionEnd for the above
emulateTransitionEnd(targetElement,callback)
// check if element is in scroll range
// emulateTransitionEnd for the above
if (isElementInScrollRange(targetElement)){
doSomeAction()
}
// set component options
const options = normalizeOptions( element, defaultOptions, inputOptions, nameSpace )
// element - the component target, the owned of the DATA API attributes
// defaultOptions - the component default options
// inputOptions - the component JavaScript options
// namaSpace - the DATA API namespace
// ..required to get the value of `data-NAMESPACE-option="value"`strings
- bezierEasing - an Object comprised or a set of valid CSS
transition-timing-functionbased on Cubic Bezier; EG:cubic-bezier(0.215,0.61,0.355,1)forbezierEasing.easingCubicOut - mouseSwipeEvents - preserves the pointer events from mouse actions: start:
mousedown, end:mouseup, move:mousemove, cancel:mouseout - mouseClickEvents - preserves the pointer events from mouse actions: down:
mousedown, up:mouseup - mouseHoverEvents - preserve browser specific mouse hover events:
mouseenterandmouseleaveORmouseoverandmouseout - touchEvents - preserves the pointer events from touch actions: start:
touchstart, end:touchend, move:touchmove, cancel:touchcancel - animationDuration - preserves the
animationDurationproperty name supported by the client browser - animationDelay - preserves the
animationDelayproperty name supported by the client browser - animationEndEvent - preserves the
animationEndEventevent name supported by the client browser - animationName - preserves the
animationNameproperty name supported by the client browser - transitionDuration - preserves the
transitionDurationproperty name supported by the client browser - transitionDelay - preserves the
transitionDelayproperty name supported by the client browser - transitionEndEvent - preserves the
transitionendevent name supported by the client browser - transitionProperty - preserves the
transitionPropertyproperty name supported by the client browser - addEventListener - preserves the
addEventListenermethod name - removeEventListener - preserves the
removeEventListenermethod name
// EXAMPLES
import {on,off,one,mouseClickEvents,touchEvents,passiveHandler} from 'shorter-js'
// attach a passive mousedown eventHandler
on(targetElement,mouseClickEvents.down,eventHandler,passiveHandler)
// detach a passive mousedown eventHandler
off(targetElement,mouseClickEvents.down,eventHandler,passiveHandler)
// attach a single instance passive touchstart eventHandler
one(targetElement,touchEvents.start,eventHandler,passiveHandler)Advanced Use
To avoid adding un-necessary shorties into your code, you might want to import them directly from their location.
// Example
import on from 'shorter-js/src/event/on.js'
import addClass from 'shorter-js/src/class/addClass.js'
on(document.getElementById('my-elem'),'eventName',function(e){
addClass(document.getElementById('my-elem'),'my-className')
})