serialize.js 625 B

12345678910111213141516
  1. 'use strict';
  2. const { cppdb } = require('../util');
  3. module.exports = function serialize(options) {
  4. if (options == null) options = {};
  5. // Validate arguments
  6. if (typeof options !== 'object') throw new TypeError('Expected first argument to be an options object');
  7. // Interpret and validate options
  8. const attachedName = 'attached' in options ? options.attached : 'main';
  9. if (typeof attachedName !== 'string') throw new TypeError('Expected the "attached" option to be a string');
  10. if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
  11. return this[cppdb].serialize(attachedName);
  12. };