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 🙏

© 2026 – Pkg Stats / Ryan Hefner

pwr-fe-utils

v4.9.4

Published

Frontend utilities

Readme

pwr-fe-utils

A lightweight frontend utilities package for React/Next.js applications.
It provides authentication helpers, reusable hooks, and higher-order components (HOCs) to simplify development.


📦 Installation

npm install pwr-fe-utils
# or
yarn add pwr-fe-utils
✨ Features
🔐 Authentication
withAuth → Protects pages/components with an AuthGuard.

AuthGuard → Redirects unauthenticated users to login, supports custom loaders.

📝 Validation
withLoginValidationSchema → Wrap forms with a prebuilt Yup validation schema.

useLoginValidation → Provides a Yup schema for login (email, password).

💰 Formatting
useFormattedPrice → Format prices according to the current next-intl locale (USD/UAH).

useNumberToWords → Convert numbers into words according to the current locale.

🔑 JWT Utilities
useDecodedToken → Decode JWT tokens stored in localStorage.

⚡ Developer Friendly
Built with TypeScript.

Fully compatible with Next.js 13+ and React 18/19.

Organized modular structure for clean imports.

📖 Usage Examples
1. Protecting a Page with withAuth
tsx
Copy
Edit
"use client";
import { withAuth } from "pwr-fe-utils";

function ProfilePage() {
  return <div>Welcome to Profile</div>;
}

export default withAuth(ProfilePage);
2. Using withLoginValidationSchema
tsx
Copy
Edit
"use client";
import { withLoginValidationSchema } from "pwr-fe-utils";

function LoginForm({ form }) {
  const { register, handleSubmit, formState: { errors } } = form;

  const onSubmit = (data: any) => {
    console.log("Login submitted", data);
  };

  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <input {...register("email")} placeholder="Email" />
      <p>{errors.email?.message}</p>

      <input {...register("password")} type="password" placeholder="Password" />
      <p>{errors.password?.message}</p>

      <button type="submit">Login</button>
    </form>
  );
}

export default withLoginValidationSchema(LoginForm);
3. Using useFormattedPrice
tsx
Copy
Edit
import { useFormattedPrice } from "pwr-fe-utils";

function PriceTag() {
  const { formatPrice } = useFormattedPrice();

  return <span>{formatPrice(1200)}</span>;
  // $1,200.00 or 1 200,00 ₴ based on locale
}
4. Using useDecodedToken
tsx
Copy
Edit
import { useDecodedToken } from "pwr-fe-utils";

function Profile() {
  const token = useDecodedToken<{ name: string }>();

  return <div>Hello, {token?.name}</div>;
}
5. Using useNumberToWords
tsx
Copy
Edit
"use client";
import { useNumberToWords } from "pwr-fe-utils";

function PriceInWords() {
  const { numberToWords } = useNumberToWords();

  return <div>{numberToWords(123456)}</div>;
  // "one hundred twenty-three thousand four hundred fifty-six"
  // Output is based on current next-intl locale, fallback is English
}
📂 Project Structure
css
Copy
Edit
src/
 ┣ hooks/
 ┃ ┣ useFormattedPrice.ts
 ┃ ┣ useDecodedToken.ts
 ┃ ┣ useLoginValidation.ts
 ┃ ┗ useNumberToWords.ts
 ┣ hoc/
 ┃ ┣ withAuth.tsx
 ┃ ┗ withLoginValidationSchema.tsx
 ┣ guards/
 ┃ ┗ authGuard.tsx
 ┗ index.ts
⚙️ Peer Dependencies
Make sure your project has:

next >= 13.0.0

react ^18.0.0 || ^19.0.0

react-dom ^18.0.0 || ^19.0.0

🙌 Contributing

Contributions, issues, and feature requests are welcome!
Feel free to open a PR or issue on https://github.com/Abdul-rehman-pwr/pwr-fe-utils
.