أولاً قم بتثبيت مكتبتنا باستخدام npm:
npm install gender-api.com-client --save
const { Client } = require('gender-api.com-client');
const client = new Client('your-api-key');
client.getByFirstName('Theresa').then(result => {
console.log(`${result.first_name} is ${result.gender} (Probability: ${result.probability}`);
}).catch(error => {
console.error('Error:', error);
});
client.getByFirstName('Andrea', { country: 'IT' }).then(result => {
console.log(`${result.first_name} in Italy is ${result.gender}`);
}).catch(error => {
console.error('Error:', error);
});
client.getByFullName('John Smith').then(result => {
console.log(`${result.first_name} ${result.last_name} is ${result.gender}`);
}).catch(error => {
console.error('Error:', error);
});
client.getByEmailAddress('marie.curie@example.com').then(result => {
console.log(`Email gender: ${result.gender}`);
}).catch(error => {
console.error('Error:', error);
});
const names = [
{ id: '1', first_name: 'Theresa', country: 'US' },
{ id: '2', first_name: 'John', country: 'US' }
];
client.getByFirstNameMultiple(names).then(results => {
results.forEach(r => {
console.log(`ID: ${r.input.id}, Gender: ${r.gender}`);
});
}).catch(error => {
console.error('Error:', error);
});
client.getStatistics().then(stats => {
console.log(`Credits Remaining: ${stats.remaining_credits}`);
}).catch(error => {
console.error('Error:', error);
});
شاهد وثائق العميل الكاملة هنا:
https://github.com/markus-perl/gender-api-client-npm