### Install Yandex Market Language with NPM Source: https://github.com/lotustm/yandex-market-language/blob/master/README.md Instructions to install the `yandex-market-language` library using npm, the Node.js package manager. ```shell npm install yandex-market-language ``` -------------------------------- ### Write Generated YML to File Source: https://github.com/lotustm/yandex-market-language/blob/master/README.md Provides an example of how to save the generated YML string to a file using Node.js's built-in `fs.writeFile` method. This snippet includes basic error handling for the file write operation. ```javascript const { writeFile } = require('fs') writeFile('yandex-market.yml', YML, (err) => { if (err) throw err console.log('YML has been saved!') }) ``` -------------------------------- ### Initialize YML Generator and Validate Input Source: https://github.com/lotustm/yandex-market-language/blob/master/README.md Demonstrates how to initialize the YML generator by requiring the library and passing an input object. The library automatically validates the input against its schema, throwing an error if validation fails. ```javascript const yml = require('yandex-market-language') const YML = yml({ name: 'BestSeller', ... }) ``` -------------------------------- ### API: yml(...).create() Method Source: https://github.com/lotustm/yandex-market-language/blob/master/README.md Creates an XML object from the initialized YML instance, with all necessary nodes formed and in place. It returns an `xmlbuilder` `XMLElement`, allowing further manipulation using `xmlbuilder`'s methods. ```APIDOC yml(...).create() Returns: `xmlbuilder` `XMLElement` ``` ```javascript const yml = require('yandex-market-language') const YML = yml({...VALID_INPUT...}).create() // => XMLElement { ... } ``` -------------------------------- ### API: yml(input: object, options?: object) Function Source: https://github.com/lotustm/yandex-market-language/blob/master/README.md The main entry point for the Yandex Market Language generator. It accepts a JSON input object for YML generation and an optional options object to control validation and date settings. This function returns library methods `create` and `end`. ```APIDOC yml(input: object, options?: object) input: object — JSON which will be validated and used to generate YML. Object must be fully formed and conform to schema format, otherwise it will throw validation error. Examples of valid inputs can be seen in fixtures. To bypass validation, use `options.validate: false`. options?: object — Library options. options.validate?: boolean — Validate or not input. Default: `true`. Not recommended to set to `false`. options.date?: string — Fixed date for YML `date` attribute, which should represent time of YML update. If not defined, will fallback to current date. Should be in RFC2822 or ISO format. ``` ```javascript const yml = require('yandex-market-language') const YML = yml({...VALID_INPUT...}) ``` -------------------------------- ### API: yml(...).end(options?: object) Method Source: https://github.com/lotustm/yandex-market-language/blob/master/README.md Creates the XML object and immediately prints it as a final YML in the form of a string. It accepts any options that would normally be passed to `xmlbuilder`'s `end()` method, such as `pretty` for formatting. ```APIDOC yml(...).end(options?: object) options?: object — Any options you'd normally pass to `xmlbuilder` `end()` method. ``` ```javascript const yml = require('yandex-market-language') const YML = yml({...VALID_INPUT...}).end({ pretty: true }) // => ... ``` -------------------------------- ### Create XML Object from YML Input Source: https://github.com/lotustm/yandex-market-language/blob/master/README.md Shows how to generate an XML object from the previously initialized YML instance using the `create()` method. This method returns an `xmlbuilder` XMLElement, which can be further manipulated if needed. ```javascript YML.create() ``` -------------------------------- ### Convert YML Object to String Source: https://github.com/lotustm/yandex-market-language/blob/master/README.md Illustrates how to convert the YML object into a final YML string using the `end()` method. The `pretty: true` option can be passed to format the output for readability. ```javascript YML.end({ pretty: true }) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.