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
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
Options:
Parameter |
Required |
Default |
Date Object |
Yes |
Current date time |
Format String |
Yes |
y-m-d H:i:s |
Available format charecter:
Format Character |
Description |
Example returned values |
Day |
--- |
--- |
d |
Day of the month, 2 digits with leading zeros |
01 to 31 |
D |
A textual representation of a day, three letters |
Mon through Sun |
j |
Day of the month without leading zeros |
1 to 31 |
l (lowercase 'L') |
A full textual representation of the day of the week |
Sunday through Saturday |
Month |
--- |
--- |
F |
A full textual representation of a month, such as January or March |
January through December |
m |
Numeric representation of a month, with leading zeros |
01 through 12 |
M |
A short textual representation of a month, three letters |
Jan through Dec |
n |
Numeric representation of a month, without leading zeros |
1 through 12 |
Year |
--- |
--- |
Y |
A full numeric representation of a year, at least 4 digits, with - for years BCE. |
Examples: 2022, 2023 |
y |
A two digit representation of a year |
Examples: 99 or 03 |
Time |
--- |
--- |
a |
Lowercase Ante meridiem and Post meridiem |
am or pm |
A |
Uppercase Ante meridiem and Post meridiem |
AM or PM |
g |
12-hour format of an hour without leading zeros |
1 through 12 |
G |
24-hour format of an hour without leading zeros |
0 through 23 |
h |
12-hour format of an hour with leading zeros |
01 through 12 |
H |
24-hour format of an hour with leading zeros |
00 through 23 |
i |
Minutes with leading zeros |
00 to 59 |
s |
Seconds with leading zeros |
00 through 59 |
Example:
DateHelper.format(new Date(), 'Y-m-d H:i:s'); // 2023-08-15 15:25:00
Options:
Parameter |
Required |
Time String |
Yes |
Example:
DateHelper.format12hours('13:30'); // 01:30 PM
Options:
Parameter |
Required |
Default |
Time Interval |
Yes |
10 |
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', ...]
Options:
Parameter |
Required |
Default |
Integer |
Yes |
10 |
Example:
DateHelper.getLastNYears(10); // [2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015, 2014]
Options:
Parameter |
Required |
Default |
Start date |
Yes |
null |
Endd ate |
Yes |
null |
Example:
DateHelper.getDateRange('2020-01-01', '2020-01-02'); // [2020-01-01T00:00:00.000Z, 2020-01-02T00:00:00.000Z]
Options:
Parameter |
Required |
Default |
Date |
Yes |
null |
No. of days |
Yes |
null |
Example:
DateHelper.addDays('2020-01-01', 10); // 2020-01-11T00:00:00.000Z
Options:
Parameter |
Required |
Default |
Date |
Yes |
null |
No. of Months |
Yes |
null |
Example:
DateHelper.addMonths('2020-01-01', 5); // 2020-06-01T00:00:00.000Z
Options:
Parameter |
Required |
Default |
Date |
Yes |
null |
No. of Years |
Yes |
null |
Example:
DateHelper.addYears('2020-01-01', 5); // 2025-01-01T00:00:00.000Z
Options:
Parameter |
Required |
Default |
Date |
Yes |
null |
No. of Days |
Yes |
null |
Example:
DateHelper.subtractDays('2020-01-01', 5); // 2019-12-27T00:00:00.000Z
- DateHelper.subtractMonths
Options:
Parameter |
Required |
Default |
Date |
Yes |
null |
No. of Monts |
Yes |
null |
Example:
DateHelper.subtractMonths('2020-01-01', 5); // 2019-08-01T00:00:00.000Z
Options:
Parameter |
Required |
Default |
Date |
Yes |
null |
No. of Years |
Yes |
null |
Example:
DateHelper.subtractYears('2020-01-01', 10); // 2010-01-01T00:00:00.000Z
- DateHelper.getDateDifference
Options:
Parameter |
Required |
Default |
Date 1 |
Yes |
null |
Date 2 |
Yes |
null |
Example:
DateHelper.getDateDifference('2020-01-01', '2020-01-05'); // 4
Options:
Parameter |
Required |
Default |
Date 1 |
Yes |
null |
Date 2 |
Yes |
null |
Example:
DateHelper.isDateBefore('2020-01-01', '2020-01-05'); // true
Options:
Parameter |
Required |
Default |
Date 1 |
Yes |
null |
Date 2 |
Yes |
null |
Example:
DateHelper.isDateAfter('2020-01-01', '2020-01-05'); // false
Options:
Parameter |
Required |
Default |
Date Time |
Yes |
null |
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';
Options:
Parameter |
Required |
Default |
Image File |
Yes |
null |
Example:
ImageHelper.fileToBase64(<file>); // returns base64 of a file
Options:
Parameter |
Required |
Default |
Base64 Image data |
Yes |
null |
File name without extention |
Yes |
null |
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:
Parameter |
Required |
Default |
Latitude 1 |
Yes |
null |
Longitude 1 |
Yes |
null |
Latitude 2 |
Yes |
null |
Longitude 2 |
Yes |
null |
Example:
AddressHelper.getDistanceInKm(24.8607, 67.0011, 24.8607, 67.0011); // 0
- AddressHelper.getDistanceInMiles
Options:
Parameter |
Required |
Default |
Latitude 1 |
Yes |
null |
Longitude 1 |
Yes |
null |
Latitude 2 |
Yes |
null |
Longitude 2 |
Yes |
null |
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:
Parameter |
Required |
Default |
lengts of password |
Yes |
8 |
Example:
StringHelper.generatePassword(10); // SHUH456@#$
- StringHelper.generateUUID
Example:
StringHelper.generateUUID(); // 123e4567-e89b-12d3-a456-426614174000
- StringHelper.generateSlug
Options:
Parameter |
Required |
Default |
Text |
Yes |
null |
Example:
StringHelper.generateSlug("Hello World"); // hello-world
- StringHelper.generateRandomString
Options:
Parameter |
Required |
Default |
Integer |
Yes |
10 |
Example:
StringHelper.generateRandomString(10); // aBcDeFgHiJ