@sebbo2002/genderize 6.0.1-develop.9 → 7.0.0-develop.2

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Sebastian Pekarek
3
+ Copyright (c) 2026 Sebastian Pekarek
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6
6
  documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var l=(i,e)=>{for(var r in e)a(i,r,{get:e[r],enumerable:!0})},m=(i,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of g(e))!u.call(i,n)&&n!==r&&a(i,n,{get:()=>e[n],enumerable:!(t=p(e,n))||t.enumerable});return i};var c=i=>m(a({},"__esModule",{value:!0}),i);var y={};l(y,{GenderizeGender:()=>o,default:()=>s});module.exports=c(y);var o=(r=>(r.FEMALE="female",r.MALE="male",r))(o||{}),s=class i{get limit(){if(this.latestHeaders){let e=i.getIntHeader(this.latestHeaders[0].get("x-rate-limit-limit")),r=i.getIntHeader(this.latestHeaders[0].get("x-rate-limit-remaining")),t=i.getIntHeader(this.latestHeaders[0].get("x-rate-limit-reset"));if(e!==void 0&&r!==void 0&&t!==void 0)return{limit:e,remaining:r,reset:new Date(this.latestHeaders[1].getTime()+t*1e3)}}return null}apiKey;latestHeaders=null;constructor(e){this.apiKey=e}static getIntHeader(e){if(Array.isArray(e))return this.getIntHeader(e[0]);if(e!=null)return parseInt(e)}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(n=>t.append("name",n)):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()}async predict(e,r){let t=new URLSearchParams(this.params(e,r)),n=await fetch("https://api.genderize.io/?"+t,{headers:{"Content-Type":"application/json"}});if(!n.ok)throw new Error(`Unable to query genderize.io: ${await n.text()}`);let d=await n.json();return this.latestHeaders=[n.headers,new Date],d}};0&&(module.exports={GenderizeGender});
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=function(e){return e.FEMALE=`female`,e.MALE=`male`,e}({});var t=class e{get limit(){if(this.latestHeaders){let t=e.getIntHeader(this.latestHeaders[0].get(`x-rate-limit-limit`)),n=e.getIntHeader(this.latestHeaders[0].get(`x-rate-limit-remaining`)),r=e.getIntHeader(this.latestHeaders[0].get(`x-rate-limit-reset`));if(t!==void 0&&n!==void 0&&r!==void 0)return{limit:t,remaining:n,reset:new Date(this.latestHeaders[1].getTime()+r*1e3)}}return null}apiKey;latestHeaders=null;constructor(e){this.apiKey=e}static getIntHeader(e){if(Array.isArray(e))return this.getIntHeader(e[0]);if(e!=null)return parseInt(e)}params(e,t){let n=new URLSearchParams;if(Array.isArray(e)&&e.length>10)throw Error(`Too many names given: ${e.length} names provided, but 10 is the maximum allowed`);if(Array.isArray(e)&&e.length===0)throw Error(`No name given, but at least one is required`);return Array.isArray(e)?e.forEach(e=>n.append(`name`,e)):n.append(`name`,e),t&&n.append(`country_id`,t),this.apiKey&&n.append(`apikey`,this.apiKey),Array.isArray(e)?n.toString().replace(/name=/g,`name[]=`):n.toString()}async predict(e,t){let n=this.params(e,t),r=await fetch(`https://api.genderize.io/?`+n,{headers:{"Content-Type":`application/json`}});if(!r.ok)throw Error(`Unable to query genderize.io: ${await r.text()}`);let i=await r.json();return this.latestHeaders=[r.headers,new Date],i}};exports.GenderizeGender=e,exports.default=t;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/lib/index.ts"],"sourcesContent":["/**\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 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}\nexport interface GenderizeResponse {\n /**\n * The number of data rows examined in order\n * to calculate the API response\n */\n count: number;\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 * Name which was used for this prediction\n */\n name: string;\n\n /**\n * Value between 0 and 1 (including)\n */\n probability: number;\n}\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 default class Genderize {\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 const limit = Genderize.getIntHeader(\n this.latestHeaders[0].get('x-rate-limit-limit'),\n );\n const remaining = Genderize.getIntHeader(\n this.latestHeaders[0].get('x-rate-limit-remaining'),\n );\n const reset = Genderize.getIntHeader(\n this.latestHeaders[0].get('x-rate-limit-reset'),\n );\n\n if (\n limit !== undefined &&\n remaining !== undefined &&\n reset !== undefined\n ) {\n return {\n limit,\n remaining,\n reset: new Date(\n this.latestHeaders[1].getTime() + reset * 1000,\n ),\n };\n }\n }\n\n return null;\n }\n private readonly apiKey;\n\n private latestHeaders: [Headers, 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(\n value: null | string | string[] | undefined,\n ): number | undefined {\n if (Array.isArray(value)) {\n return this.getIntHeader(value[0]);\n }\n\n if (value === undefined || value === null) {\n return undefined;\n }\n\n return parseInt(value);\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(\n `Too many names given: ${names.length} names provided, but 10 is the maximum allowed`,\n );\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().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 * 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 * 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(\n name: string,\n country: string,\n ): Promise<GenderizeResponseWithCountry>;\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(\n names: string[],\n country: string,\n ): Promise<GenderizeResponseWithCountry[]>;\n async predict(\n names: string | string[],\n country?: string,\n ): Promise<\n | GenderizeResponse\n | GenderizeResponse[]\n | GenderizeResponseWithCountry\n | GenderizeResponseWithCountry[]\n > {\n const queryString = new URLSearchParams(this.params(names, country));\n const response = await fetch(\n 'https://api.genderize.io/?' + queryString,\n {\n headers: {\n 'Content-Type': 'application/json',\n },\n },\n );\n if (!response.ok) {\n throw new Error(\n `Unable to query genderize.io: ${await response.text()}`,\n );\n }\n\n const body = (await response.json()) as\n | GenderizeResponse\n | GenderizeResponse[];\n this.latestHeaders = [response.headers, new Date()];\n return body;\n }\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAGO,IAAKE,OACRA,EAAA,OAAS,SACTA,EAAA,KAAO,OAFCA,OAAA,IA6DSC,EAArB,MAAqBE,CAAU,CAO3B,IAAI,OAA+B,CAC/B,GAAI,KAAK,cAAe,CACpB,IAAMC,EAAQD,EAAU,aACpB,KAAK,cAAc,CAAC,EAAE,IAAI,oBAAoB,CAClD,EACME,EAAYF,EAAU,aACxB,KAAK,cAAc,CAAC,EAAE,IAAI,wBAAwB,CACtD,EACMG,EAAQH,EAAU,aACpB,KAAK,cAAc,CAAC,EAAE,IAAI,oBAAoB,CAClD,EAEA,GACIC,IAAU,QACVC,IAAc,QACdC,IAAU,OAEV,MAAO,CACH,MAAAF,EACA,UAAAC,EACA,MAAO,IAAI,KACP,KAAK,cAAc,CAAC,EAAE,QAAQ,EAAIC,EAAQ,GAC9C,CACJ,CAER,CAEA,OAAO,IACX,CACiB,OAET,cAAwC,KAiBhD,YAAYC,EAAiB,CACzB,KAAK,OAASA,CAClB,CAKA,OAAO,aACHC,EACkB,CAClB,GAAI,MAAM,QAAQA,CAAK,EACnB,OAAO,KAAK,aAAaA,EAAM,CAAC,CAAC,EAGrC,GAA2BA,GAAU,KAIrC,OAAO,SAASA,CAAK,CACzB,CAQA,OAAOC,EAA0BC,EAA0B,CACvD,IAAMC,EAAe,IAAI,gBACzB,GAAI,MAAM,QAAQF,CAAK,GAAKA,EAAM,OAAS,GACvC,MAAM,IAAI,MACN,yBAAyBA,EAAM,MAAM,gDACzC,EAEJ,GAAI,MAAM,QAAQA,CAAK,GAAKA,EAAM,SAAW,EACzC,MAAM,IAAI,MAAM,6CAA6C,EAgBjE,OAbI,MAAM,QAAQA,CAAK,EACnBA,EAAM,QAASG,GAASD,EAAa,OAAO,OAAQC,CAAI,CAAC,EAEzDD,EAAa,OAAO,OAAQF,CAAK,EAGjCC,GACAC,EAAa,OAAO,aAAcD,CAAO,EAGzC,KAAK,QACLC,EAAa,OAAO,SAAU,KAAK,MAAM,EAEzC,MAAM,QAAQF,CAAK,EACZE,EAAa,SAAS,EAAE,QAAQ,SAAU,SAAS,EAGvDA,EAAa,SAAS,CACjC,CAwGA,MAAM,QACFF,EACAC,EAMF,CACE,IAAMG,EAAc,IAAI,gBAAgB,KAAK,OAAOJ,EAAOC,CAAO,CAAC,EAC7DI,EAAW,MAAM,MACnB,6BAA+BD,EAC/B,CACI,QAAS,CACL,eAAgB,kBACpB,CACJ,CACJ,EACA,GAAI,CAACC,EAAS,GACV,MAAM,IAAI,MACN,iCAAiC,MAAMA,EAAS,KAAK,CAAC,EAC1D,EAGJ,IAAMC,EAAQ,MAAMD,EAAS,KAAK,EAGlC,YAAK,cAAgB,CAACA,EAAS,QAAS,IAAI,IAAM,EAC3CC,CACX,CACJ","names":["index_exports","__export","GenderizeGender","Genderize","__toCommonJS","_Genderize","limit","remaining","reset","apiKey","value","names","country","searchParams","name","queryString","response","body"]}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/lib/index.ts"],"sourcesContent":["/**\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 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}\nexport interface GenderizeResponse {\n /**\n * The number of data rows examined in order\n * to calculate the API response\n */\n count: number;\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 * Name which was used for this prediction\n */\n name: string;\n\n /**\n * Value between 0 and 1 (including)\n */\n probability: number;\n}\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 default class Genderize {\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 const limit = Genderize.getIntHeader(\n this.latestHeaders[0].get('x-rate-limit-limit'),\n );\n const remaining = Genderize.getIntHeader(\n this.latestHeaders[0].get('x-rate-limit-remaining'),\n );\n const reset = Genderize.getIntHeader(\n this.latestHeaders[0].get('x-rate-limit-reset'),\n );\n\n if (\n limit !== undefined &&\n remaining !== undefined &&\n reset !== undefined\n ) {\n return {\n limit,\n remaining,\n reset: new Date(\n this.latestHeaders[1].getTime() + reset * 1000,\n ),\n };\n }\n }\n\n return null;\n }\n private readonly apiKey;\n\n private latestHeaders: [Headers, 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(\n value: null | string | string[] | undefined,\n ): number | undefined {\n if (Array.isArray(value)) {\n return this.getIntHeader(value[0]);\n }\n\n if (value === undefined || value === null) {\n return undefined;\n }\n\n return parseInt(value);\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(\n `Too many names given: ${names.length} names provided, but 10 is the maximum allowed`,\n );\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().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 * 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 * 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(\n name: string,\n country: string,\n ): Promise<GenderizeResponseWithCountry>;\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(\n names: string[],\n country: string,\n ): Promise<GenderizeResponseWithCountry[]>;\n async predict(\n names: string | string[],\n country?: string,\n ): Promise<\n | GenderizeResponse\n | GenderizeResponse[]\n | GenderizeResponseWithCountry\n | GenderizeResponseWithCountry[]\n > {\n const queryString = this.params(names, country);\n const response = await fetch(\n 'https://api.genderize.io/?' + queryString,\n {\n headers: {\n 'Content-Type': 'application/json',\n },\n },\n );\n if (!response.ok) {\n throw new Error(\n `Unable to query genderize.io: ${await response.text()}`,\n );\n }\n\n const body = (await response.json()) as\n | GenderizeResponse\n | GenderizeResponse[];\n this.latestHeaders = [response.headers, new Date()];\n return body;\n }\n}\n"],"mappings":"+FAGA,IAAY,EAAL,SAAA,EAAA,OACH,GAAA,OAAA,SACA,EAAA,KAAA,QACJ,EAAA,CAAA,CAAA,EA0DA,IAAqB,EAArB,MAAqB,CAAU,CAO3B,IAAI,OAA+B,CAC/B,GAAI,KAAK,cAAe,CACpB,IAAM,EAAQ,EAAU,aACpB,KAAK,cAAc,GAAG,IAAI,oBAAoB,CAClD,EACM,EAAY,EAAU,aACxB,KAAK,cAAc,GAAG,IAAI,wBAAwB,CACtD,EACM,EAAQ,EAAU,aACpB,KAAK,cAAc,GAAG,IAAI,oBAAoB,CAClD,EAEA,GACI,IAAU,IAAA,IACV,IAAc,IAAA,IACd,IAAU,IAAA,GAEV,MAAO,CACH,QACA,YACA,MAAO,IAAI,KACP,KAAK,cAAc,GAAG,QAAQ,EAAI,EAAQ,GAC9C,CACJ,CAER,CAEA,OAAO,IACX,CACA,OAEA,cAAgD,KAiBhD,YAAY,EAAiB,CACzB,KAAK,OAAS,CAClB,CAKA,OAAO,aACH,EACkB,CAClB,GAAI,MAAM,QAAQ,CAAK,EACnB,OAAO,KAAK,aAAa,EAAM,EAAE,EAGjC,MAAiC,KAIrC,OAAO,SAAS,CAAK,CACzB,CAQA,OAAO,EAA0B,EAA0B,CACvD,IAAM,EAAe,IAAI,gBACzB,GAAI,MAAM,QAAQ,CAAK,GAAK,EAAM,OAAS,GACvC,MAAU,MACN,yBAAyB,EAAM,OAAO,+CAC1C,EAEJ,GAAI,MAAM,QAAQ,CAAK,GAAK,EAAM,SAAW,EACzC,MAAU,MAAM,6CAA6C,EAoBjE,OAjBI,MAAM,QAAQ,CAAK,EACnB,EAAM,QAAS,GAAS,EAAa,OAAO,OAAQ,CAAI,CAAC,EAEzD,EAAa,OAAO,OAAQ,CAAK,EAGjC,GACA,EAAa,OAAO,aAAc,CAAO,EAGzC,KAAK,QACL,EAAa,OAAO,SAAU,KAAK,MAAM,EAEzC,MAAM,QAAQ,CAAK,EACZ,EAAa,SAAS,EAAE,QAAQ,SAAU,SAAS,EAGvD,EAAa,SAAS,CACjC,CAwGA,MAAM,QACF,EACA,EAMF,CACE,IAAM,EAAc,KAAK,OAAO,EAAO,CAAO,EACxC,EAAW,MAAM,MACnB,6BAA+B,EAC/B,CACI,QAAS,CACL,eAAgB,kBACpB,CACJ,CACJ,EACA,GAAI,CAAC,EAAS,GACV,MAAU,MACN,iCAAiC,MAAM,EAAS,KAAK,GACzD,EAGJ,IAAM,EAAQ,MAAM,EAAS,KAAK,EAIlC,MADA,MAAK,cAAgB,CAAC,EAAS,QAAS,IAAI,IAAM,EAC3C,CACX,CACJ"}
package/dist/index.d.cts CHANGED
@@ -1,192 +1,194 @@
1
+ //#region src/lib/index.d.ts
1
2
  /**
2
3
  * Enum that can be used to compare and check the results
3
4
  */
4
5
  declare enum GenderizeGender {
5
- FEMALE = "female",
6
- MALE = "male"
6
+ FEMALE = "female",
7
+ MALE = "male"
7
8
  }
8
9
  interface GenderizeLimit {
9
- /**
10
- * The amount of names available in the current time window
11
- */
12
- limit: number;
13
- /**
14
- * The number of names left in the current time window
15
- */
16
- remaining: number;
17
- /**
18
- * Next time window start time
19
- *
20
- * ```javascript
21
- * import Genderize from '@sebbo2002/genderize';
22
- * const genderize = new Genderize('API-KEY');
23
- *
24
- * // execute a predicition
25
- *
26
- * genderize.limit?.reset.toString()
27
- * ```
28
- */
29
- reset: Date;
10
+ /**
11
+ * The amount of names available in the current time window
12
+ */
13
+ limit: number;
14
+ /**
15
+ * The number of names left in the current time window
16
+ */
17
+ remaining: number;
18
+ /**
19
+ * Next time window start time
20
+ *
21
+ * ```javascript
22
+ * import Genderize from '@sebbo2002/genderize';
23
+ * const genderize = new Genderize('API-KEY');
24
+ *
25
+ * // execute a predicition
26
+ *
27
+ * genderize.limit?.reset.toString()
28
+ * ```
29
+ */
30
+ reset: Date;
30
31
  }
31
32
  interface GenderizeResponse {
32
- /**
33
- * The number of data rows examined in order
34
- * to calculate the API response
35
- */
36
- count: number;
37
- /**
38
- * Either a [[`GenderizeGender`]] value (male/female) or null
39
- * if the API was not able to predict a gender.
40
- */
41
- gender: GenderizeGender | null;
42
- /**
43
- * Name which was used for this prediction
44
- */
45
- name: string;
46
- /**
47
- * Value between 0 and 1 (including)
48
- */
49
- probability: number;
33
+ /**
34
+ * The number of data rows examined in order
35
+ * to calculate the API response
36
+ */
37
+ count: number;
38
+ /**
39
+ * Either a [[`GenderizeGender`]] value (male/female) or null
40
+ * if the API was not able to predict a gender.
41
+ */
42
+ gender: GenderizeGender | null;
43
+ /**
44
+ * Name which was used for this prediction
45
+ */
46
+ name: string;
47
+ /**
48
+ * Value between 0 and 1 (including)
49
+ */
50
+ probability: number;
50
51
  }
51
52
  interface GenderizeResponseWithCountry extends GenderizeResponse {
52
- /**
53
- * ISO 3166-1 alpha-2 country code which was used for this prediction
54
- */
55
- country_id: string;
53
+ /**
54
+ * ISO 3166-1 alpha-2 country code which was used for this prediction
55
+ */
56
+ country_id: string;
56
57
  }
57
58
  declare class Genderize {
58
- /**
59
- * Outputs information about the current state of the rate limit. Updated and cached
60
- * each time [[`predict`]] is called. If no information is available, for example because
61
- * [[`predict`]] has not been executed yet, `null` is returned. Otherwise the response is
62
- * of type [[`GenderizeLimit`]].
63
- */
64
- get limit(): GenderizeLimit | null;
65
- private readonly apiKey;
66
- private latestHeaders;
67
- /**
68
- * Usually you get an `Genderize` instance like this:
69
- * ```javascript
70
- * import Genderize from '@sebbo2002/genderize';
71
- * const genderize = new Genderize('API-KEY');
72
- * ```
73
- *
74
- * You can get an API key from [store.genderize.io](https://store.genderize.io/).
75
- *
76
- * If you don't have an API key yet, you can start with the free plan:
77
- * ```javascript
78
- * import Genderize from '@sebbo2002/genderize';
79
- * const genderize = new Genderize();
80
- * ```
81
- */
82
- constructor(apiKey?: string);
83
- /**
84
- * @internal
85
- */
86
- static getIntHeader(value: null | string | string[] | undefined): number | undefined;
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[]>;
59
+ /**
60
+ * Outputs information about the current state of the rate limit. Updated and cached
61
+ * each time [[`predict`]] is called. If no information is available, for example because
62
+ * [[`predict`]] has not been executed yet, `null` is returned. Otherwise the response is
63
+ * of type [[`GenderizeLimit`]].
64
+ */
65
+ get limit(): GenderizeLimit | null;
66
+ private readonly apiKey;
67
+ private latestHeaders;
68
+ /**
69
+ * Usually you get an `Genderize` instance like this:
70
+ * ```javascript
71
+ * import Genderize from '@sebbo2002/genderize';
72
+ * const genderize = new Genderize('API-KEY');
73
+ * ```
74
+ *
75
+ * You can get an API key from [store.genderize.io](https://store.genderize.io/).
76
+ *
77
+ * If you don't have an API key yet, you can start with the free plan:
78
+ * ```javascript
79
+ * import Genderize from '@sebbo2002/genderize';
80
+ * const genderize = new Genderize();
81
+ * ```
82
+ */
83
+ constructor(apiKey?: string);
84
+ /**
85
+ * @internal
86
+ */
87
+ static getIntHeader(value: null | string | string[] | undefined): number | undefined;
88
+ /**
89
+ * Internal function which builds the url parameters
90
+ * used to query the prediction endpoint.
91
+ *
92
+ * @internal
93
+ */
94
+ params(names: string | string[], country?: string): string;
95
+ /**
96
+ * Predict a single name
97
+ *
98
+ * ```typescript
99
+ * import Genderize from '@sebbo2002/genderize';
100
+ * const genderize = new Genderize('API-KEY');
101
+ * genderize.predict('Mia').then(result => {
102
+ * console.log(result);
103
+ * });
104
+ * ```
105
+ *
106
+ * ```json
107
+ * {
108
+ * name: 'Mia',
109
+ * gender: 'female',
110
+ * probability: 0.96,
111
+ * count: 19266
112
+ * }
113
+ * ```
114
+ */
115
+ predict(name: string): Promise<GenderizeResponse>;
116
+ /**
117
+ * Predict multiple names. Works for up to 10 names at the same time.
118
+ *
119
+ * Please check [this list](https://genderize.io/our-data) if you're unsure about
120
+ * the country code you have to use.
121
+ *
122
+ * It is recommended to check the count of the response when using localization.
123
+ * If the count is very low or gender is null, you can fallback to a request
124
+ * with no localization.
125
+ *
126
+ * ```typescript
127
+ * import Genderize from '@sebbo2002/genderize';
128
+ * const genderize = new Genderize('API-KEY');
129
+ * genderize.predict(['Noah', 'Evelyn']).then(result => {
130
+ * console.log(result);
131
+ * });
132
+ * ```
133
+ *
134
+ * ```json
135
+ * [
136
+ * { name: 'Noah', gender: 'male', probability: 0.88, count: 3939 },
137
+ * { name: 'Evelyn', gender: 'female', probability: 0.98, count: 12188 }
138
+ * ]
139
+ * ```
140
+ */
141
+ predict(names: string[]): Promise<GenderizeResponse[]>;
142
+ /**
143
+ * Predict a single name with a given ISO 3166-1 alpha-2 country code
144
+ *
145
+ * ```typescript
146
+ * import Genderize from '@sebbo2002/genderize';
147
+ * const genderize = new Genderize('API-KEY');
148
+ * genderize.predict('Mia', 'DE').then(result => {
149
+ * console.log(result);
150
+ * });
151
+ * ```
152
+ *
153
+ * ```json
154
+ * {
155
+ * name: 'Mia',
156
+ * gender: 'female',
157
+ * probability: 0.97,
158
+ * count: 1786,
159
+ * country_id: 'DE'
160
+ * }
161
+ * ```
162
+ */
163
+ predict(name: string, country: string): Promise<GenderizeResponseWithCountry>;
164
+ /**
165
+ * Predict multiple names with a given ISO 3166-1 alpha-2
166
+ * country code. Works for up to 10 names at the same time.
167
+ *
168
+ * Please check [this list](https://genderize.io/our-data) if you're unsure about
169
+ * the country code you have to use.
170
+ *
171
+ * It is recommended to check the count of the response when using localization.
172
+ * If the count is very low or gender is null, you can fallback to a request
173
+ * with no localization.
174
+ *
175
+ * ```typescript
176
+ * import Genderize from '@sebbo2002/genderize';
177
+ * const genderize = new Genderize('API-KEY');
178
+ * genderize.predict(['Noah', 'Evelyn'], 'DE').then(result => {
179
+ * console.log(result);
180
+ * });
181
+ * ```
182
+ *
183
+ * ```json
184
+ * [
185
+ * { name: 'Noah', gender: 'male', probability: 1, count: 608, country_id: 'DE' },
186
+ * { name: 'Evelyn', gender: 'female', probability: 0.97, count: 1665, country_id: 'DE' }
187
+ * ]
188
+ * ```
189
+ */
190
+ predict(names: string[], country: string): Promise<GenderizeResponseWithCountry[]>;
190
191
  }
191
-
192
- export { GenderizeGender, type GenderizeLimit, type GenderizeResponse, type GenderizeResponseWithCountry, Genderize as default };
192
+ //#endregion
193
+ export { GenderizeGender, GenderizeLimit, GenderizeResponse, GenderizeResponseWithCountry, Genderize as default };
194
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1,194 @@
1
+ //#region src/lib/index.d.ts
2
+ /**
3
+ * Enum that can be used to compare and check the results
4
+ */
5
+ declare enum GenderizeGender {
6
+ FEMALE = "female",
7
+ MALE = "male"
8
+ }
9
+ interface GenderizeLimit {
10
+ /**
11
+ * The amount of names available in the current time window
12
+ */
13
+ limit: number;
14
+ /**
15
+ * The number of names left in the current time window
16
+ */
17
+ remaining: number;
18
+ /**
19
+ * Next time window start time
20
+ *
21
+ * ```javascript
22
+ * import Genderize from '@sebbo2002/genderize';
23
+ * const genderize = new Genderize('API-KEY');
24
+ *
25
+ * // execute a predicition
26
+ *
27
+ * genderize.limit?.reset.toString()
28
+ * ```
29
+ */
30
+ reset: Date;
31
+ }
32
+ interface GenderizeResponse {
33
+ /**
34
+ * The number of data rows examined in order
35
+ * to calculate the API response
36
+ */
37
+ count: number;
38
+ /**
39
+ * Either a [[`GenderizeGender`]] value (male/female) or null
40
+ * if the API was not able to predict a gender.
41
+ */
42
+ gender: GenderizeGender | null;
43
+ /**
44
+ * Name which was used for this prediction
45
+ */
46
+ name: string;
47
+ /**
48
+ * Value between 0 and 1 (including)
49
+ */
50
+ probability: number;
51
+ }
52
+ interface GenderizeResponseWithCountry extends GenderizeResponse {
53
+ /**
54
+ * ISO 3166-1 alpha-2 country code which was used for this prediction
55
+ */
56
+ country_id: string;
57
+ }
58
+ declare class Genderize {
59
+ /**
60
+ * Outputs information about the current state of the rate limit. Updated and cached
61
+ * each time [[`predict`]] is called. If no information is available, for example because
62
+ * [[`predict`]] has not been executed yet, `null` is returned. Otherwise the response is
63
+ * of type [[`GenderizeLimit`]].
64
+ */
65
+ get limit(): GenderizeLimit | null;
66
+ private readonly apiKey;
67
+ private latestHeaders;
68
+ /**
69
+ * Usually you get an `Genderize` instance like this:
70
+ * ```javascript
71
+ * import Genderize from '@sebbo2002/genderize';
72
+ * const genderize = new Genderize('API-KEY');
73
+ * ```
74
+ *
75
+ * You can get an API key from [store.genderize.io](https://store.genderize.io/).
76
+ *
77
+ * If you don't have an API key yet, you can start with the free plan:
78
+ * ```javascript
79
+ * import Genderize from '@sebbo2002/genderize';
80
+ * const genderize = new Genderize();
81
+ * ```
82
+ */
83
+ constructor(apiKey?: string);
84
+ /**
85
+ * @internal
86
+ */
87
+ static getIntHeader(value: null | string | string[] | undefined): number | undefined;
88
+ /**
89
+ * Internal function which builds the url parameters
90
+ * used to query the prediction endpoint.
91
+ *
92
+ * @internal
93
+ */
94
+ params(names: string | string[], country?: string): string;
95
+ /**
96
+ * Predict a single name
97
+ *
98
+ * ```typescript
99
+ * import Genderize from '@sebbo2002/genderize';
100
+ * const genderize = new Genderize('API-KEY');
101
+ * genderize.predict('Mia').then(result => {
102
+ * console.log(result);
103
+ * });
104
+ * ```
105
+ *
106
+ * ```json
107
+ * {
108
+ * name: 'Mia',
109
+ * gender: 'female',
110
+ * probability: 0.96,
111
+ * count: 19266
112
+ * }
113
+ * ```
114
+ */
115
+ predict(name: string): Promise<GenderizeResponse>;
116
+ /**
117
+ * Predict multiple names. Works for up to 10 names at the same time.
118
+ *
119
+ * Please check [this list](https://genderize.io/our-data) if you're unsure about
120
+ * the country code you have to use.
121
+ *
122
+ * It is recommended to check the count of the response when using localization.
123
+ * If the count is very low or gender is null, you can fallback to a request
124
+ * with no localization.
125
+ *
126
+ * ```typescript
127
+ * import Genderize from '@sebbo2002/genderize';
128
+ * const genderize = new Genderize('API-KEY');
129
+ * genderize.predict(['Noah', 'Evelyn']).then(result => {
130
+ * console.log(result);
131
+ * });
132
+ * ```
133
+ *
134
+ * ```json
135
+ * [
136
+ * { name: 'Noah', gender: 'male', probability: 0.88, count: 3939 },
137
+ * { name: 'Evelyn', gender: 'female', probability: 0.98, count: 12188 }
138
+ * ]
139
+ * ```
140
+ */
141
+ predict(names: string[]): Promise<GenderizeResponse[]>;
142
+ /**
143
+ * Predict a single name with a given ISO 3166-1 alpha-2 country code
144
+ *
145
+ * ```typescript
146
+ * import Genderize from '@sebbo2002/genderize';
147
+ * const genderize = new Genderize('API-KEY');
148
+ * genderize.predict('Mia', 'DE').then(result => {
149
+ * console.log(result);
150
+ * });
151
+ * ```
152
+ *
153
+ * ```json
154
+ * {
155
+ * name: 'Mia',
156
+ * gender: 'female',
157
+ * probability: 0.97,
158
+ * count: 1786,
159
+ * country_id: 'DE'
160
+ * }
161
+ * ```
162
+ */
163
+ predict(name: string, country: string): Promise<GenderizeResponseWithCountry>;
164
+ /**
165
+ * Predict multiple names with a given ISO 3166-1 alpha-2
166
+ * country code. Works for up to 10 names at the same time.
167
+ *
168
+ * Please check [this list](https://genderize.io/our-data) if you're unsure about
169
+ * the country code you have to use.
170
+ *
171
+ * It is recommended to check the count of the response when using localization.
172
+ * If the count is very low or gender is null, you can fallback to a request
173
+ * with no localization.
174
+ *
175
+ * ```typescript
176
+ * import Genderize from '@sebbo2002/genderize';
177
+ * const genderize = new Genderize('API-KEY');
178
+ * genderize.predict(['Noah', 'Evelyn'], 'DE').then(result => {
179
+ * console.log(result);
180
+ * });
181
+ * ```
182
+ *
183
+ * ```json
184
+ * [
185
+ * { name: 'Noah', gender: 'male', probability: 1, count: 608, country_id: 'DE' },
186
+ * { name: 'Evelyn', gender: 'female', probability: 0.97, count: 1665, country_id: 'DE' }
187
+ * ]
188
+ * ```
189
+ */
190
+ predict(names: string[], country: string): Promise<GenderizeResponseWithCountry[]>;
191
+ }
192
+ //#endregion
193
+ export { GenderizeGender, GenderizeLimit, GenderizeResponse, GenderizeResponseWithCountry, Genderize as default };
194
+ //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ let e=function(e){return e.FEMALE=`female`,e.MALE=`male`,e}({});var t=class e{get limit(){if(this.latestHeaders){let t=e.getIntHeader(this.latestHeaders[0].get(`x-rate-limit-limit`)),n=e.getIntHeader(this.latestHeaders[0].get(`x-rate-limit-remaining`)),r=e.getIntHeader(this.latestHeaders[0].get(`x-rate-limit-reset`));if(t!==void 0&&n!==void 0&&r!==void 0)return{limit:t,remaining:n,reset:new Date(this.latestHeaders[1].getTime()+r*1e3)}}return null}apiKey;latestHeaders=null;constructor(e){this.apiKey=e}static getIntHeader(e){if(Array.isArray(e))return this.getIntHeader(e[0]);if(e!=null)return parseInt(e)}params(e,t){let n=new URLSearchParams;if(Array.isArray(e)&&e.length>10)throw Error(`Too many names given: ${e.length} names provided, but 10 is the maximum allowed`);if(Array.isArray(e)&&e.length===0)throw Error(`No name given, but at least one is required`);return Array.isArray(e)?e.forEach(e=>n.append(`name`,e)):n.append(`name`,e),t&&n.append(`country_id`,t),this.apiKey&&n.append(`apikey`,this.apiKey),Array.isArray(e)?n.toString().replace(/name=/g,`name[]=`):n.toString()}async predict(e,t){let n=this.params(e,t),r=await fetch(`https://api.genderize.io/?`+n,{headers:{"Content-Type":`application/json`}});if(!r.ok)throw Error(`Unable to query genderize.io: ${await r.text()}`);let i=await r.json();return this.latestHeaders=[r.headers,new Date],i}};export{e as GenderizeGender,t as default};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/lib/index.ts"],"sourcesContent":["/**\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 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}\nexport interface GenderizeResponse {\n /**\n * The number of data rows examined in order\n * to calculate the API response\n */\n count: number;\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 * Name which was used for this prediction\n */\n name: string;\n\n /**\n * Value between 0 and 1 (including)\n */\n probability: number;\n}\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 default class Genderize {\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 const limit = Genderize.getIntHeader(\n this.latestHeaders[0].get('x-rate-limit-limit'),\n );\n const remaining = Genderize.getIntHeader(\n this.latestHeaders[0].get('x-rate-limit-remaining'),\n );\n const reset = Genderize.getIntHeader(\n this.latestHeaders[0].get('x-rate-limit-reset'),\n );\n\n if (\n limit !== undefined &&\n remaining !== undefined &&\n reset !== undefined\n ) {\n return {\n limit,\n remaining,\n reset: new Date(\n this.latestHeaders[1].getTime() + reset * 1000,\n ),\n };\n }\n }\n\n return null;\n }\n private readonly apiKey;\n\n private latestHeaders: [Headers, 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(\n value: null | string | string[] | undefined,\n ): number | undefined {\n if (Array.isArray(value)) {\n return this.getIntHeader(value[0]);\n }\n\n if (value === undefined || value === null) {\n return undefined;\n }\n\n return parseInt(value);\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(\n `Too many names given: ${names.length} names provided, but 10 is the maximum allowed`,\n );\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().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 * 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 * 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(\n name: string,\n country: string,\n ): Promise<GenderizeResponseWithCountry>;\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(\n names: string[],\n country: string,\n ): Promise<GenderizeResponseWithCountry[]>;\n async predict(\n names: string | string[],\n country?: string,\n ): Promise<\n | GenderizeResponse\n | GenderizeResponse[]\n | GenderizeResponseWithCountry\n | GenderizeResponseWithCountry[]\n > {\n const queryString = this.params(names, country);\n const response = await fetch(\n 'https://api.genderize.io/?' + queryString,\n {\n headers: {\n 'Content-Type': 'application/json',\n },\n },\n );\n if (!response.ok) {\n throw new Error(\n `Unable to query genderize.io: ${await response.text()}`,\n );\n }\n\n const body = (await response.json()) as\n | GenderizeResponse\n | GenderizeResponse[];\n this.latestHeaders = [response.headers, new Date()];\n return body;\n }\n}\n"],"mappings":"AAGA,IAAY,EAAL,SAAA,EAAA,OACH,GAAA,OAAA,SACA,EAAA,KAAA,QACJ,EAAA,CAAA,CAAA,EA0DA,IAAqB,EAArB,MAAqB,CAAU,CAO3B,IAAI,OAA+B,CAC/B,GAAI,KAAK,cAAe,CACpB,IAAM,EAAQ,EAAU,aACpB,KAAK,cAAc,GAAG,IAAI,oBAAoB,CAClD,EACM,EAAY,EAAU,aACxB,KAAK,cAAc,GAAG,IAAI,wBAAwB,CACtD,EACM,EAAQ,EAAU,aACpB,KAAK,cAAc,GAAG,IAAI,oBAAoB,CAClD,EAEA,GACI,IAAU,IAAA,IACV,IAAc,IAAA,IACd,IAAU,IAAA,GAEV,MAAO,CACH,QACA,YACA,MAAO,IAAI,KACP,KAAK,cAAc,GAAG,QAAQ,EAAI,EAAQ,GAC9C,CACJ,CAER,CAEA,OAAO,IACX,CACA,OAEA,cAAgD,KAiBhD,YAAY,EAAiB,CACzB,KAAK,OAAS,CAClB,CAKA,OAAO,aACH,EACkB,CAClB,GAAI,MAAM,QAAQ,CAAK,EACnB,OAAO,KAAK,aAAa,EAAM,EAAE,EAGjC,MAAiC,KAIrC,OAAO,SAAS,CAAK,CACzB,CAQA,OAAO,EAA0B,EAA0B,CACvD,IAAM,EAAe,IAAI,gBACzB,GAAI,MAAM,QAAQ,CAAK,GAAK,EAAM,OAAS,GACvC,MAAU,MACN,yBAAyB,EAAM,OAAO,+CAC1C,EAEJ,GAAI,MAAM,QAAQ,CAAK,GAAK,EAAM,SAAW,EACzC,MAAU,MAAM,6CAA6C,EAoBjE,OAjBI,MAAM,QAAQ,CAAK,EACnB,EAAM,QAAS,GAAS,EAAa,OAAO,OAAQ,CAAI,CAAC,EAEzD,EAAa,OAAO,OAAQ,CAAK,EAGjC,GACA,EAAa,OAAO,aAAc,CAAO,EAGzC,KAAK,QACL,EAAa,OAAO,SAAU,KAAK,MAAM,EAEzC,MAAM,QAAQ,CAAK,EACZ,EAAa,SAAS,EAAE,QAAQ,SAAU,SAAS,EAGvD,EAAa,SAAS,CACjC,CAwGA,MAAM,QACF,EACA,EAMF,CACE,IAAM,EAAc,KAAK,OAAO,EAAO,CAAO,EACxC,EAAW,MAAM,MACnB,6BAA+B,EAC/B,CACI,QAAS,CACL,eAAgB,kBACpB,CACJ,CACJ,EACA,GAAI,CAAC,EAAS,GACV,MAAU,MACN,iCAAiC,MAAM,EAAS,KAAK,GACzD,EAGJ,IAAM,EAAQ,MAAM,EAAS,KAAK,EAIlC,MADA,MAAK,cAAgB,CAAC,EAAS,QAAS,IAAI,IAAM,EAC3C,CACX,CACJ"}
package/package.json CHANGED
@@ -5,38 +5,39 @@
5
5
  },
6
6
  "description": "genderize is a simple client for genderize.io, a gender prediction API",
7
7
  "devDependencies": {
8
- "@eslint/js": "^9.30.1",
9
- "@qiwi/semantic-release-gh-pages-plugin": "^5.4.3",
8
+ "@eslint/js": "^10.0.1",
10
9
  "@semantic-release/changelog": "^6.0.3",
11
10
  "@semantic-release/exec": "^7.1.0",
12
11
  "@semantic-release/git": "^10.0.1",
13
- "@semantic-release/npm": "^12.0.2",
12
+ "@semantic-release/npm": "^13.1.5",
14
13
  "@types/mocha": "^10.0.10",
15
- "@types/node": "^22.15.30",
16
- "c8": "^10.1.3",
17
- "eslint": "^9.29.0",
18
- "eslint-config-prettier": "^10.1.5",
19
- "eslint-plugin-jsonc": "^2.20.1",
20
- "eslint-plugin-perfectionist": "^4.15.0",
14
+ "@types/node": "^25.9.1",
15
+ "c8": "^11.0.0",
16
+ "eslint": "^10.4.0",
17
+ "eslint-config-prettier": "^10.1.8",
18
+ "eslint-plugin-jsonc": "^3.1.2",
19
+ "eslint-plugin-perfectionist": "^5.9.0",
21
20
  "esm": "^3.2.25",
21
+ "globals": "^17.6.0",
22
22
  "husky": "^9.1.7",
23
23
  "license-checker": "^25.0.1",
24
- "mocha": "^11.7.1",
25
- "mochawesome": "^7.1.3",
26
- "prettier": "^3.6.2",
24
+ "mocha": "^11.7.6",
25
+ "mochawesome": "^7.1.4",
26
+ "prettier": "^3.8.3",
27
+ "semantic-release": "^25.0.3",
27
28
  "semantic-release-license": "^1.0.3",
28
29
  "source-map-support": "^0.5.21",
29
- "tsup": "^8.5.0",
30
- "tsx": "^4.20.3",
31
- "typedoc": "^0.28.7",
32
- "typescript": "^5.8.3",
33
- "typescript-eslint": "^8.34.1"
30
+ "tsdown": "^0.22.0",
31
+ "tsx": "^4.22.3",
32
+ "typedoc": "^0.28.19",
33
+ "typescript": "^6.0.3",
34
+ "typescript-eslint": "^8.60.0"
34
35
  },
35
36
  "engines": {
36
- "node": "20 || >=22.0.0"
37
+ "node": "22 || >=24.0.0"
37
38
  },
38
39
  "exports": {
39
- "import": "./dist/lib/index.js",
40
+ "import": "./dist/lib/index.mjs",
40
41
  "require": "./dist/lib/index.cjs"
41
42
  },
42
43
  "files": [
@@ -44,21 +45,22 @@
44
45
  ],
45
46
  "homepage": "https://github.com/sebbo2002/genderize#readme",
46
47
  "license": "MIT",
47
- "main": "./dist/index.js",
48
- "module": "./dist/index.js",
48
+ "main": "./dist/lib/index.cjs",
49
+ "module": "./dist/lib/index.mjs",
49
50
  "name": "@sebbo2002/genderize",
50
51
  "repository": {
51
52
  "type": "git",
52
53
  "url": "git+https://github.com/sebbo2002/genderize.git"
53
54
  },
54
55
  "scripts": {
55
- "build": "tsup && cp ./dist/index.d.ts ./dist/index.d.cts",
56
+ "build": "tsdown",
56
57
  "build-all": "./.github/workflows/build.sh",
57
58
  "coverage": "c8 mocha",
58
59
  "license-check": "license-checker --production --summary",
59
60
  "lint": "npx eslint . --fix && npx prettier . --write",
61
+ "prepare": "husky",
60
62
  "test": "mocha"
61
63
  },
62
64
  "type": "module",
63
- "version": "6.0.1-develop.9"
65
+ "version": "7.0.0-develop.2"
64
66
  }
package/dist/index.d.ts DELETED
@@ -1,192 +0,0 @@
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 GenderizeLimit {
9
- /**
10
- * The amount of names available in the current time window
11
- */
12
- limit: number;
13
- /**
14
- * The number of names left in the current time window
15
- */
16
- remaining: number;
17
- /**
18
- * Next time window start time
19
- *
20
- * ```javascript
21
- * import Genderize from '@sebbo2002/genderize';
22
- * const genderize = new Genderize('API-KEY');
23
- *
24
- * // execute a predicition
25
- *
26
- * genderize.limit?.reset.toString()
27
- * ```
28
- */
29
- reset: Date;
30
- }
31
- interface GenderizeResponse {
32
- /**
33
- * The number of data rows examined in order
34
- * to calculate the API response
35
- */
36
- count: number;
37
- /**
38
- * Either a [[`GenderizeGender`]] value (male/female) or null
39
- * if the API was not able to predict a gender.
40
- */
41
- gender: GenderizeGender | null;
42
- /**
43
- * Name which was used for this prediction
44
- */
45
- name: string;
46
- /**
47
- * Value between 0 and 1 (including)
48
- */
49
- probability: number;
50
- }
51
- interface GenderizeResponseWithCountry extends GenderizeResponse {
52
- /**
53
- * ISO 3166-1 alpha-2 country code which was used for this prediction
54
- */
55
- country_id: string;
56
- }
57
- declare class Genderize {
58
- /**
59
- * Outputs information about the current state of the rate limit. Updated and cached
60
- * each time [[`predict`]] is called. If no information is available, for example because
61
- * [[`predict`]] has not been executed yet, `null` is returned. Otherwise the response is
62
- * of type [[`GenderizeLimit`]].
63
- */
64
- get limit(): GenderizeLimit | null;
65
- private readonly apiKey;
66
- private latestHeaders;
67
- /**
68
- * Usually you get an `Genderize` instance like this:
69
- * ```javascript
70
- * import Genderize from '@sebbo2002/genderize';
71
- * const genderize = new Genderize('API-KEY');
72
- * ```
73
- *
74
- * You can get an API key from [store.genderize.io](https://store.genderize.io/).
75
- *
76
- * If you don't have an API key yet, you can start with the free plan:
77
- * ```javascript
78
- * import Genderize from '@sebbo2002/genderize';
79
- * const genderize = new Genderize();
80
- * ```
81
- */
82
- constructor(apiKey?: string);
83
- /**
84
- * @internal
85
- */
86
- static getIntHeader(value: null | string | string[] | undefined): number | undefined;
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, type GenderizeLimit, type GenderizeResponse, type GenderizeResponseWithCountry, Genderize as default };
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- var o=(t=>(t.FEMALE="female",t.MALE="male",t))(o||{}),s=class i{get limit(){if(this.latestHeaders){let e=i.getIntHeader(this.latestHeaders[0].get("x-rate-limit-limit")),t=i.getIntHeader(this.latestHeaders[0].get("x-rate-limit-remaining")),r=i.getIntHeader(this.latestHeaders[0].get("x-rate-limit-reset"));if(e!==void 0&&t!==void 0&&r!==void 0)return{limit:e,remaining:t,reset:new Date(this.latestHeaders[1].getTime()+r*1e3)}}return null}apiKey;latestHeaders=null;constructor(e){this.apiKey=e}static getIntHeader(e){if(Array.isArray(e))return this.getIntHeader(e[0]);if(e!=null)return parseInt(e)}params(e,t){let r=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(n=>r.append("name",n)):r.append("name",e),t&&r.append("country_id",t),this.apiKey&&r.append("apikey",this.apiKey),Array.isArray(e)?r.toString().replace(/name=/g,"name[]="):r.toString()}async predict(e,t){let r=new URLSearchParams(this.params(e,t)),n=await fetch("https://api.genderize.io/?"+r,{headers:{"Content-Type":"application/json"}});if(!n.ok)throw new Error(`Unable to query genderize.io: ${await n.text()}`);let a=await n.json();return this.latestHeaders=[n.headers,new Date],a}};export{o as GenderizeGender,s as default};
2
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/index.ts"],"sourcesContent":["/**\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 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}\nexport interface GenderizeResponse {\n /**\n * The number of data rows examined in order\n * to calculate the API response\n */\n count: number;\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 * Name which was used for this prediction\n */\n name: string;\n\n /**\n * Value between 0 and 1 (including)\n */\n probability: number;\n}\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 default class Genderize {\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 const limit = Genderize.getIntHeader(\n this.latestHeaders[0].get('x-rate-limit-limit'),\n );\n const remaining = Genderize.getIntHeader(\n this.latestHeaders[0].get('x-rate-limit-remaining'),\n );\n const reset = Genderize.getIntHeader(\n this.latestHeaders[0].get('x-rate-limit-reset'),\n );\n\n if (\n limit !== undefined &&\n remaining !== undefined &&\n reset !== undefined\n ) {\n return {\n limit,\n remaining,\n reset: new Date(\n this.latestHeaders[1].getTime() + reset * 1000,\n ),\n };\n }\n }\n\n return null;\n }\n private readonly apiKey;\n\n private latestHeaders: [Headers, 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(\n value: null | string | string[] | undefined,\n ): number | undefined {\n if (Array.isArray(value)) {\n return this.getIntHeader(value[0]);\n }\n\n if (value === undefined || value === null) {\n return undefined;\n }\n\n return parseInt(value);\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(\n `Too many names given: ${names.length} names provided, but 10 is the maximum allowed`,\n );\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().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 * 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 * 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(\n name: string,\n country: string,\n ): Promise<GenderizeResponseWithCountry>;\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(\n names: string[],\n country: string,\n ): Promise<GenderizeResponseWithCountry[]>;\n async predict(\n names: string | string[],\n country?: string,\n ): Promise<\n | GenderizeResponse\n | GenderizeResponse[]\n | GenderizeResponseWithCountry\n | GenderizeResponseWithCountry[]\n > {\n const queryString = new URLSearchParams(this.params(names, country));\n const response = await fetch(\n 'https://api.genderize.io/?' + queryString,\n {\n headers: {\n 'Content-Type': 'application/json',\n },\n },\n );\n if (!response.ok) {\n throw new Error(\n `Unable to query genderize.io: ${await response.text()}`,\n );\n }\n\n const body = (await response.json()) as\n | GenderizeResponse\n | GenderizeResponse[];\n this.latestHeaders = [response.headers, new Date()];\n return body;\n }\n}\n"],"mappings":"AAGO,IAAKA,OACRA,EAAA,OAAS,SACTA,EAAA,KAAO,OAFCA,OAAA,IA6DSC,EAArB,MAAqBC,CAAU,CAO3B,IAAI,OAA+B,CAC/B,GAAI,KAAK,cAAe,CACpB,IAAMC,EAAQD,EAAU,aACpB,KAAK,cAAc,CAAC,EAAE,IAAI,oBAAoB,CAClD,EACME,EAAYF,EAAU,aACxB,KAAK,cAAc,CAAC,EAAE,IAAI,wBAAwB,CACtD,EACMG,EAAQH,EAAU,aACpB,KAAK,cAAc,CAAC,EAAE,IAAI,oBAAoB,CAClD,EAEA,GACIC,IAAU,QACVC,IAAc,QACdC,IAAU,OAEV,MAAO,CACH,MAAAF,EACA,UAAAC,EACA,MAAO,IAAI,KACP,KAAK,cAAc,CAAC,EAAE,QAAQ,EAAIC,EAAQ,GAC9C,CACJ,CAER,CAEA,OAAO,IACX,CACiB,OAET,cAAwC,KAiBhD,YAAYC,EAAiB,CACzB,KAAK,OAASA,CAClB,CAKA,OAAO,aACHC,EACkB,CAClB,GAAI,MAAM,QAAQA,CAAK,EACnB,OAAO,KAAK,aAAaA,EAAM,CAAC,CAAC,EAGrC,GAA2BA,GAAU,KAIrC,OAAO,SAASA,CAAK,CACzB,CAQA,OAAOC,EAA0BC,EAA0B,CACvD,IAAMC,EAAe,IAAI,gBACzB,GAAI,MAAM,QAAQF,CAAK,GAAKA,EAAM,OAAS,GACvC,MAAM,IAAI,MACN,yBAAyBA,EAAM,MAAM,gDACzC,EAEJ,GAAI,MAAM,QAAQA,CAAK,GAAKA,EAAM,SAAW,EACzC,MAAM,IAAI,MAAM,6CAA6C,EAgBjE,OAbI,MAAM,QAAQA,CAAK,EACnBA,EAAM,QAASG,GAASD,EAAa,OAAO,OAAQC,CAAI,CAAC,EAEzDD,EAAa,OAAO,OAAQF,CAAK,EAGjCC,GACAC,EAAa,OAAO,aAAcD,CAAO,EAGzC,KAAK,QACLC,EAAa,OAAO,SAAU,KAAK,MAAM,EAEzC,MAAM,QAAQF,CAAK,EACZE,EAAa,SAAS,EAAE,QAAQ,SAAU,SAAS,EAGvDA,EAAa,SAAS,CACjC,CAwGA,MAAM,QACFF,EACAC,EAMF,CACE,IAAMG,EAAc,IAAI,gBAAgB,KAAK,OAAOJ,EAAOC,CAAO,CAAC,EAC7DI,EAAW,MAAM,MACnB,6BAA+BD,EAC/B,CACI,QAAS,CACL,eAAgB,kBACpB,CACJ,CACJ,EACA,GAAI,CAACC,EAAS,GACV,MAAM,IAAI,MACN,iCAAiC,MAAMA,EAAS,KAAK,CAAC,EAC1D,EAGJ,IAAMC,EAAQ,MAAMD,EAAS,KAAK,EAGlC,YAAK,cAAgB,CAACA,EAAS,QAAS,IAAI,IAAM,EAC3CC,CACX,CACJ","names":["GenderizeGender","Genderize","_Genderize","limit","remaining","reset","apiKey","value","names","country","searchParams","name","queryString","response","body"]}