Skip to content
yoyoazs edited this page Jan 27, 2024 · 12 revisions

Welcome to the documentation for YoyoLib, a lightweight library designed for logging and multilingual support in your Node.js applications.

Installation

To start using YoyoLib in your project, follow these installation steps:

npm install yoyolib

Key Features

YoyoLib offers several useful features to simplify the development of your application:

  • Logging: Manage your application logs with the Logger. Customize the log format and save them to files if needed.

  • Multi-language Support: Use the LangManager to support multiple languages in your application. Easily manage language files and access messages in the active language.

Usage Examples

Logger

// Import YoyoLib
const { createLogger } = require('yoyolib');

// Create a logger instance
const logger = createLogger();

// Print a log on the console
logger.log("test log");

// Print an info on the console
logger.info("test info");

// Print a warn on the console
logger.warn("test warn");

// Print an error on the console
logger.error("test error");

// Print a log with additional options
logger.log({ content: "test log", name: "TEST" });

// Print a log with options to control console and log writing
logger.log({ content: "test log", console: false, log: false });

Multi-language Support

JSON Files Create language files (e.g., en_EN.json and fr_FR.json) with content like:

// "en_EN.json"
{
    "message": {
        "test": "This is a test.",
        "testVariables" : "Hello {user}!"
    }
}

// "fr_FR.json"
{
    "message": {
        "test": "Ceci est un test.",
        "testVariables" : "Bonjour {user} !"
    }
}

Place these files in a folder named lang.

// Import YoyoLib
const { createLangManager } = require('yoyolib');

// Create a multi-language support handler
const langManager = createLangManager();
let message;

// Add languages
langManager.add('en', 'en_EN');
langManager.add('fr', 'fr_FR');

// Set the active language
langManager.set('en');

// Use the multi-language system
message = langManager.use('message.test');
console.log(message); // Output: This is a test.
message = langManager.use('message.testVariables', { user: "yoyoazs" });
console.log(message); // Output: Hello yoyoazs !

// Set the active language
langManager.set('fr');

// Use the multi-language system
message = langManager.use('message.test');
console.log(message); // Output: Ceci est un test.
message = langManager.use('message.testVariables', { user: "yoyoazs" });
console.log(message); // Output: Bonjour yoyoazs !

API

License

This project is licensed under the YoyoLib Custom License - see the LICENSE file for details.

Clone this wiki locally