How to create <defs> element

The createDefs() function is used to create an SVG <defs> element.

import { createDefs } from 'mz-svg';

const $defs = createDefs();

In Node.js, you need to first create a JSDom document, as described here, and then pass this document as additional parameter:

import { createDefs } from 'mz-svg';

const $defs = createDefs({
    document: doc
});

The function can accept the following parameters. Note that all parameters are optional:

import { createDefs } from 'mz-svg';

const $defs = createDefs({
    
    // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/id
    id: 'my-defs-id',
    
    // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/class
    classes: 'css-class1 css-class2',
});