@wave-dev/plugins v1.1.1
Packcages
@wave-dev/plugins
(source) Useful plugins for development.
Instalation
Node.js 16.9.0 or newer is required.
npm install @wave-dev/plugins
List of available plugins
KVString allows you to store data by (key:value) pairs in a single string and format it interpreting it as different data types as well. This was powered by Discord Bot Development. In order to avoid databases and collection for storing short data, i use strings to do it in the Message Component Custom ID So whenever i need to store the target of an interaction or command, page or any other data, this is a strong way to do it because it will be exiting forever until the message/component get deleted.
// Creating it from the constructor: import { KVString } from "@wave-dev/plugins"; const myKVString = new KVString({ // Setting the values with their keys values: [ { key: "name", value: "Sam" }, { key: "age", value: "20" }, ], // Specifying the max length for the result string maxLength: 100, });
// Creating it by its methods import { KVString } from "@wave-dev/plugins"; const myKVString = new KVString(); myKVString.setMaxLength(100); myKVString.addValue("name", "Sam"); if (true) myKVString.addValue("age", "20");
// Getting data const name = myKVString.getString("name", true); // "Sam" const age = myKVString.getNumber("age", true); // 20 const surname = myKVString.getString("surname"); // undefined const petName = myKVString.getString("petName", true); // Error (Unnnable to get the value named petName) const { name, age } = myKVString.toObject("name", "age"); // All properties are of type string console.log(name); // "Sam" console.log(parseInt(age)); // 20
StringBuilder allows you to dynamicaly create an string.
import { StringBuilder } from "@wave-dev/plugins"; const content = new StringBuilder("Hummmm..."); if (1 + 1 === 2) content.update("it's true!", ", "); console.log(content.toString()); // "Hummmm..., it's true!"
- stringEquals allows you to get the equality between two strings with additional options.
import { stringEquals } from "@wave-dev/plugins"; stringEquals("Apple", "Apple"); // true stringEquals("My name is Jhon", "JHON", { allowCaseSensitive: true, allowIncludes: "booth", }); // true
JSONStorage allows you to store JSON data in JSON files like a local Database.
// fruits.ts import { JSONStorage, BaseDocumentData } from "@wave-dev/plugins"; import { join } from "path"; // Create an interface for the document data interface FruitData extends BaseDocumentData { name: string; amount: number; } // Create the dir and JSON file const Fruits = new JSONStorage<FruitData>( process.cwd(), "storage", "fruits.json" ); // Create the first document Fruits.create({ id: "12345678912345678", name: "Apple", amount: 1 }); // Get the document by its id const fruit = Fruits.getById("12345678912345678", true); // Modify and save the document fruit.name = "Lemon"; fruit.amount++; fruit.save(); console.log(Fruits.getById("12345678912345678", true)); // { id: "12345678912345678", name: "Lemon", amount: 3 }
PageBuilder allows you to create a pagination.
import { PageBuilder } from "@wave-dev/plugins"; const fruits = [ { name: "Apple", amount: 1 }, { name: "Lemon", amount: 3 }, { name: "Melon", amount: 6 }, ]; const pagination = new PageBuilder<{ name: string; amount: number }, .addValues(...fruits) .setLimit(1) .setDisplayFormat((value) => `${value.name} x${value.amount}`) .setSearchFormat((value) => `${value.name} x${value.amount} 👈`) .setEmptyMessage("There aren't any fruits in this page") .setUnfoundMessage("Unnable to find that fruit :c");
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago