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

@suouzuki/nodeutils

v1.3.2

Published

This library was created specifically for personal use, but you can also use it! It only contains things that I, suouzuki, need in my projects.

Downloads

104

Readme

NodeUtils

This library was created specifically for personal use, but you can also use it! It only contains things that I, suouzuki, need in my projects.

Installation

To install it in your project is quite simple! Just use the code below

npm install @suouzuki/nodeutils

This is...

It checks if the value is indeed that, in the example above we used 'isString', which checks if it's a string, but there are various others such as:

isJSON(value) -> Check if the value is JSON or valid JSON.

isJSON({ name: "John", age: 30, city: "New York" }); // true
isJSON('{"name":"John","age":30,"city":"New York"}'); // true

isJSON('{"name":"John","age":30,"city":"New York"'); // false (invalid JSON)
isJSON([]); // false

isEmpty(value) -> Check if the value is empty. (String, Array, Object, Map)

isEmpty('  '); // true (empty string)
isEmpty([]); // true (empty array)
isEmpty(new Map()); // true (empty map)
isEmpty({}); // true (empty object)

isEmpty('Hello World!'); // false (non-empty string)
isEmpty([1, 2, 3]); // false (non-empty array)
isEmpty({ key: 'value' }); // false (non-empty object)

isPrimitive(value) -> Check if the value is a primitive (null, number, string, boolean, undefined, or symbol).

isPrimitive(42); // true
isPrimitive("Hello World!"); // true
isPrimitive({}); // false

isBoolean(value)* -> Check if the value is a Boolean.

isBoolean(false); // true
isBoolean("false"); // false

isString(value) -> Check if the value is a String.

isString("Hello World!"); // true
isString(42); // false

... -> And there are numerous functions like these that I can't mention all of.

String, Number, and Array

Useful functions for manipulating: String, Number, and Array. There are many more functions, but I'll only include two of each (my favorites for each).

- String

limit(string, limit, final) -> Limits the length of a string and adds a final character.

const limitedString = limit("Olá, eu me chamo Suouzuki e programo Node.js!", 20, "...");
// Returns: "Olá, eu me chamo Suo..."

verify(string, ...search) -> Verifies the presence of specific substrings in a string.

const searchResults = verify("Olá, quem é você?", "Olá", "você", "eu");
// Returns: [true, true, false]

...

- Number

toRoman(number) -> Convert a number to its Roman numeral representation.

toRoman(42) // "XLII"
toRoman(1999) // "MCMXCIX"

abbrev(number) -> Convert a large number to an abbreviated format (e.g., 1000 to 1K, 1000000 to 1M).

abbrev(1000) // "1K"
abbrev(1000000) // "1M"

...

- Array

get(array, search) -> Get an item from an array based on a search text using Fuse.js.

const arr = ["Nino.", "José.", "Suouzuki."];
const value = get(arr, "josé"); // [{ name: "José.", ID: 1, score: 0.02 }]

random(array, path) -> Returns a random element from an array, based on a probability value.

const arr = [
  { value: 'Suouzuki.', probability: 0.2 },
  { value: 'José.', probability: 0.3 },
  { value: 'Nino.', probability: 0.5 },
];

const randomElement = random(arr, 'probability'); // { value: 'Nino.', probability: 0.5 } or other.

...

Custom Error

It creates a custom error, allowing you to choose the name and description of the error.

Error.custom("myError", "Oops! An unexpected error occurred.");
// myError: Oops! An unexpected error occurred.

Custom Console

To create a custom console, it's very easy. Using the 'format' method transforms the text into the desired format, making it colorful and personalized (please note that it only accepts strings, so make sure to convert your text to a string before formatting). Additionally, we also use the 'addText' function, which allows you to add a new template for formatting.

logger.addText("success", "{type:color}{type}</>({time}): {text} {path}");
console.success = function success(text) {
  console.log(logger.format(text, { time: { snow: true, format: "HH-mm-ss" }}));
};
console.fail = function fail(text) {
  console.log(logger.format(text, { time: { snow: true, format: "HH-mm-ss" }, path: true }));
};

Collection

Creates a collector similar to discord.js but changing certain things.

const myCollection = new collection();
myCollection.set("value1", { test: true });
myCollection.set("value2", "hello");

Color

Adds color to texts using the 'colors' library. To add a new color, you can use '<color=>' followed by the desired color name. For example, '<color=red>' will set the text color to red. Don't forget to include '</>' to indicate where you want the color to end. For instance, if you want the word 'hello' to be yellow in 'Hello World!', you can do '<color=yellow>Hello</> World!'.

We also have styles available. Instead of '<color=>', you can use '<style=>' followed by the desired style type.

For backgrounds, we use '<background=>' followed by the desired color after the '=' sign.

Oh, and if you're wondering how to make the colors bright, just add a '+' sign after the color name. For example, '<color=red+>VERY RED</>'.

Do you want to know which styles and colors are available? Check out the 'colors' library. If you want more styles, here are some that we have created ourselves:

  • Undefined (Working....)
console.log(color("<color=red>Hello</>, are you <style=random>okay</>?"));