suouzuki
v1.0.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 (especially projects related to Discord).
Downloads
8
Maintainers
Readme
Suouzuki.
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 (especially projects related to Discord).
Installation
To install it in your project is quite simple! Just use the code below
npm install suouzuki
> Utility
This topic has numerous functions, but I will only cover the main ones.
Oh, and to have the functions below, use the example code provided below.
const { util } = require("suouzuki");
util.isString("Hello World!"); // true
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
...
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.
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.
console.log(color("<color=red>Hello</>, are you <style=random>okay?</>"));
> Discord
Utilities and functions for the discord.js library.
Oh, and to have the functions below, use the example code provided below.
const { discord } = require("suouzuki");
SlashCommandCreate
A class that dynamically creates slash commands (/).
const CommandSlash = new slashCommandCreate("mycommand", "my first slash command");
CommandSlash.addOption("string", { length: { max: 10, min: 5 }, required: true });