@rzl-zone/utils-js
v3.11.0
Published
A modern, lightweight set of JavaScript utility functions with TypeScript support for everyday development, crafted to enhance code readability and maintainability.
Maintainers
Readme
- 💻 Requirements
- ⚙️ Installation
- ✨ Features
- 🧬 NextJS Support
- 💎 Detailed Features
- 🔥 Usage
- ❤️ Sponsor
- 📜 Changelog
- 🤝 Contributing
- 🔒 Security
- 🙌 Credits
- 📄 License
Node.js
≥18.18.0
This package leverages modern JavaScript & TypeScript features that require Node.js version 18.18.0 if not using Next.js, and for Next.js it must follow the official minimum Node.js version requirement depending on the version you use.- 🔗 See official Next.js documentation: NextJS System Requirements.
Works with:
TypeScript Build Info:
- Target:
ES2022 - Module:
ES2022 - Module Resolution:
bundler
ℹ️ Note:
These TypeScript settings are used to build the package, consumers do not need to match these settings unless they plan to build or modify the source code.- Target:
With NPM
npm install @rzl-zone/utils-js@latestWith Yarn
yarn add @rzl-zone/utils-js@latestWith PNPM
pnpm add @rzl-zone/utils-js@latest- 🚀 Written in TypeScript — fully typed & safe
- ⚡ Small, tree-shakable & fast
- 📦 Works in Node.js & modern browsers
- ❤️ Simple API, easy to extend
- 🧬 Next.js support: helpers for dynamic routes, building URLs, reading env, extracting client IP
This package also provides utilities specially built for Next.js environments, neatly separated into their own entry points:
✅ Safe to use in both Next.js pages & API routes.
⚠️ Will throw Error if used outside a Next.js server environment.
For now, explore the examples or dive into the source — all utilities are documented via TSDoc and typed properly.
import { | } from "@rzl-zone/utils-js/assertions";
import { | } from "@rzl-zone/utils-js/conversions";
import { | } from "@rzl-zone/utils-js/events";
import { | } from "@rzl-zone/utils-js/formatters";
import { | } from "@rzl-zone/utils-js/generators";
import { | } from "@rzl-zone/utils-js/next";
import { | } from "@rzl-zone/utils-js/next/server";
import { | } from "@rzl-zone/utils-js/operations";
import { | } from "@rzl-zone/utils-js/parsers";
import { | } from "@rzl-zone/utils-js/predicates";
import { | } from "@rzl-zone/utils-js/promises";
import { | } from "@rzl-zone/utils-js/strings";
import { | } from "@rzl-zone/utils-js/tailwind";
import { | } from "@rzl-zone/utils-js/urls"; Place your cursor inside { } or after "@rzl-zone/utils-js/{{ | }}" then press Ctrl+Space to see all available functions/types with full TSDoc hints.
⚠️ Note: Starting from version
3.4.0+, the extra TypeScript types (e.g.,OmitStrict,PartialOnly, etc), have been removed from the package, to use them, you now need to install@rzl-zone/ts-types-plusseparately.
Including via CDN
<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/@rzl-zone/utils-js@latest"></script>
<!-- unpkg -->
<script src="https://unpkg.com/@rzl-zone/utils-js@latest"></script>⚠️ Note:
When using the library via CDN in the browser:
- Always include first the <script> tag before your own scripts when using the CDN version.
- Some Node.js-specific utilities may not be available, e.g.:
- Category utils of
tailwind,next,next/server.- Server-only features (like Next.js helpers) will not be available.
- The global object provided is
RzlUtilsJs.- The CDN bundle is ~350KB minified, for production, consider using bundlers or npm packages for smaller size and tree-shaking.
Make TypeScript & VSCode automatically provide autocomplete for @rzl-zone/utils-js without needing triple-slash references in every file:
1️⃣ Install @rzl-zone/utils-js.
Make sure the package is installed:
npm install @rzl-zone/utils-js@latest # or yarn add @rzl-zone/utils-js@latest # or pnpm add @rzl-zone/utils-js@latest
2️⃣ Create a types folder.
Inside your project root, make a folder called
types:project-root/ ├─ src/ ├─ types/ │ └─ index.d.ts ├─ tsconfig.json └─ jsconfig.json
3️⃣ Add the global reference file.
Create
types/index.d.tswith this content:/// <reference types="@rzl-zone/utils-js" />- This tells TypeScript to include the types from
@rzl-zone/utils-jsglobally. - You can add more references here if needed, for example:
/// <reference types="@rzl-zone/utils-js" /> // eg more references (if needed): /// <reference types="node" /> /// <reference types="react" />- This tells TypeScript to include the types from
4️⃣ Update tsconfig.json.
Make sure not to override "types" (or leave it empty) so TypeScript automatically picks up your types folder:
// tsconfig.json { "compilerOptions": { "strict": true, "typeRoots": [ "./types", "./node_modules/@types" ], // other your config... }, "include": [ "src", "types" ], // other your config... }typeRootstells TS where to look for global type definitions.- The
typesfolder comes first, so your references override or add to the default@typespackages
5️⃣ Update jsconfig.json (for JavaScript projects).
If you also work with JS, do the same:
// jsconfig.json { "compilerOptions": { "checkJs": true, // Optional, enables type checking "typeRoots": [ "./types", "./node_modules/@types" ], // other your config... }, "include": [ "src", "types" ], // other your config... }ℹ️ Tip: For JS projects, consider adding "checkJs": true for better IntelliSense.
Now, all types from @rzl-zone/utils-js are globally available, and you don’t need "types": ["@rzl-zone/utils-js"] in tsconfig.json.
Easy to use, just import on your code base.
Example Function Import:
import { isServer } from "@rzl-zone/utils-js/predicates";
console.log(isServer());
// ➔ `true` if running on server-side, `false` if in browser.Help support development:
👉 Become a sponsor.
See CHANGELOG.
See CONTRIBUTING.
Please report issues to [email protected].
The MIT License (MIT).
Please see License File for more information.
Star this repo ⭐ and share it with other JavaScript developers!
