Skip to content

PunitSoniME/js-ts-utilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js-ts-utilities

npm version downloads license

Types Included gzip size


Installation

With Yarn:

yarn add js-ts-utilities

With npm:

npm install --save js-ts-utilities


URL Utilities

import { getBaseURL, isAbsoluteURL, getURLParameters } from 'js-ts-utilities';
Method Parameters Example Output
getBaseURL (url: string) getBaseURL('https://url.com/page?name=Punit&surname=Soni'); https://url.com/page
isAbsoluteURL (url: string) isAbsoluteURL('https://google.com'); true
getURLParameters (url: string) getURLParameters('https://url.com/page?name=Punit&surname=Soni'); { name: 'Punit', surname: 'Soni' }


HTML Utilities

import { containsElement, getAncestors, smoothScroll, onClickOutside, getSelectedText } from 'js-ts-utilities';
Method Parameters Example Output
containsElement (element1: HTMLElement, element2: HTMLElement) containsElement(document.querySelector('head'), document.querySelector('title')); true
getAncestors (element: HTMLElement) getAncestors(document.querySelector('body')); [document, html, body]
smoothScroll (elementIdOrClass: string) smoothScroll('#fooBar'); scrolls smoothly to the element with the id fooBar
onClickOutside (elementIdOrClass: string, method: Function) onClickOutside('#my-element', () => console.log('Hello')); Will log 'Hello' whenever the user clicks outside of #my-element
getSelectedText - getSelectedText() 'Lorem ipsum'
fullscreen (isFullScreen?: boolean) fullscreen()
fullscreen(false)
> fullscreen() - Opens `body` in fullscreen mode
> fullscreen(false) - Exit from fullscreen mode

Common Utilities

import { generateUUID } from 'js-ts-utilities';
Method Parameters Example Output
generateUUID - generateUUID(); 7982fcfe-5721-4632-bede-6000885be57d

Date Utilities

import { isDateValid, getTimestamp } from 'js-ts-utilities';
Method Parameters Example Output
isDateValid (date: string) isDateValid('December 17, 1995 03:24:00'); true
getTimestamp - getTimestamp(); 1602162242

Array Utilities

import { push, filter, update, remove } from 'js-ts-utilities';
Method Parameters Example Output
push (array: any[], elementToAdd: any) push([10, 20, 30, 40], 50) [10, 20, 30, 40, 50]
filter (array: any[], callback: Function) filter([10, 20, 30, 40], (d: number) => d < 40) [10, 20, 30]
update (array: any[], indexToUpdate: number, newElement: any) update([10, 20, 40], 2, 30) [10, 20, 30]
remove (array: any[], indexToRemove: number) remove([10, 20, 30], 2) [10, 20]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published