pronouny 0.3.1 → 0.4.0
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/README.md +12 -3
- package/lib/cjs/index.d.ts +26 -12
- package/lib/cjs/index.js +24 -20
- package/lib/esm/index.d.ts +26 -12
- package/lib/esm/index.js +24 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Pronouny
|
|
2
2
|
|
|
3
|
-
**Pronouny** is a typed library intended to make programmatically resolving English pronouns easier.
|
|
3
|
+
**Pronouny** is a typed library intended to make programmatically resolving English pronouns easier.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -26,6 +26,9 @@ const p = new Pronouny({
|
|
|
26
26
|
// Will default to using random pronouns in arrays.
|
|
27
27
|
// Set to false to force using 0 index.
|
|
28
28
|
useRandom: true,
|
|
29
|
+
|
|
30
|
+
// Will default to using "they" as a fallback pronoun.
|
|
31
|
+
fallbackPronoun: "they",
|
|
29
32
|
});
|
|
30
33
|
|
|
31
34
|
// Create a new Pronoun object using Pronouny.new()
|
|
@@ -49,7 +52,7 @@ p.add(pronounZe);
|
|
|
49
52
|
p.remove(p.resolve("I"));
|
|
50
53
|
// this deletes the "I" pronoun from the map.
|
|
51
54
|
|
|
52
|
-
// Methods are chainable
|
|
55
|
+
// Methods are chainable so you can reach the Pronoun class.
|
|
53
56
|
p.add(pronounZe).set("he/they").use().subject();
|
|
54
57
|
// ^Pronouny ^PronounSet ^Pronoun ^string
|
|
55
58
|
|
|
@@ -58,7 +61,7 @@ const vayne = {
|
|
|
58
61
|
username: "vaynegarden",
|
|
59
62
|
pronouns: p.set("she/ze/they"),
|
|
60
63
|
};
|
|
61
|
-
// from there, you can use `[PronounSet].use()` to get a random
|
|
64
|
+
// from there, you can use `[PronounSet].use()` to get a random `Pronoun`.
|
|
62
65
|
|
|
63
66
|
// Resolve the pronouns in your app by referencing the form
|
|
64
67
|
// that you need. There's `subject`, `object`, `possessive`,
|
|
@@ -73,6 +76,12 @@ console.log(
|
|
|
73
76
|
|
|
74
77
|
## Changelog
|
|
75
78
|
|
|
79
|
+
### v0.4.0
|
|
80
|
+
|
|
81
|
+
- Optimized `forEach()` calls to use `for` loops instead.
|
|
82
|
+
- Added `fallbackPronoun` option to allow for configuration of pronoun to use in case of quiet failure states.
|
|
83
|
+
- Removed redundant `set` parameter from `[PronounSet].remove()` calls.
|
|
84
|
+
|
|
76
85
|
### v0.3.1
|
|
77
86
|
|
|
78
87
|
- Added documentation.
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -140,7 +140,7 @@ declare class PronounSet {
|
|
|
140
140
|
* @param failQuietly
|
|
141
141
|
* Override default behavior to fail into 'they'.
|
|
142
142
|
*/
|
|
143
|
-
add(pronoun: string | Pronoun | Array<string> | Array<Pronoun>, failQuietly?: boolean
|
|
143
|
+
add(pronoun: string | Pronoun | Array<string> | Array<Pronoun>, failQuietly?: boolean): this;
|
|
144
144
|
/**# `.remove()` from PronounSet
|
|
145
145
|
* Remove pronoun/s from a given Pronoun or strings
|
|
146
146
|
* (resolved using the {@linkcode Pronouny} instance
|
|
@@ -153,7 +153,7 @@ declare class PronounSet {
|
|
|
153
153
|
* @param failQuietly
|
|
154
154
|
* Override default behavior to fail into no removal.
|
|
155
155
|
*/
|
|
156
|
-
remove(
|
|
156
|
+
remove(pronoun: string | Pronoun | Array<string> | Array<Pronoun>, failQuietly?: boolean): this;
|
|
157
157
|
/**# `.use()` a PronounSet
|
|
158
158
|
* A method to retrieve one Pronoun at random. Use with
|
|
159
159
|
* {@link Pronoun|`Pronoun` methods} to get a specific
|
|
@@ -174,17 +174,17 @@ declare class PronounSet {
|
|
|
174
174
|
* Override default behavior to use random as per
|
|
175
175
|
* Pronouny config.
|
|
176
176
|
*/
|
|
177
|
-
use(index?: number, failQuietly?: boolean
|
|
177
|
+
use(index?: number, failQuietly?: boolean, useRandom?: boolean): Pronoun;
|
|
178
178
|
/**Retrieves a random subject pronoun. */
|
|
179
|
-
subject(index?: number, failQuietly?: boolean
|
|
179
|
+
subject(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
|
|
180
180
|
/**Retrieves a random object pronoun. */
|
|
181
|
-
object(index?: number, failQuietly?: boolean
|
|
181
|
+
object(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
|
|
182
182
|
/**Retrieves a random possessive pronoun. */
|
|
183
|
-
possessive(index?: number, failQuietly?: boolean
|
|
183
|
+
possessive(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
|
|
184
184
|
/**Retrieves a random possessive adjective pronoun. */
|
|
185
|
-
psAdjective(index?: number, failQuietly?: boolean
|
|
185
|
+
psAdjective(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
|
|
186
186
|
/**Retrieves a random reflexive pronoun. */
|
|
187
|
-
reflexive(index?: number, failQuietly?: boolean
|
|
187
|
+
reflexive(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
|
|
188
188
|
}
|
|
189
189
|
/**# Config
|
|
190
190
|
* `failQuietly`: Controls various quiet failure states.
|
|
@@ -197,19 +197,33 @@ declare class PronounSet {
|
|
|
197
197
|
* used. If false, it will default to 0. If failing
|
|
198
198
|
* quietly and indexing out of bounds, it will use the
|
|
199
199
|
* last item.
|
|
200
|
+
*
|
|
201
|
+
* `fallbackPronoun`: Controls what is considered the
|
|
202
|
+
* default pronoun for when one is not assigned or for
|
|
203
|
+
* quiet failure states. By default, this is `they`. **It
|
|
204
|
+
* is not recommended to change this.**
|
|
200
205
|
*/
|
|
201
206
|
type PronounyConfig = {
|
|
202
207
|
/**Controls various quiet failure states. */
|
|
203
|
-
failQuietly
|
|
208
|
+
failQuietly: boolean;
|
|
204
209
|
/**Controls how deeply Pronouny will search for
|
|
205
210
|
* queries. By default, `string` parameters will
|
|
206
211
|
* only resolve using the first subject pronoun. */
|
|
207
|
-
deepSearch
|
|
212
|
+
deepSearch: boolean;
|
|
208
213
|
/**Controls whether random selection will be used.
|
|
209
214
|
* If false, it will default to 0. If failing
|
|
210
215
|
* quietly and indexing out of bounds, it will
|
|
211
216
|
* use the last item. */
|
|
212
|
-
useRandom
|
|
217
|
+
useRandom: boolean;
|
|
218
|
+
/**Controls what is considered the default pronoun
|
|
219
|
+
* for when one is not assigned or for quiet failure
|
|
220
|
+
* states. By default, this is `they`. **It is not
|
|
221
|
+
* recommended to change this.**
|
|
222
|
+
*
|
|
223
|
+
* If you remove `they` from the Pronouny instance,
|
|
224
|
+
* you are responsible for setting this to a valid
|
|
225
|
+
* pronoun string and ensuring it will resolve. */
|
|
226
|
+
fallbackPronoun: string;
|
|
213
227
|
};
|
|
214
228
|
/**# Pronouny
|
|
215
229
|
* A typed library intended to make English pronoun
|
|
@@ -244,7 +258,7 @@ export default class Pronouny {
|
|
|
244
258
|
* Pronouny's config to determine the depth of search.
|
|
245
259
|
* By default, only checks the first subject pronoun.
|
|
246
260
|
*/
|
|
247
|
-
resolve(pronoun: string, deepSearch?: boolean
|
|
261
|
+
resolve(pronoun: string, deepSearch?: boolean): Pronoun;
|
|
248
262
|
/**# `.add()` an Unlisted Pronoun
|
|
249
263
|
* If you made a `.new()` Pronoun but disabled
|
|
250
264
|
* `autoAppend`, you can later append it back by
|
package/lib/cjs/index.js
CHANGED
|
@@ -216,27 +216,27 @@ class PronounSet {
|
|
|
216
216
|
this.resolver = resolver;
|
|
217
217
|
switch (true) {
|
|
218
218
|
case Array.isArray(pronouns):
|
|
219
|
-
|
|
219
|
+
for (const x of pronouns) {
|
|
220
220
|
if (x instanceof Pronoun) {
|
|
221
221
|
this.pronouns.add(x);
|
|
222
222
|
}
|
|
223
223
|
else {
|
|
224
224
|
this.pronouns.add(resolver.resolve(x));
|
|
225
225
|
}
|
|
226
|
-
}
|
|
226
|
+
}
|
|
227
227
|
break;
|
|
228
228
|
case typeof pronouns === "string":
|
|
229
229
|
this.pronouns.add(resolver.resolve(pronouns));
|
|
230
230
|
break;
|
|
231
231
|
default:
|
|
232
|
-
|
|
232
|
+
for (const x of pronouns) {
|
|
233
233
|
if (x instanceof Pronoun) {
|
|
234
234
|
this.pronouns.add(x);
|
|
235
235
|
}
|
|
236
236
|
else {
|
|
237
237
|
this.pronouns.add(resolver.resolve(x));
|
|
238
238
|
}
|
|
239
|
-
}
|
|
239
|
+
}
|
|
240
240
|
break;
|
|
241
241
|
}
|
|
242
242
|
return this;
|
|
@@ -262,12 +262,12 @@ class PronounSet {
|
|
|
262
262
|
this.pronouns.add(this.resolver.resolve(pronoun));
|
|
263
263
|
break;
|
|
264
264
|
case pronoun instanceof Array:
|
|
265
|
-
|
|
265
|
+
for (const p of pronoun) {
|
|
266
266
|
this.add(p, failQuietly);
|
|
267
|
-
}
|
|
267
|
+
}
|
|
268
268
|
break;
|
|
269
269
|
case failQuietly:
|
|
270
|
-
this.pronouns.add(this.resolver.resolve(
|
|
270
|
+
this.pronouns.add(this.resolver.resolve(this.resolver.config.fallbackPronoun));
|
|
271
271
|
break;
|
|
272
272
|
case !failQuietly:
|
|
273
273
|
default:
|
|
@@ -287,18 +287,18 @@ class PronounSet {
|
|
|
287
287
|
* @param failQuietly
|
|
288
288
|
* Override default behavior to fail into no removal.
|
|
289
289
|
*/
|
|
290
|
-
remove(
|
|
290
|
+
remove(pronoun, failQuietly = this.resolver.config.failQuietly) {
|
|
291
291
|
switch (true) {
|
|
292
292
|
case pronoun instanceof Pronoun:
|
|
293
|
-
|
|
293
|
+
this.pronouns.delete(pronoun);
|
|
294
294
|
break;
|
|
295
295
|
case typeof pronoun === "string":
|
|
296
|
-
|
|
296
|
+
this.pronouns.delete(this.resolver.resolve(pronoun));
|
|
297
297
|
break;
|
|
298
298
|
case pronoun instanceof Array:
|
|
299
|
-
|
|
300
|
-
this.remove(
|
|
301
|
-
}
|
|
299
|
+
for (const p of pronoun) {
|
|
300
|
+
this.remove(p);
|
|
301
|
+
}
|
|
302
302
|
break;
|
|
303
303
|
case failQuietly:
|
|
304
304
|
break;
|
|
@@ -346,7 +346,7 @@ class PronounSet {
|
|
|
346
346
|
case indexable[index] !== undefined:
|
|
347
347
|
return indexable[index];
|
|
348
348
|
case failQuietly:
|
|
349
|
-
return this.resolver.resolve(
|
|
349
|
+
return this.resolver.resolve(this.resolver.config.fallbackPronoun);
|
|
350
350
|
default:
|
|
351
351
|
throw new Error(`Index ${index} out of range`);
|
|
352
352
|
}
|
|
@@ -418,6 +418,7 @@ const PronounyDefaultConfig = {
|
|
|
418
418
|
failQuietly: true,
|
|
419
419
|
deepSearch: false,
|
|
420
420
|
useRandom: true,
|
|
421
|
+
fallbackPronoun: "they",
|
|
421
422
|
};
|
|
422
423
|
/**# Pronouny
|
|
423
424
|
* A typed library intended to make English pronoun
|
|
@@ -468,18 +469,18 @@ class Pronouny {
|
|
|
468
469
|
return resolvedPronoun;
|
|
469
470
|
case deepSearch:
|
|
470
471
|
let searchResult;
|
|
471
|
-
this.resolveMap
|
|
472
|
-
Object.values(
|
|
472
|
+
for (const [_, value] of this.resolveMap) {
|
|
473
|
+
for (const type of Object.values(value)) {
|
|
473
474
|
if (type.includes(pronoun)) {
|
|
474
|
-
searchResult =
|
|
475
|
+
searchResult = value;
|
|
475
476
|
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
478
479
|
if (searchResult) {
|
|
479
480
|
return searchResult;
|
|
480
481
|
}
|
|
481
482
|
case this.config.failQuietly:
|
|
482
|
-
return this.resolveMap.get(
|
|
483
|
+
return this.resolveMap.get(this.config.fallbackPronoun);
|
|
483
484
|
default:
|
|
484
485
|
throw new Error(`Pronoun "${pronoun}" not found`);
|
|
485
486
|
}
|
|
@@ -498,6 +499,9 @@ class Pronouny {
|
|
|
498
499
|
* Pronouny instance. Returns `Pronouny`.
|
|
499
500
|
*/
|
|
500
501
|
remove(pronoun) {
|
|
502
|
+
if (pronoun === this.resolveMap.get(this.config.fallbackPronoun)) {
|
|
503
|
+
throw new Error(`Cannot remove fallback pronoun. Assign a new one before removal.`);
|
|
504
|
+
}
|
|
501
505
|
this.resolveMap.delete(pronoun.sbj[0]);
|
|
502
506
|
return this;
|
|
503
507
|
}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -140,7 +140,7 @@ declare class PronounSet {
|
|
|
140
140
|
* @param failQuietly
|
|
141
141
|
* Override default behavior to fail into 'they'.
|
|
142
142
|
*/
|
|
143
|
-
add(pronoun: string | Pronoun | Array<string> | Array<Pronoun>, failQuietly?: boolean
|
|
143
|
+
add(pronoun: string | Pronoun | Array<string> | Array<Pronoun>, failQuietly?: boolean): this;
|
|
144
144
|
/**# `.remove()` from PronounSet
|
|
145
145
|
* Remove pronoun/s from a given Pronoun or strings
|
|
146
146
|
* (resolved using the {@linkcode Pronouny} instance
|
|
@@ -153,7 +153,7 @@ declare class PronounSet {
|
|
|
153
153
|
* @param failQuietly
|
|
154
154
|
* Override default behavior to fail into no removal.
|
|
155
155
|
*/
|
|
156
|
-
remove(
|
|
156
|
+
remove(pronoun: string | Pronoun | Array<string> | Array<Pronoun>, failQuietly?: boolean): this;
|
|
157
157
|
/**# `.use()` a PronounSet
|
|
158
158
|
* A method to retrieve one Pronoun at random. Use with
|
|
159
159
|
* {@link Pronoun|`Pronoun` methods} to get a specific
|
|
@@ -174,17 +174,17 @@ declare class PronounSet {
|
|
|
174
174
|
* Override default behavior to use random as per
|
|
175
175
|
* Pronouny config.
|
|
176
176
|
*/
|
|
177
|
-
use(index?: number, failQuietly?: boolean
|
|
177
|
+
use(index?: number, failQuietly?: boolean, useRandom?: boolean): Pronoun;
|
|
178
178
|
/**Retrieves a random subject pronoun. */
|
|
179
|
-
subject(index?: number, failQuietly?: boolean
|
|
179
|
+
subject(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
|
|
180
180
|
/**Retrieves a random object pronoun. */
|
|
181
|
-
object(index?: number, failQuietly?: boolean
|
|
181
|
+
object(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
|
|
182
182
|
/**Retrieves a random possessive pronoun. */
|
|
183
|
-
possessive(index?: number, failQuietly?: boolean
|
|
183
|
+
possessive(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
|
|
184
184
|
/**Retrieves a random possessive adjective pronoun. */
|
|
185
|
-
psAdjective(index?: number, failQuietly?: boolean
|
|
185
|
+
psAdjective(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
|
|
186
186
|
/**Retrieves a random reflexive pronoun. */
|
|
187
|
-
reflexive(index?: number, failQuietly?: boolean
|
|
187
|
+
reflexive(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
|
|
188
188
|
}
|
|
189
189
|
/**# Config
|
|
190
190
|
* `failQuietly`: Controls various quiet failure states.
|
|
@@ -197,19 +197,33 @@ declare class PronounSet {
|
|
|
197
197
|
* used. If false, it will default to 0. If failing
|
|
198
198
|
* quietly and indexing out of bounds, it will use the
|
|
199
199
|
* last item.
|
|
200
|
+
*
|
|
201
|
+
* `fallbackPronoun`: Controls what is considered the
|
|
202
|
+
* default pronoun for when one is not assigned or for
|
|
203
|
+
* quiet failure states. By default, this is `they`. **It
|
|
204
|
+
* is not recommended to change this.**
|
|
200
205
|
*/
|
|
201
206
|
type PronounyConfig = {
|
|
202
207
|
/**Controls various quiet failure states. */
|
|
203
|
-
failQuietly
|
|
208
|
+
failQuietly: boolean;
|
|
204
209
|
/**Controls how deeply Pronouny will search for
|
|
205
210
|
* queries. By default, `string` parameters will
|
|
206
211
|
* only resolve using the first subject pronoun. */
|
|
207
|
-
deepSearch
|
|
212
|
+
deepSearch: boolean;
|
|
208
213
|
/**Controls whether random selection will be used.
|
|
209
214
|
* If false, it will default to 0. If failing
|
|
210
215
|
* quietly and indexing out of bounds, it will
|
|
211
216
|
* use the last item. */
|
|
212
|
-
useRandom
|
|
217
|
+
useRandom: boolean;
|
|
218
|
+
/**Controls what is considered the default pronoun
|
|
219
|
+
* for when one is not assigned or for quiet failure
|
|
220
|
+
* states. By default, this is `they`. **It is not
|
|
221
|
+
* recommended to change this.**
|
|
222
|
+
*
|
|
223
|
+
* If you remove `they` from the Pronouny instance,
|
|
224
|
+
* you are responsible for setting this to a valid
|
|
225
|
+
* pronoun string and ensuring it will resolve. */
|
|
226
|
+
fallbackPronoun: string;
|
|
213
227
|
};
|
|
214
228
|
/**# Pronouny
|
|
215
229
|
* A typed library intended to make English pronoun
|
|
@@ -244,7 +258,7 @@ export default class Pronouny {
|
|
|
244
258
|
* Pronouny's config to determine the depth of search.
|
|
245
259
|
* By default, only checks the first subject pronoun.
|
|
246
260
|
*/
|
|
247
|
-
resolve(pronoun: string, deepSearch?: boolean
|
|
261
|
+
resolve(pronoun: string, deepSearch?: boolean): Pronoun;
|
|
248
262
|
/**# `.add()` an Unlisted Pronoun
|
|
249
263
|
* If you made a `.new()` Pronoun but disabled
|
|
250
264
|
* `autoAppend`, you can later append it back by
|
package/lib/esm/index.js
CHANGED
|
@@ -214,27 +214,27 @@ class PronounSet {
|
|
|
214
214
|
this.resolver = resolver;
|
|
215
215
|
switch (true) {
|
|
216
216
|
case Array.isArray(pronouns):
|
|
217
|
-
|
|
217
|
+
for (const x of pronouns) {
|
|
218
218
|
if (x instanceof Pronoun) {
|
|
219
219
|
this.pronouns.add(x);
|
|
220
220
|
}
|
|
221
221
|
else {
|
|
222
222
|
this.pronouns.add(resolver.resolve(x));
|
|
223
223
|
}
|
|
224
|
-
}
|
|
224
|
+
}
|
|
225
225
|
break;
|
|
226
226
|
case typeof pronouns === "string":
|
|
227
227
|
this.pronouns.add(resolver.resolve(pronouns));
|
|
228
228
|
break;
|
|
229
229
|
default:
|
|
230
|
-
|
|
230
|
+
for (const x of pronouns) {
|
|
231
231
|
if (x instanceof Pronoun) {
|
|
232
232
|
this.pronouns.add(x);
|
|
233
233
|
}
|
|
234
234
|
else {
|
|
235
235
|
this.pronouns.add(resolver.resolve(x));
|
|
236
236
|
}
|
|
237
|
-
}
|
|
237
|
+
}
|
|
238
238
|
break;
|
|
239
239
|
}
|
|
240
240
|
return this;
|
|
@@ -260,12 +260,12 @@ class PronounSet {
|
|
|
260
260
|
this.pronouns.add(this.resolver.resolve(pronoun));
|
|
261
261
|
break;
|
|
262
262
|
case pronoun instanceof Array:
|
|
263
|
-
|
|
263
|
+
for (const p of pronoun) {
|
|
264
264
|
this.add(p, failQuietly);
|
|
265
|
-
}
|
|
265
|
+
}
|
|
266
266
|
break;
|
|
267
267
|
case failQuietly:
|
|
268
|
-
this.pronouns.add(this.resolver.resolve(
|
|
268
|
+
this.pronouns.add(this.resolver.resolve(this.resolver.config.fallbackPronoun));
|
|
269
269
|
break;
|
|
270
270
|
case !failQuietly:
|
|
271
271
|
default:
|
|
@@ -285,18 +285,18 @@ class PronounSet {
|
|
|
285
285
|
* @param failQuietly
|
|
286
286
|
* Override default behavior to fail into no removal.
|
|
287
287
|
*/
|
|
288
|
-
remove(
|
|
288
|
+
remove(pronoun, failQuietly = this.resolver.config.failQuietly) {
|
|
289
289
|
switch (true) {
|
|
290
290
|
case pronoun instanceof Pronoun:
|
|
291
|
-
|
|
291
|
+
this.pronouns.delete(pronoun);
|
|
292
292
|
break;
|
|
293
293
|
case typeof pronoun === "string":
|
|
294
|
-
|
|
294
|
+
this.pronouns.delete(this.resolver.resolve(pronoun));
|
|
295
295
|
break;
|
|
296
296
|
case pronoun instanceof Array:
|
|
297
|
-
|
|
298
|
-
this.remove(
|
|
299
|
-
}
|
|
297
|
+
for (const p of pronoun) {
|
|
298
|
+
this.remove(p);
|
|
299
|
+
}
|
|
300
300
|
break;
|
|
301
301
|
case failQuietly:
|
|
302
302
|
break;
|
|
@@ -344,7 +344,7 @@ class PronounSet {
|
|
|
344
344
|
case indexable[index] !== undefined:
|
|
345
345
|
return indexable[index];
|
|
346
346
|
case failQuietly:
|
|
347
|
-
return this.resolver.resolve(
|
|
347
|
+
return this.resolver.resolve(this.resolver.config.fallbackPronoun);
|
|
348
348
|
default:
|
|
349
349
|
throw new Error(`Index ${index} out of range`);
|
|
350
350
|
}
|
|
@@ -416,6 +416,7 @@ const PronounyDefaultConfig = {
|
|
|
416
416
|
failQuietly: true,
|
|
417
417
|
deepSearch: false,
|
|
418
418
|
useRandom: true,
|
|
419
|
+
fallbackPronoun: "they",
|
|
419
420
|
};
|
|
420
421
|
/**# Pronouny
|
|
421
422
|
* A typed library intended to make English pronoun
|
|
@@ -466,18 +467,18 @@ export default class Pronouny {
|
|
|
466
467
|
return resolvedPronoun;
|
|
467
468
|
case deepSearch:
|
|
468
469
|
let searchResult;
|
|
469
|
-
this.resolveMap
|
|
470
|
-
Object.values(
|
|
470
|
+
for (const [_, value] of this.resolveMap) {
|
|
471
|
+
for (const type of Object.values(value)) {
|
|
471
472
|
if (type.includes(pronoun)) {
|
|
472
|
-
searchResult =
|
|
473
|
+
searchResult = value;
|
|
473
474
|
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
475
|
+
}
|
|
476
|
+
}
|
|
476
477
|
if (searchResult) {
|
|
477
478
|
return searchResult;
|
|
478
479
|
}
|
|
479
480
|
case this.config.failQuietly:
|
|
480
|
-
return this.resolveMap.get(
|
|
481
|
+
return this.resolveMap.get(this.config.fallbackPronoun);
|
|
481
482
|
default:
|
|
482
483
|
throw new Error(`Pronoun "${pronoun}" not found`);
|
|
483
484
|
}
|
|
@@ -496,6 +497,9 @@ export default class Pronouny {
|
|
|
496
497
|
* Pronouny instance. Returns `Pronouny`.
|
|
497
498
|
*/
|
|
498
499
|
remove(pronoun) {
|
|
500
|
+
if (pronoun === this.resolveMap.get(this.config.fallbackPronoun)) {
|
|
501
|
+
throw new Error(`Cannot remove fallback pronoun. Assign a new one before removal.`);
|
|
502
|
+
}
|
|
499
503
|
this.resolveMap.delete(pronoun.sbj[0]);
|
|
500
504
|
return this;
|
|
501
505
|
}
|
package/package.json
CHANGED