Skip to content

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().

department

Returns a department inside a shop.

Available since v3.0.0

Returns: string

ts
function department(): string;

Examples

ts
faker.commerce.department() // 'Industrial'

isbn

Returns a random ISBN identifier.

Available since v8.1.0

Parameters

NameTypeDefaultDescription
options10 | 13 | { ... }{}

The variant to return or an options object.

options.separator?string'-'

The separator to use in the format.

options.variant?10 | 1313

The variant of the identifier to return. Can be either 10 (10-digit format) or 13 (13-digit format).

Returns: string

ts
function isbn(
  options:
    | 10
    | 13
    | {
        variant?: 10 | 13;
        separator?: string;
      } = {}
): string;

Examples

ts
faker.commerce.isbn() // '978-1-76546-489-4'
faker.commerce.isbn(10) // '0-7559-0008-1'
faker.commerce.isbn(13) // '978-1-897471-61-6'
faker.commerce.isbn({ separator: ' ' }) // '978 1 5427 4506 2'
faker.commerce.isbn({ variant: 10, separator: ' ' }) // '1 6963 4606 1'
faker.commerce.isbn({ variant: 13, separator: ' ' }) // '978 1 213 35491 3'

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 0 to 9

Available since v3.0.0

Parameters

NameTypeDefaultDescription
options{ ... }{}

An options object.

options.dec?number2

The number of decimal places.

options.max?number1000

The maximum price.

options.min?number1

The minimum price.

options.symbol?string''

The currency value to use.

Returns: string

ts
function price(
  options: {
    min?: number;
    max?: number;
    dec?: number;
    symbol?: string;
  } = {}
): string;

Examples

ts
faker.commerce.price() // '549.25'
faker.commerce.price({ min: 100 }) // '590.45'
faker.commerce.price({ min: 100, max: 200 }) // '143.78'
faker.commerce.price({ min: 100, max: 200, dec: 0 }) // '138'
faker.commerce.price({ min: 100, max: 200, dec: 0, symbol: '$' }) // '$179'

product

Returns a short product name.

Available since v3.0.0

Returns: string

ts
function product(): string;

Examples

ts
faker.commerce.product() // 'Mouse'

productAdjective

Returns an adjective describing a product.

Available since v3.0.0

Returns: string

ts
function productAdjective(): string;

Examples

ts
faker.commerce.productAdjective() // 'Luxurious'

productDescription

Returns a product description.

Available since v5.0.0

Returns: string

ts
function productDescription(): string;

Examples

ts
faker.commerce.productDescription() // 'Our savory-inspired Mouse brings a taste of luxury to your punctual lifestyle'

productMaterial

Returns a material of a product.

Available since v3.0.0

Returns: string

ts
function productMaterial(): string;

Examples

ts
faker.commerce.productMaterial() // 'Metal'

productName

Generates a random descriptive product name.

Available since v3.0.0

Returns: string

ts
function productName(): string;

Examples

ts
faker.commerce.productName() // 'Luxurious Rubber Pants'

Released under the MIT License.