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 🙏

© 2026 – Pkg Stats / Ryan Hefner

the-basic-utils

v1.0.1

Published

A collective package of basic utils

Downloads

68

Readme

Basic Utilities npm Package

This npm package provides a comprehensive set of utility functions that make your development process easier by providing reusable, well-tested helper methods for common tasks.

Installation

To install this package, run:

npm install the-basic-utils

Importing Utilities

You can import specific functions or the entire module:

const { isEmpty, isJson, deepClone } = require('the-basic-utils');
// or
const utils = require('the-basic-utils');

Functions and Usage

1. isEmpty

Checks if a value is empty.

  • Input: Any type.
  • Output: true if the value is empty, otherwise false.
console.log(isEmpty('')); // true
console.log(isEmpty({})); // true
console.log(isEmpty([1, 2, 3])); // false

2. isJson

Checks if a string is a valid JSON.

  • Input: string
  • Output: true if valid JSON, otherwise false.
console.log(isJson('{"key": "value"}')); // true
console.log(isJson('Not JSON')); // false

3. deepClone

Deep clones an object or array.

  • Input: Object or Array.
  • Output: A deep copy of the input.
const obj = { a: 1, b: { c: 2 } };
const clone = deepClone(obj);
console.log(clone); // { a: 1, b: { c: 2 } }

4. randomString

Generates a random string of a specified length.

  • Input: length (default: 8).
  • Output: Random string.
console.log(randomString(10)); // Example: 'aB3dEfGHi1'

5. capitalize

Capitalizes the first letter of a string.

  • Input: string
  • Output: String with the first letter capitalized.
console.log(capitalize('hello')); // Hello

6. formatDate

Formats a date to YYYY-MM-DD.

  • Input: Date object (default: current date).
  • Output: Formatted date string.
console.log(formatDate(new Date())); // 2024-12-24

7. debounce

Debounces a function, delaying its execution.

  • Input: Function, delay in milliseconds.
  • Output: Debounced function.
const debouncedFunc = debounce(() => console.log('Run!'), 500);
debouncedFunc();

8. throttle

Throttles a function, ensuring it's called at most once every specified time.

  • Input: Function, delay in milliseconds.
  • Output: Throttled function.
const throttledFunc = throttle(() => console.log('Run!'), 500);
throttledFunc();

9. isPlainObject

Checks if a value is a plain object.

  • Input: Any value.
  • Output: true if plain object, otherwise false.
console.log(isPlainObject({})); // true
console.log(isPlainObject([])); // false

10. deepMerge

Merges multiple objects deeply.

  • Input: Target object, source objects.
  • Output: Merged object.
const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { b: { d: 3 } };
console.log(deepMerge({}, obj1, obj2)); // { a: 1, b: { c: 2, d: 3 } }

11. objectToQueryString

Converts an object to a query string.

  • Input: Object.
  • Output: Query string.
console.log(objectToQueryString({ a: 1, b: 2 })); // 'a=1&b=2'

12. compactArray

Removes falsy values from an array.

  • Input: Array.
  • Output: Filtered array.
console.log(compactArray([0, 1, false, 2, '', 3])); // [1, 2, 3]

13. toCamelCase

Converts a string to camelCase.

  • Input: string
  • Output: Camel-cased string.
console.log(toCamelCase('hello-world')); // helloWorld

14. toPascalCase

Converts a string to PascalCase.

  • Input: string
  • Output: Pascal-cased string.
console.log(toPascalCase('hello-world')); // HelloWorld

15. bytesToHumanReadable

Converts bytes to a human-readable format.

  • Input: Bytes, decimals (default: 2).
  • Output: Human-readable string.
console.log(bytesToHumanReadable(1024)); // '1 KB'

16. sleep

Pauses execution for a specified duration.

  • Input: Milliseconds.
  • Output: Promise.
await sleep(1000); // Pauses for 1 second.

17. escapeHtml

Escapes HTML special characters.

  • Input: String.
  • Output: Escaped string.
console.log(escapeHtml('<div>Test</div>')); // '&lt;div&gt;Test&lt;/div&gt;'

18. unescapeHtml

Unescapes HTML special characters.

  • Input: String.
  • Output: Unescaped string.
console.log(unescapeHtml('&lt;div&gt;Test&lt;/div&gt;')); // '<div>Test</div>'

19. dateDifferenceInDays

Calculates the difference in days between two dates.

  • Input: Two date strings or objects.
  • Output: Difference in days.
console.log(dateDifferenceInDays('2024-12-24', '2024-12-31')); // 7

20. groupBy

Groups an array of objects by a property.

  • Input: Array, key.
  • Output: Grouped object.
const data = [
  { group: 'A', value: 1 },
  { group: 'B', value: 2 },
  { group: 'A', value: 3 }
];
console.log(groupBy(data, 'group'));
// { A: [{ group: 'A', value: 1 }, { group: 'A', value: 3 }], B: [{ group: 'B', value: 2 }] }

21. clamp

Clamps a number between a minimum and maximum value.

  • Input: Value, min, max.
  • Output: Clamped value.
console.log(clamp(5, 1, 10)); // 5
console.log(clamp(-5, 1, 10)); // 1

22. isPalindrome

Checks if a value is a palindrome.

  • Input: String or number.
  • Output: true if palindrome, otherwise false.
console.log(isPalindrome('racecar')); // true
console.log(isPalindrome(12321)); // true

Contributing

Contributions are welcome! Please submit issues or pull requests via the GitHub repository.

License

This package is licensed under the MIT License.