### Install Dependencies
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Ensure all project dependencies are installed.
```bash
yarn
```
--------------------------------
### Install and Use Node.js Version (Windows)
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Use nvm-windows to install and switch to the recommended Node.js LTS version for development.
```bash
nvm install 20
nvm use 20
```
--------------------------------
### Install and Use Node.js Version (macOS/Linux)
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Use nvm to install and switch to the recommended Node.js LTS version for development.
```bash
nvm install
nvm use
```
--------------------------------
### Build ml5.js Library for Production
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Install dependencies and build a production-ready version of the ml5.js library.
```bash
yarn
yarn run build
```
--------------------------------
### User Options Object Example
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
An example of a `userObject` used to configure model detection, such as setting `maxHands` and `modelType` for the `handpose` model.
```javascript
const optionsObject = {
maxHands: 4,
modelType: full,
};
```
--------------------------------
### Include ml5.js Version 0.6.1
Source: https://github.com/ml5js/ml5-next-gen/blob/main/README.md
Example of including a specific version (0.6.1) of ml5.js.
```html
```
--------------------------------
### Enable Corepack and Install Dependencies
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Enable Corepack to manage package managers and install project dependencies using Yarn.
```bash
corepack enable
yarn
yarn start
```
--------------------------------
### Build Project
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Compile the project. Wait for the build process to complete before proceeding.
```bash
yarn run build
```
--------------------------------
### Configure p5 Web Editor Upload
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Create a .env file with your p5 web editor username and password to enable sketch uploading.
```dotenv
P5_USERNAME=
P5_PASSWORD=
```
--------------------------------
### Run Unit Tests
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Execute the project's unit tests. Currently, the test suite is limited but expected to improve.
```bash
yarn test
```
--------------------------------
### Upload p5 Web Editor Sketches
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Run this command to update existing sketches or create new ones on the p5 web editor based on local directory names.
```bash
yarn run upload-examples
```
--------------------------------
### Checkout and Pull Main Branch
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Switch to the main branch and ensure it is up to date before making a release.
```bash
git checkout main
git pull
```
--------------------------------
### Format All JavaScript Files
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Run this command to format all JavaScript files in the repository using Yarn and Prettier.
```bash
yarn run format
```
--------------------------------
### Instantiate ml5.js Models
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Use factory functions like `ml5.()` to instantiate ml5.js models. These functions support p5.js's `preload()` and the callback interface, returning an unready instance synchronously.
```javascript
let bodyPose = ml5.bodyPose("BlazePose");
let neuralNetwork = ml5.neuralNetwork();
```
--------------------------------
### Unpkg URL for New Release
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
The URL to access the newly published package on unpkg. Replace `` with the SemVer number set in step 1.
```bash
https://unpkg.com/ml5@/dist/ml5.js
```
--------------------------------
### Login to npm
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Log in to your npm account that has write access to the ml5 package. Authentication may redirect to a browser.
```bash
npm login
```
--------------------------------
### Publish npm Package
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Publish the ml5 package to npm. Authentication may redirect to a browser.
```bash
npm publish --access public
```
--------------------------------
### Format Specific File with Prettier
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Use npx and Prettier to format a specific file via the command line.
```bash
npx prettier --write path/to/file
```
--------------------------------
### Include Latest ml5.js Version
Source: https://github.com/ml5js/ml5-next-gen/blob/main/README.md
Add this script tag to your HTML's head to fetch the latest 1.x version of ml5.js.
```html
```
--------------------------------
### Add New Contributor
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Use this command to initiate the process of adding a new contributor. Follow the terminal prompts to update README.md and .all-contributorsrc.
```bash
yarn all-contributors add
```
--------------------------------
### Filter User Options with `handleOptions`
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
The `handleOptions` utility function filters user-defined options against a defined 'mold' object, returning a validated object and logging warnings for any invalid options.
```javascript
const filteredOptions = handleOptions(userObject, moldObject);
```
--------------------------------
### Update README Version
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Run this command to update the version number in README.md after changing the SemVer in package.json.
```bash
yarn run update-readme
```
--------------------------------
### Handle Invalid Options with Warnings
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
ml5.js provides friendly warnings for invalid parameters or options, proceeding with default values when possible. This ensures robustness even with incorrect user input.
```javascript
let bodyPose = ml5.bodyPose({ modelType: "foo" });
// Console:
// 🟪ml5.js warns: The 'modelType' option for bodyPose has to be set to 'lite', 'full', or 'heavy', but it is being set to 'foo' instead.
//
// ml5.js is using default value of 'full'.
```
--------------------------------
### Flexible Parameter Order
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
ml5.js functions allow parameters to be passed in any order when possible, enhancing usability and reducing the need to memorize specific argument sequences.
```javascript
let bodyPose = ml5.bodyPose("blazepose", { modelType: "full" });
```
```javascript
let bodyPose = ml5.bodyPose({ modelType: "full" }, "blazepose");
```
--------------------------------
### Case-Insensitive Model Name and Options
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Model names and configuration options are matched case-insensitively. This allows for flexibility when specifying model types or other settings.
```javascript
let bodyPose = ml5.bodyPose("BlazePose", { modelType: "Full" });
```
```javascript
let bodyPose = ml5.bodyPose("blazepose", { modelType: "full" });
```
--------------------------------
### Include Specific ml5.js Version
Source: https://github.com/ml5js/ml5-next-gen/blob/main/README.md
Use this script tag to include a specific version of ml5.js by replacing '' with the desired version number.
```html
```
--------------------------------
### Callback Interface for Asynchronous Functions
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Asynchronous ml5.js functions should utilize the callback interface, following the `callback(result, error)` pattern. While promise/async await is considered, the callback interface is currently the officially supported method.
```javascript
// Example of callback pattern (not directly shown in source, but implied by guidelines)
```
--------------------------------
### Define Rule in moldObject
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
Defines rules for filtering options in a moldObject. Specifies types, defaults, and optional constraints like min/max for numbers and enums for specific values.
```javascript
const mold = {
runtime: {
type: "enum",
enums: ["mediapipe", "tfjs"],
default: "mediapipe",
},
maxHands: {
type: "number",
min: 1,
default: (filteredObject) => filteredObject.runtime === "mediapipe" ? 4 : 2;
},
};
```
--------------------------------
### Mold Object Definition for Option Validation
Source: https://github.com/ml5js/ml5-next-gen/blob/main/CONTRIBUTING.md
A 'mold' object defines the rules for filtering user options, including data types, minimum/maximum values, allowed enumerations, and default values. This ensures options conform to expected formats.
```javascript
const mold = {
maxHands: {
type: "number",
min: 1,
default: 2,
},
runtime: {
type: "enum",
enums: ["mediapipe", "tfjs"],
default: "mediapipe",
},
modelType: {
type: "enum",
enums: ["lite", "full"],
default: "full",
},
};
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.