pronouny 0.1.1 → 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 +80 -31
- package/lib/cjs/index.d.ts +53 -246
- package/lib/cjs/index.js +300 -371
- package/lib/esm/index.d.ts +53 -246
- package/lib/esm/index.js +299 -370
- package/package.json +33 -28
package/README.md
CHANGED
|
@@ -4,47 +4,96 @@
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
To install, simply
|
|
7
|
+
To install, simply run `npm install pronouny`.
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Usage
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
```ts
|
|
12
|
+
// Single import
|
|
13
|
+
import Pronouny from 'pronouny';
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
// Create a new instance of the Validate class
|
|
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
|
+
});
|
|
30
|
+
|
|
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);
|
|
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.
|
|
48
|
+
|
|
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
|
|
52
|
+
|
|
53
|
+
// Instantiate a set of pronouns using Pronouny.set().
|
|
54
|
+
const vayne = {
|
|
55
|
+
username: "vaynegarden",
|
|
56
|
+
pronouns: p.set("she/ze/they"),
|
|
57
|
+
};
|
|
58
|
+
// from there, you can use `[PronounSet].use()` to get a random pronoun.
|
|
59
|
+
|
|
60
|
+
// Resolve the pronouns in your app by referencing the form
|
|
61
|
+
// that you need. There's `subject`, `object`, `possessive`,
|
|
62
|
+
// `psAdjective`, and `reflexive`.
|
|
63
|
+
console.log(
|
|
64
|
+
`${vayne.username} has updated ${vayne.pronouns.psAdjective()} status.`
|
|
65
|
+
);
|
|
66
|
+
// This returns "vaynegarden updated her status", "vaynegarden
|
|
67
|
+
// updated hir status", or "vaynegarden updated their status",
|
|
68
|
+
// selected randomly among the three.
|
|
69
|
+
```
|
|
14
70
|
|
|
15
|
-
|
|
71
|
+
## Changelog
|
|
16
72
|
|
|
17
|
-
|
|
73
|
+
### v0.3.0
|
|
18
74
|
|
|
19
|
-
|
|
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.
|
|
20
79
|
|
|
21
|
-
|
|
80
|
+
### v0.2.0
|
|
22
81
|
|
|
23
|
-
|
|
24
|
-
|
|
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`
|
|
25
86
|
|
|
26
|
-
|
|
27
|
-
const pronounValidator = new Pronouny.Validate();
|
|
87
|
+
### v0.1.2
|
|
28
88
|
|
|
29
|
-
|
|
30
|
-
const pronounZe = new Pronouny.Pronoun(
|
|
31
|
-
'ze', 'hir', 'hir', 'hirs', 'hirself'
|
|
32
|
-
);
|
|
89
|
+
- Initial release.
|
|
33
90
|
|
|
34
|
-
|
|
35
|
-
pronounValidator.extend( "ze", pronounZe );
|
|
91
|
+
## TODO
|
|
36
92
|
|
|
37
|
-
|
|
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.
|
|
93
|
+
[ ] Full rewrite
|
|
49
94
|
|
|
50
|
-
|
|
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.
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,247 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 {};
|