npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

frontend-helper-methods

v1.0.7

Published

Helper methods for your frontend application, you can use these methods in web, mobile

Downloads

8

Readme

frontend-helper-methods

Helper Methods for frontend application

Installation

npm i frontend-helper-methods

Methods

passwordValidator(password: string, minimumLength?: number) => boolean

It provides validation for the password whether it is valid or not.You have to pass a password and optionally you can pass minimum length the password should be. It checks for following rules.

  • Password must include atleast one Capital Letter.
  • Password must include atleast one Numeric value.
  • Password must include atleast one Alphanumeric value.
  • Password must include atleast one Number.
  • Password must be of minimum length by default minimum length is 8

Usage

//Usage

import { passwordValidator } from "frontend-helper-methods";

console.log(passwordValidator("<Provide password you want to validate>"));

emailValidator: (email: string) => boolean

It validates the email and returns a boolean value, true means email is valid, false means email is invalid. It checks for '@' and '.' symbol in the email.

Usage

//Usage

import { emailValidator } from "frontend-helper-methods";

console.log(emailValidator("<Provide email you want to validate>"));

getDifferenceInDays: (startDate: string | Date, endDate: string | Date) => number

It takes start date, end date values and gives the difference between two dates. date format should be in yyyy-mm-dd or yyyy/mm/dd or yyyy-mm-ddT00:00:00Z.

Usage

//Usage

import { getDifferenceInDays } from "frontend-helper-methods";

console.log(getDifferenceInDays("<Provide start date>", "<Provide end date>"));

console.log(getDifferenceInDays("2024-02-07", "2024/02/07")); // return value 0

console.log(getDifferenceInDays("2024/02/07", "2024/02/09")); // return value 2

console.log(
  getDifferenceInDays("2024-02-07T00:00:00Z", "2024-02-09T00:00:00Z")
); // return value 2

getDateMilliseconds: (selectedDate: string | Date): { start_date: number; end_date: number } | Error

It accepts Date in the form of string or Date and it should be in the format yyyy-mm-dd or yyyy/mm/ddd or yyyy-mm-ddT00:00:00Z and returns the updated date in milliseconds as {start_date: number, end_date: number}

Usage

// Usage

import { getDateMilliseconds } from "frontend-helper-methods";

console.log(getDateMilliseconds("<Provide selected date>"));

console.log(getDateMilliseconds("2024-04-29")); // returns { start_date: 1714329061000, end_date: 1714415399000 }

// if you provide an empty string, method will throw an Error with string `Please provide a non empty string`
console.log(getDateMilliseconds("")); // returns Error: Please provide a non empty string

getMonthDifference = ( start_date: Date, end_date: Date ): number | null

This methods accepts two dates start_date, end_date and calculates the difference in months between the two dates ad returns the value. Please note that, lowest number date should be start_date and highest number date should be end_date, otherwise you will get the value in negatives. i.e start_date: "2024-04-29", end_date: "2024-05-29" it returns 1, if you give it in reverse order then you will get -1.

Usage

// Usage

import { getMonthDifference } from "frontend-helper-methods";

console.log(getMonthDifference(new Date("2024-04-02"), new Date("2024-05-29"))); // returns 1

console.log(getMonthDifference(new Date("2024-05-02"), new Date("2024-04-29"))); // returns -1

console.log(getMonthDifference("", new Date("2024-04-29"))); // returns null

console.log(getMonthDifference(new Date("2024-05-02"), "")); // returns null

generateMonthsCalendar = ( startingMonth: string | Date, monthTypeString?: boolean): string[]

This methods accepts startingMonth and monthTypeString(optional) as parameters. based on the starting month it will generate array of months till current date.

Usage

// Usage

import { generateMonthsCalendar } from "frontend-helper-methods";

console.log(generateMonthsCalendar("2023-12-02")); // returns ["2023-12-01","2024-01-01", "2024-02-01","2024-03-01", "2024-04-01", "2024-05-01"]

console.log(generateMonthsCalendar("2023-12-02", true)); // returns ["December 2023", "January 2024", "February 2024", "March 2024", "April 2024", "May 2024"]