Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/definitions/science.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ChemicalElement, Unit } from '../modules/science';
import type { ChemicalElement, Notation, Unit } from '../modules/science';
import type { LocaleEntry } from './definitions';

/**
Expand All @@ -14,4 +14,9 @@ export type ScienceDefinition = LocaleEntry<{
* Some periodic table element information.
*/
chemicalElement: ReadonlyArray<ChemicalElement>;

/**
* Some science notations
*/
notation: ReadonlyArray<Notation>;
}>;
2 changes: 2 additions & 0 deletions src/locales/en/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
*/
import type { ScienceDefinition } from '../../..';
import chemicalElement from './chemicalElement';
import notation from './notation';
import unit from './unit';

const science: ScienceDefinition = {
chemicalElement,
notation,
unit,
};

Expand Down
50 changes: 50 additions & 0 deletions src/locales/en/science/notation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export default Object.freeze([
{
symbol: 'W',
name: 'work',
},
{
symbol: 'F',
name: 'force',
},
{
name: 'gravity',
symbol: 'G',
},
{
name: 'friction force',
symbol: 'f',
},
{
name: 'pressure',
symbol: 'P',
},
{
name: 'power',
symbol: 'P',
},
{
name: 'heat capacity',
symbol: 'c',
},
{
name: 'square',
symbol: 'S',
},
{
name: 'time',
symbol: 't',
},
{
name: 'velocity',
symbol: 'v',
},
{
name: 'volume',
symbol: 'V',
},
{
name: 'mass',
symbol: 'm',
},
]);
26 changes: 26 additions & 0 deletions src/modules/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export interface Unit {
symbol: string;
}

export interface Notation {
/**
* The long version of the notations (e.g. `work`).
*/
name: string;
/**
* The short version/abbreviation of the notations (e.g. `w`)
*/
symbol: string;
}
/**
* Module to generate science related entries.
*
Expand Down Expand Up @@ -66,4 +76,20 @@ export class ScienceModule extends ModuleBase {
unit(): Unit {
return this.faker.helpers.arrayElement(this.faker.definitions.science.unit);
}

/**
* Retunrs a ransom scientific notation.
*
* @example
* faker.science.notation() // { name: 'work', symbol: 'w' }
* faker.science.notation() // { name: 'force', symbol: 'F' }
* faker.science.notation() // { name: 'work', symbol: 'W'}
*
* @since 8.2.0
*/
notation(): Notation {
return this.faker.helpers.arrayElement(
this.faker.definitions.science.notation
);
}
}
21 changes: 21 additions & 0 deletions test/modules/__snapshots__/science.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ exports[`science > 42 > chemicalElement 1`] = `
}
`;

exports[`science > 42 > notation 1`] = `
{
"name": "pressure",
"symbol": "P",
}
`;

exports[`science > 42 > unit 1`] = `
{
"name": "pascal",
Expand All @@ -23,6 +30,13 @@ exports[`science > 1211 > chemicalElement 1`] = `
}
`;

exports[`science > 1211 > notation 1`] = `
{
"name": "mass",
"symbol": "m",
}
`;

exports[`science > 1211 > unit 1`] = `
{
"name": "henry",
Expand All @@ -38,6 +52,13 @@ exports[`science > 1337 > chemicalElement 1`] = `
}
`;

exports[`science > 1337 > notation 1`] = `
{
"name": "friction force",
"symbol": "f",
}
`;

exports[`science > 1337 > unit 1`] = `
{
"name": "radian",
Expand Down
2 changes: 1 addition & 1 deletion test/modules/science.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const NON_SEEDED_BASED_RUN = 5;

describe('science', () => {
seededTests(faker, 'science', (t) => {
t.itEach('chemicalElement', 'unit');
t.itEach('chemicalElement', 'unit', 'notation');
});

// Create and log-back the seed for debug purposes
Expand Down