@bhhaskin/next-utils
v0.1.2
Published
Utility functions for Next.js projects
Readme
@bhhaskin/next-utils
A small TypeScript utilities library for Next.js projects, bundled with Rollup.
Currently it provides one handy extension on the JavaScript Array prototype:
Array.prototype.css()
Joins array elements into a space-separated string of CSS classes, trimmed, and returnsnullif the result is empty.
Table of Contents
Installation
Pin to the v0.1.x release line:
Using Yarn (v4+ with Corepack):
yarn add @bhhaskin/next-utils@~0.1.0Or with npm:
npm install @bhhaskin/next-utils@~0.1.0Usage
Since this package augments the global Array interface, you only need to import it once (for example, in your _app.tsx or main entry file):
// _app.tsx or src/index.ts
import '@bhhaskin/next-utils';After that, every array has the .css() method:
const classes = ['btn', 'btn-primary', '', 'active'];
console.log(classes.css()); // → "btn btn-primary active"
const empty: string[] = ['', ' '];
console.log(empty.css()); // → nullArray.prototype.css
css(this: Array<any>): string | null- Behavior
- Converts every element to a string
- Joins them with a single space
- Trims leading/trailing whitespace
- Returns
nullif the trimmed result is an empty string
Building
This project uses Rollup to bundle for both CommonJS and ESM.
Dev build (watches for changes):
yarn build:watchOne-off build:
yarn build
Your bundled files will be output to dist/ (as configured in rollup.config.js).
Contributing
- Fork the repo
- Create a feature branch:
git checkout -b feat/my-new-util - Implement your utility in
src/ - Add tests (if applicable)
- Build locally:
yarn build - Open a Pull Request—describe your changes and any migration steps
License
Distributed under the MIT License. See LICENSE.md for details.
