helplib is an npm module that provides useful functions, including date, formatting, generation functionalities.
You can install the module using the node package manager:
npm install helplib
const { formatDate } = require('helplib');
console.log(formatDate()); // 02/19/2023 17:04:1
console.log(formatDate(new Date(), 'd/MM/y H:mm:s')); // 19/02/2023 17:04:1
console.log(formatDate(undefined, 'd/MM/y H:mm:s:f')); // 19/02/2023 17:04:1:95
date
: The date object to get the day of the week for. If not provided, the current date and time will be used.
const { getDayOfWeek } = require('helplib');
console.log(getDayOfWeek()); // Sunday
console.log(getDayOfWeek(new Date(), 'en-US')); // Sunday
console.log(getDayOfWeek(undefined, 'tr-TR')); // Pazar
date
: The date object to get the month name for. If not provided, the current date and time will be used.
const { getMonthName } = require('helplib');
console.log(getMonthName()); // Februrary
console.log(getMonthName(new Date(), 'en-US')); // Februrary
console.log(getMonthName(undefined, 'tr-TR')); // Şubat
date
: The date object to get the year and week number for. If not provided, the current date and time will be used.
const { getYearAndWeekNumber } = require('helplib');
console.log(getYearAndWeekNumber()); // { year: 2023, weekNumber: 7 }
console.log(getYearAndWeekNumber(new Date())); // { year: 2023, weekNumber: 7 }
console.log(getYearAndWeekNumber(undefined)); // { year: 2023, weekNumber: 7 }
data
: The date object to get the year and week number for. If not provided, the current date and time will be used.
const { formatData } = require('helplib');
const data = {
name: 'John Doe',
age: 32,
city: 'New York'
};
const text = 'Hi, my name is {name} and I am {age} years old. I live in {city}.';
const formattedText = formatData(data, text);
console.log(formattedText); // Hi, my name is John Doe and I am 32 years old. I live in New York.
const { formatString } = require('helplib');
const name = "John Doe";
const age = 30;
const country = "USA";
const result = formatString("My name is {0}, I am {1} years old and I live in {2}.", name, age, country);
console.log(result); // My name is John Doe, I am 30 years old and I live in USA.
length info
If the length value is less than six, a 6-character id is generated, and likewise, if the length value is greater than fifteen, a 15-character id is generated.
const { generateId } = require('helplib');
console.log(generateId()); // 47545019992 => length = 11;
console.log(generateId(5)); // 014915 => length = 6;
console.log(generateId(16)); // 226306621525260 => length = 15;
const { generatePassword } = require('helplib');
console.log(generatePassword()); // i2o2a3My => length = 8;
console.log(generatePassword(7)); // fUYzWVZ0 => length = 8;