util.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.mergeOptions = mergeOptions;
  6. exports.isIterableIterator = isIterableIterator;
  7. function mergeOptions(target, source) {
  8. for (const k of Object.keys(source)) {
  9. if (k === "parserOpts" && source.parserOpts) {
  10. const parserOpts = source.parserOpts;
  11. const targetObj = target.parserOpts = target.parserOpts || {};
  12. mergeDefaultFields(targetObj, parserOpts);
  13. } else if (k === "generatorOpts" && source.generatorOpts) {
  14. const generatorOpts = source.generatorOpts;
  15. const targetObj = target.generatorOpts = target.generatorOpts || {};
  16. mergeDefaultFields(targetObj, generatorOpts);
  17. } else {
  18. const val = source[k];
  19. if (val !== undefined) target[k] = val;
  20. }
  21. }
  22. }
  23. function mergeDefaultFields(target, source) {
  24. for (const k of Object.keys(source)) {
  25. const val = source[k];
  26. if (val !== undefined) target[k] = val;
  27. }
  28. }
  29. function isIterableIterator(value) {
  30. return !!value && typeof value.next === "function" && typeof value[Symbol.iterator] === "function";
  31. }