### End-to-End Keyv with Redis Example Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/keyv/README.md Provides a complete example of using Keyv with the Redis adapter, demonstrating set, get, delete, and clear operations, including setting a time-to-live for a key. ```javascript import Keyv from 'keyv'; import KeyvRedis from '@keyv/redis'; const keyvRedis = new KeyvRedis('redis://user:pass@localhost:6379'); const keyv = new Keyv({ store: keyvRedis }); await keyv.set('foo', 'expires in 1 second', 1000); // true await keyv.set('foo', 'never expires'); // true await keyv.get('foo'); // 'never expires' await keyv.delete('foo'); // true await keyv.clear(); // undefined ``` -------------------------------- ### Clone and Setup iconv-lite Repository Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/iconv-lite/README.md Initial setup commands to clone the iconv-lite repository from GitHub and install dependencies. Prepares the development environment for testing and running performance benchmarks. ```bash git clone git@github.com:ashtuchkin/iconv-lite.git cd iconv-lite npm install npm test ``` -------------------------------- ### Install get-proto using npm Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/get-proto/README.md This command installs the 'get-proto' package as a dependency for your project. It is a prerequisite for using the library's functionality. ```sh npm install --save get-proto ``` -------------------------------- ### GET Request Example Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/axios/README.md Shows how to perform a GET request to fetch data, including handling success and errors. ```APIDOC ## GET Request Example ### Using Promises: ```js axios.get('/user?ID=12345') .then(function (response) { // handle success console.log(response); }) .catch(function (error) { // handle error console.log(error); }) .finally(function () { // always executed }); // With params object: axios.get('/user', { params: { ID: 12345 } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }) .finally(function () { // always executed }); ``` ### Using async/await: ```js async function getUser() { try { const response = await axios.get('/user?ID=12345'); console.log(response); } catch (error) { console.error(error); } } ``` ``` -------------------------------- ### Package Installation Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/axios/README.md Instructions for installing Axios using various package managers. ```APIDOC ## Package Installation ### Using npm: ```bash $ npm install axios ``` ### Using bower: ```bash $ bower install axios ``` ### Using yarn: ```bash $ yarn add axios ``` ### Using pnpm: ```bash $ pnpm add axios ``` ### Using bun: ```bash $ bun add axios ``` ``` -------------------------------- ### Install fflate Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/fflate/README.md Instructions for installing the fflate library using different package managers like npm, yarn, or pnpm. ```sh npm i fflate # or yarn add fflate, or pnpm add fflate ``` -------------------------------- ### Install pino-abstract-transport Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/pino-abstract-transport/README.md Installs the pino-abstract-transport package using npm. This is the first step to using the library in your project. ```sh npm i pino-abstract-transport ``` -------------------------------- ### Install call-bind-apply-helpers via npm Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/call-bind-apply-helpers/README.md Install the call-bind-apply-helpers package from npm registry. This is a prerequisite for using the helper functions in your project. ```shell npm install --save call-bind-apply-helpers ``` -------------------------------- ### Install Tmp Package Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/libsignal/node_modules/protobufjs/cli/node_modules/tmp/README.md Installs the 'tmp' package using npm. This is the initial step to use the library in a Node.js project. ```bash npm install tmp ``` -------------------------------- ### Local Command Line Usage and npm Scripts for xml-js Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/xml-js/README.md Explains how to use the xml-js library as a locally accessible command-line tool within a project, particularly for integration into npm scripts for task automation. It includes installation steps and an example of how to define a 'convert' script in package.json. ```bash npm install --save xml-js // no need to install this library globally ``` ```json ... "dependencies": { "xml-js": "latest" }, "scripts": { "convert": "xml-js test.json --spaces 4" } ... ``` ```bash npm run convert // task 'scripts.convert' will be executed ``` -------------------------------- ### Install protobuf.js for Node.js Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/protobufjs/README.md Installs the protobuf.js library using npm. This command adds the library as a dependency to your Node.js project. ```sh npm install protobufjs --save ``` -------------------------------- ### Global Command Line Usage for xml-js Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/xml-js/README.md Demonstrates how to install and use the xml-js library as a globally accessible command-line tool for converting between XML and JSON files. It shows examples for both XML to JSON and JSON to XML conversions, including outputting to the console or to a file. ```bash npm install -g xml-js // install this library globally xml-js test.json --spaces 4 // xml result will be printed on screen xml-js test.json --spaces 4 --out test.xml // xml result will be saved to test.xml xml-js test.xml --spaces 4 // json result will be printed on screen xml-js test.xml --spaces 4 --out test.json // json result will be saved to test.json ``` -------------------------------- ### Install qified Package Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/qified/README.md Install the qified package using pnpm. This is the first step to using the library in your Node.js project. ```bash pnpm add qified ``` -------------------------------- ### Install Axios with Package Managers Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/axios/README.md Installs the Axios library using different package managers. Ensure the chosen package manager is installed on your system. ```bash $ npm install axios ``` ```bash $ bower install axios ``` ```bash $ yarn add axios ``` ```bash $ pnpm add axios ``` ```bash $ bun add axios ``` -------------------------------- ### Install semver Package Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/semver/README.md Installs the semver package using npm. This is the initial step to use the library in your Node.js project. ```bash npm install semver ``` -------------------------------- ### Install protobufjs-cli for Node.js Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/protobufjs/README.md Installs the protobufjs-cli package as a development dependency using npm. This command is used for installing the command-line utility for generating static code and reflection bundles. ```sh npm install protobufjs-cli --save-dev ``` -------------------------------- ### Install Pino via NPM Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/baileys/node_modules/pino/README.md Command-line instructions to install Pino using the NPM package manager. Provides the standard installation command for adding Pino as a dependency to a Node.js project. ```bash npm install pino ``` -------------------------------- ### Install node-webpmux via npm Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/node-webpmux/README.md Install the node-webpmux package using npm package manager. This is the required first step before using the library in your project. ```bash npm install node-webpmux ``` -------------------------------- ### Install @keyv/bigmap Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/@keyv/bigmap/README.md Installs the @keyv/bigmap package and its peer dependency keyv using npm. ```bash npm install --save keyv @keyv/bigmap ``` -------------------------------- ### Install tslib using yarn Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/tslib/README.md Provides yarn installation commands for tslib, mirroring the versioning recommendations available for npm installations. This ensures consistent dependency management across package managers. ```bash # TypeScript 3.9.2 or later yarn add tslib # TypeScript 3.8.4 or earlier yarn add tslib@^1 # TypeScript 2.3.2 or earlier yarn add tslib@1.6.1 ``` -------------------------------- ### Install Sharp Node.js Module Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/sharp/README.md Installs the 'sharp' module using npm. This is the first step before using the sharp library in a Node.js project. ```sh npm install sharp ``` -------------------------------- ### Install Pino via Yarn Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/baileys/node_modules/pino/README.md Command-line instructions to install Pino using the Yarn package manager as an alternative to NPM for dependency management. ```bash yarn add pino ``` -------------------------------- ### Install media-typer Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/media-typer/README.md Installs the media-typer module using npm. This is a prerequisite for using the module in a Node.js project. ```sh npm install media-typer ``` -------------------------------- ### Install xml-js globally using npm Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/xml-js/README.md This command installs the xml-js library globally, allowing it to be used as a command-line tool. This is useful for running conversions directly from the terminal. ```bash npm install --global xml-js ``` -------------------------------- ### Install uint8array-extras via npm Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/uint8array-extras/readme.md Installs the uint8array-extras package using npm. This is the first step to using the package's utilities in your project. ```sh npm install uint8array-extras ``` -------------------------------- ### Initialize Keyv with Redis Adapter Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/keyv/README.md Demonstrates how to initialize a Keyv instance using the KeyvRedis adapter, connecting to a Redis server with provided credentials and host. ```javascript import KeyvRedis from '@keyv/redis'; const keyv = new KeyvRedis('redis://user:pass@localhost:6379'); ``` -------------------------------- ### Install @tokenizer/inflate using npm Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/@tokenizer/inflate/README.md Installs the @tokenizer/inflate package and its dependencies using npm. This is the first step to using the library in your Node.js project. ```bash npm install @tokenizer/inflate ``` -------------------------------- ### Testing Procedures for xml-js Project Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/xml-js/README.md Provides instructions on how to set up and run tests for the xml-js project. It details the steps required, including cloning the repository, installing dependencies, and executing the test suite using npm commands. ```bash cd xml-js npm install npm test ``` ```bash npm start ``` -------------------------------- ### Install token-types and strtok3 Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/token-types/README.md Installs the 'token-types' library and 'strtok3' for efficient file tokenization. This is a common setup for projects utilizing these libraries. ```sh npm install --save token-types npm install --save strtok3 ``` -------------------------------- ### Initialize Keyv with SQLite Adapter and Options Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/keyv/README.md Shows how to initialize Keyv with the KeyvSqlite adapter and configure options like 'ttl' and 'namespace' for the Keyv instance. ```javascript import KeyvSqlite from '@keyv/sqlite'; const keyvSqlite = new KeyvSqlite('sqlite://path/to/database.sqlite'); const keyv = new Keyv({ store: keyvSqlite, ttl: 5000, namespace: 'cache' }); ``` -------------------------------- ### Axios GET Request for Stream in Node.js Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/axios/README.md Example of making a GET request for a remote image in Node.js, specifying `responseType` as 'stream'. Requires the 'fs' module for file system operations. ```javascript // GET request for remote image in node.js axios({ method: 'get', url: 'https://bit.ly/2mTM3nY', responseType: 'stream' }) .then(function (response) { response.data.pipe(fs.createWriteStream('ada_lovelace.jpg')) }); ``` -------------------------------- ### Install Keyv and Storage Adapters Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/keyv/README.md Install the core Keyv package and optional storage adapters for different backends like Redis, MongoDB, SQLite, etc. These adapters enable Keyv to persist data beyond in-memory storage. ```bash npm install --save keyv npm install --save @keyv/redis npm install --save @keyv/valkey npm install --save @keyv/mongo npm install --save @keyv/sqlite npm install --save @keyv/postgres npm install --save @keyv/mysql npm install --save @keyv/etcd npm install --save @keyv/memcache npm install --save @keyv/dynamo ``` -------------------------------- ### Make GET Request with Axios (Promises) Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/axios/README.md Example of making a GET request using Axios with Promises. Handles success, error, and finally blocks. Also shows how to pass parameters. ```javascript axios.get('/user?ID=12345') .then(function (response) { // handle success console.log(response); }) .catch(function (error) { // handle error console.log(error); }) .finally(function () { // always executed }); // Optionally the request above could also be done asaxios.get('/user', { params: { ID: 12345 } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }) .finally(function () { // always executed }); ``` -------------------------------- ### Make GET Request with Axios (Async/Await) Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/axios/README.md Example of making a GET request using Axios with async/await syntax. Requires the 'async' keyword in the outer function. Note that async/await is part of ECMAScript 2017. ```javascript async function getUser() { try { const response = await axios.get('/user?ID=12345'); console.log(response); } catch (error) { console.error(error); } } ``` -------------------------------- ### Testing a Custom Compression Adapter with Keyv Test Suite Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/keyv/README.md Illustrates how to test a custom compression adapter using Keyv's provided test suite. This requires importing the test suite and an instance of the compression adapter. ```javascript import { keyvCompresstionTests } from '@keyv/test-suite'; import KeyvGzip from '@keyv/compress-gzip'; keyvCompresstionTests(test, new KeyvGzip()); ``` -------------------------------- ### Navigate to Baileys Directory Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/baileys/README.md Changes the current directory in the terminal to the root of the Baileys project. This is typically the first step before running installation or example scripts. ```bash cd path/to/Baileys ``` -------------------------------- ### Pretty Print Pino Logs with pino-pretty (JavaScript) Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/baileys/node_modules/pino/docs/pretty.md Configures Pino to use 'pino-pretty' for development logs. Requires 'pino-pretty' to be installed as a dependency. This setup outputs human-readable log messages instead of NDJSON. ```javascript const pino = require('pino') const logger = pino({ transport: { target: 'pino-pretty' }, }) logger.info('hi') ``` ```javascript const pino = require('pino') const logger = pino({ transport: { target: 'pino-pretty', options: { colorize: true } } }) logger.info('hi') ``` -------------------------------- ### Get and Cache JS Intrinsics with get-intrinsic Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/get-intrinsic/README.md Demonstrates how to use the `get-intrinsic` module to retrieve and cache JavaScript's built-in global objects (intrinsics). It shows examples of accessing static methods like `Math.pow` and instance methods like `Array.prototype.push`, including scenarios where these methods are deleted and then re-accessed using the cached intrinsic. It also illustrates handling missing intrinsics. ```javascript var GetIntrinsic = require('get-intrinsic'); var assert = require('assert'); // static methods assert.equal(GetIntrinsic('%Math.pow%'), Math.pow); assert.equal(Math.pow(2, 3), 8); assert.equal(GetIntrinsic('%Math.pow%')(2, 3), 8); delete Math.pow; assert.equal(GetIntrinsic('%Math.pow%')(2, 3), 8); // instance methods var arr = [1]; assert.equal(GetIntrinsic('%Array.prototype.push%'), Array.prototype.push); assert.deepEqual(arr, [1]); arr.push(2); assert.deepEqual(arr, [1, 2]); GetIntrinsic('%Array.prototype.push%').call(arr, 3); assert.deepEqual(arr, [1, 2, 3]); delete Array.prototype.push; GetIntrinsic('%Array.prototype.push%').call(arr, 4); assert.deepEqual(arr, [1, 2, 3, 4]); // missing features delete JSON.parse; // to simulate a real intrinsic that is missing in the environment assert.throws(() => GetIntrinsic('%JSON.parse%')); assert.equal(undefined, GetIntrinsic('%JSON.parse%', true)); ``` -------------------------------- ### Full Baileys Connection and Event Handling Example Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/baileys/README.md This comprehensive example shows a complete setup for connecting to WhatsApp using Baileys, including session management, connection status updates, and message handling. It implements reconnection logic for `connection.close` events and logs incoming messages, sending a simple 'Hello Word' reply. The `saveCreds` function is hooked to `creds.update` to persist session information. ```typescript import makeWASocket, { DisconnectReason, useMultiFileAuthState } from '@whiskeysockets/baileys' import { Boom } from '@hapi/boom' async function connectToWhatsApp () { const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys') const sock = makeWASocket({ // can provide additional config here auth: state, printQRInTerminal: true }) sock.ev.on('connection.update', (update) => { const { connection, lastDisconnect } = update if(connection === 'close') { const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect) // reconnect if not logged out if(shouldReconnect) { connectToWhatsApp() } } else if(connection === 'open') { console.log('opened connection') } }) sock.ev.on('messages.upsert', event => { for (const m of event.messages) { console.log(JSON.stringify(m, undefined, 2)) console.log('replying to', m.key.remoteJid) await sock.sendMessage(m.key.remoteJid!, { text: 'Hello Word' }) } }) // to storage creds (session info) when it updates sock.ev.on('creds.update', saveCreds) } // run in main file connectToWhatsApp() ``` -------------------------------- ### Enabling LZ4 Compression in Keyv Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/keyv/README.md Provides an example of using LZ4 compression with Keyv. The process mirrors enabling other compression types, by importing KeyvLz4 and setting it in the Keyv options. ```javascript import Keyv from 'keyv'; import KeyvLz4 from '@keyv/compress-lz4'; const keyvLz4 = new KeyvLz4(); const keyv = new Keyv({ compression: keyvLz4 }); ``` -------------------------------- ### Quick Start: Publish and Subscribe Messages with qified Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/qified/README.md Demonstrates how to quickly set up a qified instance, subscribe to a 'notifications' topic, and publish a message. It uses the MemoryMessageProvider for in-memory message handling. Remember to disconnect the instance after use. ```javascript import { Qified, MemoryMessageProvider } from 'qified'; // Create a new Qified instance with a memory provider const qified = new Qified({ messageProviders: new MemoryMessageProvider() }); // Subscribe to a topic await qified.subscribe('notifications', { id: 'notificationHandler', handler: async (message) => { console.log('Received:', message.data); } }); // Publish a message await qified.publish('notifications', { id: 'msg-1', data: { text: 'Hello, World!' } }); // Clean up await qified.disconnect(); ``` -------------------------------- ### Manage Message Providers in Qified Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/qified/README.md Shows how to get, set, and dynamically manage the array of message providers in a Qified instance. This example demonstrates adding multiple providers (Memory, Nats, Redis) and accessing their properties. ```typescript import { Qified, MemoryMessageProvider } from 'qified'; import { NatsMessageProvider } from '@qified/nats'; import { RedisMessageProvider } from '@qified/redis'; const qified = new Qified({ messageProviders: new MemoryMessageProvider() }); // Get current providers const providers = qified.messageProviders; console.log(`Currently using ${providers.length} provider(s)`); // Add another provider qified.messageProviders = [ new MemoryMessageProvider(), new NatsMessageProvider() ]; // Replace all providers qified.messageProviders = [ new RedisMessageProvider({ uri: 'redis://localhost:6379' }) ]; // Access provider properties qified.messageProviders.forEach(provider => { console.log('Provider ID:', provider.id); }); ``` -------------------------------- ### Initialize Keyv Instance (JavaScript) Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/keyv/README.md Create a new Keyv instance using an ES module import. This instance will manage the key-value storage operations. ```javascript import Keyv from 'keyv'; ``` -------------------------------- ### Pino Pretty Printing with Custom Options Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/pino/docs/pretty.md Enables pretty printing for Pino logs using 'pino-pretty' while also passing custom options to the prettifier. This example demonstrates enabling colorization for improved log readability. Ensure 'pino-pretty' is installed. ```javascript const pino = require('pino') const logger = pino({ transport: { target: 'pino-pretty', options: { colorize: true } } }) logger.info('hi') ``` -------------------------------- ### Tilde Ranges Syntax and Examples Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/semver/README.md Explains Tilde Ranges ('~') which allow for patch-level or minor-level changes depending on the specified version. Includes examples for full versions, minor versions, and major versions, along with prerelease handling. ```text ~1.2.3 := >=1.2.3 <1.3.0-0 ~1.2 := >=1.2.0 <1.3.0-0 ~1 := >=1.0.0 <2.0.0-0 ~0.2.3 := >=0.2.3 <0.3.0-0 ~0.2 := >=0.2.0 <0.3.0-0 ~0 := >=0.0.0 <1.0.0-0 ~1.2.3-beta.2 := >=1.2.3-beta.2 <1.3.0-0 ``` -------------------------------- ### Basic BigMap Usage (TypeScript) Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/@keyv/bigmap/README.md Demonstrates the fundamental operations of BigMap: creating an instance, setting and getting key-value pairs, checking for key existence, deleting keys, retrieving the size, and clearing all entries. This example uses TypeScript for type safety. ```typescript import { BigMap } from '@keyv/bigmap'; // Create a new BigMap const bigMap = new BigMap(); // Set values bigMap.set('key1', 100); bigMap.set('key2', 200); // Get values const value = bigMap.get('key1'); // 100 // Check if key exists bigMap.has('key1'); // true // Delete a key bigMap.delete('key1'); // true // Get size console.log(bigMap.size); // 1 // Clear all entries bigMap.clear(); ``` -------------------------------- ### Initialize Realtime WebSocket Connection (TypeScript) Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/openai/README.md Establishes a WebSocket connection for the Realtime API to enable low-latency, multi-modal conversational experiences. It supports text and audio input/output and function calling. This example shows basic setup and listening for text deltas. ```typescript import { OpenAIRealtimeWebSocket } from 'openai/realtime/websocket'; const rt = new OpenAIRealtimeWebSocket({ model: 'gpt-realtime' }); rt.on('response.text.delta', (event) => process.stdout.write(event.delta)); ``` -------------------------------- ### Axios URL-Only GET Request Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/axios/README.md A shorthand for making a GET request where only the URL is provided to the `axios` function. The method defaults to GET. ```javascript // Send a GET request (default method)axios('/user/12345'); ``` -------------------------------- ### Namespacing Keyv Instances Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/keyv/README.md Demonstrates how to create multiple Keyv instances with different namespaces using the same Redis adapter to prevent key collisions and manage data separation. ```javascript const users = new Keyv(new KeyvRedis('redis://user:pass@localhost:6379'), { namespace: 'users' }); const cache = new Keyv(new KeyvRedis('redis://user:pass@localhost:6379'), { namespace: 'cache' }); await users.set('foo', 'users'); // true await cache.set('foo', 'cache'); // true await users.get('foo'); // 'users' await cache.get('foo'); // 'cache' await users.clear(); // undefined await users.get('foo'); // undefined await cache.get('foo'); // 'cache' ``` -------------------------------- ### Enabling Brotli Compression in Keyv Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/keyv/README.md Demonstrates how to integrate Brotli compression with Keyv. Similar to gzip, this involves importing KeyvBrotli and configuring it in the Keyv constructor. ```javascript import Keyv from 'keyv'; import KeyvBrotli from '@keyv/compress-brotli'; const keyvBrotli = new KeyvBrotli(); const keyv = new Keyv({ compression: keyvBrotli }); ``` -------------------------------- ### Install on-exit-leak-free Module Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/on-exit-leak-free/README.md This snippet shows how to install the 'on-exit-leak-free' module using npm. It is a standard package installation command. ```bash npm i on-exit-leak-free ``` -------------------------------- ### Enabling Gzip Compression in Keyv Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/keyv/README.md Shows how to enable gzip compression for Keyv storage. This is achieved by importing the KeyvGzip adapter and passing an instance of it to the Keyv constructor's 'compression' option. ```javascript import Keyv from 'keyv'; import KeyvGzip from '@keyv/compress-gzip'; const keyvGzip = new KeyvGzip(); const keyv = new Keyv({ compression: keyvGzip }); ``` -------------------------------- ### Install proxy-from-env Package Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/proxy-from-env/README.md This command installs the 'proxy-from-env' package using npm. It is a prerequisite for using the package in a Node.js project. Ensure Node.js and npm are installed. ```sh npm install proxy-from-env ``` -------------------------------- ### Configure Pino Asynchronous Transports Startup Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/pino/docs/transports.md Demonstrates how to handle asynchronous startup of Pino transports using `transport.on('ready', ...)` to ensure logs are not lost before `process.exit()` is called. ```javascript const pino = require('pino') const transport = pino.transport({ targets: [ { target: '/absolute/path/to/my-transport.mjs', level: 'error' }, { target: 'some-file-transport', options: { destination: '/dev/null' } } ] }) const logger = pino(transport) logger.info('hello') // If logs are printed before the transport is ready when process.exit(0) is called, // they will be lost. transport.on('ready', function () { process.exit(0) }) ``` -------------------------------- ### Install p-timeout using npm Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/p-timeout/readme.md This snippet shows the command to install the p-timeout package using npm, the Node Package Manager. Ensure you have Node.js and npm installed to use this command. ```sh npm install p-timeout ``` -------------------------------- ### Install @pinojs/redact with npm Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/@pinojs/redact/README.md This command installs the @pinojs/redact package using npm, making it available for use in your Node.js project. Ensure you have Node.js and npm installed. ```bash npm install @pinojs/redact ``` -------------------------------- ### Initialize node-cache Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/node-cache/README.md Demonstrates how to initialize the node-cache. You can create a cache instance with default settings or provide custom options like stdTTL and checkperiod. ```javascript const NodeCache = require( "node-cache" ); const myCache = new NodeCache(); ``` ```javascript const NodeCache = require( "node-cache" ); const myCache = new NodeCache( { stdTTL: 100, checkperiod: 120 } ); ``` -------------------------------- ### Install Cacheable Package Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/cacheable/README.md Installs the cacheable package using npm. This is the primary step to begin using the caching engine in your project. ```bash npm install cacheable ``` -------------------------------- ### Load Protobuf.js Light Library from CDN - Production Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/libsignal/node_modules/protobufjs/dist/light/README.md Include the protobuf.js light library in production environments using the rawgit CDN with the minified version. Replace 6.X.X with the specific release version your project requires. The minified version reduces payload size for faster loading. ```html ``` -------------------------------- ### POST Request Example Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/axios/README.md Demonstrates how to send data using a POST request. ```APIDOC ## POST Request Example ```js axios.post('/user', { firstName: 'Fred', lastName: 'Flintstone' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); ``` ``` -------------------------------- ### Install EventEmitter3 using npm Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/eventemitter3/README.md This command installs the eventemitter3 package as a dependency for your project. ```bash npm install --save eventemitter3 ``` -------------------------------- ### pbjs CLI Help Text Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/libsignal/node_modules/protobufjs/README.md Displays the available command-line options for the pbjs tool, including targets, path settings, output options, and specific configurations for module targets, proto sources, and static targets. ```bash Translates between file formats and generates static code. -t, --target Specifies the target format. Also accepts a path to require a custom target. json JSON representation json-module JSON representation as a module proto2 Protocol Buffers, Version 2 proto3 Protocol Buffers, Version 3 static Static code without reflection (non-functional on its own) static-module Static code without reflection as a module -p, --path Adds a directory to the include path. -o, --out Saves to a file instead of writing to stdout. --sparse Exports only those types referenced from a main file (experimental). Module targets only: -w, --wrap Specifies the wrapper to use. Also accepts a path to require a custom wrapper. default Default wrapper supporting both CommonJS and AMD commonjs CommonJS wrapper amd AMD wrapper es6 ES6 wrapper (implies --es6) closure A closure adding to protobuf.roots where protobuf is a global -r, --root Specifies an alternative protobuf.roots name. -l, --lint Linter configuration. Defaults to protobuf.js-compatible rules: eslint-disable block-scoped-var, no-redeclare, no-control-regex, no-prototype-builtins --es6 Enables ES6 syntax (const/let instead of var) Proto sources only: --keep-case Keeps field casing instead of converting to camel case. Static targets only: --no-create Does not generate create functions used for reflection compatibility. --no-encode Does not generate encode functions. --no-decode Does not generate decode functions. --no-verify Does not generate verify functions. --no-convert Does not generate convert functions like from/toObject --no-delimited Does not generate delimited encode/decode functions. --no-beautify Does not beautify generated code. --no-comments Does not output any JSDoc comments. --force-long Enfores the use of 'Long' for s-/u-/int64 and s-/fixed64 fields. --force-message Enfores the use of message instances instead of plain objects. usage: pbjs [options] file1.proto file2.json ... (or pipe) other | pbjs [options] - ``` -------------------------------- ### Combining Characters Example in UTF-8 Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/@protobufjs/utf8/tests/data/utf8.txt This example illustrates how UTF-8 handles combining characters, where multiple Unicode characters are used to form a single visual glyph. It shows examples like accented letters and special symbols. ```text STARGΛ̊TE SG-1, a = v̇ = r̈, a⃑ ⊥ b⃑ ``` -------------------------------- ### Load Protobuf.js from CDN - Production Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/libsignal/node_modules/protobufjs/dist/minimal/README.md Include the production version of protobuf.js minimal library from CDN using the minified distribution. This optimized version reduces file size and load time for production environments. Replace 6.X.X with the exact release version your project depends upon. ```html ``` -------------------------------- ### Install LRU Cache Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/lru-cache/README.md This command installs the lru-cache package as a dependency for your project using npm. ```bash npm install lru-cache --save ``` -------------------------------- ### Import fflate (ES Modules) Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/fflate/README.md Demonstrates how to import the entire fflate library or specific modules like gzipSync for ES Module environments to minimize bundle size. ```js // I will assume that you use the following for the rest of this guide import * as fflate from 'fflate'; // However, you should import ONLY what you need to minimize bloat. // So, if you just need GZIP compression support: import { gzipSync } from 'fflate'; // Woo! You just saved 20 kB off your bundle with one line. ``` -------------------------------- ### Frontend Usage for protobuf.js Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/libsignal/node_modules/protobufjs/dist/README.md Provides instructions for including the protobuf.js library in frontend projects by referencing local files within the 'node_modules' directory. Offers separate paths for development (unminified) and production (minified) builds. ```html ``` ```html ``` -------------------------------- ### Install combined-stream Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/combined-stream/Readme.md Installs the combined-stream package using npm. This is the first step before using the module in your Node.js project. ```bash npm install combined-stream ``` -------------------------------- ### Setup Pino HTTP logging with H3 server Source: https://github.com/guiireal/takeshi-bot/blob/main/node_modules/pino/docs/web.md Create an H3 server with Pino HTTP middleware integration. Demonstrates middleware registration, event handler setup, and request logging using the pino logger attached to the request object. ```javascript import { createApp, createRouter, eventHandler, fromNodeMiddleware } from "h3"; import pino from 'pino-http' export const app = createApp(); const router = createRouter(); app.use(router); app.use(fromNodeMiddleware(pino())) app.use(eventHandler((event) => { event.node.req.log.info('something') return 'hello world' })) router.get( "/", eventHandler((event) => { return { path: event.path, message: "Hello World!" }; }), ); ```