myjs

A simple JavaScript Facade library, to facilitate my life on frontend stuffs.

Installation

Just include the myjs.min.js file in you web page.

<script src="https://cdn.jsdelivr.net/gh/assisfery/myjs@1.1/myjs.min.js"></script>

Cookies

To manage cookies use those functions.

myjs.setCookie(key, value)

Set a value to cookie.

myjs.setCookie(key, value, days)

Set a value for a cookie with expiration days.

myjs.getCookie(key)

Get a defined cookie.

myjs.hasCookie(key)

Verify if a cookie exists.

myjs.removeCookie(key)

Delete a cookie.

Query String

To get query string parameters from url you can use that function.

myjs.getQuery(key)

Get query string from current page url.

myjs.getQuery(key, url)

Get query string from a url.

Validations

To validate some data use those functions.

myjs.isEmail(str)

To validate if a string is email.

myjs.isUrl(str)

To validate if a string is URL.

myjs.isNumber(str)

To validate if a string is a number.

Slugify

To slugify a string use that function.

myjs.slug(str)

Return a string slug.

Random

To get the random number use that function.

myjs.random(min, max)

Get a random number from min to max, but max is not included.

myjs.random(max)

Get a random number from zero to max, but max is not included.

Navigator

To execute navigator utils use that function.

myjs.redirect(url)

Redirect page to another url.

Element

To manipulate dom use those functions.

myjs.e(query)

Get all elements that match with query done. For example: myjs.e(".btn") will select all elements that has class "btn".

myjs.addClass(query, class)

Add a class to all elements that match with query.

myjs.removeClass(query, class)

Remove a class to all elements that match with query.

myjs.setHtml(query, html)

Set a inner html in all elements that match with query.

myjs.getHtml(query)

Get a inner html of the first element that match with query.

myjs.setVal(query, value)

Set a value html in all elements that match with query.

myjs.getVal(query)

Get a value of the first element that match with query.

myjs.hide(query)

Hide all elements that match with query.

myjs.show(query)

Show all elements that match with query.

AutoSelect

To auto select value in select (dropdown) element use tag data-value="value1" and execute the function myjs.autoSelect() when page is ready.

myjs.autoSelect()

Auto select dropdown element value.

DrawChart

To draw a chart you can use those functions.
Those functions depends of ChartJS libray.

<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js"></script>

myjs.drawChart(area, type, title, labels, data)

To draw a simple chart of any type supported by ChartJS.

myjs.drawChartSerie(area, type, labels, datasets)

To draw a series chart of any type supported by ChartJS.

Datetime timezone convertion

To convert a time to or from UTC use those functions.
Those functions depends of MomentJS Library.

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.27.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.31/moment-timezone-with-data-1970-2030.min.js"></script>


myjs.toUtc(datetime, timezone)

Convert a datetime from a timezone to UTC.



myjs.fromUtc(datetime, timezone)

Convert a datetime from UTC to a timezone.

Swap array elements

To swap array elements position (to left or right) use myjs.swapArray() function.

myjs.swapArray(elements, position, direction = "right", callback = null)