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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mar-util-helper

v1.0.2

Published

A lightweight library of utility functions for everyday tasks.

Downloads

3

Readme

mar-util-helper

A lightweight library of essential utility functions for everyday tasks. This library is designed to be simple, efficient, and easy to use, providing commonly needed functionalities such as deep cloning objects, debouncing and throttling functions, determining value types, and formatting currencies.

Installation

To install the Mar util helper, use npm:

npm install mar-util-helper

Features

Easy usage 
Lightweight
Provides commonly needed utility functions

Functions

deepClone(obj)

Performs a deep clone of an object or array, creating a new instance with the same properties and values.

Parameters:

obj (Object|Array) - The object or array to clone.

Returns:

(Object|Array) - A deep clone of the input object or array.

debounce(func, wait)

Creates a debounced version of a function that delays its execution until after the specified wait time has elapsed since the last time it was invoked.

Parameters:

    func (Function) - The function to debounce.
    wait (Number) - The number of milliseconds to delay.

Returns:

(Function) - A debounced version of the original function.

throttle(func, limit)

Creates a throttled version of a function that can only be called once per specified time interval.

Parameters:

    func (Function) - The function to throttle.
    limit (Number) - The number of milliseconds to limit function calls.

Returns:

(Function) - A throttled version of the original function.

getType(value)

Determines the type of a given value, returning a string that represents its type.

Parameters:

    value (Any) - The value to check.

Returns:

(String) - The type of the value ('array', 'object', 'null', etc.).

formatCurrency(amount, currency = 'USD', locale = 'en-US')

Formats a number as a currency string according to a specified currency code and locale.

Parameters:

    amount (Number) - The amount to format.
    currency (String) - The currency code (default: 'USD').
    locale (String) - The locale for formatting (default: 'en-US').
    

Returns:

 (String) - The formatted currency string.

QuickStart

Example Usage:

javascript

// Import the utility functions from the mar-util-helper
const {
    deepClone,
    debounce,
    throttle,
    getType,
    formatCurrency
} = require('mar-util-helper'); 

// 1. deepClone Example
const originalObj = { a: 1, b: { c: 2 } };
const clonedObj = deepClone(originalObj);
console.log('Original Object:', originalObj); // Output: { a: 1, b: { c: 2 } }
console.log('Cloned Object:', clonedObj);    // Output: { a: 1, b: { c: 2 } }
console.log('Are they equal?', originalObj === clonedObj); // Output: false

// 2. debounce Example
const logMessage = () => console.log('Debounced!');
const debouncedLog = debounce(logMessage, 1000);

// Simulate rapid calls to debouncedLog
debouncedLog(); // Will log 'Debounced!' only once if called within 1000ms intervals
debouncedLog();
debouncedLog();

// 3. throttle Example
const throttleMessage = () => console.log('Throttled!');
const throttledLog = throttle(throttleMessage, 2000);

// Simulate rapid calls to throttledLog

// Will log 'Throttled!' immediately
throttledLog(); 

// Will ignore this call if within 2000ms from the last call
throttledLog(); 

// 4. getType Example
console.log(getType([]));      // Output: 'array'
console.log(getType({}));      // Output: 'object'
console.log(getType(null));    // Output: 'null'
console.log(getType(42));      // Output: 'number'
console.log(getType('hello')); // Output: 'string'

// 5. formatCurrency Example
console.log(formatCurrency(1234.56)); // Output: '$1,234.56' (in 'en-US' locale)
console.log(formatCurrency(1234.56, 'EUR', 'de-DE')); // Output: '1.234,56 €' (in 'de-DE' locale)

People

The original author of the package is Sriram

Contributing

We welcome contributions! Feel free to submit issues or pull requests.

License

This project is licensed under the MIT License.