pronouny 0.1.2 → 0.3.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 CHANGED
@@ -4,51 +4,96 @@
4
4
 
5
5
  ## Installation
6
6
 
7
- To install, simply do `npm install pronouny`.
7
+ To install, simply run `npm install pronouny`.
8
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
9
+ ## Usage
22
10
 
23
11
  ```ts
24
- import { Pronouny } from "pronouny";
12
+ // Single import
13
+ import Pronouny from 'pronouny';
25
14
 
26
15
  // Create a new instance of the Validate class
27
- const pronounValidator = new Pronouny.Validate();
16
+ // All options are optional
17
+ const p = new Pronouny({
18
+ // Will default to failing quietly into "they"
19
+ failQuietly: true,
20
+
21
+ // Will default to only querying the first subject
22
+ // pronoun to limit scope. Set to "true" to force
23
+ // recursive search.
24
+ deepSearch: false,
25
+
26
+ // Will default to using random pronouns in arrays.
27
+ // Set to false to force using 0 index.
28
+ useRandom: true,
29
+ });
28
30
 
29
- // Create a new Pronoun object for ze/hir pronouns
30
- const pronounZe = new Pronouny.Pronoun({
31
+ // Create a new Pronoun object using Pronouny.new()
32
+ const pronounZe: Pronoun = p.new({
31
33
  subject: "ze",
32
34
  object: "hir",
33
- possessiveAdjective: "hir",
34
- possessivePronoun: "hirs",
35
+ possessive: "hirs",
36
+ psAdjective: "hir",
35
37
  reflexive: "hirself",
36
- });
38
+ }, false);
39
+
40
+ // .new() will automatically add new Pronouns to its
41
+ // validation map. however, if you want to do so manually,
42
+ // you can do it with Pronouny.add().
43
+ p.add(pronounZe);
44
+
45
+ // .remove() also works;
46
+ p.remove(p.resolve("I"));
47
+ // this deletes the "I" pronoun from the map.
37
48
 
38
- // Add the pronoun to the pronounSet map
39
- pronounValidator.extend("ze", pronounZe);
49
+ // Methods are chainable and you can reach the Pronoun class.
50
+ p.add(pronounZe).set("he/they").use().subject().
51
+ // ^Pronouny ^PronounSet ^Pronoun ^string
40
52
 
41
- // Set someone's pronouns.
53
+ // Instantiate a set of pronouns using Pronouny.set().
42
54
  const vayne = {
43
- username: vaynegarden,
44
- pronouns: pronounValidator.createSetFrom("she/ze/they"),
55
+ username: "vaynegarden",
56
+ pronouns: p.set("she/ze/they"),
45
57
  };
58
+ // from there, you can use `[PronounSet].use()` to get a random pronoun.
46
59
 
47
- // Resolve the pronouns in your app
60
+ // Resolve the pronouns in your app by referencing the form
61
+ // that you need. There's `subject`, `object`, `possessive`,
62
+ // `psAdjective`, and `reflexive`.
48
63
  console.log(
49
- vayne.username + " updated " + vayne.pronouns.use("psAdj") + " status."
64
+ `${vayne.username} has updated ${vayne.pronouns.psAdjective()} status.`
50
65
  );
51
- // Returns "vaynegarden updated her status", "vaynegarden
66
+ // This returns "vaynegarden updated her status", "vaynegarden
52
67
  // updated hir status", or "vaynegarden updated their status",
53
68
  // selected randomly among the three.
54
69
  ```
70
+
71
+ ## Changelog
72
+
73
+ ### v0.3.0
74
+
75
+ - Rewritten to consolidate functionality into a single default export `Pronouny`.
76
+ - Includes "we", "you", and "I" pronouns by default.
77
+ - Added a config object so you can decide on error handling globally.
78
+ - All methods are now chainable for ease of use.
79
+
80
+ ### v0.2.0
81
+
82
+ - Now fails silently when trying to resolve pronouns that don't exist or indexing out of bounds.
83
+ - Implementation of `PronounSet` class changed to Set from Array to prevent duplicate pronouns.
84
+ - added `get()` method to `PronounSet` class to retrieve a random Pronoun object.
85
+ - Added `add()` and `remove()` on `PronounSet`
86
+
87
+ ### v0.1.2
88
+
89
+ - Initial release.
90
+
91
+ ## TODO
92
+
93
+ [ ] Full rewrite
94
+
95
+ - [x] Consolidate implementation into one general-use class.
96
+ - [x] Add global configuration for pronoun use.
97
+ - [ ] Use more performant data structures.
98
+ - [ ] Cleaner error handling.
99
+ - [ ] Unique pronoun identifiers to allow for pronouns with the same first subject pronoun to have multiple forms.
@@ -1,247 +1,54 @@
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
- }
1
+ declare class Pronoun {
2
+ sbj: Array<string>;
3
+ obj: Array<string>;
4
+ psv: Array<string>;
5
+ psj: Array<string>;
6
+ rfx: Array<string>;
7
+ constructor(pronouns: {
8
+ subject: Array<string> | string;
9
+ object: Array<string> | string;
10
+ possessive: Array<string> | string;
11
+ psAdjective: Array<string> | string;
12
+ reflexive: Array<string> | string;
13
+ });
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;
247
19
  }
20
+ declare class PronounSet {
21
+ pronouns: Set<Pronoun>;
22
+ resolver: Pronouny;
23
+ constructor(resolver: Pronouny, pronouns?: Set<Pronoun> | Array<Pronoun> | Set<string> | Array<string> | string);
24
+ add(pronoun: string | Pronoun | Array<string> | Array<Pronoun>, failQuietly?: boolean | undefined): this;
25
+ remove(set: PronounSet, pronoun: string | Pronoun | Array<string> | Array<Pronoun>, failQuietly?: boolean | undefined): this;
26
+ use(index?: number, failQuietly?: boolean | undefined, useRandom?: boolean | undefined): Pronoun;
27
+ subject(index?: number, failQuietly?: boolean | undefined, useRandom?: boolean | undefined): string;
28
+ object(index?: number, failQuietly?: boolean | undefined, useRandom?: boolean | undefined): string;
29
+ possessive(index?: number, failQuietly?: boolean | undefined, useRandom?: boolean | undefined): string;
30
+ psAdjective(index?: number, failQuietly?: boolean | undefined, useRandom?: boolean | undefined): string;
31
+ reflexive(index?: number, failQuietly?: boolean | undefined, useRandom?: boolean | undefined): string;
32
+ }
33
+ type PronounyConfig = {
34
+ failQuietly?: boolean;
35
+ deepSearch?: boolean;
36
+ useRandom?: boolean;
37
+ };
38
+ export default class Pronouny {
39
+ config: PronounyConfig;
40
+ resolveMap: Map<string, Pronoun>;
41
+ constructor(config?: PronounyConfig);
42
+ resolve(pronoun: string, deepSearch?: boolean | undefined): Pronoun;
43
+ add(pronoun: Pronoun): this;
44
+ remove(pronoun: Pronoun): this;
45
+ set(pronouns: string | Array<string>, delimiter?: string): PronounSet;
46
+ new(pronouns: {
47
+ subject: Array<string> | string;
48
+ object: Array<string> | string;
49
+ possessive: Array<string> | string;
50
+ psAdjective: Array<string> | string;
51
+ reflexive: Array<string> | string;
52
+ }, autoAppend?: boolean): Pronoun;
53
+ }
54
+ export {};