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

utility-soup

v1.0.2

Published

Practical utility functions for React projects

Downloads

2

Readme

Utility Soup

Utility Soup is a collection of practical utility functions designed to simplify common tasks in JavaScript and TypeScript development. Whether you're working on a React project, a Node.js application, or any other JavaScript-based project, Utility Soup provides a set of versatile tools to enhance your development experience.

Functions

Counter Functions

  • increment(count): Increments the counter of passed variable by 1 and returns the updated value.
  • decrement(count): Decrements the counter of passed variable by 1 and returns the updated value.

String Utilities

  • upperCaseify(text): Converts the input string text to uppercase.

Date and Time Tools

  • dateToText(): Formats the current date into a readable string (i.e. Feb 5, 2024, 10:00 PM).

Array Manipulators

  • sortArray(array): Sorts an array of integers in ascending order.

Installation

You can install Utility Soup via npm:

npm install utility-soup

Usage

Basic Example

import {
  increment,
  decrement,
  upperCaseify,
  dateToText,
  sortArray,
} from "utility-soup";

console.log(increment(3)); // 4
console.log(decrement(3)); // 2
console.log(upperCaseify("Hello, world!")); // 'HELLO, WORLD!'
console.log(dateToText()); // e.g., 'April 1, 2024, 10:00 AM'
console.log(sortArray([3, 1, 4, 1, 5, 9])); // [1, 1, 3, 4, 5, 9]

React Project Implementation

Here's an example of how to use Utility Soup in a React project:

import { useState } from "react";
import "./App.css";
import {
  increment,
  decrement,
  upperCaseify,
  dateToText,
  sortArray,
} from "utility-soup";

function App() {
  const [count, setCount] = useState(0);
  const [message, setMessage] = useState("");
  const [messageSubmitted, setMessageSubmitted] = useState(false);
  const [date, setDate] = useState("");
  const [array, setArray] = useState([]);
  const [arraySubmitted, setArraySubmitted] = useState(false);

  const handleIncrement = () => {
    setCount((prevCount) => increment(prevCount));
  };
  const handleDecrement = () => {
    setCount((prevCount) => decrement(prevCount));
  };

  const handleChangeUpperCaseify = (event) => {
    setMessage(upperCaseify(event?.target?.value));
  };
  const handleSubmitMessage = (event) => {
    event.preventDefault();
    handleFormSubmitUpperCaseify(message);
  };
  const handleFormSubmitUpperCaseify = (value) => {
    console.log("Form submitted with: ", value);
    setMessageSubmitted(true);
  };

  const handleDateSubmit = () => {
    setDate(dateToText());
  };

  const handleChangeSortArray = (event) => {
    const arrayFromInputString = event?.target?.value.split(",").map(Number);
    setArray(sortArray(arrayFromInputString));
  };
  const handleSubmitArray = (event) => {
    event.preventDefault();
    handleFormSubmitSortArray(array);
  };
  const handleFormSubmitSortArray = (value) => {
    console.log("Form submitted with: ", value);
    setArraySubmitted(true);
  };

  return (
    <>
      <div style={{ display: "flex", alignItems: "center" }}>
        <button onClick={handleIncrement} style={{ margin: "10px" }}>
          Increment
        </button>
        {count !== 0 && <div>{count}</div>}
      </div>
      <div style={{ display: "flex", alignItems: "center" }}>
        <button onClick={handleDecrement} style={{ margin: "10px" }}>
          Decrement
        </button>
        {count !== 0 && <div>{count}</div>}
      </div>
      <form
        onSubmit={handleSubmitMessage}
        style={{ display: "flex", alignItems: "center" }}
      >
        <button style={{ margin: "10px" }} type="submit">
          upperCaseify!
        </button>
        <input
          type="text"
          placeholder="Type text to upperCaseify"
          onChange={handleChangeUpperCaseify}
        />
        {message && messageSubmitted && <div>{message}</div>}
      </form>
      <div style={{ display: "flex", alignItems: "center" }}>
        <button onClick={handleDateSubmit} style={{ margin: "10px" }}>
          Show current date
        </button>
        {date && <div>{date}</div>}
      </div>
      <form
        onSubmit={handleSubmitArray}
        style={{ display: "flex", alignItems: "center" }}
      >
        <button style={{ margin: "10px" }} type="submit">
          Sort the array!
        </button>
        <input
          type="text"
          placeholder="Type numbers separated by commas"
          onChange={handleChangeSortArray}
        />
        {array.length > 0 && arraySubmitted && (
          <div style={{ display: "flex", marginLeft: "10px" }}>
            {array.map((number, index) => (
              <p key={index}>{number}, </p>
            ))}
          </div>
        )}
      </form>
    </>
  );
}

export default App;

This example showcases how to integrate Utility Soup into a React (Vite) application, demonstrating various functionalities such as incrementing/decrementing a counter, converting text to uppercase, displaying the current date, and sorting an array of numbers.