@modernman00/shared-js-lib

v1.2.64

Published

Reusable JS utilities for numerous js problems

Readme

npm Usage Guide for @modernman00/shared-js-lib This guide explains how to install and use the @modernman00/shared-js-lib package, now available on the npm registry, in your Node.js or JavaScript project. Installation To install the package from npm, run the following command in your project directory: npm install @modernman00/shared-js-lib

This installs the latest published version from the npm registry. Ensure you have an internet connection and npm access to the @modernman00 scope (authentication may be required if the package is private).

Usage The package exports various utility functions from its modules (e.g., Http.js, Utility.js). Import and use them as follows: Example: Using fetchData from Http.js Assume Http.js exports a function to fetch data using Axios: import { fetchData } from '@modernman00/shared-js-lib';

async function getUserData() { try { const userData = await fetchData('/api/users/1', { method: 'GET' }); console.log(userData); } catch (error) { console.error('Error fetching data:', error.message); } }

getUserData();

Example: Using sanitizeInput from Utility.js Assume Utility.js exports a sanitization function: import { sanitizeInput } from '@modernman00/shared-js-lib';

const cleanInput = sanitizeInput('alert("xss")'); console.log(cleanInput); // Sanitized output

Configuration

Ensure your project uses ES Modules by adding "type": "module" to your package.json, or use a bundler like Laravel Mix/Webpack. If using Laravel Mix, configure an alias in webpack.mix.js:const mix = require('laravel-mix'); const path = require('path');

mix.js('resources/js/app.js', 'public/js') .webpackConfig({ resolve: { alias: { '@shared': path.resolve(__dirname, 'node_modules/@modernman00/shared-js-lib') } } });

Updating the Package To update to the latest version, run: npm update @modernman00/shared-js-lib

Check the latest version on the npm website (https://www.npmjs.com/package/@modernman00/shared-js-lib) or with: npm info @modernman00/shared-js-lib version

If a specific version is needed, install it directly: npm install @modernman00/[email protected]

Rebuild assets if using a bundler: npm run dev

Troubleshooting

Installation Fails: Ensure you have npm access and the package is published. Use verbose mode for details:npm install @modernman00/shared-js-lib --verbose

TypeScript Errors: Add declaration files (e.g., Http.d.ts) to the package if needed, and republish. Permission Issues: If the package is scoped and private, log in to npm:npm login