0.0.25 โ€ข Published 5 months ago

@andrmhndr/cleankit v0.0.25

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

๐Ÿงผ @andrmhndr/cleankit

A beautifully structured utility kit for React & Next.js projects. Includes global dialogs, query param management, debouncing, date formatting, and object/list cleaning helpers.

Made for developers who care about clean code, efficiency, and a little bit of magic โœจ


๐Ÿ“ฆ Installation

npm install @andrmhndr/cleankit
# or
yarn add @andrmhndr/cleankit

๐Ÿ“š Features

  • ๐Ÿง  DialogProvider โ€” Promise-based global modals.
  • ๐Ÿ” useQueryParams โ€” Easy query param management.
  • ๐Ÿ•’ debounce โ€” Lightweight function throttling.
  • ๐Ÿ“… formatDate โ€” Date formatting with locale support.
  • ๐Ÿงน cleanObject & cleanList โ€” Remove noise from objects and arrays.

๐Ÿ”˜ DialogProvider

Setup

import { DialogProvider } from "@andrmhndr/cleankit";

export default function App({ Component, pageProps }) {
  return (
    <DialogProvider>
      <Component {...pageProps} />
    </DialogProvider>
  );
}

Usage

import { useContext } from "react";
import { DialogContext } from "@andrmhndr/cleankit";

const MyComponent = () => {
  const dialog = useContext(DialogContext);

  const handleClick = async () => {
    const result = await dialog?.openDialog({
      content: (close) => (
        <div>
          <p>Are you sure?</p>
          <button onClick={() => close(true)}>Yes</button>
          <button onClick={() => close(false)}>No</button>
        </div>
      ),
    });

    console.log("Dialog result:", result);
  };

  return <button onClick={handleClick}>Show Dialog</button>;
};

๐Ÿ”— useQueryParams

Manage URL query params with ease (works with Next.js and React Router).

import { useQueryParams } from "@andrmhndr/cleankit/react";

const { getOne, setQuery, removeQuery, clearQuery } = useQueryParams();

getOne("search");
setQuery({ search: "Next.js" });
removeQuery("search");
clearQuery();

// With debounce
setQuery({ search: "react" }, { debounce: 300 });

โš ๏ธ For Next.js, make sure your useQueryParams imports from @andrmhndr/cleankit/next instead of base package.


๐Ÿ•’ debounce

import { debounce } from "@andrmhndr/cleankit";

const log = debounce((val: string) => console.log(val), 500);

log("Hello world");

๐Ÿ“… formatDate

import { formatDate } from "@andrmhndr/cleankit/server";


dateFormatter("2023-12-25T14:30:00", { format: "dd MMMM yyyy HH:mm" })
dateFormatter(new Date(), {
  format: "EEEE, d MMM yyyy hh:mm a",
  dayNamesFull: ["Minggu", "Senin", ...],
  monthNames: ["Januari", "Februari", ...],
  amPmLabels: ["pagi", "malam"]
})

๐Ÿงน cleanObject & cleanList

Clean out unwanted values from data objects and arrays.

๐Ÿงผ cleanObject

Removes null, undefined, and empty string "" values from an object.

import { cleanObject } from "@andrmhndr/cleankit/server";

const cleaned = cleanObject({
  name: "Felicia",
  age: null,
  email: "",
  location: undefined,
});
// => { name: "Felicia" }

๐Ÿงผ cleanList

Removes null, undefined, empty strings "", and empty arrays []. Optionally inserts a spacer between items.

import { cleanList } from "@andrmhndr/cleankit/server";

const cleaned = cleanList([null, "React", "", [], "Next.js", undefined]);
// => ["React", "Next.js"]

const spaced = cleanList(["A", "B", "C"], (i) => <hr key={i} />);
// => ["A", <hr />, "B", <hr />, "C"]

๐Ÿ“– License

MIT โ€” Use it, love it, and make something beautiful.
And remember... Keep pushin' your self up!

0.0.25

5 months ago

0.0.24

5 months ago

0.0.23

5 months ago

0.0.22

5 months ago

0.0.21

5 months ago

0.0.20

5 months ago

0.0.18

5 months ago

0.0.17

5 months ago

0.0.16

5 months ago

0.0.15

5 months ago

0.0.14

5 months ago

0.0.13

5 months ago

0.0.12

5 months ago

0.0.11

5 months ago

0.0.9

5 months ago

0.0.8

5 months ago

0.0.7

5 months ago

0.0.6

5 months ago

0.0.5

5 months ago

0.0.2

5 months ago