rita 3.0.8 → 3.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rita.js CHANGED
@@ -5,9 +5,6 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
 
8
- // src/rita.js
9
- import RiScript from "riscript";
10
-
11
8
  // src/stemmer.js
12
9
  var SnowballStemmer = class {
13
10
  constructor() {
@@ -4789,6 +4786,9 @@ var Util = class _Util {
4789
4786
  static isNum(n) {
4790
4787
  return !isNaN(parseFloat(n)) && isFinite(n);
4791
4788
  }
4789
+ static numOpt(opts, name, def = 0) {
4790
+ return _Util.isNum(opts?.[name]) ? opts[name] : def;
4791
+ }
4792
4792
  };
4793
4793
  var RE2 = class {
4794
4794
  constructor(regex2, offset, suffix) {
@@ -26971,41 +26971,8 @@ var Lexicon = class {
26971
26971
  }
26972
26972
  return false;
26973
26973
  }
26974
- /*findStem(word) { // JC: what is this function doing?
26975
-
26976
- let part = word;
26977
- let dict = this.data;
26978
- let words = Object.keys(dict);
26979
-
26980
- while (part.length > 1) {
26981
-
26982
- let pattern = new RegExp('^' + part);
26983
- let guess = words.filter(w => pattern.test(w));
26984
- if (guess && guess.length) {
26985
-
26986
- // always look for shorter words first
26987
- guess.sort((a, b) => a.length - b.length);
26988
-
26989
- // look for words stem(b)===a
26990
- for (let i = 0; i < guess.length; i++) {
26991
- if (this.RiTa.stem(guess[i]) === word) {
26992
- return guess[i];
26993
- }
26994
- }
26995
- }
26996
- part = part.slice(0, -1);
26997
- }
26998
-
26999
- return undefined;
27000
- }*/
27001
- async alliterations(theWord, opts = {}) {
27002
- return new Promise((resolve, reject) => {
27003
- try {
27004
- resolve(this.alliterationsSync(theWord, opts));
27005
- } catch (e) {
27006
- reject(e);
27007
- }
27008
- });
26974
+ async alliterations(word, options = {}) {
26975
+ return this._promise(this.alliterationsSync, [word, options]);
27009
26976
  }
27010
26977
  alliterationsSync(theWord, opts = {}) {
27011
26978
  this._parseArgs(opts);
@@ -27052,14 +27019,8 @@ var Lexicon = class {
27052
27019
  }
27053
27020
  return result;
27054
27021
  }
27055
- async rhymes(theWord, opts = {}) {
27056
- return new Promise((resolve, reject) => {
27057
- try {
27058
- resolve(this.rhymesSync(theWord, opts));
27059
- } catch (e) {
27060
- reject(e);
27061
- }
27062
- });
27022
+ async rhymes(word, options = {}) {
27023
+ return this._promise(this.rhymesSync, [word, options]);
27063
27024
  }
27064
27025
  rhymesSync(theWord, opts = {}) {
27065
27026
  this._parseArgs(opts);
@@ -27097,13 +27058,7 @@ var Lexicon = class {
27097
27058
  return result;
27098
27059
  }
27099
27060
  async spellsLike(word, options = {}) {
27100
- return new Promise((resolve, reject) => {
27101
- try {
27102
- resolve(this.spellsLikeSync(word, options));
27103
- } catch (e) {
27104
- reject(e);
27105
- }
27106
- });
27061
+ return this._promise(this.spellsLikeSync, [word, options]);
27107
27062
  }
27108
27063
  spellsLikeSync(word, options = {}) {
27109
27064
  if (!word || !word.length)
@@ -27112,13 +27067,7 @@ var Lexicon = class {
27112
27067
  return this._byTypeSync(word, options);
27113
27068
  }
27114
27069
  async soundsLike(word, options = {}) {
27115
- return new Promise((resolve, reject) => {
27116
- try {
27117
- resolve(this.soundsLikeSync(word, options));
27118
- } catch (e) {
27119
- reject(e);
27120
- }
27121
- });
27070
+ return this._promise(this.soundsLikeSync, [word, options]);
27122
27071
  }
27123
27072
  soundsLikeSync(word, opts = {}) {
27124
27073
  if (!word || !word.length)
@@ -27137,9 +27086,10 @@ var Lexicon = class {
27137
27086
  }
27138
27087
  }
27139
27088
  opts = opts || {};
27140
- opts.strictPos = true;
27141
- opts.shuffle = true;
27142
27089
  opts.limit = 1;
27090
+ opts.shuffle = true;
27091
+ opts.strictPos = true;
27092
+ opts.minLength = util_default.numOpt(opts, "minLength", 4);
27143
27093
  let result = this.searchSync(regex2, opts);
27144
27094
  if (result.length < 1 && opts.hasOwnProperty("pos")) {
27145
27095
  opts.strictPos = false;
@@ -27152,13 +27102,7 @@ var Lexicon = class {
27152
27102
  return result[0];
27153
27103
  }
27154
27104
  async search(pattern, options) {
27155
- return new Promise((resolve, reject) => {
27156
- try {
27157
- resolve(this.searchSync(pattern, options));
27158
- } catch (e) {
27159
- reject(e);
27160
- }
27161
- });
27105
+ return this._promise(this.searchSync, [pattern, options]);
27162
27106
  }
27163
27107
  searchSync(pattern, options) {
27164
27108
  let words = Object.keys(this.data);
@@ -27209,15 +27153,6 @@ var Lexicon = class {
27209
27153
  return dict ? Object.keys(dict).length : 0;
27210
27154
  }
27211
27155
  //////////////////////////// helpers /////////////////////////////////
27212
- // async similarByType(pattern, options) {
27213
- // return new Promise((resolve, reject) => {
27214
- // try {
27215
- // resolve(this.similarByTypeSync(pattern, options));
27216
- // } catch (e) {
27217
- // reject(e);
27218
- // }
27219
- // });
27220
- // }
27221
27156
  _byTypeSync(theWord, opts) {
27222
27157
  this._parseArgs(opts);
27223
27158
  const dict = this.data;
@@ -27302,14 +27237,13 @@ var Lexicon = class {
27302
27237
  // Handles: pos, limit, numSyllables, minLength, maxLength
27303
27238
  // potentially appends pluralize, conjugate, targetPos
27304
27239
  _parseArgs(opts) {
27305
- opts.limit = opts.limit || 10;
27306
- opts.minDistance = opts.minDistance || 1;
27307
- opts.numSyllables = opts.numSyllables || 0;
27308
- opts.maxLength = opts.maxLength || Number.MAX_SAFE_INTEGER;
27309
- opts.minLength = opts.minLength || 3;
27310
- if (typeof opts.limit !== "number" || opts.limit < 1) {
27240
+ opts.limit = util_default.numOpt(opts, "limit", 10);
27241
+ opts.minDistance = util_default.numOpt(opts, "minDistance", 1);
27242
+ opts.numSyllables = util_default.numOpt(opts, "numSyllables", 0);
27243
+ opts.maxLength = util_default.numOpt(opts, "maxLength", Number.MAX_SAFE_INTEGER);
27244
+ opts.minLength = util_default.numOpt(opts, "minLength", 3);
27245
+ if (opts.limit < 1)
27311
27246
  opts.limit = Number.MAX_SAFE_INTEGER;
27312
- }
27313
27247
  let tpos = opts.pos || false;
27314
27248
  if (tpos && tpos.length) {
27315
27249
  opts.pluralize = tpos === "nns";
@@ -27352,13 +27286,7 @@ var Lexicon = class {
27352
27286
  }
27353
27287
  async _bySoundAndLetter(word, opts) {
27354
27288
  let types = ["sound", "letter"];
27355
- let promises = types.map((type) => new Promise((resolve, reject) => {
27356
- try {
27357
- resolve(this._byTypeSync(word, { ...opts, type }));
27358
- } catch (e) {
27359
- reject(e);
27360
- }
27361
- }));
27289
+ let promises = types.map((type) => this._promise(this._byTypeSync, [word, { ...opts, type }]));
27362
27290
  let results = await Promise.allSettled(promises);
27363
27291
  let [bySound, byLetter] = results.map((r) => r.value);
27364
27292
  if (bySound.length < 1 || byLetter.length < 1)
@@ -27407,6 +27335,15 @@ var Lexicon = class {
27407
27335
  return w.endsWith("ness") || w.endsWith("ism") || pos.indexOf("vbg") > 0 || util_default.MASS_NOUNS.includes(w);
27408
27336
  }
27409
27337
  // helpers ---------------------------------------------------------------
27338
+ _promise(fun, args) {
27339
+ return new Promise((resolve, reject) => {
27340
+ try {
27341
+ resolve(fun.apply(this, args));
27342
+ } catch (e) {
27343
+ reject(e);
27344
+ }
27345
+ });
27346
+ }
27410
27347
  _parseRegex(regex2, opts) {
27411
27348
  if (typeof regex2 === "string") {
27412
27349
  if (opts && opts.type === "stresses") {
@@ -42494,6 +42431,7 @@ var MULTI_SP_RE = / +/g;
42494
42431
  var markov_default = RiMarkov;
42495
42432
 
42496
42433
  // src/rita.js
42434
+ import { RiScript } from "riscript";
42497
42435
  var { Grammar: RiGrammar } = RiScript;
42498
42436
  var RiTa2 = class _RiTa {
42499
42437
  static grammar(rules, context) {
@@ -42685,7 +42623,7 @@ RiTa2.SILENT = false;
42685
42623
  RiTa2.SILENCE_LTS = false;
42686
42624
  RiTa2.CDN = "https://www.unpkg.com/rita/";
42687
42625
  RiTa2.PHONES = ["aa", "ae", "ah", "ao", "aw", "ay", "b", "ch", "d", "dh", "eh", "er", "ey", "f", "g", "hh", "ih", "iy", "jh", "k", "l", "m", "n", "ng", "ow", "oy", "p", "r", "s", "sh", "t", "th", "uh", "uw", "v", "w", "y", "z", "zh"];
42688
- RiTa2.VERSION = "3.0.8";
42626
+ RiTa2.VERSION = "3.0.13";
42689
42627
  RiTa2.HAS_LEXICON = typeof __NOLEX__ === "undefined";
42690
42628
  RiTa2.FIRST = 1;
42691
42629
  RiTa2.SECOND = 2;
@@ -42715,8 +42653,7 @@ var ONLY_PUNCT = /^[\p{P}|\+|-|<|>|\^|\$|\ufffd|`]*$/u;
42715
42653
  var IS_LETTER = /^[a-z\u00C0-\u00ff]+$/;
42716
42654
  RiTa2.RiScript = RiScript;
42717
42655
  RiScript.RiTa = RiTa2;
42718
- var rita_default = RiTa2;
42719
42656
  export {
42720
- rita_default as default
42657
+ RiTa2 as RiTa
42721
42658
  };
42722
42659
  //# sourceMappingURL=rita.js.map