pronouny 0.3.0 → 0.3.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Pronouny
2
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.
3
+ **Pronouny** is a typed library intended to make programmatically resolving English pronouns easier. \
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,12 +10,12 @@ To install, simply run `npm install pronouny`.
10
10
 
11
11
  ```ts
12
12
  // Single import
13
- import Pronouny from 'pronouny';
13
+ import Pronouny from "pronouny";
14
14
 
15
- // Create a new instance of the Validate class
16
- // All options are optional
15
+ // Create a new instance of Pronouny. All config is optional.
16
+ // Below are defaults.
17
17
  const p = new Pronouny({
18
- // Will default to failing quietly into "they"
18
+ // Will default to failing quietly into "they".
19
19
  failQuietly: true,
20
20
 
21
21
  // Will default to only querying the first subject
@@ -29,13 +29,16 @@ const p = new Pronouny({
29
29
  });
30
30
 
31
31
  // Create a new Pronoun object using Pronouny.new()
32
- const pronounZe: Pronoun = p.new({
33
- subject: "ze",
34
- object: "hir",
35
- possessive: "hirs",
36
- psAdjective: "hir",
37
- reflexive: "hirself",
38
- }, false);
32
+ const pronounZe: Pronoun = p.new(
33
+ {
34
+ subject: "ze",
35
+ object: "hir",
36
+ possessive: "hirs",
37
+ psAdjective: "hir",
38
+ reflexive: "hirself",
39
+ },
40
+ false
41
+ );
39
42
 
40
43
  // .new() will automatically add new Pronouns to its
41
44
  // validation map. however, if you want to do so manually,
@@ -47,7 +50,7 @@ p.remove(p.resolve("I"));
47
50
  // this deletes the "I" pronoun from the map.
48
51
 
49
52
  // Methods are chainable and you can reach the Pronoun class.
50
- p.add(pronounZe).set("he/they").use().subject().
53
+ p.add(pronounZe).set("he/they").use().subject();
51
54
  // ^Pronouny ^PronounSet ^Pronoun ^string
52
55
 
53
56
  // Instantiate a set of pronouns using Pronouny.set().
@@ -70,6 +73,12 @@ console.log(
70
73
 
71
74
  ## Changelog
72
75
 
76
+ ### v0.3.1
77
+
78
+ - Added documentation.
79
+ - Reordered `failQuietly` and `useRandom` on `Pronoun`.
80
+ - Tested and fixed examples.
81
+
73
82
  ### v0.3.0
74
83
 
75
84
  - Rewritten to consolidate functionality into a single default export `Pronouny`.
@@ -90,8 +99,6 @@ console.log(
90
99
 
91
100
  ## TODO
92
101
 
93
- [ ] Full rewrite
94
-
95
102
  - [x] Consolidate implementation into one general-use class.
96
103
  - [x] Add global configuration for pronoun use.
97
104
  - [ ] Use more performant data structures.
@@ -1,9 +1,17 @@
1
+ /**# `Pronoun` class
2
+ * A private class to construct the methods for pronoun
3
+ * access. Use {@link Pronouny} to create and
4
+ * append pronouns to the main validator. You can directly
5
+ * fetch pronoun arrays with `sbj`, `obj`, `psv`, `psj`,
6
+ * and `rfx`.
7
+ */
1
8
  declare class Pronoun {
2
9
  sbj: Array<string>;
3
10
  obj: Array<string>;
4
11
  psv: Array<string>;
5
12
  psj: Array<string>;
6
13
  rfx: Array<string>;
14
+ /** @constructor */
7
15
  constructor(pronouns: {
8
16
  subject: Array<string> | string;
9
17
  object: Array<string> | string;
@@ -11,38 +19,268 @@ declare class Pronoun {
11
19
  psAdjective: Array<string> | string;
12
20
  reflexive: Array<string> | string;
13
21
  });
14
- subject(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
15
- object(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
16
- possessive(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
17
- psAdjective(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
18
- reflexive(index?: number, failQuietly?: boolean, useRandom?: boolean): string;
22
+ /**# Subject Getter
23
+ * Get a subject pronoun. By default, uses one at
24
+ * random and fails silently by using the last
25
+ * pronoun if you index out of bounds.
26
+ *
27
+ * @param index
28
+ * Get `index`th pronoun, if specified. Fails to
29
+ * last if out of bounds and failing quietly.
30
+ * Default is `-1`.
31
+ *
32
+ * @param useRandom
33
+ * Overrides default random use behavior.
34
+ * Default is `true`.
35
+ *
36
+ * @param failQuietly
37
+ * Overrides default quiet failure behavior.
38
+ * Default is `true`.
39
+ */
40
+ subject(index?: number, useRandom?: boolean, failQuietly?: boolean): string;
41
+ /**# Object Getter
42
+ * Get an object pronoun. By default, uses one at
43
+ * random and fails silently by using the last
44
+ * pronoun if you index out of bounds.
45
+ *
46
+ * @param index
47
+ * Get `index`th pronoun, if specified. Fails to
48
+ * last if out of bounds and failing quietly.
49
+ * Default is `-1`.
50
+ *
51
+ * @param useRandom
52
+ * Overrides default random use behavior.
53
+ * Default is `true`.
54
+ *
55
+ * @param failQuietly
56
+ * Overrides default quiet failure behavior.
57
+ * Default is `true`.
58
+ */
59
+ object(index?: number, useRandom?: boolean, failQuietly?: boolean): string;
60
+ /**# Possessive Getter
61
+ * Get a possessive pronoun. By default, uses one
62
+ * at random and fails silently by using the last
63
+ * pronoun if you index out of bounds.
64
+ *
65
+ * @param index
66
+ * Get `index`th pronoun, if specified. Fails to
67
+ * last if out of bounds and failing quietly.
68
+ * Default is `-1`.
69
+ *
70
+ * @param useRandom
71
+ * Overrides default random use behavior.
72
+ * Default is `true`.
73
+ *
74
+ * @param failQuietly
75
+ * Overrides default quiet failure behavior.
76
+ * Default is `true`.
77
+ */
78
+ possessive(index?: number, useRandom?: boolean, failQuietly?: boolean): string;
79
+ /**# Possessive Adjective Getter
80
+ * Get a possessive adjective pronoun. By
81
+ * default, uses one at random and fails
82
+ * silently by using the last pronoun if you
83
+ * index out of bounds.
84
+ *
85
+ * @param index
86
+ * Get `index`th pronoun, if specified. Fails to
87
+ * last if out of bounds and failing quietly.
88
+ * Default is `-1`.
89
+ *
90
+ * @param useRandom
91
+ * Overrides default random use behavior.
92
+ * Default is `true`.
93
+ *
94
+ * @param failQuietly
95
+ * Overrides default quiet failure behavior.
96
+ * Default is `true`.
97
+ */
98
+ psAdjective(index?: number, useRandom?: boolean, failQuietly?: boolean): string;
99
+ /**# Reflexive Getter
100
+ * Get a reflexive pronoun. By default, uses one
101
+ * at random and fails silently by using the last
102
+ * pronoun if you index out of bounds.
103
+ *
104
+ * @param index
105
+ * Get `index`th pronoun, if specified. Fails to
106
+ * last if out of bounds and failing quietly.
107
+ * Default is `-1`.
108
+ *
109
+ * @param useRandom
110
+ * Overrides default random use behavior.
111
+ * Default is `true`.
112
+ *
113
+ * @param failQuietly
114
+ * Overrides default quiet failure behavior.
115
+ * Default is `true`.
116
+ */
117
+ reflexive(index?: number, useRandom?: boolean, failQuietly?: boolean): string;
19
118
  }
119
+ /**# `PronounSet` class
120
+ * A private class to construct the methods on
121
+ * sets of pronouns. Use {@linkcode Pronouny.set()}
122
+ * to produce a PronounSet for an entity. You can
123
+ * add pronouns to a set using {@linkcode PronounSet.add()},
124
+ * remove them using {@linkcode PronounSet.remove()}
125
+ */
20
126
  declare class PronounSet {
21
127
  pronouns: Set<Pronoun>;
22
128
  resolver: Pronouny;
129
+ /** @constructor */
23
130
  constructor(resolver: Pronouny, pronouns?: Set<Pronoun> | Array<Pronoun> | Set<string> | Array<string> | string);
131
+ /**# `.add()` to PronounSet
132
+ * Adds pronoun/s from a given Pronoun or strings
133
+ * (resolved using the {@linkcode Pronouny} instance
134
+ * used to create this PronounSet.)
135
+ *
136
+ * @param pronoun
137
+ * A string, Pronoun, or array of either, to be
138
+ * appended to the PronounSet.
139
+ *
140
+ * @param failQuietly
141
+ * Override default behavior to fail into 'they'.
142
+ */
24
143
  add(pronoun: string | Pronoun | Array<string> | Array<Pronoun>, failQuietly?: boolean | undefined): this;
144
+ /**# `.remove()` from PronounSet
145
+ * Remove pronoun/s from a given Pronoun or strings
146
+ * (resolved using the {@linkcode Pronouny} instance
147
+ * used to create this PronounSet.)
148
+ *
149
+ * @param pronoun
150
+ * A string, Pronoun, or array of either, to be
151
+ * appended to the PronounSet.
152
+ *
153
+ * @param failQuietly
154
+ * Override default behavior to fail into no removal.
155
+ */
25
156
  remove(set: PronounSet, pronoun: string | Pronoun | Array<string> | Array<Pronoun>, failQuietly?: boolean | undefined): this;
157
+ /**# `.use()` a PronounSet
158
+ * A method to retrieve one Pronoun at random. Use with
159
+ * {@link Pronoun|`Pronoun` methods} to get a specific
160
+ * form. You can also directly use {@link PronounSet.subject|`.subject()`},
161
+ * {@link PronounSet.object|`.object()`}, {@link PronounSet.possessive|`.possessive()`},
162
+ * {@link PronounSet.possessive|`.possessive()`}, or
163
+ * {@link PronounSet.reflexive|`.reflexive()`}. This is mostly
164
+ * here if you'd like to explicitly get a `Pronoun` instance
165
+ * from a `PronounSet`.
166
+ *
167
+ * @param index
168
+ * Retrieve `index`th pronoun from insertion.
169
+ *
170
+ * @param failQuietly
171
+ * Override default behavior to fail as per Pronouny config.
172
+ *
173
+ * @param useRandom
174
+ * Override default behavior to use random as per
175
+ * Pronouny config.
176
+ */
26
177
  use(index?: number, failQuietly?: boolean | undefined, useRandom?: boolean | undefined): Pronoun;
178
+ /**Retrieves a random subject pronoun. */
27
179
  subject(index?: number, failQuietly?: boolean | undefined, useRandom?: boolean | undefined): string;
180
+ /**Retrieves a random object pronoun. */
28
181
  object(index?: number, failQuietly?: boolean | undefined, useRandom?: boolean | undefined): string;
182
+ /**Retrieves a random possessive pronoun. */
29
183
  possessive(index?: number, failQuietly?: boolean | undefined, useRandom?: boolean | undefined): string;
184
+ /**Retrieves a random possessive adjective pronoun. */
30
185
  psAdjective(index?: number, failQuietly?: boolean | undefined, useRandom?: boolean | undefined): string;
186
+ /**Retrieves a random reflexive pronoun. */
31
187
  reflexive(index?: number, failQuietly?: boolean | undefined, useRandom?: boolean | undefined): string;
32
188
  }
189
+ /**# Config
190
+ * `failQuietly`: Controls various quiet failure states.
191
+ *
192
+ * `deepSearch`: Controls how deeply Pronouny will search
193
+ * for queries. By default, `string` parameters will
194
+ * only resolve using the first subject pronoun.
195
+ *
196
+ * `useRandom`: Controls whether random selection will be
197
+ * used. If false, it will default to 0. If failing
198
+ * quietly and indexing out of bounds, it will use the
199
+ * last item.
200
+ */
33
201
  type PronounyConfig = {
202
+ /**Controls various quiet failure states. */
34
203
  failQuietly?: boolean;
204
+ /**Controls how deeply Pronouny will search for
205
+ * queries. By default, `string` parameters will
206
+ * only resolve using the first subject pronoun. */
35
207
  deepSearch?: boolean;
208
+ /**Controls whether random selection will be used.
209
+ * If false, it will default to 0. If failing
210
+ * quietly and indexing out of bounds, it will
211
+ * use the last item. */
36
212
  useRandom?: boolean;
37
213
  };
214
+ /**# Pronouny
215
+ * A typed library intended to make English pronoun
216
+ * resolution easy. Instantiate in your project using
217
+ * `new Pronouny()`, optionally passing in a
218
+ * {@link PronounyConfig|`PronounyConfig` object}.
219
+ *
220
+ * Once you have configured Pronouny, you may add new
221
+ * pronouns by using `new()` and passing in a set of
222
+ * pronouns. They are registered automatically. If you
223
+ * would like to register them manually, you can use
224
+ * `add()`. You can also `remove()` them if you would
225
+ * like to make them no longer valid.
226
+ *
227
+ * You can produce a {@linkcode PronounSet} by using
228
+ * `set()`. By passing in a string, it will
229
+ * automatically resolve each, using a delimiter if
230
+ * specified. From there, you can chain methods like
231
+ * `subject()` to retrieve a subject pronoun for use.
232
+ *
233
+ * If you would like to get a {@link Pronoun|`Pronoun` object}
234
+ * from a given text, you can use `resolve()`. Pass
235
+ * in a string and it will return the entire matched
236
+ * `Pronoun` object.
237
+ */
38
238
  export default class Pronouny {
39
239
  config: PronounyConfig;
40
240
  resolveMap: Map<string, Pronoun>;
41
241
  constructor(config?: PronounyConfig);
242
+ /**# `.resolve()` a Pronoun
243
+ * Returns a pronoun from a given string. Uses
244
+ * Pronouny's config to determine the depth of search.
245
+ * By default, only checks the first subject pronoun.
246
+ */
42
247
  resolve(pronoun: string, deepSearch?: boolean | undefined): Pronoun;
248
+ /**# `.add()` an Unlisted Pronoun
249
+ * If you made a `.new()` Pronoun but disabled
250
+ * `autoAppend`, you can later append it back by
251
+ * using this method. Returns `Pronouny`.
252
+ */
43
253
  add(pronoun: Pronoun): this;
254
+ /**# `.remove()` a Pronoun
255
+ * Renders a given Pronoun invalid within this
256
+ * Pronouny instance. Returns `Pronouny`.
257
+ */
44
258
  remove(pronoun: Pronoun): this;
259
+ /**# Make a `.set()` of Pronouns
260
+ * Returns a {@linkcode PronounSet} from a given
261
+ * string or array of strings. You can specify the
262
+ * delimiter to be used. By default, it is `/`.
263
+ */
45
264
  set(pronouns: string | Array<string>, delimiter?: string): PronounSet;
265
+ /**# `.new()`
266
+ * Returns a new pronoun. Takes in an object with
267
+ * a subject, object, possessive, possessive adjective,
268
+ * and reflexive string/s, and returns the Pronoun.
269
+ * By default, appends the new `Pronoun` to the Pronouny
270
+ * `resolveMap`.
271
+ *
272
+ * @param pronouns
273
+ * Takes an object with the structure of a `Pronoun`,
274
+ * with `Array<string>` or a `string` for `subject`,
275
+ * `object`, `possessive`, `psAdjective`, and
276
+ * `reflexive`.
277
+ *
278
+ * @param autoAppend
279
+ * Will automatically add the new Pronoun to the
280
+ * Pronouny instance. If false, will just return a
281
+ * {@link Pronoun|`Pronoun` object} without registering.
282
+ * You may register it later with {@link Pronouny.add}.
283
+ */
46
284
  new(pronouns: {
47
285
  subject: Array<string> | string;
48
286
  object: Array<string> | string;