Skip to content

Latest commit

 

History

History
297 lines (213 loc) · 8.93 KB

documentation.md

File metadata and controls

297 lines (213 loc) · 8.93 KB

📖 Documentation Utils.js

Contents

🚀 Connecting the library

const utils = require('@mr_fozan/utils.js');

🕘 Date and time

Contents:

Getting timestamp

Timestamp is a data type for storing date and time. The data is stored as the number of milliseconds elapsed since the beginning of the "Unix epoch". The range of values is: 1970-01-01 00:00:00 - 2038-12-31 00:00:00.

const timestamp = utils.date.timestamp(); // 1675871841130

Millisecond calculator

Simple millisecond calculator.

  • s - seconds
  • m - minutes
  • h - hours
  • d - days
const calculate = utils.date.inmls(10, "d"); // 864000000

Date and time via timestamp

This method will help to get the date and time timestamp

const timestamp = utils.date.timestamp();
const date_time = utils.date.getDate(timestamp); // [ '08.02.2023', ' 19:01:06' ]

Expanded time

This method helps to get an expanded time using milliseconds, e.g: 3600000 => 1 ч.

The result can be written in two languages:

  • ru - Russian language
  • en - English language
const unixTimeFull = utils.date.unixTime({ time: 1000, lang: "ru" }); // 1 сек.
const unixTimeShort = utils.date.unixTime({ time: 1000, type: "short" }); // 00:00:00

💬 Declination

Contents:

Declension by number

const apple = utils.declination.number({
    number: 101,
    first: "Яблок",
    second: "Яблоко",
    third: "Яблока"
}); // Яблоко

🔢 Numbers

Contents:

Number visualization

Separate the discharges

const division = utils.number.division(1000, "."); // 1.000

Add a suffix to a number

const suffix = utils.number.suffix(1000); // 1K

Random numbers

const random = utils.number.random(1, 1000); // min, max
const random2 = utils.number.random(1000); // max

Getting a Percentage

const percent = utils.number.percent(1, 100); // 1

Even number

const even = utils.number.even("A"); // undefined
const even2 = utils.number.even(123); // false
const even3 = utils.number.even(12346); // true

➗ Parse

Contents:

Parse URL

const url = utils.parse.url("https://github.com/Fozan-Developer/utils.js");

🟰 RegExp

Contents:

Validation Base64

const argument = "base64";

const base64 = utils.regexp.base64(argument); // false

Validating a credit card number

const sucs = utils.regexp.card("1111111111111111"); // true
const fail = utils.regexp.card("12345"); // false

Validation Date

const date1 = utils.regexp.date("29-02-2000"); // true
const date2 = utils.regexp.date("29-02-2001"); // false

Validation Email

const email = utils.regexp.email("test@gmail.com"); // true

File extension

const file_name = "index.js";

const file = utils.regexp.file(file_name); // js

Validation IPv4

const ipv4 = utils.regexp.ipv4("192.0.2.235");

Validation ISBN

const isbn1 = utils.regexp.isbn("ISBN 9781106998966"); // true
const isbn2 = utils.regexp.isbn("1106998966"); // true
const isbn3 = utils.regexp.isbn("110699896x"); // true

isNumber

Check for a number

const isNumber1 = utils.regexp.isNumber("123"); // true
const isNumber2 = utils.regexp.isNumber("123x"); // false

Validation Number

Validate phone number

const number1 = utils.regexp.isNumber("(121) 123-1234"); // true
const number2 = utils.regexp.isNumber("+1 123-123-1234"); // true
const number3 = utils.regexp.isNumber("+1 123-123-12-12"); // false

Validation URL

const url1 = utils.regexp.url("https://github.com/"); // true
const url2 = utils.regexp.url("abc"); // false

Validation Username

Validation of username by form:

  • Length from 3 to 16 characters
  • Digits
  • Small letters
  • Characters - and _
const username1 = utils.regexp.username("admin_owner-1"); // true
const username2 = utils.regexp.username("Admin_Owner-1"); // false

Validation Zip-Code

const rus = utils.regexp.zip_code("RUS", "537414"); // true
const usa = utils.regexp.zip_code("USA", "98765-4321"); // true

✡️ Symbol

Contents:

Smileys for different events

There are three kinds of events:

  • sucs - Successful
  • fail - Not successful
  • loading - Loading
const sucs = utils.symbol.actions("sucs"); // ✅
const fail = utils.symbol.actions("fail"); // ✖️
const loading = utils.symbol.actions("loading"); // 🔄

Process-bar

Process-bar types:

  • stars - returns the process-bar as stars (★★★★★)
  • squares - returns process-bar as squares (▪▪▪▪▪▪▪▪▪▪)
const stars = utils.symbol.bar({ type: "stars" current: 50, maximum: 100 }); // ★★✯☆☆
const squares = utils.symbol.bar({ type: "squares" current: 10, maximum: 100 }); // ▪▫▫▫▫▫▫▫▫▫

Number to character

Returns a number in the form of characters

const number = utils.symbol.number(123); // 1️⃣2️⃣3️⃣

Random from an array

Method helps to get a random element from an array. Use the String data type in the array to work correctly.

const pick = utils.symbol.pick(["Java", "JavaScript", "Node.JS"]); // Node.JS