# libj

> ## Adds following to __window__ variable: - __log__: which is a shortcut for console.log - __$__ and __jQuery__: the jquery's famous $ and jQuery variable - __unerscore(_)__: underscore - __stackTrace function() -> Error__: returns an error object contain

Latest version **1.3.1** (published 2019-07-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install libj
pnpm add libj
yarn add libj
bun add libj
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2019-07-04 |
| First published | 2019-05-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 459.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | saeidfarahi |

## Links

- npm: https://www.npmjs.com/package/libj
- npm.io page: https://npm.io/package/libj

## Dependencies (9)

- [mime](https://npm.io/package/mime.md) ^2.4.4
- [store](https://npm.io/package/store.md) ^2.0.12
- [urijs](https://npm.io/package/urijs.md) ^1.19.1
- [jquery](https://npm.io/package/jquery.md) ^3.4.1
- [moment](https://npm.io/package/moment.md) ^2.24.0
- [underscore](https://npm.io/package/underscore.md) ^1.9.1
- [es6-promise](https://npm.io/package/es6-promise.md) ^4.2.8
- [babel-polyfill](https://npm.io/package/babel-polyfill.md) ^6.26.0
- [moment-jalaali](https://npm.io/package/moment-jalaali.md) ^0.8.3

## Recent versions

- 1.3.1 (latest) — 2019-07-04
- 1.3.0 — 2019-07-04
- 1.2.10 — 2019-07-04
- 1.2.9 — 2019-06-23
- 1.2.8 — 2019-06-23
- 1.2.7 — 2019-06-23
- 1.2.6 — 2019-06-05
- 1.2.5 — 2019-06-05
- 1.2.4 — 2019-06-05
- 1.2.3 — 2019-06-05
- 1.2.2 — 2019-06-05
- 1.2.1 — 2019-06-05
- 1.2.0 — 2019-06-05
- 1.1.0 — 2019-06-05
- 1.0.0 — 2019-05-16

## README

# libj

## Adds following to __window__ variable:
- __log__: which is a shortcut for console.log
- __$__ and __jQuery__: the jquery's famous $ and jQuery variable
- __unerscore(_)__: underscore
- __stackTrace function() -> Error__: returns an error object containing current stack trace
- __logStackTrace function() -> void__: prints current stack trace in console

## Adds the following methods to any __jQuery__ variable:
- __hasAttr function (name) -> Boolean__: checks if a jquery object has the given attribute.
    > $('.test').hasAttr('id')
- __equals function(jQueryObject) -> Boolean__: checks if a jquery object equals the given jquery object. 
    > $('.test').equals($('.test'))
- __outerHTML function() -> String__: returns the jquery object's outer html.
    > $('.test').outerHTML()

## Adds the following methods to javascript __Number__:
- __padZero function(size) -> String__: inserts 0s before a number until the length is equal to _size_ parameter
    > var x = 123; <br/>
    > x.padZero(5) <br/>
    > prints: 00123
- __format function(separator = ',') -> String__: thousand separator for mostly currencies
    > var x = 123000; <br>
    > x.format('/') <br>
    > prints: 123/000
## Adds the following methods to javascript __String__:
- __format function(templateString, ...args)__: just like c# String.format function
    > String.format('Hi, {0}', 'Akbar') <br/>
    > prints: Hi, Akbar
- __endsWith function(suffix)__: just like c# String.endsWith function
## Adds the following to __FormData__:
- __print function() -> String__: prints FormData object
- __put function(object) -> FormData__: puts all properties of object recursively into FormData

## jQuery __classes__ polyfill for IE 
will be automatically injected on import

## __IE10 viewport__ hack for Surface/desktop Windows 8 bug
will be automatically injected on import

## fix for __safari__ bug on __readonly input__
will be automatically injected on import

## Opacity:
- import 'libj/dist/opacity.css' to add opacity-{0, 25, 50, 75, 100} css classes
- __getOpacityCss(opactiy) -> String__: returns css style for the given _opacity_ parameter. _opacity_ must be a fload number between 0 and 1

## Media Query:
- __queryMedia function(query, callOnChange, callback) -> void__:
    - @param {string} query: e.g: '(max-width: 769px)'
    - @param {boolean} callOnChange: whether or not to invoke _callback_ parameter on window resize
    - @event callback : function (isMatch: boolean) -> void

- __queryMediaSync function(query = '(max-width: 769px)') -> Boolean__: checks css query and returns the result immediateley

## Id Generator:
- __guid function() -> String__: returns a c# Guid.NewGuid().ToString("N") like string
    > guid() <br>
    > returns: 976edaa0d2464573a6ea01aabaa98899
- __newId function() -> String__: returns guid() plus a prefix to make it suitable for html id attributes
    > newId() <br>
    > returns: e_976edaa0d2464573a6ea01a4bca98899

## Browser support:
- __browserSupport class()__:
    - methods:
        - __fileInput()__: returns true if browser supports file input
        - __fileApi()__: returns true if browser supports FileReader
        - __dragDropApi()__: returns true if browser supports drag & drop

## Type system:
- __isVoid function(value) -> Boolean__: checks if the _value_ is either _null_ or _undefined_
    > isVoid(null) <br/>
    > returns: true
- __isJquery function(value) -> Boolean__: checks if the _value_ is an instance of _jQuery_
    > isJquery($('.test')) <br>
    > returns: true
- __toJquery function(value) -> jQuery__: if the _value_ is not a _jQuery instance_, assumes that _value_ is a _jquery selector_ and returns the jquery instance of that selector
    > toJquery($('.test')) <br>
    > returns: $('.test') variable <br>
    > toJquery('.test') <br>
    > returns: $('.test') variable

## Utility:
- __callSafe function(func) -> return value of func__: calls the given function if it is available
- __kebab_case_to_camelCase function(kebabCase) -> String__: converts kebab-case string into camelCase equivalent
    > kebab_case_to_camelCase('libj-underscore') <br>
    > returns: libjUnderscore
- __containsArabic function(value) -> Boolean__: checks if a string contains persian or arabic characters
- __isKeyAlphaNumeric function(keyCode) -> Boolean__: checks if the given _keyCode_ of a jquery's _keyup_ or _keydown_ events is either digit or letter
- __isKeyTextInput function(keyCode) -> Boolean__: checks if the given _keyCode_ of a jquery's _keyup_ or _keydown_ events is either digit or letter and is __NOT__ _backspace: 8_ nor _delete: 46_
- __render function(template: String, data: Object) -> String__: renders a template using the data as its model with underscorejs template engine
- __toEnglishNumbers function(string) -> String__: changes arabic or persian digits in a string to english digits
- __flatten and unflatten__ from https://www.npmjs.com/package/flat
- __isBuffer__ from https://github.com/feross/is-buffer

## Synchronization:
- __spinLock class(locked: func, unlocked: func)__:
    - methods:
        - __lock()__ -> void: locks the object
        - __unlock()__ -> void: unlocks the object
        - __isLocked()__ -> Boolean: tells if the object is locked
        - __waitForLock(callback: func)__: invokes the _callback_ asynchronously when the object is unlocked

## Mime types:
- __MediaTypes class()__:
    - methods:
        - __acceptToFileTypes(accept)__: convert Html5 accept string to array of separate accepts
            * @param {String} accept example: image/\*, audio/\*, video/\*, ....
        - __getExtension(type)__: returns file extension of the given mime type.
        - __getMediaType(extensionOrPath)__: returns mime type of given file extension or url
        - __getIconPath(fileIconPath, extension, size = 48, type = 'png')__: returns icon url of the given file extension
            * @param {String} fileIconPath: folder in wwwroot on server e.g: /file-icon-set
            * @param {Number} size: 16, 24, 48, 64, 128
            * @param {String} type: png | gif
        - __getUrlThumb(url, done, iconSize = 48, iconType = 'png')__: returns icon for a given url (of a file)
            * @returns an object of type:
                * path {String}: url of the icon
                * isIcon {Boolean}: whether it is icon or not
                * height {Number | Null}: _iconSize_ parameter if _isIcon_ is true
        - __getFileThumb(file, done, iconSize = 48, iconType = 'png')__: returns icon for a given file (File)
            * @returns an object of type:
                * path {String}: data uri of icon
                * isIcon {Boolean}: whether it is icon or not
                * height {Number | Undefined}:
                _iconSize_ parameter if _isIcon_ is true

## Local Database:
- __Database class()__:
    - methods:
        - __set(key, value)__: sets the _value_ of _key_
        - __get(key, seed)__: gets the value of _key_ and _seeds_ that key for the first usage
        - __remove(key)__: removes _key_
        - __clear()__: clears database
        - __all()__: returns all as array of:
            * key
            * value

## Ajax:
- __registerXsrfHeaderInAjaxPost function() -> void__: registers current _xsrf.headerName()_ and _xsrf.value()_ in ajax-post
- __createUrl function(url) -> String__: gets localized url
- __createAjaxOptions function(method, url, data, success, error, completed) -> jQuery ajax options__
- __send function(method, url, data, success, error, completed) -> void__
- __sendGet function(url, data, success, error, completed) -> void__
- __sendPost function(url, data, success, error, completed) -> void__

## XSRF:
- __xsrfConfig class()__:
    - methods:
        - __headerName(xsrfHeaderName)__: gets or sets XSRF header name
        - __value(containerSelector, tagName)__: gets or sets XSRF value
        - __tag()__: gets hidden input of xsrf tag provided by asp.net core

## Culture:
- __cultureConfig class()__:
    - methods;
        - __cultures(cultures)__: gets or sets allowed cultures
        - __cultureObjects()__: gets culture objects as array of:
            - __id__: culture
            - __text__: name of culture
            - __url__: current url with this culture
        - __defaultCulture(culture)__: gets or sets default (fallback) culture, used for routing and operational stuff
        - __defaultUICulture(culture)__: gets or sets default UI culture, used for localization mostly
        - __culture(culture)__: gets or sets current _culture_
        - __getCultureName(culture)__: gets name of the give _culture_
        - __dir(culture)__: gets direction (rtl, ltr) of the give _culture_. if the _culture_ passed is _null_ or _undefined_ gets direction of _current culture_
        - __calendar()__: gets calendar of the _current culture_
- _.activeCultures Array of String

## Google:
- __googleConfig class()__:
    - methods:
        - __googletMapApiKey(apiKey)__: gets or sets current google map api key

## Url:
- __currentUrl__: a method returning info about current url
    - __culture__: culture
    - __url__: path part of url
    - __query__: query string

## Server Data:
- __serverItems()__:
    - properties:
        - __serverItems__: An _object_ of server <json></json> and <raw></raw> tags
        - __serverResults__: An _array_ of server _Results_
            - name
            - title
            - message
            - color
            - duration
            - returnValue

## Imaging:
- __thumberOptions(options)__: gets or sets _thumber options_
    - @param __options__:
        * extensions: 'png, jpg, jpeg, bmp'
        * widthParameterName: 'w'
        * heightParameterName: 'h'
        * qualityParameterName: 'q'
- __getImageUrl(path, quality = 100, width = null, height = null)__: gets _url_ of the compressed image

## Scrollbar:
- import 'libj/dist/scrollbar.css' to have nice little scrollbar on the window instead of the default one
- __infiniteScroller(scrollTarget, callback, locked, unlocked)__: 
    - @param scrollTarget: jQuery object for target container. pass _undefined_ to watch window scroll
    - @param callback: function (page, done: function(boolean)) -> void
    - @param locked: function () -> void
    - @param unlocked: function () -> void
- __windowScroll object__:
    - methods:
        - remove() -> void: removes window scrollbar
        - restore() -> void: restores window scrollbar

---
_Source: https://npm.io/package/libj · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
