Skip to content

Commit

Permalink
feat: return dictionary from element()
Browse files Browse the repository at this point in the history
  • Loading branch information
import-brain committed May 29, 2022
1 parent db2f011 commit 727776a
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/modules/science/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { Faker } from '../..';

export type Element = {
name: string;
symbol: string;
};

/**
* Module to generate science related entries.
*/
Expand All @@ -15,27 +20,17 @@ export class Science {
}

/**
* Returns a random element name.
*
* @example
* faker.science.elementName() // 'Praseodymium'
*/
elementName(): string {
return this.faker.helpers.arrayElement(
this.faker.definitions.science.chemicalElement
).name;
}

/**
* Returns a random element symbol.
* Returns a random element.
*
* @example
* faker.science.elementSymbol() // 'Rg'
* faker.science.element() // { name: 'Hydrogen', symbol: 'H' }
*/
elementSymbol(): string {
return this.faker.helpers.arrayElement(
this.faker.definitions.science.chemicalElement
).symbol;
element(): Element {
const index = this.faker.datatype.number({ min: 0, max: 117 });
return {
name: this.faker.definitions.science.chemicalElement[index].name,
symbol: this.faker.definitions.science.chemicalElement[index].symbol,
};
}

/**
Expand Down

0 comments on commit 727776a

Please sign in to comment.