node-helper-function v1.0.5-LTS-d
Node Helper Function
Introducing "Node Helper Function" – Your Ultimate Developer Companion!
Node Helper Function 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 Helper 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 has been depricated and is moved to new npm package node-simplify
Getting started
Installation
npm i node-helper-function
Date Helper function
The "DateHelper" function 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.
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:
import DateHelper from 'node-helper-function/Helper/DateHelper';
<!-- OR -->
import { DateHelper } from 'node-helper-function';
DateHelper(new Date(), 'Y-m-d H:i:s'); // 2023-08-15 15:25:00
Convert Time To 12 Hour format
The "ConvertTimeTo12HourFormat" function is a useful tool for transforming a given time value from the standard 24-hour format to the more familiar 12-hour format. This function takes a time input and returns the corresponding time in the AM/PM notation, making it easier for users to interpret and display time in a more user-friendly manner.
Options:
Parameter | Required |
---|---|
Time String | Yes |
Example:
import ConvertTimeTo12Hour from 'node-helper-function/Helper/ConvertTimeTo12Hour';
<!-- OR -->
import { ConvertTimeTo12Hour } from 'node-helper-function';
ConvertTimeTo12Hour('13:30'); // 01:30 PM
ConvertTimeTo12Hour('15:30'); // 03:30 PM
Generate Hours
The "GenerateHours" function is a practical tool designed to create a range or list of hours based on specific criteria. This function enables the automated generation of hour values, which can be useful in scenarios like scheduling, time-based calculations, or data visualization. By utilizing the "GenerateHours" function, developers can save time and effort when creating hour sequences for various programming tasks.
Options:
Parameter | Required | Default |
---|---|---|
Time Interval | Yes | 10 |
Example:
import GenerateHours from 'node-helper-function/Helper/GenerateHours';
<!-- OR -->
import { GenerateHours } from 'node-helper-function';
GenerateHours(10); // ['00:00', '00:10', '00:20', '00:30', '00:40', '00:50', '01:00', '01:10', '01:20', '01:30', '01:40', ...]
File to base64 string
The "GetBase64" function is a convenient utility that converts a given data input, such as files into its corresponding Base64 encoded format. This function is valuable for scenarios involving data transmission, storage, or manipulation, as Base64 encoding ensures data integrity and compatibility across different systems. By utilizing the "GetBase64" function, developers can seamlessly incorporate Base64 encoding into their applications, facilitating smooth data handling processes.
Options:
Parameter | Required |
---|---|
File Object | Yes |
Example:
import GetBase64 from 'node-helper-function/Helper/GetBase64';
<!-- OR -->
import { GetBase64 } from 'node-helper-function';
const handleFileChange = (event) => {
const file = event.target.files[0];
const base64Data = await GetBase64(file);
}; // data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==
Calculate distance in KM with latitude and longitude
The "GetDistanceFromLatLonInKm" function is a practical tool for calculating the distance between two geographical points on the Earth's surface using their latitude and longitude coordinates. By providing these coordinates as inputs, the function returns the distance between the points in kilometers. This function is particularly useful in applications involving location-based services, mapping, and navigation, where accurate distance calculations are essential for making informed decisions.
Options:
Parameter | Required |
---|---|
Starting Latitude | Yes |
Starting Longitude | Yes |
Ending Latitude | Yes |
Ending Longitude | Yes |
Example:
import GetDistanceFromLatLonInKm from 'node-helper-function/Helper/GetDistanceFromLatLonInKm';
<!-- OR -->
import { GetDistanceFromLatLonInKm } from 'node-helper-function';
GetDistanceFromLatLonInKm('24.8607', '67.0011', '24.8607', '67.0012') // 0.01
Get Last N Years
The "GetLastNYears" function is a useful utility designed to retrieve a list of the most recent "N" years, based on the current date. This function allows you to specify the number of years you're interested in, and it generates a collection of year values that represent the past "N" years. This function is valuable for tasks like data filtering, trend analysis, or generating dynamic date ranges in applications where working with recent years is relevant.
Options:
Parameter | Required | Default Value |
---|---|---|
Number | Yes | 10 |
Example:
import GetLastNYears from 'node-helper-function/Helper/GetLastNYears';
<!-- OR -->
import { GetLastNYears } from 'node-helper-function';
GetLastNYears(10) // [2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015, 2014]