Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Schascha committed Feb 20, 2024
1 parent 0729dd0 commit 50415a8
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/copy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Copy text to the clipboard
* @param {*} text - The text to copy
* @returns {void}
*/
export function copy(text) {
if (navigator && navigator.clipboard) {
Expand Down
18 changes: 9 additions & 9 deletions src/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Add days to a date
* @param {Date} date - The date to add days to
* @param {number} days - The number of days to add
* @returns Date
* @returns {Date} The new date
*/
export function addDays(date, days) {
const result = new Date(date);
Expand All @@ -14,7 +14,7 @@ export function addDays(date, days) {
* Add months to a date
* @param {Date} date - The date to add months to
* @param {number} months - The number of months to add
* @returns Date
* @returns {Date} The new date
*/
export function addMonths(date, months) {
const result = new Date(date);
Expand All @@ -26,7 +26,7 @@ export function addMonths(date, months) {
* Add years to a date
* @param {Date} date - The date to add years to
* @param {number} years - The number of years to add
* @returns Date
* @returns {Date} The new date
*/
export function addYears(date, years) {
const result = new Date(date);
Expand All @@ -38,7 +38,7 @@ export function addYears(date, years) {
* Get the difference in days between two dates
* @param {Date} date1 - The first date
* @param {Date} date2 - The second date
* @returns number
* @returns {number} The number of days between the two dates
*/
export function diffInDays(date1, date2) {
return Math.ceil((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24));
Expand All @@ -47,7 +47,7 @@ export function diffInDays(date1, date2) {
/**
* Get the number of days in a month
* @param {Date} date - The date to get the number of days in the month for
* @returns number
* @returns {number} The number of days in the month
*/
export function daysInMonth(date) {
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
Expand All @@ -57,12 +57,12 @@ export function daysInMonth(date) {
* Format a date as YYYY-MM-DD or a custom format
* @param {Date} date - The date to format
* @param {string} format - The format to use, defaults to YYYY-MM-DD
* @returns string
* @returns {string} The formatted date as a string
*/
export function formatDate(date, format = 'YYYY-MM-DD') {
const day = date.getDate(),
month = date.getMonth() + 1,
year = date.getFullYear();
const day = date.getDate();
const month = date.getMonth() + 1;
const year = date.getFullYear();
return format
.replace('DD', day < 10 ? `0${day}` : day)
.replace('D', day)
Expand Down
5 changes: 3 additions & 2 deletions src/scroll.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* Scroll to the top of the element
* @param {HTMLElement} el - The element to scroll to
* @param {string|number|HTMLElement} offset - The offset to apply, can be a number, a string selector or an HTMLElement, default is 0
* @param {ScrollBehavior} behavior - The scroll behavior, can be 'auto', 'smooth', 'instant', default is 'smooth'
* @param {string|number|HTMLElement} [offset=0] - The offset to apply, can be a number, a string selector or an HTMLElement, default is 0
* @param {ScrollBehavior} [behavior='smooth'] - The scroll behavior, can be 'auto', 'smooth', 'instant', default is 'smooth'
* @returns {void}
*/
export function scrollToTop(el, offset = 0, behavior = 'smooth') {
if (!el) {
Expand Down
6 changes: 3 additions & 3 deletions src/text.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Truncate a string to a certain length
* @param {string} str - The string to truncate
* @param {number} length - The length to truncate the string, default is 250
* @param {string} ending - The ending to append to the truncated string, default is '...'
* @returns
* @param {number} [length=250] - The length to truncate the string to, default is 250
* @param {string} [ending='...'] - The ending to append to the string, default is '...'
* @returns {string} The truncated string
*/
export function truncate(str, length = 250, ending = '...') {
str = str.trim();
Expand Down
6 changes: 3 additions & 3 deletions src/type.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Type-checking with Object.prototype.toString() method.
* @param {*} value The value to inspect.
* @returns {string} Returns type as lowercase string.
* Type-checking with Object.prototype.toString() method
* @param {*} value - The value to inspect
* @returns {string} Returns type as lowercase string
*/
export function typeOf(value) {
return Object.prototype.toString
Expand Down
2 changes: 1 addition & 1 deletion src/visible.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export function isVisible(el: Element): any;
export function isVisible(el: Element): boolean | undefined;
12 changes: 6 additions & 6 deletions src/visible.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* Returns if the DOM element is visible on the users viewport.
* @param {Element} el The DOM element to be inspected.
* @return {*} Return `true` if element is visible, else `false` or ``undefined`.
* Returns if the DOM element is visible on the users viewport
* @param {Element} el - The DOM element to be inspected
* @return {boolean|undefined} Return `true` if element is visible, else `false` or `undefined`
*/
export function isVisible(el) {
if (!el) {
return;
}

const { top, right, bottom, left } = el.getBoundingClientRect(),
width = window.innerWidth || document.documentElement.clientWidth,
height = window.innerHeight || document.documentElement.clientHeight;
const { top, right, bottom, left } = el.getBoundingClientRect();
const width = window.innerWidth || document.documentElement.clientWidth;
const height = window.innerHeight || document.documentElement.clientHeight;
return top >= 0 && right <= width && bottom <= height && left >= 0;
}

0 comments on commit 50415a8

Please sign in to comment.