1.0.0 • Published 4 months ago

node-simplify v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Node Simplify

Introducing "Node Simplify" – Your Ultimate Developer Companion!

Node Simplify is a versatile npm package designed to empower developers by simplifying complex tasks and enhancing productivity. Packed with a robust collection of meticulously crafted helper functions, Node Simplify Function streamlines various functionalities, enabling developers to achieve more with less effort. No matter the node version of your project it works with all.

Click here to give any suggestions or report an issue

NOTE: This package will be updated more as the time progress.

Getting started

Installation

npm i node-simplify

Date Helper

The "DateHelper" is a versatile utility that streamlines working with dates in programming. It provides an array of formatting, comparison, and manipulation. By simplifying complex temporal operations, this function enhances efficiency and accuracy in date-related programming tasks.


Example:
import { DateHelper } from 'node-simplify';

Available Functions

  • DateHelper.format
Options:
ParameterRequiredDefault
Date ObjectYesCurrent date time
Format StringYesy-m-d H:i:s
Available format charecter:
Format CharacterDescriptionExample returned values
Day------
dDay of the month, 2 digits with leading zeros01 to 31
DA textual representation of a day, three lettersMon through Sun
jDay of the month without leading zeros1 to 31
l (lowercase 'L')A full textual representation of the day of the weekSunday through Saturday
Month------
FA full textual representation of a month, such as January or MarchJanuary through December
mNumeric representation of a month, with leading zeros01 through 12
MA short textual representation of a month, three lettersJan through Dec
nNumeric representation of a month, without leading zeros1 through 12
Year------
YA full numeric representation of a year, at least 4 digits, with - for years BCE.Examples: 2022, 2023
yA two digit representation of a yearExamples: 99 or 03
Time------
aLowercase Ante meridiem and Post meridiemam or pm
AUppercase Ante meridiem and Post meridiemAM or PM
g12-hour format of an hour without leading zeros1 through 12
G24-hour format of an hour without leading zeros0 through 23
h12-hour format of an hour with leading zeros01 through 12
H24-hour format of an hour with leading zeros00 through 23
iMinutes with leading zeros00 to 59
sSeconds with leading zeros00 through 59

Example:
DateHelper.format(new Date(), 'Y-m-d H:i:s'); // 2023-08-15 15:25:00

  • DateHelper.format12hours
Options:
ParameterRequired
Time StringYes
Example:
DateHelper.format12hours('13:30'); // 01:30 PM

  • DateHelper.generateHours
Options:
ParameterRequiredDefault
Time IntervalYes10
Example:
DateHelper.generateHours(10); // ['00:00', '00:10', '00:20', '00:30', '00:40', '00:50', '01:00', '01:10', '01:20', '01:30', '01:40', ...]

  • DateHelper.getLastNYears
Options:
ParameterRequiredDefault
IntegerYes10
Example:
DateHelper.getLastNYears(10); // [2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015, 2014]

  • DateHelper.getDateRange
Options:
ParameterRequiredDefault
Start dateYesnull
Endd ateYesnull
Example:
DateHelper.getDateRange('2020-01-01', '2020-01-02'); // [2020-01-01T00:00:00.000Z, 2020-01-02T00:00:00.000Z]

  • DateHelper.addDays
Options:
ParameterRequiredDefault
DateYesnull
No. of daysYesnull
Example:
DateHelper.addDays('2020-01-01', 10); // 2020-01-11T00:00:00.000Z

  • DateHelper.addMonths
Options:
ParameterRequiredDefault
DateYesnull
No. of MonthsYesnull
Example:
DateHelper.addMonths('2020-01-01', 5); // 2020-06-01T00:00:00.000Z

  • DateHelper.addYears
Options:
ParameterRequiredDefault
DateYesnull
No. of YearsYesnull
Example:
DateHelper.addYears('2020-01-01', 5); // 2025-01-01T00:00:00.000Z

  • DateHelper.subtractDays
Options:
ParameterRequiredDefault
DateYesnull
No. of DaysYesnull
Example:
DateHelper.subtractDays('2020-01-01', 5); // 2019-12-27T00:00:00.000Z

  • DateHelper.subtractMonths
Options:
ParameterRequiredDefault
DateYesnull
No. of MontsYesnull
Example:
DateHelper.subtractMonths('2020-01-01', 5); // 2019-08-01T00:00:00.000Z

  • DateHelper.subtractYears
Options:
ParameterRequiredDefault
DateYesnull
No. of YearsYesnull
Example:
DateHelper.subtractYears('2020-01-01', 10); // 2010-01-01T00:00:00.000Z

  • DateHelper.getDateDifference
Options:
ParameterRequiredDefault
Date 1Yesnull
Date 2Yesnull
Example:
DateHelper.getDateDifference('2020-01-01', '2020-01-05'); // 4

  • DateHelper.isDateBefore
Options:
ParameterRequiredDefault
Date 1Yesnull
Date 2Yesnull
Example:
DateHelper.isDateBefore('2020-01-01', '2020-01-05'); // true

  • DateHelper.isDateAfter
Options:
ParameterRequiredDefault
Date 1Yesnull
Date 2Yesnull
Example:
DateHelper.isDateAfter('2020-01-01', '2020-01-05'); // false

  • DateHelper.timeAgo
Options:
ParameterRequiredDefault
Date TimeYesnull
Example:
DateHelper.timeAgo('2023-01-01'); // 1 year ago

Image Helper

The ImageHelper is a convenient utility to manupilate image datal

Example:
import { ImageHelper } from 'node-simplify';
  • ImageHelper.fileToBase64
Options:
ParameterRequiredDefault
Image FileYesnull
Example:
ImageHelper.fileToBase64(<file>); // returns base64 of a file

  • ImageHelper.base64toFile
Options:
ParameterRequiredDefault
Base64 Image dataYesnull
File name without extentionYesnull
Example:
ImageHelper.base64toFile(<base64>, <name>) // returns file

Address Helper

The AddressHelper is a convenient utility to manupilate Address details

Example:
import { AddressHelper } from 'node-simplify';
  • AddressHelper.getDistanceInKm
Options:
ParameterRequiredDefault
Latitude 1Yesnull
Longitude 1Yesnull
Latitude 2Yesnull
Longitude 2Yesnull
Example:
AddressHelper.getDistanceInKm(24.8607, 67.0011, 24.8607, 67.0011); // 0

  • AddressHelper.getDistanceInMiles
Options:
ParameterRequiredDefault
Latitude 1Yesnull
Longitude 1Yesnull
Latitude 2Yesnull
Longitude 2Yesnull
Example:
AddressHelper.getDistanceInMiles(24.8607, 67.0011, 24.8607, 67.0011); // 0

String Helper

The StringHelper is a convenient utility to manupilate Strings.

Example:
import { StringHelper } from 'node-simplify';
  • StringHelper.generatePassword
Options:
ParameterRequiredDefault
lengts of passwordYes8
Example:
StringHelper.generatePassword(10); // SHUH456@#$

  • StringHelper.generateUUID
Example:
StringHelper.generateUUID(); // 123e4567-e89b-12d3-a456-426614174000

  • StringHelper.generateSlug
Options:
ParameterRequiredDefault
TextYesnull
Example:
StringHelper.generateSlug("Hello World"); // hello-world

  • StringHelper.generateRandomString
Options:
ParameterRequiredDefault
IntegerYes10
Example:
StringHelper.generateRandomString(10); // aBcDeFgHiJ