UNPKG

node-simplify

Version:

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 functiona

482 lines (315 loc) 12.4 kB
# Node Simplify <p align="center"> <a href="https://www.npmjs.com/package/node-simplify"> <img src="https://img.shields.io/npm/v/node-simplify.svg?orange=blue&logo=npm" /> </a> <img src="https://img.shields.io/bundlephobia/min/node-simplify?orange=blue" /> <img alt="downloads" src="https://img.shields.io/npm/dm/node-simplify?style=social&color=blue" /> </p> 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](https://forms.gle/Niz1333FpYnqq5Pq5) to give any suggestions or report an issue > NOTE: This package will be updated more as the time progress. ## Getting started ### Installation ```bash 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: ```code import { DateHelper } from 'node-simplify'; ``` --- #### Available Functions - DateHelper.format ##### 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: ```code DateHelper.format(new Date(), 'Y-m-d H:i:s'); // 2023-08-15 15:25:00 ``` --- - DateHelper.format12hours ##### Options: | Parameter | Required | | ----------- | -------- | | Time String | Yes | ##### Example: ```code DateHelper.format12hours('13:30'); // 01:30 PM ``` --- - DateHelper.generateHours ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Time Interval | Yes | 10 | ##### Example: ```code 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: | Parameter | Required | Default | | ------------- | -------- | ------- | | Integer | Yes | 10 | ##### Example: ```code DateHelper.getLastNYears(10); // [2023, 2022, 2021, 2020, 2019, 2018, 2017, 2016, 2015, 2014] ``` --- - DateHelper.getDateRange ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Start date | Yes | null | | Endd ate | Yes | null | ##### Example: ```code DateHelper.getDateRange('2020-01-01', '2020-01-02'); // [2020-01-01T00:00:00.000Z, 2020-01-02T00:00:00.000Z] ``` --- - DateHelper.addDays ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Date | Yes | null | | No. of days | Yes | null | ##### Example: ```code DateHelper.addDays('2020-01-01', 10); // 2020-01-11T00:00:00.000Z ``` --- - DateHelper.addMonths ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Date | Yes | null | | No. of Months | Yes | null | ##### Example: ```code DateHelper.addMonths('2020-01-01', 5); // 2020-06-01T00:00:00.000Z ``` --- - DateHelper.addYears ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Date | Yes | null | | No. of Years | Yes | null | ##### Example: ```code DateHelper.addYears('2020-01-01', 5); // 2025-01-01T00:00:00.000Z ``` --- - DateHelper.subtractDays ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Date | Yes | null | | No. of Days | Yes | null | ##### Example: ```code 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: ```code DateHelper.subtractMonths('2020-01-01', 5); // 2019-08-01T00:00:00.000Z ``` --- - DateHelper.subtractYears ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Date | Yes | null | | No. of Years | Yes | null | ##### Example: ```code 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: ```code DateHelper.getDateDifference('2020-01-01', '2020-01-05'); // 4 ``` --- - DateHelper.isDateBefore ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Date 1 | Yes | null | | Date 2 | Yes | null | ##### Example: ```code DateHelper.isDateBefore('2020-01-01', '2020-01-05'); // true ``` --- - DateHelper.isDateAfter ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Date 1 | Yes | null | | Date 2 | Yes | null | ##### Example: ```code DateHelper.isDateAfter('2020-01-01', '2020-01-05'); // false ``` --- - DateHelper.timeAgo ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Date Time | Yes | null | ##### Example: ```code DateHelper.timeAgo('2023-01-01'); // 1 year ago ``` --- ### Image Helper The ImageHelper is a convenient utility to manupilate image datal ##### Example: ```code import { ImageHelper } from 'node-simplify'; ``` - ImageHelper.fileToBase64 ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Image File | Yes | null | ##### Example: ```code ImageHelper.fileToBase64(<file>); // returns base64 of a file ``` --- - ImageHelper.base64toFile ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Base64 Image data | Yes | null | | File name without extention | Yes | null | ##### Example: ```code ImageHelper.base64toFile(<base64>, <name>) // returns file ``` --- ### Address Helper The AddressHelper is a convenient utility to manupilate Address details ##### Example: ```code 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: ```code 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: ```code AddressHelper.getDistanceInMiles(24.8607, 67.0011, 24.8607, 67.0011); // 0 ``` --- ### String Helper The StringHelper is a convenient utility to manupilate Strings. ##### Example: ```code import { StringHelper } from 'node-simplify'; ``` - StringHelper.generatePassword ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | lengts of password | Yes | 8 | ##### Example: ```code StringHelper.generatePassword(10); // SHUH456@#$ ``` --- - StringHelper.generateUUID ##### Example: ```code StringHelper.generateUUID(); // 123e4567-e89b-12d3-a456-426614174000 ``` --- - StringHelper.generateSlug ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Text | Yes | null | ##### Example: ```code StringHelper.generateSlug("Hello World"); // hello-world ``` --- - StringHelper.generateRandomString ##### Options: | Parameter | Required | Default | | ------------- | -------- | ------- | | Integer | Yes | 10 | ##### Example: ```code StringHelper.generateRandomString(10); // aBcDeFgHiJ ``` ---