libj-globals v1.1.2
libj-globals
Part of libj tools
Usage (npm)
npm install libj-globalsand on top of your entry point:
import 'libj-globals'Adds jQuery symbols (jQuery, $), underscorejs (_) and moment (moment) symbols to window global variable, in order to use them anywhere without importing them.
Also adds support for Jalaali calendar system to moment using moment-jalaali npm package.
For other type checkings See Underscorejs website
Adds these to underscore _ symbol
_.isVoid(value) -> boolean
Is a function that if value is either null or undefined returns true, otherwise returns false.
_.isJquery(value) -> boolean
Checks if the given value argument is a jquery object
_.isBuffer(value) -> boolean
Checks if the given value argument is a Buffer object
_.searchObjects(search, objects, properties = null) -> array of objects
Searches for given search parameter
in the give objects parameter. properties is an array of string which you can pass to limit searching an
object to only these properties, if you don't pass this parameter or pass null all properties of an
object will be searched.
_.sortObjects(objects, columns) -> array of objects
Sorts given objects according to given columns.
columns is an array of { column: String, ascending: Boolean } in which 'column' is name of the name
of property to sort and 'ascending' is a boolean for sorting direction based on that property.
Adds the following ECMA polyfills:
- Object.assign method
- Object.entries method
- array.sort method
Adds the following for specific browser bugs:
- classList for IE10 & IE11 See this
- viewport fix for IE10 See this
- maxlength attribute bug in many browsers
Adds these to window global variable for logging:
logfunction is a replacement for console.log and can be used globally. Usage:
log('test') //prints test in consolestackTracefunction is added globally to show current stack trace. Usage:
stackTrace() //returns a string containing current stack tracelogStackTracefunction is added globally to printstackTraceoutput to console. Usage:
logStackTrace() //prints current stack trace in consoleAdds these to polyfill jquery in older browsers (Safari, IE):
$.fn.classes$.fn.hasAttrchecks if a jquery element contains an attribute. Calls$.fn.attrinternally. Usage:
$('#someElementId').hasAttr('custom-attribute')$.fn.equalschecks if a given element equals another element. Usage:
$('#el1').equals($('#el1)) //returns true$.fn.outerHTMLreturns outer html of the calling element. Usage:<div id="el1">iii</div> $('#el1').outerHTML() //returns <div id="el1">iii</div>Adds these to
Stringprototype in borwsers:format: Usage:String.format("Hello %0. Welcome to %1", "Saeid", "libj") //returns "Hello Saeid. Welcome to libj"endsWith: See thisstartsWith`: See thisAdds these to
Numberprototype in browsers:padZero`: Inserts specified number of zeros at the beginning of the calling number. Usage:var x = 12; x.padZero(4); //returns "0012"