@sebbo2002/genderize 3.0.0-develop.1 → 3.0.0-develop.3

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.
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Enum that can be used to compare and check the results
3
+ */
4
+ declare enum GenderizeGender {
5
+ FEMALE = "female",
6
+ MALE = "male"
7
+ }
8
+ interface GenderizeResponse {
9
+ /**
10
+ * Name which was used for this prediction
11
+ */
12
+ name: string;
13
+ /**
14
+ * Either a [[`GenderizeGender`]] value (male/female) or null
15
+ * if the API was not able to predict a gender.
16
+ */
17
+ gender: GenderizeGender | null;
18
+ /**
19
+ * Value between 0 and 1 (including)
20
+ */
21
+ probability: number;
22
+ /**
23
+ * The number of data rows examined in order
24
+ * to calculate the API response
25
+ */
26
+ count: number;
27
+ }
28
+ interface GenderizeResponseWithCountry extends GenderizeResponse {
29
+ /**
30
+ * ISO 3166-1 alpha-2 country code which was used for this prediction
31
+ */
32
+ country_id: string;
33
+ }
34
+ interface GenderizeLimit {
35
+ /**
36
+ * The amount of names available in the current time window
37
+ */
38
+ limit: number;
39
+ /**
40
+ * The number of names left in the current time window
41
+ */
42
+ remaining: number;
43
+ /**
44
+ * Next time window start time
45
+ *
46
+ * ```javascript
47
+ * import Genderize from '@sebbo2002/genderize';
48
+ * const genderize = new Genderize('API-KEY');
49
+ *
50
+ * // execute a predicition
51
+ *
52
+ * genderize.limit?.reset.toString()
53
+ * ```
54
+ */
55
+ reset: Date;
56
+ }
57
+ declare class Genderize {
58
+ private readonly apiKey;
59
+ private latestHeaders;
60
+ /**
61
+ * Usually you get an `Genderize` instance like this:
62
+ * ```javascript
63
+ * import Genderize from '@sebbo2002/genderize';
64
+ * const genderize = new Genderize('API-KEY');
65
+ * ```
66
+ *
67
+ * You can get an API key from [store.genderize.io](https://store.genderize.io/).
68
+ *
69
+ * If you don't have an API key yet, you can start with the free plan:
70
+ * ```javascript
71
+ * import Genderize from '@sebbo2002/genderize';
72
+ * const genderize = new Genderize();
73
+ * ```
74
+ */
75
+ constructor(apiKey?: string);
76
+ /**
77
+ * @internal
78
+ */
79
+ static getIntHeader(value: string | string[] | undefined): number | undefined;
80
+ /**
81
+ * Outputs information about the current state of the rate limit. Updated and cached
82
+ * each time [[`predict`]] is called. If no information is available, for example because
83
+ * [[`predict`]] has not been executed yet, `null` is returned. Otherwise the response is
84
+ * of type [[`GenderizeLimit`]].
85
+ */
86
+ get limit(): GenderizeLimit | null;
87
+ /**
88
+ * Internal function which builds the url parameters
89
+ * used to query the prediction endpoint.
90
+ *
91
+ * @internal
92
+ */
93
+ params(names: string | string[], country?: string): string;
94
+ /**
95
+ * Predict a single name
96
+ *
97
+ * ```typescript
98
+ * import Genderize from '@sebbo2002/genderize';
99
+ * const genderize = new Genderize('API-KEY');
100
+ * genderize.predict('Mia').then(result => {
101
+ * console.log(result);
102
+ * });
103
+ * ```
104
+ *
105
+ * ```json
106
+ * {
107
+ * name: 'Mia',
108
+ * gender: 'female',
109
+ * probability: 0.96,
110
+ * count: 19266
111
+ * }
112
+ * ```
113
+ */
114
+ predict(name: string): Promise<GenderizeResponse>;
115
+ /**
116
+ * Predict multiple names. Works for up to 10 names at the same time.
117
+ *
118
+ * Please check [this list](https://genderize.io/our-data) if you're unsure about
119
+ * the country code you have to use.
120
+ *
121
+ * It is recommended to check the count of the response when using localization.
122
+ * If the count is very low or gender is null, you can fallback to a request
123
+ * with no localization.
124
+ *
125
+ * ```typescript
126
+ * import Genderize from '@sebbo2002/genderize';
127
+ * const genderize = new Genderize('API-KEY');
128
+ * genderize.predict(['Noah', 'Evelyn']).then(result => {
129
+ * console.log(result);
130
+ * });
131
+ * ```
132
+ *
133
+ * ```json
134
+ * [
135
+ * { name: 'Noah', gender: 'male', probability: 0.88, count: 3939 },
136
+ * { name: 'Evelyn', gender: 'female', probability: 0.98, count: 12188 }
137
+ * ]
138
+ * ```
139
+ */
140
+ predict(names: string[]): Promise<GenderizeResponse[]>;
141
+ /**
142
+ * Predict a single name with a given ISO 3166-1 alpha-2 country code
143
+ *
144
+ * ```typescript
145
+ * import Genderize from '@sebbo2002/genderize';
146
+ * const genderize = new Genderize('API-KEY');
147
+ * genderize.predict('Mia', 'DE').then(result => {
148
+ * console.log(result);
149
+ * });
150
+ * ```
151
+ *
152
+ * ```json
153
+ * {
154
+ * name: 'Mia',
155
+ * gender: 'female',
156
+ * probability: 0.97,
157
+ * count: 1786,
158
+ * country_id: 'DE'
159
+ * }
160
+ * ```
161
+ */
162
+ predict(name: string, country: string): Promise<GenderizeResponseWithCountry>;
163
+ /**
164
+ * Predict multiple names with a given ISO 3166-1 alpha-2
165
+ * country code. Works for up to 10 names at the same time.
166
+ *
167
+ * Please check [this list](https://genderize.io/our-data) if you're unsure about
168
+ * the country code you have to use.
169
+ *
170
+ * It is recommended to check the count of the response when using localization.
171
+ * If the count is very low or gender is null, you can fallback to a request
172
+ * with no localization.
173
+ *
174
+ * ```typescript
175
+ * import Genderize from '@sebbo2002/genderize';
176
+ * const genderize = new Genderize('API-KEY');
177
+ * genderize.predict(['Noah', 'Evelyn'], 'DE').then(result => {
178
+ * console.log(result);
179
+ * });
180
+ * ```
181
+ *
182
+ * ```json
183
+ * [
184
+ * { name: 'Noah', gender: 'male', probability: 1, count: 608, country_id: 'DE' },
185
+ * { name: 'Evelyn', gender: 'female', probability: 0.97, count: 1665, country_id: 'DE' }
186
+ * ]
187
+ * ```
188
+ */
189
+ predict(names: string[], country: string): Promise<GenderizeResponseWithCountry[]>;
190
+ }
191
+
192
+ export { GenderizeGender, GenderizeLimit, GenderizeResponse, GenderizeResponseWithCountry, Genderize as default };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Enum that can be used to compare and check the results
3
3
  */
4
- export declare enum GenderizeGender {
4
+ declare enum GenderizeGender {
5
5
  FEMALE = "female",
6
6
  MALE = "male"
7
7
  }
8
- export interface GenderizeResponse {
8
+ interface GenderizeResponse {
9
9
  /**
10
10
  * Name which was used for this prediction
11
11
  */
@@ -25,13 +25,13 @@ export interface GenderizeResponse {
25
25
  */
26
26
  count: number;
27
27
  }
28
- export interface GenderizeResponseWithCountry extends GenderizeResponse {
28
+ interface GenderizeResponseWithCountry extends GenderizeResponse {
29
29
  /**
30
30
  * ISO 3166-1 alpha-2 country code which was used for this prediction
31
31
  */
32
32
  country_id: string;
33
33
  }
34
- export interface GenderizeLimit {
34
+ interface GenderizeLimit {
35
35
  /**
36
36
  * The amount of names available in the current time window
37
37
  */
@@ -54,7 +54,7 @@ export interface GenderizeLimit {
54
54
  */
55
55
  reset: Date;
56
56
  }
57
- export default class Genderize {
57
+ declare class Genderize {
58
58
  private readonly apiKey;
59
59
  private latestHeaders;
60
60
  /**
@@ -188,3 +188,5 @@ export default class Genderize {
188
188
  */
189
189
  predict(names: string[], country: string): Promise<GenderizeResponseWithCountry[]>;
190
190
  }
191
+
192
+ export { GenderizeGender, GenderizeLimit, GenderizeResponse, GenderizeResponseWithCountry, Genderize as default };
package/dist/index.js CHANGED
@@ -1,114 +1,2 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import got from 'got';
11
- /**
12
- * Enum that can be used to compare and check the results
13
- */
14
- export var GenderizeGender;
15
- (function (GenderizeGender) {
16
- GenderizeGender["FEMALE"] = "female";
17
- GenderizeGender["MALE"] = "male";
18
- })(GenderizeGender || (GenderizeGender = {}));
19
- export default class Genderize {
20
- /**
21
- * Usually you get an `Genderize` instance like this:
22
- * ```javascript
23
- * import Genderize from '@sebbo2002/genderize';
24
- * const genderize = new Genderize('API-KEY');
25
- * ```
26
- *
27
- * You can get an API key from [store.genderize.io](https://store.genderize.io/).
28
- *
29
- * If you don't have an API key yet, you can start with the free plan:
30
- * ```javascript
31
- * import Genderize from '@sebbo2002/genderize';
32
- * const genderize = new Genderize();
33
- * ```
34
- */
35
- constructor(apiKey) {
36
- this.latestHeaders = null;
37
- this.apiKey = apiKey;
38
- }
39
- /**
40
- * @internal
41
- */
42
- static getIntHeader(value) {
43
- if (Array.isArray(value)) {
44
- return this.getIntHeader(value[0]);
45
- }
46
- if (value === undefined) {
47
- return undefined;
48
- }
49
- return parseInt(value);
50
- }
51
- /**
52
- * Outputs information about the current state of the rate limit. Updated and cached
53
- * each time [[`predict`]] is called. If no information is available, for example because
54
- * [[`predict`]] has not been executed yet, `null` is returned. Otherwise the response is
55
- * of type [[`GenderizeLimit`]].
56
- */
57
- get limit() {
58
- if (!this.latestHeaders) {
59
- return null;
60
- }
61
- const limit = Genderize.getIntHeader(this.latestHeaders[0]['x-rate-limit-limit']);
62
- const remaining = Genderize.getIntHeader(this.latestHeaders[0]['x-rate-limit-remaining']);
63
- const reset = Genderize.getIntHeader(this.latestHeaders[0]['x-rate-limit-reset']);
64
- if (limit !== undefined && remaining !== undefined && reset !== undefined) {
65
- return {
66
- limit,
67
- remaining,
68
- reset: new Date(this.latestHeaders[1].getTime() + (reset * 1000))
69
- };
70
- }
71
- return null;
72
- }
73
- /**
74
- * Internal function which builds the url parameters
75
- * used to query the prediction endpoint.
76
- *
77
- * @internal
78
- */
79
- params(names, country) {
80
- const searchParams = new URLSearchParams();
81
- if (Array.isArray(names) && names.length > 10) {
82
- throw new Error(`Too many names given: ${names.length} names provided, but 10 is the maximum allowed`);
83
- }
84
- if (Array.isArray(names) && names.length === 0) {
85
- throw new Error('No name given, but at least one is required');
86
- }
87
- if (Array.isArray(names)) {
88
- names.forEach(name => searchParams.append('name', name));
89
- }
90
- else {
91
- searchParams.append('name', names);
92
- }
93
- if (country) {
94
- searchParams.append('country_id', country);
95
- }
96
- if (this.apiKey) {
97
- searchParams.append('apikey', this.apiKey);
98
- }
99
- if (Array.isArray(names)) {
100
- return searchParams.toString()
101
- .replace(/name=/g, 'name[]=');
102
- }
103
- return searchParams.toString();
104
- }
105
- predict(names, country) {
106
- return __awaiter(this, void 0, void 0, function* () {
107
- const searchParams = this.params(names, country);
108
- const { body, headers } = yield got.get('https://api.genderize.io/', { searchParams, responseType: 'json' });
109
- this.latestHeaders = [headers, new Date()];
110
- return body;
111
- });
112
- }
113
- }
1
+ var p=(g,e,r)=>new Promise((t,s)=>{var a=n=>{try{o(r.next(n))}catch(d){s(d)}},m=n=>{try{o(r.throw(n))}catch(d){s(d)}},o=n=>n.done?t(n.value):Promise.resolve(n.value).then(a,m);o((r=r.apply(g,e)).next())});import u from"got";var l=(r=>(r.FEMALE="female",r.MALE="male",r))(l||{}),i=class{constructor(e){this.latestHeaders=null;this.apiKey=e}static getIntHeader(e){if(Array.isArray(e))return this.getIntHeader(e[0]);if(e!==void 0)return parseInt(e)}get limit(){if(!this.latestHeaders)return null;let e=i.getIntHeader(this.latestHeaders[0]["x-rate-limit-limit"]),r=i.getIntHeader(this.latestHeaders[0]["x-rate-limit-remaining"]),t=i.getIntHeader(this.latestHeaders[0]["x-rate-limit-reset"]);return e!==void 0&&r!==void 0&&t!==void 0?{limit:e,remaining:r,reset:new Date(this.latestHeaders[1].getTime()+t*1e3)}:null}params(e,r){let t=new URLSearchParams;if(Array.isArray(e)&&e.length>10)throw new Error(`Too many names given: ${e.length} names provided, but 10 is the maximum allowed`);if(Array.isArray(e)&&e.length===0)throw new Error("No name given, but at least one is required");return Array.isArray(e)?e.forEach(s=>t.append("name",s)):t.append("name",e),r&&t.append("country_id",r),this.apiKey&&t.append("apikey",this.apiKey),Array.isArray(e)?t.toString().replace(/name=/g,"name[]="):t.toString()}predict(e,r){return p(this,null,function*(){let t=this.params(e,r),{body:s,headers:a}=yield u.get("https://api.genderize.io/",{searchParams:t,responseType:"json"});return this.latestHeaders=[a,new Date],s})}};export{l as GenderizeGender,i as default};
114
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB;;GAEG;AACH,MAAM,CAAN,IAAY,eAGX;AAHD,WAAY,eAAe;IACvB,oCAAiB,CAAA;IACjB,gCAAa,CAAA;AACjB,CAAC,EAHW,eAAe,KAAf,eAAe,QAG1B;AA0DD,MAAM,CAAC,OAAO,OAAO,SAAS;IAI1B;;;;;;;;;;;;;;OAcG;IACH,YAAY,MAAe;QAjBnB,kBAAa,GAAiE,IAAI,CAAC;QAkBvF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,KAAoC;QACpD,IAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACrB,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SACtC;QAED,IAAG,KAAK,KAAK,SAAS,EAAE;YACpB,OAAO,SAAS,CAAC;SACpB;QAED,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACH,IAAI,KAAK;QACL,IAAG,CAAC,IAAI,CAAC,aAAa,EAAE;YACpB,OAAO,IAAI,CAAC;SACf;QAED,MAAM,KAAK,GAAG,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC;QAClF,MAAM,SAAS,GAAG,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC;QAC1F,MAAM,KAAK,GAAG,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC;QAElF,IAAG,KAAK,KAAK,SAAS,IAAI,SAAS,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,EAAE;YACtE,OAAO;gBACH,KAAK;gBACL,SAAS;gBACT,KAAK,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;aACpE,CAAC;SACL;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,KAAwB,EAAE,OAAgB;QAC7C,MAAM,YAAY,GAAG,IAAI,eAAe,EAAE,CAAC;QAC3C,IAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,EAAE;YAC1C,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,CAAC,MAAM,gDAAgD,CAAC,CAAC;SAC1G;QACD,IAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YAC3C,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;SAClE;QAED,IAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACrB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;SAC5D;aAAM;YACH,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;SACtC;QAED,IAAG,OAAO,EAAE;YACR,YAAY,CAAC,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;SAC9C;QAED,IAAG,IAAI,CAAC,MAAM,EAAE;YACZ,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;SAC9C;QACD,IAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACrB,OAAO,YAAY,CAAC,QAAQ,EAAE;iBACzB,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;SACrC;QAED,OAAO,YAAY,CAAC,QAAQ,EAAE,CAAC;IACnC,CAAC;IAsGK,OAAO,CAAC,KAAwB,EAAE,OAAgB;;YACpD,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACjD,MAAM,EAAC,IAAI,EAAE,OAAO,EAAC,GAAG,MAAM,GAAG,CAAC,GAAG,CAAC,2BAA2B,EAAE,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC;YAC3G,IAAI,CAAC,aAAa,GAAG,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;YAC3C,OAAO,IAA+C,CAAC;QAC3D,CAAC;KAAA;CACJ"}
1
+ {"version":3,"sources":["../src/lib/index.ts"],"sourcesContent":["import got from 'got';\n\n/**\n * Enum that can be used to compare and check the results\n */\nexport enum GenderizeGender {\n FEMALE = 'female',\n MALE = 'male'\n}\n\nexport interface GenderizeResponse {\n /**\n * Name which was used for this prediction\n */\n name: string;\n\n /**\n * Either a [[`GenderizeGender`]] value (male/female) or null\n * if the API was not able to predict a gender.\n */\n gender: GenderizeGender | null;\n\n /**\n * Value between 0 and 1 (including)\n */\n probability: number;\n\n /**\n * The number of data rows examined in order\n * to calculate the API response\n */\n count: number;\n}\nexport interface GenderizeResponseWithCountry extends GenderizeResponse {\n /**\n * ISO 3166-1 alpha-2 country code which was used for this prediction\n */\n country_id: string;\n}\n\nexport interface GenderizeLimit {\n /**\n * The amount of names available in the current time window\n */\n limit: number;\n\n /**\n * The number of names left in the current time window\n */\n remaining: number;\n\n /**\n * Next time window start time\n *\n * ```javascript\n * import Genderize from '@sebbo2002/genderize';\n * const genderize = new Genderize('API-KEY');\n *\n * // execute a predicition\n *\n * genderize.limit?.reset.toString()\n * ```\n */\n reset: Date;\n}\n\nexport default class Genderize {\n private readonly apiKey;\n private latestHeaders: [Record<string, string[] | string | undefined>, Date] | null = null;\n\n /**\n * Usually you get an `Genderize` instance like this:\n * ```javascript\n * import Genderize from '@sebbo2002/genderize';\n * const genderize = new Genderize('API-KEY');\n * ```\n *\n * You can get an API key from [store.genderize.io](https://store.genderize.io/).\n *\n * If you don't have an API key yet, you can start with the free plan:\n * ```javascript\n * import Genderize from '@sebbo2002/genderize';\n * const genderize = new Genderize();\n * ```\n */\n constructor(apiKey?: string) {\n this.apiKey = apiKey;\n }\n\n /**\n * @internal\n */\n static getIntHeader(value: string | string[] | undefined): number | undefined {\n if(Array.isArray(value)) {\n return this.getIntHeader(value[0]);\n }\n\n if(value === undefined) {\n return undefined;\n }\n\n return parseInt(value);\n }\n\n /**\n * Outputs information about the current state of the rate limit. Updated and cached\n * each time [[`predict`]] is called. If no information is available, for example because\n * [[`predict`]] has not been executed yet, `null` is returned. Otherwise the response is\n * of type [[`GenderizeLimit`]].\n */\n get limit(): GenderizeLimit | null {\n if(!this.latestHeaders) {\n return null;\n }\n\n const limit = Genderize.getIntHeader(this.latestHeaders[0]['x-rate-limit-limit']);\n const remaining = Genderize.getIntHeader(this.latestHeaders[0]['x-rate-limit-remaining']);\n const reset = Genderize.getIntHeader(this.latestHeaders[0]['x-rate-limit-reset']);\n\n if(limit !== undefined && remaining !== undefined && reset !== undefined) {\n return {\n limit,\n remaining,\n reset: new Date(this.latestHeaders[1].getTime() + (reset * 1000))\n };\n }\n\n return null;\n }\n\n /**\n * Internal function which builds the url parameters\n * used to query the prediction endpoint.\n *\n * @internal\n */\n params(names: string | string[], country?: string): string {\n const searchParams = new URLSearchParams();\n if(Array.isArray(names) && names.length > 10) {\n throw new Error(`Too many names given: ${names.length} names provided, but 10 is the maximum allowed`);\n }\n if(Array.isArray(names) && names.length === 0) {\n throw new Error('No name given, but at least one is required');\n }\n\n if(Array.isArray(names)) {\n names.forEach(name => searchParams.append('name', name));\n } else {\n searchParams.append('name', names);\n }\n\n if(country) {\n searchParams.append('country_id', country);\n }\n\n if(this.apiKey) {\n searchParams.append('apikey', this.apiKey);\n }\n if(Array.isArray(names)) {\n return searchParams.toString()\n .replace(/name=/g, 'name[]=');\n }\n\n return searchParams.toString();\n }\n\n /**\n * Predict a single name\n *\n * ```typescript\n * import Genderize from '@sebbo2002/genderize';\n * const genderize = new Genderize('API-KEY');\n * genderize.predict('Mia').then(result => {\n * console.log(result);\n * });\n * ```\n *\n * ```json\n * {\n * name: 'Mia',\n * gender: 'female',\n * probability: 0.96,\n * count: 19266\n * }\n * ```\n */\n async predict(name: string): Promise<GenderizeResponse>;\n\n /**\n * Predict multiple names. Works for up to 10 names at the same time.\n *\n * Please check [this list](https://genderize.io/our-data) if you're unsure about\n * the country code you have to use.\n *\n * It is recommended to check the count of the response when using localization.\n * If the count is very low or gender is null, you can fallback to a request\n * with no localization.\n *\n * ```typescript\n * import Genderize from '@sebbo2002/genderize';\n * const genderize = new Genderize('API-KEY');\n * genderize.predict(['Noah', 'Evelyn']).then(result => {\n * console.log(result);\n * });\n * ```\n *\n * ```json\n * [\n * { name: 'Noah', gender: 'male', probability: 0.88, count: 3939 },\n * { name: 'Evelyn', gender: 'female', probability: 0.98, count: 12188 }\n * ]\n * ```\n */\n async predict(names: string[]): Promise<GenderizeResponse[]>;\n\n /**\n * Predict a single name with a given ISO 3166-1 alpha-2 country code\n *\n * ```typescript\n * import Genderize from '@sebbo2002/genderize';\n * const genderize = new Genderize('API-KEY');\n * genderize.predict('Mia', 'DE').then(result => {\n * console.log(result);\n * });\n * ```\n *\n * ```json\n * {\n * name: 'Mia',\n * gender: 'female',\n * probability: 0.97,\n * count: 1786,\n * country_id: 'DE'\n * }\n * ```\n */\n async predict(name: string, country: string): Promise<GenderizeResponseWithCountry>;\n\n /**\n * Predict multiple names with a given ISO 3166-1 alpha-2\n * country code. Works for up to 10 names at the same time.\n *\n * Please check [this list](https://genderize.io/our-data) if you're unsure about\n * the country code you have to use.\n *\n * It is recommended to check the count of the response when using localization.\n * If the count is very low or gender is null, you can fallback to a request\n * with no localization.\n *\n * ```typescript\n * import Genderize from '@sebbo2002/genderize';\n * const genderize = new Genderize('API-KEY');\n * genderize.predict(['Noah', 'Evelyn'], 'DE').then(result => {\n * console.log(result);\n * });\n * ```\n *\n * ```json\n * [\n * { name: 'Noah', gender: 'male', probability: 1, count: 608, country_id: 'DE' },\n * { name: 'Evelyn', gender: 'female', probability: 0.97, count: 1665, country_id: 'DE' }\n * ]\n * ```\n */\n async predict(names: string[], country: string): Promise<GenderizeResponseWithCountry[]>;\n\n async predict(names: string | string[], country?: string): Promise<GenderizeResponse | GenderizeResponse[] | GenderizeResponseWithCountry | GenderizeResponseWithCountry[]> {\n const searchParams = this.params(names, country);\n const {body, headers} = await got.get('https://api.genderize.io/', { searchParams, responseType: 'json' });\n this.latestHeaders = [headers, new Date()];\n return body as GenderizeResponse | GenderizeResponse[];\n }\n}\n"],"mappings":"6MAAA,OAAOA,MAAS,MAKT,IAAKC,OACRA,EAAA,OAAS,SACTA,EAAA,KAAO,OAFCA,OAAA,IA6DSC,EAArB,KAA+B,CAmB3B,YAAYC,EAAiB,CAjB7B,KAAQ,cAA8E,KAkBlF,KAAK,OAASA,CAClB,CAKA,OAAO,aAAaC,EAA0D,CAC1E,GAAG,MAAM,QAAQA,CAAK,EAClB,OAAO,KAAK,aAAaA,EAAM,CAAC,CAAC,EAGrC,GAAGA,IAAU,OAIb,OAAO,SAASA,CAAK,CACzB,CAQA,IAAI,OAA+B,CAC/B,GAAG,CAAC,KAAK,cACL,OAAO,KAGX,IAAMC,EAAQH,EAAU,aAAa,KAAK,cAAc,CAAC,EAAE,oBAAoB,CAAC,EAC1EI,EAAYJ,EAAU,aAAa,KAAK,cAAc,CAAC,EAAE,wBAAwB,CAAC,EAClFK,EAAQL,EAAU,aAAa,KAAK,cAAc,CAAC,EAAE,oBAAoB,CAAC,EAEhF,OAAGG,IAAU,QAAaC,IAAc,QAAaC,IAAU,OACpD,CACH,MAAAF,EACA,UAAAC,EACA,MAAO,IAAI,KAAK,KAAK,cAAc,CAAC,EAAE,QAAQ,EAAKC,EAAQ,GAAK,CACpE,EAGG,IACX,CAQA,OAAOC,EAA0BC,EAA0B,CACvD,IAAMC,EAAe,IAAI,gBACzB,GAAG,MAAM,QAAQF,CAAK,GAAKA,EAAM,OAAS,GACtC,MAAM,IAAI,MAAM,yBAAyBA,EAAM,sDAAsD,EAEzG,GAAG,MAAM,QAAQA,CAAK,GAAKA,EAAM,SAAW,EACxC,MAAM,IAAI,MAAM,6CAA6C,EAgBjE,OAbG,MAAM,QAAQA,CAAK,EAClBA,EAAM,QAAQG,GAAQD,EAAa,OAAO,OAAQC,CAAI,CAAC,EAEvDD,EAAa,OAAO,OAAQF,CAAK,EAGlCC,GACCC,EAAa,OAAO,aAAcD,CAAO,EAG1C,KAAK,QACJC,EAAa,OAAO,SAAU,KAAK,MAAM,EAE1C,MAAM,QAAQF,CAAK,EACXE,EAAa,SAAS,EACxB,QAAQ,SAAU,SAAS,EAG7BA,EAAa,SAAS,CACjC,CAsGM,QAAQF,EAA0BC,EAAoI,QAAAG,EAAA,sBACxK,IAAMF,EAAe,KAAK,OAAOF,EAAOC,CAAO,EACzC,CAAC,KAAAI,EAAM,QAAAC,CAAO,EAAI,MAAMC,EAAI,IAAI,4BAA6B,CAAE,aAAAL,EAAc,aAAc,MAAO,CAAC,EACzG,YAAK,cAAgB,CAACI,EAAS,IAAI,IAAM,EAClCD,CACX,GACJ","names":["got","GenderizeGender","Genderize","apiKey","value","limit","remaining","reset","names","country","searchParams","name","__async","body","headers","got"]}
package/package.json CHANGED
@@ -27,25 +27,27 @@
27
27
  "semantic-release-license": "^1.0.3",
28
28
  "source-map-support": "^0.5.21",
29
29
  "ts-node": "^10.8.1",
30
+ "tsup": "^6.7.0",
30
31
  "typedoc": "^0.23.24",
31
32
  "typescript": "^4.9.5"
32
33
  },
33
34
  "engines": {
34
35
  "node": "^14.8.0 || >=16.0.0"
35
36
  },
36
- "exports": "./dist/index.js",
37
37
  "files": [
38
38
  "/dist"
39
39
  ],
40
40
  "homepage": "https://github.com/sebbo2002/genderize#readme",
41
41
  "license": "MIT",
42
+ "main": "./dist/index.js",
43
+ "module": "./dist/index.js",
42
44
  "name": "@sebbo2002/genderize",
43
45
  "repository": {
44
46
  "type": "git",
45
47
  "url": "git+https://github.com/sebbo2002/genderize.git"
46
48
  },
47
49
  "scripts": {
48
- "build": "tsc",
50
+ "build": "tsup && cp ./dist/index.d.ts ./dist/index.d.cts",
49
51
  "build-all": "./.github/workflows/build.sh",
50
52
  "coverage": "c8 mocha",
51
53
  "license-check": "license-checker --production --summary",
@@ -53,5 +55,5 @@
53
55
  "test": "mocha"
54
56
  },
55
57
  "type": "module",
56
- "version": "3.0.0-develop.1"
58
+ "version": "3.0.0-develop.3"
57
59
  }