1.0.17 • Published 9 months ago

utilities-functions v1.0.17

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

intro

Javascript utilities functions and methods for browser and nodejs to 10x faster developer experience

Fast, generic JavaScript browser and some nodejs utility functions.

Install with npm

Install

npm i utilities-functions

Overview

  • clipboard JavaScript clipboard function browser
  • convert convert utility string number etc.
  • cookies This cookies only works client side javascript
  • datetime convience function to convert date and time
  • detection detection device theme scheme and browser information
  • exportion export pdt or doc file with client side javascript
  • generate generate random number uuid and much more
  • storage browser local storage or session management
  • str string utilies capitalize and firrsuppercase letters
  • types we also have typescript support for types safety
  • url manage url to string and string to url is very convenient
  • validation validate client side email, number ete.
  • author project author details and github page
  • license license

Usage

clipboard

copyImageToClipboard

import { copyImageToClipboard } from "utilities-functions/clipboard";

//copy image to clipboard
const imageUrl = "path/to/image";

copyImageToClipboard(imageUrl);
//will return blob

imageToBlob

import { imageToBlob } from "utilities-functions/clipboard";

const imageUrl = "path/to/image";

imageToBlob(imageUrl);
//will return blob

toClipboard or copyToClipboard

import { toClipboard } from "utilities-functions/clipboard";

//copy text to clipboard
toClipboard("hello world");

convert

formatPrice

import { formatPrice } from "utilities-functions/convert";

//formate the prite for payment gateway : stipe or anything else
formatPrice(20.3);

currencyToSymbol

import { currencyToSymbol } from "utilities-functions/convert";

//Currency to symbol
currencyToSymbol("USD");
//output: $

objectToStr

import { objectToStr } from "utilities-functions/convert";

objectToStr({ a: "hello", b: " world" });
// will return string { a: "hello", b: " world" }

errorToString

import { errorToString } from "utilities-functions/convert";

errorToString("any errors like: object or string");
//I will return only string

Our online rgb to hex tool rgbToHex | hexToRgb

import { rgbToHex } from "utilities-functions/convert";
import { hexToRgb } from "utilities-functions/convert";

rgbToHex(10, 20, 100);
//I will return hex string: #0a1464

hexToRgb("#1a098b");
/*
 * will return hex object
 * @return { red: number, green: number, blue: number } or  null
 */

cookies

setCookie

import { setCookie } from "utilities-functions/cookies";

const cookieName = "cookie-name";
const cookieValue = "value";
const cookieDays = 30;
const cookiePath = ""; // optional

setCookie(cookieName, cookieValue, cookieDays);

getCookie | hasCookie

import { getCookie } from "utilities-functions/cookies";
import { hasCookie } from "utilities-functions/cookies";

const cookieName = "cookie-name";

getCookie(cookieName);

hasCookie(cookieName); // reurn true or false;

datetime

import { dbTodate } from "utilities-functions/datetime";
import { dbTotime } from "utilities-functions/datetime";

dbTodate("2023-03-28 20:04:10");
// output: Mar 28, 23

dbTotime("2023-03-28 20:04:10");
// output: 08:04 PM

detection

import { isDark } from "utilities-functions/detection";
import { deviceTheme } from "utilities-functions/detection";

isDark(); // will return true or false

deviceTheme(); // will return dark or light

exportion

import { exportTopdf } from "utilities-functions/exportion";
import { exportToDocs } from "utilities-functions/exportion";

exportTopdf("filename", "dat content", options); //options is optional

exportToDocs("filename", "dat content");

generate

import { uuid } from "utilities-functions/generate";
import { uuidv1 } from "utilities-functions/generate";
import { uuidv4 } from "utilities-functions/generate";
import { avatar } from "utilities-functions/generate";

uuid(); //will return string unique uuid

uuidv1(); //will return string unique uuidv1

uuidv4(); //will return string unique uuidv4

avatar("name"); //will return avatar url by first latter

storage

Session storage

import {
  getSession,
  setSession,
  removeSession,
} from "utilities-functions/storage";

setSession("sessionName", "session data  with any data type");

getSession("sessionName");
// I will return session data with as some format data was saved

removeSession("sessionName");
// The session is removed

localStorage

import { setLocalStorage } from "utilities-functions/storage";

setLocalStorage("storageName", "session data  with any data type");

getLocalStorage("sessionName");
// I will return local storage data with as some format data was saved

themeStorage

import { setThemeStore } from "utilities-functions/storage";
import { getThemeStore } from "utilities-functions/storage";

setThemeStore("dark");

getThemeStore(); // output: dark

str

import { capitalize, firstUpper } from "utilities-functions/str";

capitalize("hello world"); // output: Hello world

firstUpper("hello world"); // output: Hello world

url

toSeoUrl

import { toSeoUrl } from "utilities-functions/url";

toSeoUrl("Hello: I am javascript");
//output: hello-i-am-javascript

seoToString

import { seoToString } from "utilities-functions/url";

seoToString("hello-iam-javascript");
//output: hello i am javascript

urlToString

import { urlToString } from "utilities-functions/url";

urlToString("hello-iam-javascript");
//output: hello i am javascript

adslash

import { adslash } from "utilities-functions/url";

adslash("hello-iam-javascript");
//output: hello i am javascript

unslash

import { unslash } from "utilities-functions/url";

unslash("hello-iam-javascript");
//output: hello i am javascript

validation

import { isMail, isPhoneNumber } from "utilities-functions/validation";

isMail("yourmail@domain.com"); // true or false

isPhoneNumber("abc10832749"); // false

isPhoneNumber("10986499204"); // true

Typescript

types (pre-defined types for typescript)

RangeOf(strint number and end numbe)

import { FileExtensions, FileOpenInfo } from "utilities-functions/types/files";

export type FileOpenInfo = {
  name: string;
  data: string;
  extension: FileExtensions;
};
//some more types will come sooner
import { ThemeType } from "utilities-functions/types/themes";
import { setThemeStore } from "utilities-functions/storage";

const theme: ThemeType = "light";

setThemeStore(theme);

Author

Saeed

License

Copyright © 2023 appsaeed

MIT

1.0.17

9 months ago

1.0.16

9 months ago

1.0.10

9 months ago

1.0.15

9 months ago

1.0.14

9 months ago

1.0.13

9 months ago

1.0.12

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago

1.0.9

9 months ago