speech_rule_functions.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.CustomGenerators = exports.ContextFunctions = exports.CustomStrings = exports.CustomQueries = void 0;
  4. class FunctionsStore {
  5. constructor(prefix, store) {
  6. this.prefix = prefix;
  7. this.store = store;
  8. }
  9. add(name, func) {
  10. if (this.checkCustomFunctionSyntax_(name)) {
  11. this.store[name] = func;
  12. }
  13. }
  14. addStore(store) {
  15. const keys = Object.keys(store.store);
  16. for (let i = 0, key; (key = keys[i]); i++) {
  17. this.add(key, store.store[key]);
  18. }
  19. }
  20. lookup(name) {
  21. return this.store[name];
  22. }
  23. checkCustomFunctionSyntax_(name) {
  24. const reg = new RegExp('^' + this.prefix);
  25. if (!name.match(reg)) {
  26. console.error('FunctionError: Invalid function name. Expected prefix ' + this.prefix);
  27. return false;
  28. }
  29. return true;
  30. }
  31. }
  32. class CustomQueries extends FunctionsStore {
  33. constructor() {
  34. const store = {};
  35. super('CQF', store);
  36. }
  37. }
  38. exports.CustomQueries = CustomQueries;
  39. class CustomStrings extends FunctionsStore {
  40. constructor() {
  41. const store = {};
  42. super('CSF', store);
  43. }
  44. }
  45. exports.CustomStrings = CustomStrings;
  46. class ContextFunctions extends FunctionsStore {
  47. constructor() {
  48. const store = {};
  49. super('CTF', store);
  50. }
  51. }
  52. exports.ContextFunctions = ContextFunctions;
  53. class CustomGenerators extends FunctionsStore {
  54. constructor() {
  55. const store = {};
  56. super('CGF', store);
  57. }
  58. }
  59. exports.CustomGenerators = CustomGenerators;