punctuation.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /** @typedef {import('./types').OfflinePunctuationHandle} OfflinePunctuationHandle */
  2. /** @typedef {import('./types').OfflinePunctuationConfig} OfflinePunctuationConfig */
  3. /** @typedef {import('./types').OnlinePunctuationConfig} OnlinePunctuationConfig */
  4. /** @typedef {import('./types').OnlinePunctuationHandle} OnlinePunctuationHandle */
  5. const addon = require('./addon.js');
  6. class OfflinePunctuation {
  7. /**
  8. * @param {OfflinePunctuationConfig} config
  9. */
  10. constructor(config) {
  11. this.handle = addon.createOfflinePunctuation(config);
  12. this.config = config;
  13. }
  14. /**
  15. * Add punctuation to `text` and return the punctuated text.
  16. * @param {string} text
  17. * @returns {string}
  18. */
  19. addPunct(text) {
  20. return addon.offlinePunctuationAddPunct(this.handle, text);
  21. }
  22. }
  23. class OnlinePunctuation {
  24. /**
  25. * @param {OnlinePunctuationConfig} config
  26. */
  27. constructor(config) {
  28. this.handle = addon.createOnlinePunctuation(config);
  29. this.config = config;
  30. }
  31. /** @param {string} text @returns {string} */
  32. addPunct(text) {
  33. return addon.onlinePunctuationAddPunct(this.handle, text);
  34. }
  35. }
  36. module.exports = {
  37. OfflinePunctuation,
  38. OnlinePunctuation,
  39. }