0.1.0 • Published 3 years ago

dochq-js-snippets v0.1.0

Weekly downloads
3
License
ISC
Repository
github
Last release
3 years ago

js-snippets

JavaScript Snippets as an NPM package

addScriptByURL

Arguments

Accepts arguments: url - string and tagName - string

tagName will usually be 'head' or 'body'.

Purpose

To add an external JavaScript file to the head or body if it isn't already present.

Notes

Also uses isScriptPresentByURL


addScriptByContents

Arguments

Accepts: contents - stringified JavaScript, scriptId - string (gives the script an id), tagName - string.

tagName will usually be 'head' or 'body'.

Purpose

To add JavaScript contents to the head or body if it isn't already present.

Notes

Also uses isScriptPresentByID


isScriptPresentByURL

Arguments

Accepts: url - string

Purpose

To check if an external JavaScript file has been loaded by using it's URL to match.


isScriptPresentByID

Arguments

Accepts: id - string

Purpose

To check if an external JavaScript file has been loaded by using it's ID to match.


getDates

Arguments

Accepts: startDate, stopDate - Dates

Purpose

Returns array of dates between start and stop date.


calcWorkingDays

Arguments

Accepts: startDate, stopDate

Purpose

Returns array of dates between start and stop date not including weekends.


dataURItoBlob

Arguments

Accepts: dataURI

Purpose

Converts dataURI to a Blob, returns {error} if fails.


datesAreSameDay

Arguments

Accepts: date1, date2 - Dates

Purpose

Check if two dates are the same day. Returns a boolean.


existsInArray

Arguments

Array, Field.

Purpose

Returns a boolean if field exists and is identical in array.

e.g Array= 'test', {name:'value'} returns true for: field = 'test' and field = {name:'value'}


firstCharUpper

Arguments

String - string

Purpose

UpperCase the first character of a string only


formatTimeSlot

Arguments

Date - Date

Purpose

Format a time slot hh:mm AM or hh:mm PM in local time.


formatCertificateDate

Arguments

Date - Date

Purpose

dd/mm/yyyy hh:mm


toUTCUnixSeconds

Arguments

Date - Date

Purpose

Convert date to UNIX seconds, JavaScript uses milliseconds when using new Date().getTime()


removeHHMMSS

Arguments

Date - Date

Purpose

Takes a date and removes the hours, minutes and seconds.


minusNminutes

Arguments

Date - Date, minutes - number of minutes to remove

Purpose

Returns a date with specific number of minutes removed


isClickOutsideElement

Arguments

Element Identifier - Query Selector, event - callback function

Purpose

To add a click outside event listener to an element.


removeWhiteSpace

Arguments

String - string

Purpose

Remove whitespace, tabs and line breaks.


toTitleCase

Arguments

String - String

Purpose

Return a title cased string


validateEmail

Arguments

String - String

Purpose

Uses a regex pattern to check if email is a valid email.


Template

Arguments

Purpose