2.4.2 • Published 3 months ago

yoyolib v2.4.2

Weekly downloads
-
License
YoyoLib Custom Li...
Repository
github
Last release
3 months ago

Stargazers Issues

YoyoLib

YoyoLib is a lightweight library designed for handling logging and multi-language support in your Node.js applications.

Features

  • Logging: Create log messages with customizable formatting and the ability to write logs to files using the Logger class.

  • Multi-language Support: Easily manage multi-language support for your application with the LangManager class.

Installation

npm install yoyolib

Example usage

Logger

// Import the 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 });

LangManager

json file

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

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

Create a folder named 'lang' and place your language files ('fr_FR.json' and 'en_EN.json') inside.

js

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

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

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

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

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

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

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

API

createLogger(logday = false, date = false, args = undefined): Logger

Creates a Logger instance with optional configurations.

  • logday (boolean): If true, creates a log file for the day.
  • date (boolean): If true, logs both date and hours; otherwise, only logs hours.
  • args (object): Additional configuration options for the Logger.

Returns a Logger instance.

createLangManager(): LangManager

Creates a new instance of a multi-language support handler.

Returns a LangManager instance.

License

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

For more information, please refer to our wiki

2.4.1

3 months ago

2.4.2

3 months ago

2.3.0

5 months ago

2.3.1

5 months ago

2.2.0

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago