pronouny 0.1.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 ADDED
@@ -0,0 +1,50 @@
1
+ # Pronouny
2
+
3
+ **Pronouny** is a typed library intended to make programmatically resolving English pronouns easier. It does so by providing three classes: `Pronoun`, `PronounSet` and `Validate`, each with their respective uses.
4
+
5
+ ## Installation
6
+
7
+ To install, simply do `npm install pronouny`.
8
+
9
+ ## `Pronoun` class
10
+
11
+ This class is intended to define individual `Pronoun`s. It includes subject, object, possessive adjective, possessive, and reflexive pronouns. It also contains a set of methods for extending, removing, and getting a pronoun string.
12
+
13
+ ## `PronounSet` class
14
+
15
+ This class is intended to define `Pronoun`s for an individual or entity. It contains an array of `Pronoun`s, from which you can programmatically obtain a string using `use(type)`. `type` can be any of the five kinds from `Pronoun` (`sbj`, `obj`, `psAdj`, `psPrn`, and `rfx`).
16
+
17
+ ## `Validate` class
18
+
19
+ This class is intended to verify and retrieve correct pronouns. It is centered around the `pronounSet` map, which is used to validate and return a `Pronoun` object using `resolvePronouns()` or `resolvePronounsStrict()`.
20
+
21
+ ## Example
22
+
23
+ ```
24
+ import { Pronouny } from 'pronouny';
25
+
26
+ // Create a new instance of the Validate class
27
+ const pronounValidator = new Pronouny.Validate();
28
+
29
+ // Create a new Pronoun object for ze/hir pronouns
30
+ const pronounZe = new Pronouny.Pronoun(
31
+ 'ze', 'hir', 'hir', 'hirs', 'hirself'
32
+ );
33
+
34
+ // Add the pronoun to the pronounSet map
35
+ pronounValidator.extend( "ze", pronounZe );
36
+
37
+ // Set someone's pronouns.
38
+ const vayne = {
39
+ username: vaynegarden,
40
+ pronouns: pronounValidator.createSetFrom( "she/ze/they"),
41
+ }
42
+
43
+ // Resolve the pronouns in your app
44
+ console.log( vayne.username + " updated " +
45
+ vayne.pronouns.use( "psAdj" ) + " status." );
46
+ // Returns "vaynegarden updated her status", "vaynegarden
47
+ // updated hir status", or "vaynegarden updated their status",
48
+ // selected randomly among the three.
49
+
50
+ ```
@@ -0,0 +1,247 @@
1
+ /**# Pronouny
2
+ * A TypeScript library for pronoun validation and resolution.
3
+ */
4
+ export declare namespace Pronouny {
5
+ /**# Pronoun Class
6
+ * In order to construct a new `Pronoun`, you will need to pass in an
7
+ * object which contains at least one `subject` pronoun, one `object`
8
+ * pronoun, one `possessiveAdjective`, one `possessivePronoun`, and one
9
+ * `reflexive` pronoun. You may pass in a string (which will be
10
+ * automatically placed into an array of one) or an array.
11
+ *
12
+ * methods:
13
+ * * `new`: takes in an object containing the required pronouns.
14
+ * * `sbj`: returns subject pronouns. (e.g., he, she, they)
15
+ * * `obj`: returns object pronouns. (e.g., him, her, them)
16
+ * * `psAdj`: returns possessive adjectives (e.g., his, her, their)
17
+ * * `psPrn`: returns possessive pronouns (e.g., his, hers, theirs)
18
+ * * `rfx`: returns reflexive pronouns (e.g., himself, herself, themself)
19
+ */
20
+ class Pronoun {
21
+ subject: Array<string>;
22
+ object: Array<string>;
23
+ possessiveAdjective: Array<string>;
24
+ possessivePronoun: Array<string>;
25
+ reflexive: Array<string>;
26
+ /**
27
+ * # Pronoun Constructor
28
+ * In order to construct a new `Pronoun`, you will need to pass in an
29
+ * object which contains at least one `subject` pronoun, one `object`
30
+ * pronoun, one `possessiveAdjective`, one `possessivePronoun`, and one
31
+ * `reflexive` pronoun. You may pass in a string (which will be
32
+ * automatically placed into an array of one) or an array.
33
+ *
34
+ * @param pronouns
35
+ */
36
+ constructor(pronouns: {
37
+ subject: Array<string> | string;
38
+ object: Array<string> | string;
39
+ possessiveAdjective: Array<string> | string;
40
+ possessivePronoun: Array<string> | string;
41
+ reflexive: Array<string> | string;
42
+ });
43
+ /**## Subject Getter
44
+ * Retrieves a subject pronoun. If no index is provided, it will retrieve
45
+ * a random one from the array *(recommended)*.
46
+ *
47
+ * @throws if you index out of `subject` array length.
48
+ *
49
+ * @param index
50
+ * by default, selects randomly.
51
+ *
52
+ * @returns a string.
53
+ */
54
+ sbj(index?: number): string;
55
+ /**## Object Getter
56
+ * Retrieves an object pronoun. If no index is provided, it will retrieve
57
+ * a random one from the array *(recommended)*.
58
+ *
59
+ * @throws if you index out of `object` array length.
60
+ *
61
+ * @param index
62
+ * by default, selects randomly.
63
+ *
64
+ * @returns a string.
65
+ */
66
+ obj(index?: number): string;
67
+ /**## Possessive Adjective Getter
68
+ * Retrieves a possessive adjective pronoun. If no index is provided, it will retrieve
69
+ * a random one from the array *(recommended)*.
70
+ *
71
+ * @throws if you index out of `possessiveAdjective` array length.
72
+ *
73
+ * @param index
74
+ * by default, selects randomly.
75
+ *
76
+ * @returns a string.
77
+ */
78
+ psAdj(index?: number): string;
79
+ /**## Possessive Pronoun Getter
80
+ * Retrieves a possessive pronoun. If no index is provided, it will retrieve
81
+ * a random one from the array *(recommended)*.
82
+ *
83
+ * @throws if you index out of `possessivePronoun` array length.
84
+ *
85
+ * @param index
86
+ * by default, selects randomly.
87
+ *
88
+ * @returns a string.
89
+ */
90
+ psPrn(index?: number): string;
91
+ /**## Reflexive Pronoun Getter
92
+ * Retrieves a reflexive pronoun. If no index is provided, it will retrieve
93
+ * a random one from the array *(recommended)*.
94
+ *
95
+ * @throws if you index out of `reflexive` array length.
96
+ *
97
+ * @param index
98
+ * by default, selects randomly.
99
+ *
100
+ * @returns a string.
101
+ */
102
+ rfx(index?: number): string;
103
+ /**# Pronoun Extension
104
+ * Extend the set of Pronouns with new pronouns. You may pass in a
105
+ * string or an array of strings.
106
+ *
107
+ * @param pronounType
108
+ * Denotes which type of pronoun to extend. Can be `subject`, `object`,
109
+ * `possessiveAdjective`, `possessivePronoun`, or `reflexive`.
110
+ *
111
+ * @param extensions
112
+ * A string or array of strings to extend the pronoun set with.
113
+ */
114
+ extend(pronounType: "subject" | "object" | "possessiveAdjective" | "possessivePronoun" | "reflexive", extensions: string | Array<string>): void;
115
+ /**# Pronoun Removal
116
+ * Remove a pronoun from the set. You may pass in a string or
117
+ * an array of strings.
118
+ *
119
+ * @param pronounType
120
+ * Pronoun type to remove from. Can be `subject`, `object`,
121
+ * `possessiveAdjective`, `possessivePronoun`, or `reflexive`.
122
+ *
123
+ * @param removal
124
+ * Pronoun to remove from array. Can be a string or an array
125
+ * of strings.
126
+ */
127
+ remove(pronounType: "subject" | "object" | "possessiveAdjective" | "possessivePronoun" | "reflexive", removal: string | Array<string>): void;
128
+ }
129
+ /**# Pronoun Sets
130
+ * A class intended to define pronouns on a person.
131
+ */
132
+ class PronounSet {
133
+ pronouns: Array<Pronoun>;
134
+ /**# Pronoun Set Constructor
135
+ * Build a set of constructors either from an array of pronoun strings for resolution.
136
+ *
137
+ * @param validator
138
+ * Requires a `Pronouny.Validate` object to define valid pronouns for `PronounSet` construction.
139
+ *
140
+ * @param pronounString
141
+ * A string or array of strings for resolution. (e.g., "he/they", "she", "ze/faer")
142
+ *
143
+ * @param delimiter
144
+ * Defines the delimiter for string `pronounString`s.
145
+ *
146
+ * @param type
147
+ * Defines resolution type. `resolvePronoun` is recommended, though `resolvePronounStrict`
148
+ * will be faster if the format is well-defined.
149
+ */
150
+ constructor(validator: Validate, pronounString: string | Array<string>, delimiter?: string, type?: "resolvePronoun" | "resolvePronounStrict");
151
+ /**# Pronoun Retrieval
152
+ * Retrieves a pronoun from the given set.
153
+ *
154
+ * @param type
155
+ * Specifies the pronoun desired. Uses the same syntax as {@link Pronoun}'s getters.
156
+ * Use `sbj` for Subject, `obj` for Object, `psAdj` for Possessive Adjective, `psPrn`
157
+ * for Possessive Pronoun, and `rfx` for Reflexive.
158
+ *
159
+ * @param pronounIndex
160
+ * Specifies the index in the `PronounSet`. Defaults to a random one *(recommended)*.
161
+ *
162
+ * @param index
163
+ * Specifies the index in the `Pronoun`. Defaults to a random one *(recommended)*.
164
+ *
165
+ * @returns a string.
166
+ */
167
+ use(type: "sbj" | "obj" | "psAdj" | "psPrn" | "rfx", pronounIndex?: number, index?: number | undefined): string;
168
+ }
169
+ /**# Validator Class
170
+ * Validates and checks if the pronoun specified is valid. You may extend or
171
+ * remove Pronouns specified using the `extend()` or `remove()` methods.
172
+ */
173
+ class Validate {
174
+ pronounsSet: Map<string, Pronoun>;
175
+ /**# Validator Constructor
176
+ * Simply use `new Pronouny.Validate()` to create a new instance. It will
177
+ * be automatically populated with he, she, and they pronouns. Extend or
178
+ * otherwise modify it using `extend()` or `remove()`.
179
+ */
180
+ constructor();
181
+ /**# Pronoun Resolver
182
+ * Returns the Pronoun object for the given pronoun string. Will
183
+ * return `undefined` if the pronoun is not found.
184
+ *
185
+ * @param pronoun
186
+ * String to check for against `pronounsSet`.
187
+ *
188
+ * @returns a `Pronoun` object or `undefined`.
189
+ */
190
+ resolvePronoun(pronoun: string): Pronoun | undefined;
191
+ /**# Strict Pronoun Resolver
192
+ * Only checks the string against the `strictIdentifier` (usually
193
+ * the first subject pronoun). Returns the Pronoun object for the
194
+ * given pronoun string. Will return `undefined` if the pronoun is
195
+ * not found.
196
+ *
197
+ * @param pronoun
198
+ * String to check for against `pronounsSet`.
199
+ *
200
+ * @returns a `Pronoun` object or `undefined`.
201
+ */
202
+ resolvePronounStrict(pronoun: string): Pronoun | undefined;
203
+ /**# Pronoun Set Constructor
204
+ * Convenience method to build a `PronounSet` from a string or array of
205
+ * strings. You may specify a delimiter and resolution type.
206
+ *
207
+ * @param pronounString
208
+ * `string` or `Array<string>` to build the `PronounSet` from.
209
+ *
210
+ * @param delimiter
211
+ * delimiter to split the `pronounString` by.
212
+ *
213
+ * @param type
214
+ * determines the resolution type. `resolvePronoun` is recommended, though
215
+ * `resolvePronounStrict` will be faster if the format is well-defined.
216
+ *
217
+ * @returns a PronounSet.
218
+ */
219
+ createSetFrom(pronounString: string | Array<string>, delimiter?: string, type?: "resolvePronoun" | "resolvePronounStrict"): PronounSet;
220
+ /**# Pronoun Extension
221
+ * Extend the set of Pronouns with new pronouns. You may pass in a
222
+ * string or an array of strings.
223
+ *
224
+ * @param strictIdentifier
225
+ * The strict identifier for the pronoun set. Usually the first subject pronoun.
226
+ *
227
+ * @param pronoun
228
+ * A `Pronoun` object to extend the set with.
229
+ *
230
+ * @returns a `Pronoun` object.
231
+ */
232
+ extend(strictIdentifier: string, pronoun: Pronoun): void;
233
+ /**# Pronoun Removal
234
+ * Remove a `Pronoun` from the `pronounsSet` map. You may pass in a
235
+ * string or an array of strings.
236
+ *
237
+ * @param strictIdentifier
238
+ * The strict identifier for the pronoun set. Usually the first subject pronoun.
239
+ *
240
+ * @param pronoun
241
+ * A `Pronoun` object to extend the set with.
242
+ *
243
+ * @returns a `Pronoun` object.
244
+ */
245
+ remove(strictIdentifier: string, pronoun: Pronoun): void;
246
+ }
247
+ }
@@ -0,0 +1,396 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pronouny = void 0;
4
+ /**# Pronouny
5
+ * A TypeScript library for pronoun validation and resolution.
6
+ */
7
+ var Pronouny;
8
+ (function (Pronouny) {
9
+ /**# Pronoun Class
10
+ * In order to construct a new `Pronoun`, you will need to pass in an
11
+ * object which contains at least one `subject` pronoun, one `object`
12
+ * pronoun, one `possessiveAdjective`, one `possessivePronoun`, and one
13
+ * `reflexive` pronoun. You may pass in a string (which will be
14
+ * automatically placed into an array of one) or an array.
15
+ *
16
+ * methods:
17
+ * * `new`: takes in an object containing the required pronouns.
18
+ * * `sbj`: returns subject pronouns. (e.g., he, she, they)
19
+ * * `obj`: returns object pronouns. (e.g., him, her, them)
20
+ * * `psAdj`: returns possessive adjectives (e.g., his, her, their)
21
+ * * `psPrn`: returns possessive pronouns (e.g., his, hers, theirs)
22
+ * * `rfx`: returns reflexive pronouns (e.g., himself, herself, themself)
23
+ */
24
+ class Pronoun {
25
+ /**
26
+ * # Pronoun Constructor
27
+ * In order to construct a new `Pronoun`, you will need to pass in an
28
+ * object which contains at least one `subject` pronoun, one `object`
29
+ * pronoun, one `possessiveAdjective`, one `possessivePronoun`, and one
30
+ * `reflexive` pronoun. You may pass in a string (which will be
31
+ * automatically placed into an array of one) or an array.
32
+ *
33
+ * @param pronouns
34
+ */
35
+ constructor(pronouns) {
36
+ this.subject = [];
37
+ this.object = [];
38
+ this.possessiveAdjective = [];
39
+ this.possessivePronoun = [];
40
+ this.reflexive = [];
41
+ typeof pronouns.subject === "string"
42
+ ? (this.subject[0] = pronouns.subject)
43
+ : (this.subject = pronouns.subject);
44
+ typeof pronouns.object === "string"
45
+ ? (this.subject[0] = pronouns.object)
46
+ : (this.object = pronouns.object);
47
+ typeof pronouns.possessiveAdjective === "string"
48
+ ? (this.subject[0] = pronouns.possessiveAdjective)
49
+ : (this.possessiveAdjective = pronouns.possessiveAdjective);
50
+ typeof pronouns.possessivePronoun === "string"
51
+ ? (this.subject[0] = pronouns.possessivePronoun)
52
+ : (this.possessivePronoun = pronouns.possessivePronoun);
53
+ typeof pronouns.reflexive === "string"
54
+ ? (this.subject[0] = pronouns.reflexive)
55
+ : (this.reflexive = pronouns.reflexive);
56
+ }
57
+ /**## Subject Getter
58
+ * Retrieves a subject pronoun. If no index is provided, it will retrieve
59
+ * a random one from the array *(recommended)*.
60
+ *
61
+ * @throws if you index out of `subject` array length.
62
+ *
63
+ * @param index
64
+ * by default, selects randomly.
65
+ *
66
+ * @returns a string.
67
+ */
68
+ sbj(index = Math.floor(Math.random() * this.subject.length)) {
69
+ if (index >= this.subject.length) {
70
+ throw new Error("No subject pronoun at this index");
71
+ }
72
+ return this.subject[index];
73
+ }
74
+ /**## Object Getter
75
+ * Retrieves an object pronoun. If no index is provided, it will retrieve
76
+ * a random one from the array *(recommended)*.
77
+ *
78
+ * @throws if you index out of `object` array length.
79
+ *
80
+ * @param index
81
+ * by default, selects randomly.
82
+ *
83
+ * @returns a string.
84
+ */
85
+ obj(index = Math.floor(Math.random() * this.object.length)) {
86
+ if (index >= this.object.length) {
87
+ throw new Error("No object pronoun at this index");
88
+ }
89
+ return this.object[index];
90
+ }
91
+ /**## Possessive Adjective Getter
92
+ * Retrieves a possessive adjective pronoun. If no index is provided, it will retrieve
93
+ * a random one from the array *(recommended)*.
94
+ *
95
+ * @throws if you index out of `possessiveAdjective` array length.
96
+ *
97
+ * @param index
98
+ * by default, selects randomly.
99
+ *
100
+ * @returns a string.
101
+ */
102
+ psAdj(index = Math.floor(Math.random() * this.possessiveAdjective.length)) {
103
+ if (index >= this.possessiveAdjective.length) {
104
+ throw new Error("No possessive adjective at this index");
105
+ }
106
+ return this.possessiveAdjective[index];
107
+ }
108
+ /**## Possessive Pronoun Getter
109
+ * Retrieves a possessive pronoun. If no index is provided, it will retrieve
110
+ * a random one from the array *(recommended)*.
111
+ *
112
+ * @throws if you index out of `possessivePronoun` array length.
113
+ *
114
+ * @param index
115
+ * by default, selects randomly.
116
+ *
117
+ * @returns a string.
118
+ */
119
+ psPrn(index = Math.floor(Math.random() * this.possessivePronoun.length)) {
120
+ if (index >= this.possessivePronoun.length) {
121
+ throw new Error("No possessive pronoun at this index");
122
+ }
123
+ return this.possessivePronoun[index];
124
+ }
125
+ /**## Reflexive Pronoun Getter
126
+ * Retrieves a reflexive pronoun. If no index is provided, it will retrieve
127
+ * a random one from the array *(recommended)*.
128
+ *
129
+ * @throws if you index out of `reflexive` array length.
130
+ *
131
+ * @param index
132
+ * by default, selects randomly.
133
+ *
134
+ * @returns a string.
135
+ */
136
+ rfx(index = Math.floor(Math.random() * this.reflexive.length)) {
137
+ if (index >= this.reflexive.length) {
138
+ throw new Error("No reflexive pronoun at this index");
139
+ }
140
+ return this.reflexive[index];
141
+ }
142
+ /**# Pronoun Extension
143
+ * Extend the set of Pronouns with new pronouns. You may pass in a
144
+ * string or an array of strings.
145
+ *
146
+ * @param pronounType
147
+ * Denotes which type of pronoun to extend. Can be `subject`, `object`,
148
+ * `possessiveAdjective`, `possessivePronoun`, or `reflexive`.
149
+ *
150
+ * @param extensions
151
+ * A string or array of strings to extend the pronoun set with.
152
+ */
153
+ extend(pronounType, extensions) {
154
+ if (Array.isArray(extensions)) {
155
+ extensions.forEach((extension) => {
156
+ this[pronounType].push(extension);
157
+ });
158
+ }
159
+ else {
160
+ this[pronounType].push(extensions);
161
+ }
162
+ }
163
+ /**# Pronoun Removal
164
+ * Remove a pronoun from the set. You may pass in a string or
165
+ * an array of strings.
166
+ *
167
+ * @param pronounType
168
+ * Pronoun type to remove from. Can be `subject`, `object`,
169
+ * `possessiveAdjective`, `possessivePronoun`, or `reflexive`.
170
+ *
171
+ * @param removal
172
+ * Pronoun to remove from array. Can be a string or an array
173
+ * of strings.
174
+ */
175
+ remove(pronounType, removal) {
176
+ if (Array.isArray(removal)) {
177
+ removal.forEach((remove) => {
178
+ this[pronounType] = this[pronounType].filter((pronoun) => pronoun !== remove);
179
+ });
180
+ }
181
+ else {
182
+ this[pronounType] = this[pronounType].filter((pronoun) => pronoun !== removal);
183
+ }
184
+ }
185
+ }
186
+ Pronouny.Pronoun = Pronoun;
187
+ /**# Pronoun Sets
188
+ * A class intended to define pronouns on a person.
189
+ */
190
+ class PronounSet {
191
+ /**# Pronoun Set Constructor
192
+ * Build a set of constructors either from an array of pronoun strings for resolution.
193
+ *
194
+ * @param validator
195
+ * Requires a `Pronouny.Validate` object to define valid pronouns for `PronounSet` construction.
196
+ *
197
+ * @param pronounString
198
+ * A string or array of strings for resolution. (e.g., "he/they", "she", "ze/faer")
199
+ *
200
+ * @param delimiter
201
+ * Defines the delimiter for string `pronounString`s.
202
+ *
203
+ * @param type
204
+ * Defines resolution type. `resolvePronoun` is recommended, though `resolvePronounStrict`
205
+ * will be faster if the format is well-defined.
206
+ */
207
+ constructor(validator, pronounString, delimiter = "/", type = "resolvePronoun") {
208
+ let splitPronouns = pronounString;
209
+ if (!Array.isArray(pronounString)) {
210
+ splitPronouns = pronounString.split(delimiter);
211
+ }
212
+ const returnedPronouns = splitPronouns.map((pronoun) => {
213
+ const pronounResolved = validator[type](pronoun);
214
+ if (pronounResolved === undefined) {
215
+ throw new Error("Failed to resolve pronoun");
216
+ }
217
+ else {
218
+ return pronounResolved;
219
+ }
220
+ });
221
+ this.pronouns = returnedPronouns;
222
+ }
223
+ /**# Pronoun Retrieval
224
+ * Retrieves a pronoun from the given set.
225
+ *
226
+ * @param type
227
+ * Specifies the pronoun desired. Uses the same syntax as {@link Pronoun}'s getters.
228
+ * Use `sbj` for Subject, `obj` for Object, `psAdj` for Possessive Adjective, `psPrn`
229
+ * for Possessive Pronoun, and `rfx` for Reflexive.
230
+ *
231
+ * @param pronounIndex
232
+ * Specifies the index in the `PronounSet`. Defaults to a random one *(recommended)*.
233
+ *
234
+ * @param index
235
+ * Specifies the index in the `Pronoun`. Defaults to a random one *(recommended)*.
236
+ *
237
+ * @returns a string.
238
+ */
239
+ use(type, pronounIndex = Math.floor(Math.random() * this.pronouns.length), index = undefined) {
240
+ if (pronounIndex >= this.pronouns.length) {
241
+ throw new Error("No pronoun set at this index");
242
+ }
243
+ if (index === undefined) {
244
+ return this.pronouns[pronounIndex][type]();
245
+ }
246
+ return this.pronouns[pronounIndex][type](index);
247
+ }
248
+ }
249
+ Pronouny.PronounSet = PronounSet;
250
+ /**# Validator Class
251
+ * Validates and checks if the pronoun specified is valid. You may extend or
252
+ * remove Pronouns specified using the `extend()` or `remove()` methods.
253
+ */
254
+ class Validate {
255
+ /**# Validator Constructor
256
+ * Simply use `new Pronouny.Validate()` to create a new instance. It will
257
+ * be automatically populated with he, she, and they pronouns. Extend or
258
+ * otherwise modify it using `extend()` or `remove()`.
259
+ */
260
+ constructor() {
261
+ this.pronounsSet = new Map([
262
+ [
263
+ "he",
264
+ new Pronoun({
265
+ subject: ["he"],
266
+ object: ["him"],
267
+ possessiveAdjective: ["his"],
268
+ possessivePronoun: ["his"],
269
+ reflexive: ["himself"],
270
+ }),
271
+ ],
272
+ [
273
+ "she",
274
+ new Pronoun({
275
+ subject: ["she"],
276
+ object: ["her"],
277
+ possessiveAdjective: ["her"],
278
+ possessivePronoun: ["hers"],
279
+ reflexive: ["herself"],
280
+ }),
281
+ ],
282
+ [
283
+ "they",
284
+ new Pronoun({
285
+ subject: ["they"],
286
+ object: ["them"],
287
+ possessiveAdjective: ["their"],
288
+ possessivePronoun: ["theirs"],
289
+ reflexive: [
290
+ "themself",
291
+ "themselves",
292
+ "theirself",
293
+ "theirselves",
294
+ ],
295
+ }),
296
+ ],
297
+ ]);
298
+ }
299
+ /**# Pronoun Resolver
300
+ * Returns the Pronoun object for the given pronoun string. Will
301
+ * return `undefined` if the pronoun is not found.
302
+ *
303
+ * @param pronoun
304
+ * String to check for against `pronounsSet`.
305
+ *
306
+ * @returns a `Pronoun` object or `undefined`.
307
+ */
308
+ resolvePronoun(pronoun) {
309
+ let resolvedPronoun;
310
+ if (this.pronounsSet.has(pronoun)) {
311
+ resolvedPronoun = this.pronounsSet.get(pronoun);
312
+ }
313
+ else {
314
+ this.pronounsSet.forEach((pronounSet, pronounLead) => {
315
+ if (pronoun === pronounLead) {
316
+ resolvedPronoun = pronounSet;
317
+ }
318
+ else {
319
+ Object.values(pronounSet).forEach((subtype) => {
320
+ subtype.forEach((subtypeVariant) => {
321
+ if (subtypeVariant === pronoun) {
322
+ resolvedPronoun = pronounSet;
323
+ }
324
+ });
325
+ });
326
+ }
327
+ });
328
+ }
329
+ return resolvedPronoun;
330
+ }
331
+ /**# Strict Pronoun Resolver
332
+ * Only checks the string against the `strictIdentifier` (usually
333
+ * the first subject pronoun). Returns the Pronoun object for the
334
+ * given pronoun string. Will return `undefined` if the pronoun is
335
+ * not found.
336
+ *
337
+ * @param pronoun
338
+ * String to check for against `pronounsSet`.
339
+ *
340
+ * @returns a `Pronoun` object or `undefined`.
341
+ */
342
+ resolvePronounStrict(pronoun) {
343
+ return this.pronounsSet.get(pronoun);
344
+ }
345
+ /**# Pronoun Set Constructor
346
+ * Convenience method to build a `PronounSet` from a string or array of
347
+ * strings. You may specify a delimiter and resolution type.
348
+ *
349
+ * @param pronounString
350
+ * `string` or `Array<string>` to build the `PronounSet` from.
351
+ *
352
+ * @param delimiter
353
+ * delimiter to split the `pronounString` by.
354
+ *
355
+ * @param type
356
+ * determines the resolution type. `resolvePronoun` is recommended, though
357
+ * `resolvePronounStrict` will be faster if the format is well-defined.
358
+ *
359
+ * @returns a PronounSet.
360
+ */
361
+ createSetFrom(pronounString, delimiter = "/", type = "resolvePronoun") {
362
+ return new PronounSet(this, pronounString, delimiter, type);
363
+ }
364
+ /**# Pronoun Extension
365
+ * Extend the set of Pronouns with new pronouns. You may pass in a
366
+ * string or an array of strings.
367
+ *
368
+ * @param strictIdentifier
369
+ * The strict identifier for the pronoun set. Usually the first subject pronoun.
370
+ *
371
+ * @param pronoun
372
+ * A `Pronoun` object to extend the set with.
373
+ *
374
+ * @returns a `Pronoun` object.
375
+ */
376
+ extend(strictIdentifier, pronoun) {
377
+ this.pronounsSet.set(strictIdentifier, pronoun);
378
+ }
379
+ /**# Pronoun Removal
380
+ * Remove a `Pronoun` from the `pronounsSet` map. You may pass in a
381
+ * string or an array of strings.
382
+ *
383
+ * @param strictIdentifier
384
+ * The strict identifier for the pronoun set. Usually the first subject pronoun.
385
+ *
386
+ * @param pronoun
387
+ * A `Pronoun` object to extend the set with.
388
+ *
389
+ * @returns a `Pronoun` object.
390
+ */
391
+ remove(strictIdentifier, pronoun) {
392
+ this.pronounsSet.delete(strictIdentifier);
393
+ }
394
+ }
395
+ Pronouny.Validate = Validate;
396
+ })(Pronouny || (exports.Pronouny = Pronouny = {}));
@@ -0,0 +1,247 @@
1
+ /**# Pronouny
2
+ * A TypeScript library for pronoun validation and resolution.
3
+ */
4
+ export declare namespace Pronouny {
5
+ /**# Pronoun Class
6
+ * In order to construct a new `Pronoun`, you will need to pass in an
7
+ * object which contains at least one `subject` pronoun, one `object`
8
+ * pronoun, one `possessiveAdjective`, one `possessivePronoun`, and one
9
+ * `reflexive` pronoun. You may pass in a string (which will be
10
+ * automatically placed into an array of one) or an array.
11
+ *
12
+ * methods:
13
+ * * `new`: takes in an object containing the required pronouns.
14
+ * * `sbj`: returns subject pronouns. (e.g., he, she, they)
15
+ * * `obj`: returns object pronouns. (e.g., him, her, them)
16
+ * * `psAdj`: returns possessive adjectives (e.g., his, her, their)
17
+ * * `psPrn`: returns possessive pronouns (e.g., his, hers, theirs)
18
+ * * `rfx`: returns reflexive pronouns (e.g., himself, herself, themself)
19
+ */
20
+ class Pronoun {
21
+ subject: Array<string>;
22
+ object: Array<string>;
23
+ possessiveAdjective: Array<string>;
24
+ possessivePronoun: Array<string>;
25
+ reflexive: Array<string>;
26
+ /**
27
+ * # Pronoun Constructor
28
+ * In order to construct a new `Pronoun`, you will need to pass in an
29
+ * object which contains at least one `subject` pronoun, one `object`
30
+ * pronoun, one `possessiveAdjective`, one `possessivePronoun`, and one
31
+ * `reflexive` pronoun. You may pass in a string (which will be
32
+ * automatically placed into an array of one) or an array.
33
+ *
34
+ * @param pronouns
35
+ */
36
+ constructor(pronouns: {
37
+ subject: Array<string> | string;
38
+ object: Array<string> | string;
39
+ possessiveAdjective: Array<string> | string;
40
+ possessivePronoun: Array<string> | string;
41
+ reflexive: Array<string> | string;
42
+ });
43
+ /**## Subject Getter
44
+ * Retrieves a subject pronoun. If no index is provided, it will retrieve
45
+ * a random one from the array *(recommended)*.
46
+ *
47
+ * @throws if you index out of `subject` array length.
48
+ *
49
+ * @param index
50
+ * by default, selects randomly.
51
+ *
52
+ * @returns a string.
53
+ */
54
+ sbj(index?: number): string;
55
+ /**## Object Getter
56
+ * Retrieves an object pronoun. If no index is provided, it will retrieve
57
+ * a random one from the array *(recommended)*.
58
+ *
59
+ * @throws if you index out of `object` array length.
60
+ *
61
+ * @param index
62
+ * by default, selects randomly.
63
+ *
64
+ * @returns a string.
65
+ */
66
+ obj(index?: number): string;
67
+ /**## Possessive Adjective Getter
68
+ * Retrieves a possessive adjective pronoun. If no index is provided, it will retrieve
69
+ * a random one from the array *(recommended)*.
70
+ *
71
+ * @throws if you index out of `possessiveAdjective` array length.
72
+ *
73
+ * @param index
74
+ * by default, selects randomly.
75
+ *
76
+ * @returns a string.
77
+ */
78
+ psAdj(index?: number): string;
79
+ /**## Possessive Pronoun Getter
80
+ * Retrieves a possessive pronoun. If no index is provided, it will retrieve
81
+ * a random one from the array *(recommended)*.
82
+ *
83
+ * @throws if you index out of `possessivePronoun` array length.
84
+ *
85
+ * @param index
86
+ * by default, selects randomly.
87
+ *
88
+ * @returns a string.
89
+ */
90
+ psPrn(index?: number): string;
91
+ /**## Reflexive Pronoun Getter
92
+ * Retrieves a reflexive pronoun. If no index is provided, it will retrieve
93
+ * a random one from the array *(recommended)*.
94
+ *
95
+ * @throws if you index out of `reflexive` array length.
96
+ *
97
+ * @param index
98
+ * by default, selects randomly.
99
+ *
100
+ * @returns a string.
101
+ */
102
+ rfx(index?: number): string;
103
+ /**# Pronoun Extension
104
+ * Extend the set of Pronouns with new pronouns. You may pass in a
105
+ * string or an array of strings.
106
+ *
107
+ * @param pronounType
108
+ * Denotes which type of pronoun to extend. Can be `subject`, `object`,
109
+ * `possessiveAdjective`, `possessivePronoun`, or `reflexive`.
110
+ *
111
+ * @param extensions
112
+ * A string or array of strings to extend the pronoun set with.
113
+ */
114
+ extend(pronounType: "subject" | "object" | "possessiveAdjective" | "possessivePronoun" | "reflexive", extensions: string | Array<string>): void;
115
+ /**# Pronoun Removal
116
+ * Remove a pronoun from the set. You may pass in a string or
117
+ * an array of strings.
118
+ *
119
+ * @param pronounType
120
+ * Pronoun type to remove from. Can be `subject`, `object`,
121
+ * `possessiveAdjective`, `possessivePronoun`, or `reflexive`.
122
+ *
123
+ * @param removal
124
+ * Pronoun to remove from array. Can be a string or an array
125
+ * of strings.
126
+ */
127
+ remove(pronounType: "subject" | "object" | "possessiveAdjective" | "possessivePronoun" | "reflexive", removal: string | Array<string>): void;
128
+ }
129
+ /**# Pronoun Sets
130
+ * A class intended to define pronouns on a person.
131
+ */
132
+ class PronounSet {
133
+ pronouns: Array<Pronoun>;
134
+ /**# Pronoun Set Constructor
135
+ * Build a set of constructors either from an array of pronoun strings for resolution.
136
+ *
137
+ * @param validator
138
+ * Requires a `Pronouny.Validate` object to define valid pronouns for `PronounSet` construction.
139
+ *
140
+ * @param pronounString
141
+ * A string or array of strings for resolution. (e.g., "he/they", "she", "ze/faer")
142
+ *
143
+ * @param delimiter
144
+ * Defines the delimiter for string `pronounString`s.
145
+ *
146
+ * @param type
147
+ * Defines resolution type. `resolvePronoun` is recommended, though `resolvePronounStrict`
148
+ * will be faster if the format is well-defined.
149
+ */
150
+ constructor(validator: Validate, pronounString: string | Array<string>, delimiter?: string, type?: "resolvePronoun" | "resolvePronounStrict");
151
+ /**# Pronoun Retrieval
152
+ * Retrieves a pronoun from the given set.
153
+ *
154
+ * @param type
155
+ * Specifies the pronoun desired. Uses the same syntax as {@link Pronoun}'s getters.
156
+ * Use `sbj` for Subject, `obj` for Object, `psAdj` for Possessive Adjective, `psPrn`
157
+ * for Possessive Pronoun, and `rfx` for Reflexive.
158
+ *
159
+ * @param pronounIndex
160
+ * Specifies the index in the `PronounSet`. Defaults to a random one *(recommended)*.
161
+ *
162
+ * @param index
163
+ * Specifies the index in the `Pronoun`. Defaults to a random one *(recommended)*.
164
+ *
165
+ * @returns a string.
166
+ */
167
+ use(type: "sbj" | "obj" | "psAdj" | "psPrn" | "rfx", pronounIndex?: number, index?: number | undefined): string;
168
+ }
169
+ /**# Validator Class
170
+ * Validates and checks if the pronoun specified is valid. You may extend or
171
+ * remove Pronouns specified using the `extend()` or `remove()` methods.
172
+ */
173
+ class Validate {
174
+ pronounsSet: Map<string, Pronoun>;
175
+ /**# Validator Constructor
176
+ * Simply use `new Pronouny.Validate()` to create a new instance. It will
177
+ * be automatically populated with he, she, and they pronouns. Extend or
178
+ * otherwise modify it using `extend()` or `remove()`.
179
+ */
180
+ constructor();
181
+ /**# Pronoun Resolver
182
+ * Returns the Pronoun object for the given pronoun string. Will
183
+ * return `undefined` if the pronoun is not found.
184
+ *
185
+ * @param pronoun
186
+ * String to check for against `pronounsSet`.
187
+ *
188
+ * @returns a `Pronoun` object or `undefined`.
189
+ */
190
+ resolvePronoun(pronoun: string): Pronoun | undefined;
191
+ /**# Strict Pronoun Resolver
192
+ * Only checks the string against the `strictIdentifier` (usually
193
+ * the first subject pronoun). Returns the Pronoun object for the
194
+ * given pronoun string. Will return `undefined` if the pronoun is
195
+ * not found.
196
+ *
197
+ * @param pronoun
198
+ * String to check for against `pronounsSet`.
199
+ *
200
+ * @returns a `Pronoun` object or `undefined`.
201
+ */
202
+ resolvePronounStrict(pronoun: string): Pronoun | undefined;
203
+ /**# Pronoun Set Constructor
204
+ * Convenience method to build a `PronounSet` from a string or array of
205
+ * strings. You may specify a delimiter and resolution type.
206
+ *
207
+ * @param pronounString
208
+ * `string` or `Array<string>` to build the `PronounSet` from.
209
+ *
210
+ * @param delimiter
211
+ * delimiter to split the `pronounString` by.
212
+ *
213
+ * @param type
214
+ * determines the resolution type. `resolvePronoun` is recommended, though
215
+ * `resolvePronounStrict` will be faster if the format is well-defined.
216
+ *
217
+ * @returns a PronounSet.
218
+ */
219
+ createSetFrom(pronounString: string | Array<string>, delimiter?: string, type?: "resolvePronoun" | "resolvePronounStrict"): PronounSet;
220
+ /**# Pronoun Extension
221
+ * Extend the set of Pronouns with new pronouns. You may pass in a
222
+ * string or an array of strings.
223
+ *
224
+ * @param strictIdentifier
225
+ * The strict identifier for the pronoun set. Usually the first subject pronoun.
226
+ *
227
+ * @param pronoun
228
+ * A `Pronoun` object to extend the set with.
229
+ *
230
+ * @returns a `Pronoun` object.
231
+ */
232
+ extend(strictIdentifier: string, pronoun: Pronoun): void;
233
+ /**# Pronoun Removal
234
+ * Remove a `Pronoun` from the `pronounsSet` map. You may pass in a
235
+ * string or an array of strings.
236
+ *
237
+ * @param strictIdentifier
238
+ * The strict identifier for the pronoun set. Usually the first subject pronoun.
239
+ *
240
+ * @param pronoun
241
+ * A `Pronoun` object to extend the set with.
242
+ *
243
+ * @returns a `Pronoun` object.
244
+ */
245
+ remove(strictIdentifier: string, pronoun: Pronoun): void;
246
+ }
247
+ }
@@ -0,0 +1,393 @@
1
+ /**# Pronouny
2
+ * A TypeScript library for pronoun validation and resolution.
3
+ */
4
+ export var Pronouny;
5
+ (function (Pronouny) {
6
+ /**# Pronoun Class
7
+ * In order to construct a new `Pronoun`, you will need to pass in an
8
+ * object which contains at least one `subject` pronoun, one `object`
9
+ * pronoun, one `possessiveAdjective`, one `possessivePronoun`, and one
10
+ * `reflexive` pronoun. You may pass in a string (which will be
11
+ * automatically placed into an array of one) or an array.
12
+ *
13
+ * methods:
14
+ * * `new`: takes in an object containing the required pronouns.
15
+ * * `sbj`: returns subject pronouns. (e.g., he, she, they)
16
+ * * `obj`: returns object pronouns. (e.g., him, her, them)
17
+ * * `psAdj`: returns possessive adjectives (e.g., his, her, their)
18
+ * * `psPrn`: returns possessive pronouns (e.g., his, hers, theirs)
19
+ * * `rfx`: returns reflexive pronouns (e.g., himself, herself, themself)
20
+ */
21
+ class Pronoun {
22
+ /**
23
+ * # Pronoun Constructor
24
+ * In order to construct a new `Pronoun`, you will need to pass in an
25
+ * object which contains at least one `subject` pronoun, one `object`
26
+ * pronoun, one `possessiveAdjective`, one `possessivePronoun`, and one
27
+ * `reflexive` pronoun. You may pass in a string (which will be
28
+ * automatically placed into an array of one) or an array.
29
+ *
30
+ * @param pronouns
31
+ */
32
+ constructor(pronouns) {
33
+ this.subject = [];
34
+ this.object = [];
35
+ this.possessiveAdjective = [];
36
+ this.possessivePronoun = [];
37
+ this.reflexive = [];
38
+ typeof pronouns.subject === "string"
39
+ ? (this.subject[0] = pronouns.subject)
40
+ : (this.subject = pronouns.subject);
41
+ typeof pronouns.object === "string"
42
+ ? (this.subject[0] = pronouns.object)
43
+ : (this.object = pronouns.object);
44
+ typeof pronouns.possessiveAdjective === "string"
45
+ ? (this.subject[0] = pronouns.possessiveAdjective)
46
+ : (this.possessiveAdjective = pronouns.possessiveAdjective);
47
+ typeof pronouns.possessivePronoun === "string"
48
+ ? (this.subject[0] = pronouns.possessivePronoun)
49
+ : (this.possessivePronoun = pronouns.possessivePronoun);
50
+ typeof pronouns.reflexive === "string"
51
+ ? (this.subject[0] = pronouns.reflexive)
52
+ : (this.reflexive = pronouns.reflexive);
53
+ }
54
+ /**## Subject Getter
55
+ * Retrieves a subject pronoun. If no index is provided, it will retrieve
56
+ * a random one from the array *(recommended)*.
57
+ *
58
+ * @throws if you index out of `subject` array length.
59
+ *
60
+ * @param index
61
+ * by default, selects randomly.
62
+ *
63
+ * @returns a string.
64
+ */
65
+ sbj(index = Math.floor(Math.random() * this.subject.length)) {
66
+ if (index >= this.subject.length) {
67
+ throw new Error("No subject pronoun at this index");
68
+ }
69
+ return this.subject[index];
70
+ }
71
+ /**## Object Getter
72
+ * Retrieves an object pronoun. If no index is provided, it will retrieve
73
+ * a random one from the array *(recommended)*.
74
+ *
75
+ * @throws if you index out of `object` array length.
76
+ *
77
+ * @param index
78
+ * by default, selects randomly.
79
+ *
80
+ * @returns a string.
81
+ */
82
+ obj(index = Math.floor(Math.random() * this.object.length)) {
83
+ if (index >= this.object.length) {
84
+ throw new Error("No object pronoun at this index");
85
+ }
86
+ return this.object[index];
87
+ }
88
+ /**## Possessive Adjective Getter
89
+ * Retrieves a possessive adjective pronoun. If no index is provided, it will retrieve
90
+ * a random one from the array *(recommended)*.
91
+ *
92
+ * @throws if you index out of `possessiveAdjective` array length.
93
+ *
94
+ * @param index
95
+ * by default, selects randomly.
96
+ *
97
+ * @returns a string.
98
+ */
99
+ psAdj(index = Math.floor(Math.random() * this.possessiveAdjective.length)) {
100
+ if (index >= this.possessiveAdjective.length) {
101
+ throw new Error("No possessive adjective at this index");
102
+ }
103
+ return this.possessiveAdjective[index];
104
+ }
105
+ /**## Possessive Pronoun Getter
106
+ * Retrieves a possessive pronoun. If no index is provided, it will retrieve
107
+ * a random one from the array *(recommended)*.
108
+ *
109
+ * @throws if you index out of `possessivePronoun` array length.
110
+ *
111
+ * @param index
112
+ * by default, selects randomly.
113
+ *
114
+ * @returns a string.
115
+ */
116
+ psPrn(index = Math.floor(Math.random() * this.possessivePronoun.length)) {
117
+ if (index >= this.possessivePronoun.length) {
118
+ throw new Error("No possessive pronoun at this index");
119
+ }
120
+ return this.possessivePronoun[index];
121
+ }
122
+ /**## Reflexive Pronoun Getter
123
+ * Retrieves a reflexive pronoun. If no index is provided, it will retrieve
124
+ * a random one from the array *(recommended)*.
125
+ *
126
+ * @throws if you index out of `reflexive` array length.
127
+ *
128
+ * @param index
129
+ * by default, selects randomly.
130
+ *
131
+ * @returns a string.
132
+ */
133
+ rfx(index = Math.floor(Math.random() * this.reflexive.length)) {
134
+ if (index >= this.reflexive.length) {
135
+ throw new Error("No reflexive pronoun at this index");
136
+ }
137
+ return this.reflexive[index];
138
+ }
139
+ /**# Pronoun Extension
140
+ * Extend the set of Pronouns with new pronouns. You may pass in a
141
+ * string or an array of strings.
142
+ *
143
+ * @param pronounType
144
+ * Denotes which type of pronoun to extend. Can be `subject`, `object`,
145
+ * `possessiveAdjective`, `possessivePronoun`, or `reflexive`.
146
+ *
147
+ * @param extensions
148
+ * A string or array of strings to extend the pronoun set with.
149
+ */
150
+ extend(pronounType, extensions) {
151
+ if (Array.isArray(extensions)) {
152
+ extensions.forEach((extension) => {
153
+ this[pronounType].push(extension);
154
+ });
155
+ }
156
+ else {
157
+ this[pronounType].push(extensions);
158
+ }
159
+ }
160
+ /**# Pronoun Removal
161
+ * Remove a pronoun from the set. You may pass in a string or
162
+ * an array of strings.
163
+ *
164
+ * @param pronounType
165
+ * Pronoun type to remove from. Can be `subject`, `object`,
166
+ * `possessiveAdjective`, `possessivePronoun`, or `reflexive`.
167
+ *
168
+ * @param removal
169
+ * Pronoun to remove from array. Can be a string or an array
170
+ * of strings.
171
+ */
172
+ remove(pronounType, removal) {
173
+ if (Array.isArray(removal)) {
174
+ removal.forEach((remove) => {
175
+ this[pronounType] = this[pronounType].filter((pronoun) => pronoun !== remove);
176
+ });
177
+ }
178
+ else {
179
+ this[pronounType] = this[pronounType].filter((pronoun) => pronoun !== removal);
180
+ }
181
+ }
182
+ }
183
+ Pronouny.Pronoun = Pronoun;
184
+ /**# Pronoun Sets
185
+ * A class intended to define pronouns on a person.
186
+ */
187
+ class PronounSet {
188
+ /**# Pronoun Set Constructor
189
+ * Build a set of constructors either from an array of pronoun strings for resolution.
190
+ *
191
+ * @param validator
192
+ * Requires a `Pronouny.Validate` object to define valid pronouns for `PronounSet` construction.
193
+ *
194
+ * @param pronounString
195
+ * A string or array of strings for resolution. (e.g., "he/they", "she", "ze/faer")
196
+ *
197
+ * @param delimiter
198
+ * Defines the delimiter for string `pronounString`s.
199
+ *
200
+ * @param type
201
+ * Defines resolution type. `resolvePronoun` is recommended, though `resolvePronounStrict`
202
+ * will be faster if the format is well-defined.
203
+ */
204
+ constructor(validator, pronounString, delimiter = "/", type = "resolvePronoun") {
205
+ let splitPronouns = pronounString;
206
+ if (!Array.isArray(pronounString)) {
207
+ splitPronouns = pronounString.split(delimiter);
208
+ }
209
+ const returnedPronouns = splitPronouns.map((pronoun) => {
210
+ const pronounResolved = validator[type](pronoun);
211
+ if (pronounResolved === undefined) {
212
+ throw new Error("Failed to resolve pronoun");
213
+ }
214
+ else {
215
+ return pronounResolved;
216
+ }
217
+ });
218
+ this.pronouns = returnedPronouns;
219
+ }
220
+ /**# Pronoun Retrieval
221
+ * Retrieves a pronoun from the given set.
222
+ *
223
+ * @param type
224
+ * Specifies the pronoun desired. Uses the same syntax as {@link Pronoun}'s getters.
225
+ * Use `sbj` for Subject, `obj` for Object, `psAdj` for Possessive Adjective, `psPrn`
226
+ * for Possessive Pronoun, and `rfx` for Reflexive.
227
+ *
228
+ * @param pronounIndex
229
+ * Specifies the index in the `PronounSet`. Defaults to a random one *(recommended)*.
230
+ *
231
+ * @param index
232
+ * Specifies the index in the `Pronoun`. Defaults to a random one *(recommended)*.
233
+ *
234
+ * @returns a string.
235
+ */
236
+ use(type, pronounIndex = Math.floor(Math.random() * this.pronouns.length), index = undefined) {
237
+ if (pronounIndex >= this.pronouns.length) {
238
+ throw new Error("No pronoun set at this index");
239
+ }
240
+ if (index === undefined) {
241
+ return this.pronouns[pronounIndex][type]();
242
+ }
243
+ return this.pronouns[pronounIndex][type](index);
244
+ }
245
+ }
246
+ Pronouny.PronounSet = PronounSet;
247
+ /**# Validator Class
248
+ * Validates and checks if the pronoun specified is valid. You may extend or
249
+ * remove Pronouns specified using the `extend()` or `remove()` methods.
250
+ */
251
+ class Validate {
252
+ /**# Validator Constructor
253
+ * Simply use `new Pronouny.Validate()` to create a new instance. It will
254
+ * be automatically populated with he, she, and they pronouns. Extend or
255
+ * otherwise modify it using `extend()` or `remove()`.
256
+ */
257
+ constructor() {
258
+ this.pronounsSet = new Map([
259
+ [
260
+ "he",
261
+ new Pronoun({
262
+ subject: ["he"],
263
+ object: ["him"],
264
+ possessiveAdjective: ["his"],
265
+ possessivePronoun: ["his"],
266
+ reflexive: ["himself"],
267
+ }),
268
+ ],
269
+ [
270
+ "she",
271
+ new Pronoun({
272
+ subject: ["she"],
273
+ object: ["her"],
274
+ possessiveAdjective: ["her"],
275
+ possessivePronoun: ["hers"],
276
+ reflexive: ["herself"],
277
+ }),
278
+ ],
279
+ [
280
+ "they",
281
+ new Pronoun({
282
+ subject: ["they"],
283
+ object: ["them"],
284
+ possessiveAdjective: ["their"],
285
+ possessivePronoun: ["theirs"],
286
+ reflexive: [
287
+ "themself",
288
+ "themselves",
289
+ "theirself",
290
+ "theirselves",
291
+ ],
292
+ }),
293
+ ],
294
+ ]);
295
+ }
296
+ /**# Pronoun Resolver
297
+ * Returns the Pronoun object for the given pronoun string. Will
298
+ * return `undefined` if the pronoun is not found.
299
+ *
300
+ * @param pronoun
301
+ * String to check for against `pronounsSet`.
302
+ *
303
+ * @returns a `Pronoun` object or `undefined`.
304
+ */
305
+ resolvePronoun(pronoun) {
306
+ let resolvedPronoun;
307
+ if (this.pronounsSet.has(pronoun)) {
308
+ resolvedPronoun = this.pronounsSet.get(pronoun);
309
+ }
310
+ else {
311
+ this.pronounsSet.forEach((pronounSet, pronounLead) => {
312
+ if (pronoun === pronounLead) {
313
+ resolvedPronoun = pronounSet;
314
+ }
315
+ else {
316
+ Object.values(pronounSet).forEach((subtype) => {
317
+ subtype.forEach((subtypeVariant) => {
318
+ if (subtypeVariant === pronoun) {
319
+ resolvedPronoun = pronounSet;
320
+ }
321
+ });
322
+ });
323
+ }
324
+ });
325
+ }
326
+ return resolvedPronoun;
327
+ }
328
+ /**# Strict Pronoun Resolver
329
+ * Only checks the string against the `strictIdentifier` (usually
330
+ * the first subject pronoun). Returns the Pronoun object for the
331
+ * given pronoun string. Will return `undefined` if the pronoun is
332
+ * not found.
333
+ *
334
+ * @param pronoun
335
+ * String to check for against `pronounsSet`.
336
+ *
337
+ * @returns a `Pronoun` object or `undefined`.
338
+ */
339
+ resolvePronounStrict(pronoun) {
340
+ return this.pronounsSet.get(pronoun);
341
+ }
342
+ /**# Pronoun Set Constructor
343
+ * Convenience method to build a `PronounSet` from a string or array of
344
+ * strings. You may specify a delimiter and resolution type.
345
+ *
346
+ * @param pronounString
347
+ * `string` or `Array<string>` to build the `PronounSet` from.
348
+ *
349
+ * @param delimiter
350
+ * delimiter to split the `pronounString` by.
351
+ *
352
+ * @param type
353
+ * determines the resolution type. `resolvePronoun` is recommended, though
354
+ * `resolvePronounStrict` will be faster if the format is well-defined.
355
+ *
356
+ * @returns a PronounSet.
357
+ */
358
+ createSetFrom(pronounString, delimiter = "/", type = "resolvePronoun") {
359
+ return new PronounSet(this, pronounString, delimiter, type);
360
+ }
361
+ /**# Pronoun Extension
362
+ * Extend the set of Pronouns with new pronouns. You may pass in a
363
+ * string or an array of strings.
364
+ *
365
+ * @param strictIdentifier
366
+ * The strict identifier for the pronoun set. Usually the first subject pronoun.
367
+ *
368
+ * @param pronoun
369
+ * A `Pronoun` object to extend the set with.
370
+ *
371
+ * @returns a `Pronoun` object.
372
+ */
373
+ extend(strictIdentifier, pronoun) {
374
+ this.pronounsSet.set(strictIdentifier, pronoun);
375
+ }
376
+ /**# Pronoun Removal
377
+ * Remove a `Pronoun` from the `pronounsSet` map. You may pass in a
378
+ * string or an array of strings.
379
+ *
380
+ * @param strictIdentifier
381
+ * The strict identifier for the pronoun set. Usually the first subject pronoun.
382
+ *
383
+ * @param pronoun
384
+ * A `Pronoun` object to extend the set with.
385
+ *
386
+ * @returns a `Pronoun` object.
387
+ */
388
+ remove(strictIdentifier, pronoun) {
389
+ this.pronounsSet.delete(strictIdentifier);
390
+ }
391
+ }
392
+ Pronouny.Validate = Validate;
393
+ })(Pronouny || (Pronouny = {}));
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "pronouny",
3
+ "version": "0.1.0",
4
+ "description": "a small, typed utility library to determine the correct pronoun from a string and several utility functions.",
5
+ "main": "./lib/cjs/index.js",
6
+ "module": "./lib/esm/index.js",
7
+ "files": [
8
+ "lib/"
9
+ ],
10
+ "scripts": {
11
+ "test": "tsc -p tsconfig.json && node ./lib/cjs/index.js",
12
+ "tsc": "tsc -p tsconfig.json && tsc -p tsconfig-cjs.json",
13
+ "prepublishOnly": "npm run tsc"
14
+ },
15
+ "author": "",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "typescript": "^5.3.3"
19
+ }
20
+ }