### Run an Express.js example Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/express/Readme.md After cloning the Express.js repository and installing dependencies, this bash command executes a specific example from the 'examples' directory, such as 'content-negotiation'. This is useful for understanding various features and functionalities of Express.js. ```bash node examples/content-negotiation ``` -------------------------------- ### Full Router Example with Middleware and Server Setup Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/router/README.md This comprehensive example sets up an HTTP server using the router module. It includes importing necessary modules, initializing the router, adding middleware like compression and body-parser, defining routes for GET and PATCH requests, and creating a nested router for API endpoints. ```javascript // import our modules var http = require('http'); var Router = require('router'); var finalhandler = require('finalhandler'); var compression = require('compression'); var bodyParser = require('body-parser'); // store our message to display var message = 'Hello World!'; // initialize the router & server and add a final callback. var router = Router(); var server = http.createServer(function onRequest (req, res) { router(req, res, finalhandler(req, res)); }); // use some middleware and compress all outgoing responses router.use(compression()); // handle `GET` requests to `/message` router.get('/message', function (req, res) { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain; charset=utf-8'); res.end(message + '\n'); }); // create and mount a new router for our API var api = Router(); router.use('/api/', api); // add a body parsing middleware to our API api.use(bodyParser.json()); // handle `PATCH` requests to `/api/set-message` api.patch('/set-message', function (req, res) { if (req.body.value) { message = req.body.value; res.statusCode = 200; res.setHeader('Content-Type', 'text/plain; charset=utf-8'); res.end(message + '\n'); } else { res.statusCode = 400; res.setHeader('Content-Type', 'text/plain; charset=utf-8'); res.end('Invalid API Syntax\n'); } }); // make our http server listen to connections server.listen(8080); ``` -------------------------------- ### GET Request Example Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/axios/README.md Illustrates how to perform a GET request using Axios, including handling success and error responses with Promises and async/await. ```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 }); // Alternative 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); } } ``` **Note**: `async/await` requires ECMAScript 2017 support. ``` -------------------------------- ### Basic axios GET Request Example Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/axios/README.md Demonstrates how to perform a basic GET request using axios, including handling success and error responses with Promises (`.then`, `.catch`, `.finally`). It also shows an optional way to structure parameters. ```javascript import axios from 'axios'; //const axios = require('axios'); // legacy way // Make a request for a user with a given IDaxios.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 }); ``` -------------------------------- ### Demonstrate side-channel-list Usage Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/side-channel-list/README.md This JavaScript example demonstrates how to use the side-channel-list package. It covers initialization, setting and getting values, asserting key presence, and deleting keys, along with error handling for non-existent keys. ```javascript const assert = require('assert'); const getSideChannelList = require('side-channel-list'); const channel = getSideChannelList(); const key = {}; assert.equal(channel.has(key), false); assert.throws(() => channel.assert(key), TypeError); channel.set(key, 42); channel.assert(key); // does not throw assert.equal(channel.has(key), true); assert.equal(channel.get(key), 42); channel.delete(key); assert.equal(channel.has(key), false); assert.throws(() => channel.assert(key), TypeError); ``` -------------------------------- ### Handle GET Request Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/router/README.md Illustrates how to handle a specific HTTP method (GET) for a given path ('/'). This example sets the Content-Type header and sends a 'Hello World!' response. ```javascript // handle a `GET` request router.get('/', function (req, res) { res.setHeader('Content-Type', 'text/plain; charset=utf-8') res.end('Hello World!') }) ``` -------------------------------- ### Installation Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/axios/README.md Instructions for installing Axios using various package managers. ```APIDOC ## 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 ``` ``` -------------------------------- ### Installation Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/linkify-it/README.md How to install the linkify-it library using npm. ```APIDOC ## Installation ### Description Install the linkify-it library using npm. ### Method ```bash npm install linkify-it --save ``` ### Notes Browserification is also supported. ``` -------------------------------- ### Installation of Accepts.js Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/accepts/README.md This code snippet shows how to install the accepts.js library using npm. It requires Node.js and npm to be installed on the system. ```sh npm install accepts ``` -------------------------------- ### Usage Example for side-channel-weakmap Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/side-channel-weakmap/README.md Demonstrates how to use the side-channel-weakmap package to set, get, assert, and delete values associated with keys. It utilizes Node.js's assert module for verification and shows the expected behavior when keys are present or absent. ```javascript const assert = require('assert'); const getSideChannelList = require('side-channel-weakmap'); const channel = getSideChannelList(); const key = {}; assert.equal(channel.has(key), false); assert.throws(() => channel.assert(key), TypeError); channel.set(key, 42); channel.assert(key); // does not throw assert.equal(channel.has(key), true); assert.equal(channel.get(key), 42); channel.delete(key); assert.equal(channel.has(key), false); assert.throws(() => channel.assert(key), TypeError); ``` -------------------------------- ### Day.js API Usage Examples Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/dayjs/README.md Illustrates basic Day.js API functionalities including parsing a date string, formatting a date, getting and setting month values, adding years, and querying if a date is before another. These examples cover core date operations. ```javascript dayjs('2018-08-08') // parse dayjs().format('{YYYY} MM-DDTHH:mm:ss SSS [Z] A') // display dayjs().set('month', 3).month() // get & set dayjs().add(1, 'year') // manipulate dayjs().isBefore(dayjs()) // query ``` -------------------------------- ### Install Project Dependencies with npm Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/twilio/README.md Installs all necessary packages for the project. Ensure Node.js is installed and you are in the root directory of the cloned repository. ```bash npm install ``` -------------------------------- ### Setup Automated Metadata Update Job with Launchd on macOS Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/libphonenumber-js/README.md This script automates the setup of a daily metadata update for the libphonenumber-js library. It creates a directory, clones the repository, installs npm dependencies, makes the autoupdate script executable, defines a launchd plist file for daily execution (every 24 hours), and loads the job. Errors and output are redirected to temporary files. ```sh mkdir /Users/kuchumovn/work/libphonenumber-js-autoupdate git clone https://gitlab.com/catamphetamine/libphonenumber-js.git /Users/kuchumovn/work/libphonenumber-js-autoupdate cd /Users/kuchumovn/work/libphonenumber-js-autoupdate npm install chmod u+x /Users/kuchumovn/work/libphonenumber-js-autoupdate/autoupdate.sh nano ~/Library/LaunchAgents/com.gitlab.catamphetamine.libphonenumber-js.metadata-update.plist launchctl load ~/Library/LaunchAgents/com.gitlab.catamphetamine.libphonenumber-js.metadata-update.plist launchctl list | grep 'libphonenumber-js' ``` -------------------------------- ### Create and run an Express.js application Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/express/Readme.md These bash commands outline the process of creating a new Express.js application using the Express Generator, navigating into the project directory, installing its dependencies, and starting the development server. The application will be accessible at http://localhost:3000. ```bash express /tmp/foo && cd /tmp/foo npm install npm start ``` -------------------------------- ### Install path-to-regexp Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/path-to-regexp/Readme.md This snippet shows the command to install the 'path-to-regexp' package using npm. It is a prerequisite for using the library. ```bash npm install path-to-regexp --save ``` -------------------------------- ### Install semver using npm Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/semver/README.md This command installs the semver package and its dependencies using the npm package manager. Ensure you have Node.js and npm installed to use this command. ```bash npm install semver ``` -------------------------------- ### Install xmlbuilder-js Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/xmlbuilder/README.md Installs the xmlbuilder-js package using npm. This is the first step to using the library in a Node.js project. ```sh npm install --save xmlbuilder ``` -------------------------------- ### HTTPS Module Example with HttpsProxyAgent Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/https-proxy-agent/README.md This example demonstrates how to use the HttpsProxyAgent with Node.js's built-in 'https' module. It configures an agent to connect to a proxy server and then makes an HTTPS GET request to a specified endpoint through that proxy. Ensure the 'https-proxy-agent' package is installed. ```javascript var url = require('url'); var https = require('https'); var HttpsProxyAgent = require('https-proxy-agent'); // HTTP/HTTPS proxy to connect to var proxy = process.env.http_proxy || 'http://168.63.76.32:3128'; console.log('using proxy server %j', proxy); // HTTPS endpoint for the proxy to connect to var endpoint = process.argv[2] || 'https://graph.facebook.com/tootallnate'; console.log('attempting to GET %j', endpoint); var options = url.parse(endpoint); // create an instance of the `HttpsProxyAgent` class with the proxy server information var agent = new HttpsProxyAgent(proxy); options.agent = agent; https.get(options, function (res) { console.log('"response" event!', res.headers); res.pipe(process.stdout); }); ``` -------------------------------- ### Install serve-static using npm Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/serve-static/README.md This command installs the serve-static Node.js module from the npm registry. It's a prerequisite for using the module in your project. ```sh npm install serve-static ``` -------------------------------- ### Install axios using Package Managers Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/axios/README.md Demonstrates how to install the axios library using different package managers like npm, bower, yarn, pnpm, and bun. Axios is a promise-based HTTP client for the browser and Node.js. ```bash $ npm install axios ``` ```bash $ bower install axios ``` ```bash $ yarn add axios ``` ```bash $ pnpm add axios ``` ```bash $ bun add axios ``` -------------------------------- ### Get Example Phone Number for a Country Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/libphonenumber-js/README.md This function retrieves an example phone number for a specified country code. It returns an instance of the `PhoneNumber` class or `undefined` if the country is not supported. Requires importing `examples` from 'libphonenumber-js/mobile/examples'. ```javascript import examples from 'libphonenumber-js/mobile/examples' import { getExampleNumber } from 'libphonenumber-js' const phoneNumber = getExampleNumber('RU', examples) phoneNumber.formatNational() === '8 (912) 345-67-89' ``` -------------------------------- ### Install get-proto with npm Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/get-proto/README.md Installs the 'get-proto' package as a project dependency using npm. This command should be run in your project's root directory. ```bash npm install --save get-proto ``` -------------------------------- ### Install ee-first using npm Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/ee-first/README.md This command installs the ee-first module, making it available for use in your Node.js project. It is a dependency for utilizing the module's functionality. ```sh npm install ee-first ``` -------------------------------- ### Install asynckit using npm Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/asynckit/README.md This command installs the asynckit package as a dependency for your project. It is a prerequisite for using the library's functionalities. ```sh npm install --save asynckit ``` -------------------------------- ### Install TypeScript Definitions for encoding.js Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/encoding-japanese/README.md Install the TypeScript type definitions for encoding.js using npm. This is useful for TypeScript projects to get type checking and autocompletion for the encoding.js library. ```bash npm install --save-dev @types/encoding-japanese ``` -------------------------------- ### POST Request Example Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/axios/README.md Demonstrates how to perform a POST request with a request body. ```APIDOC ## POST Request Example ```js axios.post('/user', { firstName: 'Fred', lastName: 'Flintstone' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); ``` ``` -------------------------------- ### Basic Server Setup with Router Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/router/README.md Demonstrates how to create a basic HTTP server using the router module. It sets up a root route that responds with 'Hello World!' and integrates with Node.js's http module and the finalhandler middleware. ```javascript var finalhandler = require('finalhandler') var http = require('http') var Router = require('router') var router = Router() router.get('/', function (req, res) { res.setHeader('Content-Type', 'text/plain; charset=utf-8') res.end('Hello World!') }) var server = http.createServer(function (req, res) { router(req, res, finalhandler(req, res)) }) server.listen(3000) ``` -------------------------------- ### Get raw body in Koa.js Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/raw-body/README.md An example of using raw-body with Koa.js using generator functions. It parses the request body similarly to the Express example, making the decoded string available via `this.text`. ```javascript var contentType = require('content-type') var getRawBody = require('raw-body') var koa = require('koa') var app = koa() app.use(function * (next) { this.text = yield getRawBody(this.req, { length: this.req.headers['content-length'], limit: '1mb', encoding: contentType.parse(this.req).parameters.charset }) yield next }) ``` -------------------------------- ### Router Configuration and Basic Usage Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/router/README.md Demonstrates how to install the router module and set up a basic HTTP server with routing. ```APIDOC ## Installation Install the router module using npm: ```bash $ npm install router ``` ## Basic Usage Example This example shows how to create a router instance, define a GET route for the root path, and integrate it with an HTTP server. ### Code ```javascript var finalhandler = require('finalhandler') var http = require('http') var Router = require('router') var router = Router() router.get('/', function (req, res) { res.setHeader('Content-Type', 'text/plain; charset=utf-8') res.end('Hello World!') }) var server = http.createServer(function (req, res) { router(req, res, finalhandler(req, res)) }) server.listen(3000) ``` ### Description The `Router()` constructor creates a new router instance. Options can be passed to configure the router's behavior regarding trailing slashes, case sensitivity, and parameter merging. The returned router function can be used as middleware in an HTTP server. ``` -------------------------------- ### Get Object Prototype in JavaScript Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/get-proto/README.md Demonstrates how to use the 'get-proto' library in JavaScript to retrieve the prototype of different objects. It shows examples with regular objects, objects with explicitly set prototypes, and objects with null prototypes. ```javascript const assert = require('assert'); const getProto = require('get-proto'); const a = { a: 1, b: 2, [Symbol.toStringTag]: 'foo' }; const b = { c: 3, __proto__: a }; assert.equal(getProto(b), a); assert.equal(getProto(a), Object.prototype); assert.equal(getProto({ __proto__: null }), null); ``` -------------------------------- ### Clone Express.js repository and install dependencies Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/express/Readme.md This bash script clones the Express.js GitHub repository, limiting the depth to 1 for a quicker clone, and then navigates into the cloned directory. Subsequently, it installs all project dependencies required to run examples or contribute to the project. ```bash git clone https://github.com/expressjs/express.git --depth 1 && cd express npm install ``` -------------------------------- ### Validate Phone Number Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/libphonenumber-js/README.md Provides examples of validating complete phone numbers using `isPossiblePhoneNumber`, `isValidPhoneNumber`, and `validatePhoneNumberLength`. It explains the difference between possible and valid, and how to get detailed length validation results. ```javascript import { isPossiblePhoneNumber, isValidPhoneNumber, validatePhoneNumberLength } from 'libphonenumber-js' isPossiblePhoneNumber('8 (800) 555-35-35', 'RU') === true isValidPhoneNumber('8 (800) 555-35-35', 'RU') === true validatePhoneNumberLength('8 (800) 555', 'RU') === 'TOO_SHORT' validatePhoneNumberLength('8 (800) 555-35-35', 'RU') === undefined // Length is valid. `isPossiblePhoneNumber()` only validates phone number length, while `isValidPhoneNumber()` validates both phone number length and phone number digits. `validatePhoneNumberLength()` is just a more detailed version of `isPossiblePhoneNumber()` — if the phone number length is invalid, instead of just returning `false`, it returns the actual reason why the phone number length is incorrect: `TOO_SHORT`, `TOO_LONG`, etc. ``` -------------------------------- ### Axios Configuration Precedence Example Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/axios/README.md Demonstrates how Axios merges configuration settings. It shows creating an instance, setting default timeouts for the instance, and overriding the timeout for a specific request. This highlights that later configurations take precedence. ```javascript const instance = axios.create(); // Override timeout default for the library // Now all requests using this instance will wait 2.5 seconds before timing out instance.defaults.timeout = 2500; // Override timeout for this request as it's known to take a long time instance.get('/longRequest', { timeout: 5000 }); ``` -------------------------------- ### Serve files with vanilla node.js http server Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/serve-static/README.md An example demonstrating how to use the serve-static middleware with Node.js's built-in http server and the finalhandler middleware for handling request completion. ```APIDOC ## Serve files with vanilla node.js http server ### Description This example shows how to integrate the `serve-static` middleware into a basic Node.js HTTP server. It uses `finalhandler` to manage the response lifecycle, allowing `serve-static` to serve files from the 'public/ftp' directory. ### Method N/A (This is an example of server setup) ### Endpoint N/A (This is an example of server setup) ### Parameters N/A ### Request Example ```javascript var finalhandler = require('finalhandler') var http = require('http') var serveStatic = require('serve-static') // Serve up public/ftp folder var serve = serveStatic('public/ftp', { index: ['index.html', 'index.htm'] }) // Create server var server = http.createServer(function onRequest (req, res) { serve(req, res, finalhandler(req, res)) }) // Listen server.listen(3000) ``` ### Response #### Success Response (200) - **N/A** - The server responds with static files or passes control to the next middleware if a file is not found. #### Response Example N/A ``` -------------------------------- ### Install and Use 'entities' Library in Node.js Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/entities/readme.md This snippet demonstrates how to install the 'entities' library using npm and provides examples of its core encoding and decoding functionalities for HTML and XML. It covers encoding strings to UTF-8, XML, and HTML formats, as well as decoding XML and HTML entities. ```bash npm install entities ``` ```javascript const entities = require("entities"); // Encoding entities.escapeUTF8("& ü"); // "& ü" entities.encodeXML("& ü"); // "& ü" entities.encodeHTML("& ü"); // "& ü" // Decoding entities.decodeXML("asdf & ÿ ü '"); // "asdf & ÿ ü '" entities.decodeHTML("asdf & ÿ ü '"); // "asdf & ÿ ü '" ``` -------------------------------- ### Creating an Axios Instance Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/axios/README.md Explains how to create a custom Axios instance with pre-defined configurations like `baseURL` and `timeout`. ```APIDOC ## Creating an Instance ### `axios.create([config])`: You can create a new instance of Axios with custom default settings. ```js const instance = axios.create({ baseURL: 'https://some-domain.com/api/', timeout: 1000, // in milliseconds headers: {'X-Custom-Header': 'foobar'} }); // Using the instance instance.get('/users') .then(function (response) { console.log(response.data); }); ``` Instance methods behave the same as the global Axios methods, but they inherit the instance's configuration. ``` -------------------------------- ### Configure Webpack for Front-end dotenv Usage Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/dotenv/README.md Provides a Webpack configuration example to resolve 'crypto|os|path' errors when using dotenv on the front-end. It includes installing and configuring `node-polyfill-webpack-plugin` and `webpack.DefinePlugin`. ```bash npm install node-polyfill-webpack-plugin ``` ```javascript require('dotenv').config() const path = require('path'); const webpack = require('webpack') const NodePolyfillPlugin = require('node-polyfill-webpack-plugin') module.exports = { mode: 'development', entry: './src/index.ts', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'dist'), }, plugins: [ new NodePolyfillPlugin(), new webpack.DefinePlugin({ 'process.env': { HELLO: JSON.stringify(process.env.HELLO) } }), ] }; ``` -------------------------------- ### Basic linkify-it Usage and Configuration (JavaScript) Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/linkify-it/README.md This example demonstrates basic usage of the linkify-it library in JavaScript. It shows how to instantiate the linkifier, configure it with custom top-level domains (TLDs) and protocols, and use its `test` and `match` methods to find and extract links from text. ```javascript import linkifyit from 'linkify-it'; const linkify = linkifyit(); // Reload full tlds list & add unofficial `.onion` domain. linkify .tlds(require('tlds')) // Reload with full tlds list .tlds('onion', true) // Add unofficial `.onion` domain .add('git:', 'http:') // Add `git:` protocol as "alias" .add('ftp:', null) // Disable `ftp:` protocol .set({ fuzzyIP: true }); // Enable IPs in fuzzy links (without schema) console.log(linkify.test('Site github.com!')); // true console.log(linkify.match('Site github.com!')); // [ { // schema: "", // index: 5, // lastIndex: 15, // raw: "github.com", // text: "github.com", // url: "http://github.com", // } ] ``` -------------------------------- ### Install isarray using component Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/isarray/README.md Instructions for installing the 'isarray' library using component, a front-end package manager. This method is suitable for browser-based projects. ```bash $ component install juliangruber/isarray ``` -------------------------------- ### Fetch Adapter with Tauri Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/axios/README.md Provides a minimal example of using the Fetch adapter with Tauri's platform fetch function, which bypasses CORS policy checks. This setup is suitable for Tauri applications requiring specific network configurations. ```javascript import { fetch } from "@tauri-apps/plugin-http"; import axios from "axios"; const instance = axios.create({ adapter: 'fetch', onDownloadProgress(e) { console.log('downloadProgress', e); }, env: { fetch } }); const {data} = await instance.get("https://google.com"); ``` -------------------------------- ### Handle All HTTP Methods for a Route Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/router/README.md This demonstrates how to add a handler that will be executed for all HTTP methods on a given route. It includes an example of using `next()` to pass control to subsequent handlers and a GET request handler. ```javascript router.route('/') .all(function (req, res, next) { next(); }) .all(checkSomething) .get(function (req, res) { res.setHeader('Content-Type', 'text/plain; charset=utf-8'); res.end('Hello World!'); }); ``` -------------------------------- ### Initialize Metadata with Custom Data - JavaScript Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/libphonenumber-js/README.md Demonstrates how to create a `Metadata` instance using pre-loaded custom metadata, such as 'min' metadata, imported from `libphonenumber-js/core`. This allows for optimized bundle sizes by including only necessary metadata. ```javascript import { Metadata } from 'libphonenumber-js/core' import min from 'libphonenumber-js/min/metadata' const metadata = new Metadata(min) ``` -------------------------------- ### Install libqp Module Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/libqp/README.md This command installs the libqp Node.js module using npm. This is the first step to using the library in your project. ```bash npm install libqp ``` -------------------------------- ### Day.js Date Manipulation Example Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/dayjs/README.md Demonstrates a common pattern for manipulating dates using Day.js, including starting at the beginning of a month, adding a day, setting a year, and formatting the output. This is a chainable operation typical for date libraries. ```javascript dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss'); ``` -------------------------------- ### Usage Example for side-channel Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/side-channel/README.md Demonstrates how to use the 'side-channel' package to set, get, assert, and delete values associated with a key. It utilizes Node.js's assert module for validation and highlights the behavior of 'assert' when a key is not present. ```js const assert = require('assert'); const getSideChannel = require('side-channel'); const channel = getSideChannel(); const key = {}; assert.equal(channel.has(key), false); assert.throws(() => channel.assert(key), TypeError); channel.set(key, 42); channel.assert(key); // does not throw assert.equal(channel.has(key), true); assert.equal(channel.get(key), 42); channel.delete(key); assert.equal(channel.has(key), false); assert.throws(() => channel.assert(key), TypeError); ``` -------------------------------- ### axios POST Request Example Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/axios/README.md Demonstrates how to send data to a server using an HTTP POST request with axios. It includes handling the response and potential errors. ```javascript axios.post('/user', { firstName: 'Fred', lastName: 'Flintstone' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); ``` -------------------------------- ### Example: Retrieving US Numbering Plan Details - JavaScript Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/libphonenumber-js/README.md Provides a complete example of initializing metadata, selecting the US numbering plan, and then calling methods to retrieve its leading digits, possible lengths, and IDD prefix, comparing the results to expected values. ```javascript import { Metadata } from 'libphonenumber-js' const metadata = new Metadata() metadata.selectNumberingPlan('US') metadata.numberingPlan.leadingDigits() === undefined metadata.numberingPlan.possibleLengths() === [10] metadata.numberingPlan.IDDPrefix() === '011' metadata.numberingPlan.defaultIDDPrefix() === undefined ``` -------------------------------- ### Get raw body in Express.js Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/raw-body/README.md An example of using raw-body within an Express.js middleware to parse the request body. It sets content-length, a 1mb limit, and decodes using the charset from the Content-Type header. Errors are passed to the next middleware. ```javascript var contentType = require('content-type') var express = require('express') var getRawBody = require('raw-body') var app = express() app.use(function (req, res, next) { getRawBody(req, { length: req.headers['content-length'], limit: '1mb', encoding: contentType.parse(req).parameters.charset }, function (err, string) { if (err) return next(err) req.text = string next() }) }) ``` -------------------------------- ### Configure Git to Remember Passphrase on Windows Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/libphonenumber-js/README.md A guide to setting up the OpenSSH Authentication Agent service in Windows to prevent Git from repeatedly asking for the SSH key passphrase. This involves configuring the service to start automatically and then adding the SSH key using the 'ssh-add' command. ```batch ssh-add git config --global core.sshCommand "C:/Windows/System32/OpenSSH/ssh.exe" ``` -------------------------------- ### Install call-bind-apply-helpers using npm Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/call-bind-apply-helpers/README.md This command installs the 'call-bind-apply-helpers' package as a project dependency. It is the first step to using the helper functions in your project. ```sh npm install --save call-bind-apply-helpers ``` -------------------------------- ### Importing Axios Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/axios/README.md Demonstrates how to import the Axios library using both ES module syntax (`import`) and CommonJS syntax (`require`). ```APIDOC ## Importing Axios ### ES Modules: ```js import axios, {isCancel, AxiosError} from 'axios'; ``` Or using the default export: ```js import axios from 'axios'; ``` For specific bundlers or linters: ```js import { default as axios } from 'axios'; ``` ### CommonJS: ```js const axios = require('axios'); ``` To import directly for legacy environments: ```js const axios = require('axios/dist/browser/axios.cjs'); // browser commonJS bundle // const axios = require('axios/dist/node/axios.cjs'); // node commonJS bundle ``` ``` -------------------------------- ### npm Script for Windows Debugging Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/debug/README.md This JavaScript snippet shows an example of how to define an npm script for Windows environments that utilizes PowerShell to set the DEBUG environment variable and then runs the Node.js application. This is useful for CI/CD pipelines or local development setups on Windows. ```javascript "windowsDebug": "@powershell -Command $env:DEBUG='*';node app.js" ``` -------------------------------- ### Get and Cache JS Intrinsics with get-intrinsic (JavaScript) Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/get-intrinsic/README.md Demonstrates how to use the `get-intrinsic` package to retrieve and cache JavaScript language-level intrinsics. It shows examples of accessing static methods like `Math.pow`, instance methods like `Array.prototype.push`, and handling missing intrinsics by asserting their absence or providing a default value. ```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)); ``` -------------------------------- ### Day.js Installation Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/dayjs/README.md Provides the command to install the Day.js library using npm, a common package manager for Node.js and front-end projects. This is a prerequisite for using Day.js in your project. ```bash npm install dayjs --save ``` -------------------------------- ### Express/Connect Top-Level Generic Body Parsing Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/body-parser/README.md This example demonstrates setting up generic JSON and URL-encoded parsers as top-level middleware in an Express application. This setup ensures that the bodies of all incoming requests are parsed. Dependencies include 'express' and 'body-parser'. Input is the raw request body, and output is the parsed request body available via `req.body`. ```javascript const express = require('express') const bodyParser = require('body-parser') const app = express() // parse application/x-www-form-urlencoded app.use(bodyParser.urlencoded()) // parse application/json app.use(bodyParser.json()) app.use(function (req, res) { res.setHeader('Content-Type', 'text/plain') res.write('you posted:\n') res.end(String(JSON.stringify(req.body, null, 2))) }) ``` -------------------------------- ### Create a custom axios instance Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/axios/README.md Explains how to create a custom instance of axios with a pre-configured base URL, timeout, and headers. This is useful for managing settings for specific API interactions. ```javascript const instance = axios.create({ baseURL: 'https://some-domain.com/api/', timeout: 1000, headers: {'X-Custom-Header': 'foobar'} }); ``` -------------------------------- ### Listen for the first event with ee-first (JavaScript) Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/ee-first/README.md This example demonstrates how to use the 'first' function from the ee-first module. It sets up listeners for specific events ('close', 'end', 'error') on multiple EventEmitter instances and invokes a callback function once the first event is detected. The callback receives details about the event and the emitter that triggered it. ```javascript var ee1 = new EventEmitter() var ee2 = new EventEmitter() first([ [ee1, 'close', 'end', 'error'], [ee2, 'error'] ], function (err, ee, event, args) { // listener invoked }) ``` -------------------------------- ### HTML to Selector Matching with Lead Converter (JavaScript) Source: https://github.com/simcod-vij/lead-converter/blob/main/conversion-system/node_modules/selderee/README.md This snippet demonstrates how to use the 'selderee' and 'htmlparser2' packages to build a decision tree from CSS selectors and apply it to an HTML document. It shows how to parse HTML, create a selector tree, and then use a picker to find all matching elements or the most specific match. Dependencies include 'htmlparser2', 'selderee', and '@selderee/plugin-htmlparser2'. ```javascript const htmlparser2 = require('htmlparser2'); const util = require('util'); const { DecisionTree, Treeify } = require('selderee'); const { hp2Builder } = require('@selderee/plugin-htmlparser2'); const selectorValuePairs = [ ['p', 'A'], ['p.foo[bar]', 'B'], ['p[class~=foo]', 'C'], ['div.foo', 'D'], ['div > p.foo', 'E'], ['div > p', 'F'], ['#baz', 'G'] ]; // Make a tree structure from all given selectors. const selectorsDecisionTree = new DecisionTree(selectorValuePairs); // `treeify` builder produces a string output for testing and debug purposes. // `treeify` expects string values attached to each selector. const prettyTree = selectorsDecisionTree.build(Treeify.treeify); console.log(prettyTree); const html = /*html*/`
second