Placeholder for JavaScript, CSS and SASS
NPM
NPM
$ npm i kasarda
Yarn
$ yarn add kasarda
JavaScript
Common
/* import rand from 'kasarda/common/rand'import getProgress from 'kasarda/common/getProgress'import getValue from 'kasarda/common/getValue'import setStyles from 'kasarda/common/setStyles'import animationLoop from 'kasarda/common/animationLoop'import minmax from 'kasarda/common/minmax'*/ /** * rand(from:number|string|any[]|object, to:number = 0, round:boolean = true): number * -> Return random value*/ // return random integer value from 0 to 100 // return random float value from 0 to 100 // return random character from string // return random value from array // return random value from object /** * getProgress(from:number, to:number, value:number, outside:boolean = false):number * -> Return progress between 0 and 1 or outside of this range */ // -> .5 // -> 1 // -> 1.5 /** * getValue(startWith:number, endWith:number, progress:number, fixed:number = 6):number * -> Return value from progress*/ // -> 50 // -> 34.58 // -> 35 /** * item(array:any[], index:number):any * -> get item from array by index*/const arr = 1 2 3 // -> 1 // -> 2 // -> 3 // -> 2 /** * setStyles(elem:element, styles:string|object, value:string|number):void * -> Set styles on element and add prefix if needed */const elem = document /** * createRequestFrame(duration:number, frame:function(data), done:function(requestID)) * -> create requestAnimationFrame loop with duration */ /** * minmax(min:number, max:number, value:number) * -> get number value in range of min and max */ // -> 5 // -> 0 // -> 10 /** * move(array:any[], from:number, to:number) * -> Move item in array from one position to another */ // -> [2, 3, 1] /** * * @function generateID * Generate random string id * @return **/ // -> r0fvlk8iuvk573eoap
View
Return true if the element is in the view - Example
// inView(options: Options)// example: https://codepen.io/kasarda/pen/aENRje/* interface Options { target: element, visibility: string = 'visible' || 'entire', axis:string = 'y' || 'x' || 'both' direction:string = 'linear' || 'end' || 'start' offset = { top: number = 0, left: number = 0, bottom: number = 0, right: number = 0, } }*/ const elem = document // if entire box element is visible on the screen this function will return true
Worker
const worker = 'greeting_worker.js' worker worker // greeting_worker.js const worker = worker
Easing
// bezier(x1, y1, x2, y2)(progress)5 // new progress // steps(steps)(progress)5 // new progress // spring(tension, friction, duration)(progress)5 // new progress // easing -> predefined bezier easing/* { ease(progress) easeIn(progress) easeOut(progress) easeInOut(progress) easeInSine(progress) easeOutSine(progress) easeInOutSine(progress) easeInQuad(progress) easeOutQuad(progress) easeInOutQuad(progress) easeInCubic(progress) easeOutCubic(progress) easeInOutCubic(progress) easeInQuart(progress) easeOutQuart(progress) easeInOutQuart(progress) easeInQuint(progress) easeOutQuint(progress) easeInOutQuint(progress) easeInExpo(progress) easeOutExpo(progress) easeInOutExpo(progress) easeInCirc(progress) easeOutCirc(progress) easeInOutCirc(progress) }*/ easing // new progresseasing // new progress
createElement
Create element object just like document.createElement but with more options
/* API: createElement(selector:string, options:Options|string|array, condition?:boolean) interface Options = { className: string | [string] | Promise(string|[string]), attr: object, // key is attr name and value is attr value. Value can be a Promise prop: object, // key is prop name and value is prop value. Value can be a Promise data: object // key is data name and value is data value. Value can be a Promise style: object // key is style name and value is style value. Value can be a Promise child: element | [element|Promise(element|[element])] | Promise(element, [element|Promise(element|[element])]), text: any | Promise(any), html: any | Promise(any), src: string | Promise(any),, on: object // key is eventName name and value is listener, appendTo: element, prependTo: element, ref: Function(element, Options) // this is also element appendFutureChilds:boolean = false}*/ // selector example: // <section> // <div class="wrapper"> // <div class="a b c"> // <nav id="main" class="light-theme"> // <input placeholder="Name" name="name" type="text"> // Options example:/*<nav class="light main" tabindex="1" data-visible="true" style="width:100%;height: 100px;"> <a href="#a"> <a href="#b"> <a href="#c"></nav>*/ // condition example: // <div> // null // promises example: // Shorthand syntax example:// second arguments as an string is same as option text or src for image element // <span>Hello World</span> // <img src="img.jpg"> // second arguments as an array is same as option child /* <div class="wrapper"> <nav> <a> <a> <a> </nav> <section> ... </section> <footer> ... </footer> </div>*/
Chunk
Create chunk array
const chunk = 5 chunk forlet i = 0; i < 12; i++ chunkchunk
History
Create history array
const history = historyhistoryhistoryhistorystates // -> ['a', 'b', 'c'] historycurrentState // -> 'c'historyhistorycurrentState // -> 'b'historyhistorycurrentState // -> 'a'historyhistorycurrentState // -> 'b'historyhistorystates // -> ['a', 'b', 'd']historycurrentState // -> 'd'historyisLast // -> truehistoryhistorycurrentState // -> 'b'historyhistorycurrentState // -> 'a'historyisFirst // -> truehistory // -> 'b'historyhistory // -> 'e'historyclearhistorycurrentState // -> undefined historyhistoryhistoryhistoryhistory