Skip to content

Commit

Permalink
refactor(locale)!: use snake case for all locale data (#2910)
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored May 25, 2024
1 parent b97984c commit 558b959
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 31 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,6 @@ module.exports = defineConfig({
'error',
{
case: 'snakeCase',
// TODO @ST-DDT 2023-10-21: rename the definitions in v9
ignore: [
/chemicalElement\.ts$/,
/directoryPaths\.ts$/,
/mimeTypes\.ts$/,
],
},
],
'unicorn/text-encoding-identifier-case': 'off',
Expand Down
22 changes: 22 additions & 0 deletions docs/guide/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,28 @@ Renamed deprecated locale aliases `cz`, `en_IND`, `ge` and removed `global`.
| `import { faker } from '@faker-js/faker/locale/ge'` | `import { faker } from '@faker-js/faker/locale/ka_GE'` |
| `import { faker } from '@faker-js/faker/locale/global'` | `import { faker } from '@faker-js/faker/locale/base'` |

### Renamed Locale Definitions

The following locale definitions have been renamed

| old | replacement |
| ------------------------------------------- | -------------------------------------------- |
| `faker.definitions.science.chemicalElement` | `faker.definitions.science.chemical_element` |
| `faker.definitions.system.directoryPaths` | `faker.definitions.system.directory_paths` |
| `faker.definitions.system.mimeTypes` | `faker.definitions.system.mime_types` |

With that now all our locale data use the following naming scheme:

```txt
faker.definitions.category_name.entry_name
```

Please keep in mind that property keys of complex objects remain in camel-case.

```txt
faker.definitions.science.chemical_element.atomicNumber
```

### Type Aliases

Removed deprecated type aliases
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/science.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export type ScienceDefinition = LocaleEntry<{
/**
* Some periodic table element information.
*/
chemicalElement: ReadonlyArray<ChemicalElement>;
chemical_element: ReadonlyArray<ChemicalElement>;
}>;
4 changes: 2 additions & 2 deletions src/definitions/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export type SystemDefinition = LocaleEntry<{
/**
* Returns some common file paths.
*/
directoryPaths: string[];
directory_paths: string[];

/**
* The mime type definitions with some additional information.
*/
mimeTypes: { [mimeType: string]: SystemMimeTypeEntryDefinition };
mime_types: { [mimeType: string]: SystemMimeTypeEntryDefinition };
}>;

/**
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/locales/base/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { SystemDefinition } from '../../..';
import directoryPaths from './directoryPaths';
import mimeTypes from './mimeTypes';
import directory_paths from './directory_paths';
import mime_types from './mime_types';

const system: SystemDefinition = {
directoryPaths,
mimeTypes,
directory_paths,
mime_types,
};

export default system;
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/locales/en/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { ScienceDefinition } from '../../..';
import chemicalElement from './chemicalElement';
import chemical_element from './chemical_element';
import unit from './unit';

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

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/locales/eo/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { ScienceDefinition } from '../../..';
import chemicalElement from './chemicalElement';
import chemical_element from './chemical_element';
import unit from './unit';

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

Expand Down
4 changes: 2 additions & 2 deletions src/locales/nb_NO/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { ScienceDefinition } from '../../..';
import chemicalElement from './chemicalElement';
import chemical_element from './chemical_element';
import unit from './unit';

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

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions src/locales/pl/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { ScienceDefinition } from '../../..';
import chemicalElement from './chemicalElement';
import chemical_element from './chemical_element';
import unit from './unit';

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

Expand Down
4 changes: 2 additions & 2 deletions src/locales/zh_CN/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Run 'pnpm run generate:locales' to update.
*/
import type { ScienceDefinition } from '../../..';
import chemicalElement from './chemicalElement';
import chemical_element from './chemical_element';
import unit from './unit';

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

Expand Down
2 changes: 1 addition & 1 deletion src/modules/science/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class ScienceModule extends ModuleBase {
*/
chemicalElement(): ChemicalElement {
return this.faker.helpers.arrayElement(
this.faker.definitions.science.chemicalElement
this.faker.definitions.science.chemical_element
);
}

Expand Down
8 changes: 4 additions & 4 deletions src/modules/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class SystemModule extends ModuleBase {
* @since 3.1.0
*/
mimeType(): string {
const mimeTypeKeys = Object.keys(this.faker.definitions.system.mimeTypes);
const mimeTypeKeys = Object.keys(this.faker.definitions.system.mime_types);

return this.faker.helpers.arrayElement(mimeTypeKeys);
}
Expand Down Expand Up @@ -152,7 +152,7 @@ export class SystemModule extends ModuleBase {
* @since 3.1.0
*/
fileType(): string {
const mimeTypes = this.faker.definitions.system.mimeTypes;
const mimeTypes = this.faker.definitions.system.mime_types;

const typeSet = new Set(
Object.keys(mimeTypes).map((key) => key.split('/')[0])
Expand All @@ -172,7 +172,7 @@ export class SystemModule extends ModuleBase {
* @since 3.1.0
*/
fileExt(mimeType?: string): string {
const mimeTypes = this.faker.definitions.system.mimeTypes;
const mimeTypes = this.faker.definitions.system.mime_types;

if (typeof mimeType === 'string') {
return this.faker.helpers.arrayElement(mimeTypes[mimeType].extensions);
Expand All @@ -193,7 +193,7 @@ export class SystemModule extends ModuleBase {
* @since 3.1.0
*/
directoryPath(): string {
const paths = this.faker.definitions.system.directoryPaths;
const paths = this.faker.definitions.system.directory_paths;
return this.faker.helpers.arrayElement(paths);
}

Expand Down
6 changes: 3 additions & 3 deletions test/modules/science.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('science', () => {

expect(name).toBeTypeOf('string');
expect(() => {
faker.definitions.science.chemicalElement.find(
faker.definitions.science.chemical_element.find(
(element) => element.name === name
);
}).toBeTruthy();
Expand All @@ -39,7 +39,7 @@ describe('science', () => {

expect(symbol).toBeTypeOf('string');
expect(() => {
faker.definitions.science.chemicalElement.find(
faker.definitions.science.chemical_element.find(
(element) => element.symbol === symbol
);
}).toBeTruthy();
Expand All @@ -50,7 +50,7 @@ describe('science', () => {

expect(atomicNumber).toBeTypeOf('number');
expect(() => {
faker.definitions.science.chemicalElement.find(
faker.definitions.science.chemical_element.find(
(element) => element.atomicNumber === atomicNumber
);
}).toBeTruthy();
Expand Down

0 comments on commit 558b959

Please sign in to comment.