Commerce
Module to generate commerce and product related entries.
Overview
For a long product name like 'Incredible Soft Gloves', use productName(). The product names are generated from a list of adjectives, materials, and products, which can each be accessed separately using productAdjective(), productMaterial(), and product(). You can also create a description using productDescription().
For a department in a shop or product category, use department().
You can also create a price using price().
To work with product identifiers, generate an ISBN via isbn() or a 12‑digit UPC via upc(). You can compute a UPC check digit using calculateCheckDigit().
calculateCheckDigit
Calculates the check digit for a UPC‑A using the Modulo 10 algorithm.
Available since v10.1.0
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| digits | string | The first 11 digits (UPC body) as a numeric string. |
Returns: number
Throws: If digits is not exactly 11 numeric characters.
function calculateCheckDigit(digits: string): number;
Examples
faker.commerce.calculateCheckDigit('12345678901') // 2
faker.commerce.calculateCheckDigit('01234567890') // 5
See Also
- upc
Source
department
Returns a department inside a shop.
Available since v3.0.0
Returns: string
function department(): string;
Examples
faker.commerce.department() // 'Garden'
Source
isbn
Returns a random ISBN identifier.
Available since v8.1.0
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| options | 10 | 13 | { ... } | {} | The variant to return or an options object. |
| options.separator? | string | '-' | The separator to use in the format. |
| options.variant? | 10 | 13 | 13 | The variant of the identifier to return.
Can be either |
Returns: string
function isbn(
options:
| 10
| 13
| {
variant?: 10 | 13;
separator?: string;
} = {}
): string;
Examples
faker.commerce.isbn() // '978-0-692-82459-7'
faker.commerce.isbn(10) // '1-155-36404-X'
faker.commerce.isbn(13) // '978-1-60808-867-6'
faker.commerce.isbn({ separator: ' ' }) // '978 0 452 81498 1'
faker.commerce.isbn({ variant: 10, separator: ' ' }) // '0 940319 49 7'
faker.commerce.isbn({ variant: 13, separator: ' ' }) // '978 1 6618 9122 0'
Source
price
Generates a price between min and max (inclusive).
To better represent real-world prices, when options.dec is greater than 0, the final decimal digit in the returned string will be generated as follows:
- 50% of the time:
9 - 30% of the time:
5 - 10% of the time:
0 - 10% of the time: a random digit from
0to9
Available since v3.0.0
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| options | { ... } | {} | An options object. |
| options.dec? | number | 2 | The number of decimal places. |
| options.max? | number | 1000 | The maximum price. |
| options.min? | number | 1 | The minimum price. |
| options.symbol? | string | '' | The currency value to use. |
Returns: string
function price(
options: {
min?: number;
max?: number;
dec?: number;
symbol?: string;
} = {}
): string;
Examples
faker.commerce.price() // '828.07'
faker.commerce.price({ min: 100 }) // '904.19'
faker.commerce.price({ min: 100, max: 200 }) // '154.55'
faker.commerce.price({ min: 100, max: 200, dec: 0 }) // '133'
faker.commerce.price({ min: 100, max: 200, dec: 0, symbol: '$' }) // '$114'
Source
product
Returns a short product name.
Available since v3.0.0
Returns: string
function product(): string;
Examples
faker.commerce.product() // 'Computer'
Source
productAdjective
Returns an adjective describing a product.
Available since v3.0.0
Returns: string
function productAdjective(): string;
Examples
faker.commerce.productAdjective() // 'Handcrafted'
Source
productDescription
Returns a product description.
Available since v5.0.0
Returns: string
function productDescription(): string;
Examples
faker.commerce.productDescription() // 'Featuring Phosphorus-enhanced technology, our Fish offers unparalleled Modern performance'
Source
productMaterial
Returns a material of a product.
Available since v3.0.0
Returns: string
function productMaterial(): string;
Examples
faker.commerce.productMaterial() // 'Rubber'
Source
productName
Generates a random descriptive product name.
Available since v3.0.0
Returns: string
function productName(): string;
Examples
faker.commerce.productName() // 'Incredible Soft Gloves'
Source
upc
Returns a valid UPC‑A (12 digits).
When a prefix is provided, it is sanitized to digits and padded with random
digits so that the body has 11 digits. The 12th digit (check digit) is computed
using the Modulo 10 algorithm.
Available since v10.1.0
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| prefix | string | '' | Optional numeric prefix for the UPC body (0–11 digits). Non‑digits are ignored. |
Returns: string
Throws: If prefix contains more than 11 digits after sanitization.
function upc(prefix = ''): string;
Examples
faker.commerce.upc() // '036000291452'
faker.commerce.upc('01234') // '012345678905'
See Also
- calculateCheckDigit