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

js-utilities-libs

v1.0.3

Published

js-utilities-libs is a JavaScript library that provides a collection of utility functions for common programming tasks. It includes functions for string manipulation, array operations, date and time handling, mathematical calculations, object manipulation

Downloads

7

Readme

js-utilities-libs

Description

js-utilities-libs is a JavaScript library that provides a collection of utility functions for common programming tasks. It includes functions for string manipulation, array operations, date and time handling, mathematical calculations, object manipulation, data validation, file and path operations, network utilities, data formatting, and error handling. Each function is designed to be simple, efficient, and versatile, making it easy to use in a wide range of projects.

Features

  • String Manipulation
  • Array Operations
  • Date and Time Handling
  • Mathematical Calculations
  • Object Manipulation
  • Data Validation
  • File and Path Operations
  • Network Utilities
  • Data Formatting
  • Error Handling

Installation

npm install js-utilities-libs

Usage

String Manipulation

import { trim, toCamelCase, toSnakeCase, contains } from "js-utilities-libs";

console.log(trim("  example  ")); // Output: 'example'
console.log(toCamelCase("hello_world")); // Output: 'helloWorld'
console.log(toSnakeCase("helloWorld")); // Output: 'hello_world'
console.log(contains("example", "amp")); // Output: false

Array Operations

import {
  sortArray,
  filterEvenNumbers,
  mapToUppercase,
  sumArray,
} from "js-utilities-libs";

console.log(sortArray([3, 1, 5, 2, 4])); // Output: [1, 2, 3, 4, 5]
console.log(filterEvenNumbers([1, 2, 3, 4, 5])); // Output: [2, 4]
console.log(mapToUppercase(["hello", "world"])); // Output: ['HELLO', 'WORLD']
console.log(sumArray([1, 2, 3, 4, 5])); // Output: 15

Date and Time

import { formatDate, dateDiffInDays } from "js-utilities-libs";

const today = new Date();
const tomorrow = new Date(today);
tomorrow.setDate(today.getDate() + 1);

console.log(formatDate(today)); // Output: 'YYYY-MM-DD'
console.log(dateDiffInDays(today, tomorrow)); // Output: 1

Math Functions

import { getRandomNumber, calculateAverage } from "js-utilities-libs";

console.log(getRandomNumber(1, 10)); // Output: Random number between 1 and 10
console.log(calculateAverage([1, 2, 3, 4, 5])); // Output: 3

Object Manipulation

import { mergeObjects, cloneObject, hasProperty } from "js-utilities-libs";

const obj1 = { a: 1 };
const obj2 = { b: 2 };

console.log(mergeObjects(obj1, obj2)); // Output: { a: 1, b: 2 }
console.log(cloneObject(obj1)); // Output: { a: 1 }
console.log(hasProperty(obj1, "a")); // Output: true

Validation

import { validateEmail, validateURL } from "js-utilities-libs";

console.log(validateEmail("[email protected]")); // Output: true
console.log(validateURL("https://example.com")); // Output: true

File and Path Operations

import { readFile, writeFile } from "js-utilities-libs";

readFile("example.txt")
  .then((data) => {
    console.log(data); // Output: Contents of the file
  })
  .catch((err) => {
    console.error(err);
  });

writeFile("example.txt", "Hello, world!")
  .then(() => {
    console.log("File written successfully!");
  })
  .catch((err) => {
    console.error(err);
  });

Network Utilities

import { fetchData } from "js-utilities-libs";

fetchData("https://jsonplaceholder.typicode.com/posts/1")
  .then((data) => {
    console.log(data); // Output: JSON data from the API
  })
  .catch((err) => {
    console.error(err);
  });

Data Formatting

import { objectToJson, jsonToObject } from "js-utilities-libs";

const obj = { key: "value" };
const jsonString = objectToJson(obj);

console.log(jsonString); // Output: '{"key":"value"}'
console.log(jsonToObject(jsonString)); // Output: { key: 'value' }

Error Handling

import { logError, formatErrorMessage } from "js-utilities-libs";

try {
  // Code that may throw an error
  throw new Error("An error occurred");
} catch (error) {
  logError(error); // Output: [timestamp] Error: An error occurred
  console.log(formatErrorMessage(error)); // Output: An error occurred: An error occurred
}

License

js-utilities-libs is released under the ISC License.

Version History

1.0.3

Author

Name : Deepak Sharma Email : [email protected]